Interface AutomationConfigService
- All Superinterfaces:
RuleChangePublisher
- All Known Implementing Classes:
AutomationConfigServiceImpl
Service to handle CRUD operations for automation rules
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringGeneric i18n message to write to the audit log when a rule is disabled by the system. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLabelToRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Adds a rule label to the given rulebulkCreateRules(RemoteConnectUser remoteUser, TenantContext context, CreateReason reason, List<com.codebarrel.automation.api.config.RuleConfigBean> rulesToCreate) Bulk creates a bunch of rules.io.atlassian.fugue.Either<ErrorCollection, com.codebarrel.automation.api.config.RuleConfigBean> createRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean createRequest) Creates a new rule.voiddelete(RemoteConnectUser remoteUser, TenantContext context, Long ruleId) Deletes the rule with the id provided.voiddelete(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, String reasonMessageKey) Deletes the rule with the id provided.voiddeleteAssociatedRuleProjects(TenantContext context, String... projectIds) Removes rules association with the given project id, also removes those rules if only one existsintdisableAllRules(TenantContext tenant, String disabledAuditMessageKey) Will disable all rules on a particular tenant.voiddisableRule(TenantContext context, Long ruleId, String disabledAuditMessageKey) This is an 'internal' method to be called by the rule executor when an execution loop may have been detected.voiddisableRuleAfterFailures(TenantContext context, Long ruleId, State failureState, int numConsecutiveFailures) Will check the audit log for this rule to see if the most recent executions all had the specified failurestate.longgetEnabledRuleCount(TenantContext context) Counts enabled rules on a tenant.List<com.codebarrel.automation.api.config.RuleConfigBean> getMatchingRules(TenantContext context, Set<String> projectIds) Retrieves all enabled rules that apply to the provided event.Optional<com.codebarrel.automation.api.config.RuleConfigBean> getRule(TenantContext context, Long ruleId) Retrieve a rule by idlonggetRuleCount(TenantContext context) Returns a count of all the rules for the tenantOptional<com.codebarrel.automation.api.config.RuleConfigBean> getRuleForBranch(TenantContext context, AutomationEvent event) Retrieves the rule for a Branched rulegetRuleNames(List<Long> ruleIds) Retrieve rule names by rule idsList<com.codebarrel.automation.api.config.RuleConfigBean> getRules(TenantContext context, String projectId) Get all rules for a given project.Optional<com.codebarrel.automation.api.config.ComponentConfigBean> getScheduledTriggerConfig(TenantContext context, Long ruleId) This will attempt to retrieve the scheduled trigger config to be used by the RuleScheduleService.booleanhasRulesInScope(TenantContext context, Long projectId) Whether there are rules specifically in the given scope Returns false for projectId = 10000 when all rules are global -- the rules MUST be specific to the project.voidimportRules(RemoteConnectUser remoteConnectUser, TenantContext context, List<com.codebarrel.automation.api.config.RuleConfigBean> rules) Performs actual import of automation rules.io.atlassian.fugue.Either<ErrorCollection, ExternalizedRuleReaderResult> parseRulesToImport(RemoteConnectUser remoteConnectUser, TenantContext context, ExternalizedRuleReaderResult export) Attempts to parse and perform basic validation of the provided rule export.voidremoveLabelFromRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Removes a label from a given ruleio.atlassian.fugue.Either<ErrorCollection, com.codebarrel.automation.api.config.RuleConfigBean> updateRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean updateRequest, boolean dryrun) Updates the rule with the provided configuration.Methods inherited from interface com.codebarrel.automation.api.service.listener.RuleChangePublisher
registerRuleChangedListener, unregisterRuleChangedListener
-
Field Details
-
RULE_DISABLED_MSG
Generic i18n message to write to the audit log when a rule is disabled by the system.- See Also:
-
-
Method Details
-
getMatchingRules
List<com.codebarrel.automation.api.config.RuleConfigBean> getMatchingRules(TenantContext context, Set<String> projectIds) Retrieves all enabled rules that apply to the provided event. This does NOT filter by the trigger.canHandle method- Parameters:
context- The tenant context to look up rules forprojectIds- The project context to find matching rules for- Returns:
- a list of matching automation rules that can handle the provided event
-
getRuleForBranch
Optional<com.codebarrel.automation.api.config.RuleConfigBean> getRuleForBranch(TenantContext context, AutomationEvent event) Retrieves the rule for a Branched rule- Parameters:
context- The tenant context to look up rules forevent- The automation event for the branch- Returns:
- a rule that represents the branch
-
getRules
List<com.codebarrel.automation.api.config.RuleConfigBean> getRules(TenantContext context, String projectId) Get all rules for a given project.- Parameters:
context- The tenant context to look up rules forprojectId- The id for the project- Returns:
- List of automation rules in this project and tenant
-
getRule
Optional<com.codebarrel.automation.api.config.RuleConfigBean> getRule(TenantContext context, Long ruleId) Retrieve a rule by id- Parameters:
context- The tenant context to look up the rule inruleId- The id of the rule to retrieve- Returns:
- the automation rule or empty if none exists.
-
getRuleNames
Retrieve rule names by rule ids- Parameters:
ruleIds- The ids of rules to retrieve- Returns:
- Map of rule id to rule name
-
getScheduledTriggerConfig
Optional<com.codebarrel.automation.api.config.ComponentConfigBean> getScheduledTriggerConfig(TenantContext context, Long ruleId) This will attempt to retrieve the scheduled trigger config to be used by the RuleScheduleService. May return empty if the rule doesn't exist, or if the trigger isn't a scheduled trigger.- Parameters:
context- The tenant context to look up the rule inruleId- The id of the rule to retrieve- Returns:
- The schedule trigger config or empty
-
bulkCreateRules
List<RuleCreationResult> bulkCreateRules(RemoteConnectUser remoteUser, TenantContext context, CreateReason reason, List<com.codebarrel.automation.api.config.RuleConfigBean> rulesToCreate) Bulk creates a bunch of rules. Can be used for generating sample rules or imports- Parameters:
remoteUser- The user making the requestcontext- The tenant context to look up rules forrulesToCreate- The rules to create- Returns:
- A list of results.
-
createRule
io.atlassian.fugue.Either<ErrorCollection,com.codebarrel.automation.api.config.RuleConfigBean> createRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean createRequest) Creates a new rule.- Parameters:
remoteUser- The user making the requestcontext- The tenant context to look up rules forcreateRequest- Data needed to create the new rule- Returns:
- The newly created rule or an error collection
-
updateRule
io.atlassian.fugue.Either<ErrorCollection,com.codebarrel.automation.api.config.RuleConfigBean> updateRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean updateRequest, boolean dryrun) Updates the rule with the provided configuration.- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forupdateRequest- Data needed to update the ruledryrun- If true, only validate and do not save the rule- Returns:
- The updated rule or an error collection
-
addLabelToRule
Adds a rule label to the given rule- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to updatelabelId- The id of the label to add
-
removeLabelFromRule
void removeLabelFromRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Removes a label from a given rule- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to updatelabelId- The id of the label to remove
-
disableRule
This is an 'internal' method to be called by the rule executor when an execution loop may have been detected.- Parameters:
context- The tenant context to look up rules forruleId- The id of the rule to disabledisabledAuditMessageKey- An i18n message to write to the audit log with the reason for disabling the rule
-
disableRuleAfterFailures
void disableRuleAfterFailures(TenantContext context, Long ruleId, State failureState, int numConsecutiveFailures) Will check the audit log for this rule to see if the most recent executions all had the specified failurestate.If so, the rule will be disabled.
-
delete
Deletes the rule with the id provided.- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to delete
-
delete
void delete(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, String reasonMessageKey) Deletes the rule with the id provided.- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to deletereasonMessageKey- Reason key to display for the audit log message
-
deleteAssociatedRuleProjects
Removes rules association with the given project id, also removes those rules if only one exists- Parameters:
context- The project tenant context remove associated projectsprojectIds- List of project ids to delete
-
parseRulesToImport
io.atlassian.fugue.Either<ErrorCollection,ExternalizedRuleReaderResult> parseRulesToImport(RemoteConnectUser remoteConnectUser, TenantContext context, ExternalizedRuleReaderResult export) Attempts to parse and perform basic validation of the provided rule export.- Parameters:
remoteConnectUser- The user making the requestcontext- The project tenant context to look up rules forexport- Pre-processed rules that were read from file uploaded by client- Returns:
- Either an error collection or the parsed rules to import
-
importRules
void importRules(RemoteConnectUser remoteConnectUser, TenantContext context, List<com.codebarrel.automation.api.config.RuleConfigBean> rules) Performs actual import of automation rules. This is a dumb import in the sense that it will simply shove the rule configs into the DB and not perform much validation (other than checking for duplicate names).- Parameters:
remoteConnectUser- The user making the requestcontext- The project tenant context to look up rules forrules- The rules to import.
-
getRuleCount
Returns a count of all the rules for the tenant- Parameters:
context- The tenant context to look up rule count for- Returns:
- rule count
-
hasRulesInScope
Whether there are rules specifically in the given scope Returns false for projectId = 10000 when all rules are global -- the rules MUST be specific to the project.- Parameters:
context- The tenant context to look up rule count forprojectId- The scope to retrieve rules for. Null = Global.
-
getEnabledRuleCount
Counts enabled rules on a tenant.- Parameters:
context- The tenant- Returns:
- count of enabled rules
-
disableAllRules
Will disable all rules on a particular tenant.- Parameters:
tenant- The tenantdisabledAuditMessageKey- The i18n message that will be written to the audit log- Returns:
- the number of rules actually disabled
-