Class AutomationConfigServiceImpl
java.lang.Object
com.codebarrel.automation.api.service.AutomationConfigServiceImpl
- All Implemented Interfaces:
AutomationConfigService,RuleChangePublisher
-
Field Summary
Fields inherited from interface com.codebarrel.automation.api.service.AutomationConfigService
RULE_DISABLED_MSG -
Constructor Summary
ConstructorsConstructorDescriptionAutomationConfigServiceImpl(UserService userService, I18nFactory i18nFactory, RuleComponentsValidator ruleComponentsValidator, RuleComponentProvider componentProvider, AutomationConfigStore store, RuleScheduleService ruleScheduleService, AutomationLicenseService licenseService, FeedbackStore feedbackStore, AuditService auditService, RuleLabelService ruleLabelService, RuleUserResolver ruleUserResolver, AuditEventService auditEventService, RuleScopeService ruleScopeService, RuleAbortionService ruleAbortionService, AutomationObservabilityService observabilityService, AutomationPermissionService automationPermissionService, ApplicationRoleService applicationRoleService, FeatureManager featureFlagManager) -
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 request) 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 deletedErrorKey) 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 remoteUser, TenantContext context, List<com.codebarrel.automation.api.config.RuleConfigBean> rules) Performs actual import of automation rules.io.atlassian.fugue.Either<ErrorCollection, ExternalizedRuleReaderResult> parseRulesToImport(RemoteConnectUser remoteUser, TenantContext context, ExternalizedRuleReaderResult export) Attempts to parse and perform basic validation of the provided rule export.voidvoidremoveLabelFromRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Removes a label from a given rulevoidio.atlassian.fugue.Either<ErrorCollection, com.codebarrel.automation.api.config.RuleConfigBean> updateRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean request, boolean dryrun) Updates the rule with the provided configuration.
-
Constructor Details
-
AutomationConfigServiceImpl
@Inject public AutomationConfigServiceImpl(UserService userService, I18nFactory i18nFactory, RuleComponentsValidator ruleComponentsValidator, RuleComponentProvider componentProvider, AutomationConfigStore store, RuleScheduleService ruleScheduleService, AutomationLicenseService licenseService, FeedbackStore feedbackStore, AuditService auditService, RuleLabelService ruleLabelService, RuleUserResolver ruleUserResolver, AuditEventService auditEventService, RuleScopeService ruleScopeService, RuleAbortionService ruleAbortionService, AutomationObservabilityService observabilityService, AutomationPermissionService automationPermissionService, ApplicationRoleService applicationRoleService, FeatureManager featureFlagManager)
-
-
Method Details
-
getRuleForBranch
public Optional<com.codebarrel.automation.api.config.RuleConfigBean> getRuleForBranch(TenantContext context, AutomationEvent event) Description copied from interface:AutomationConfigServiceRetrieves the rule for a Branched rule- Specified by:
getRuleForBranchin interfaceAutomationConfigService- Parameters:
context- The tenant context to look up rules forevent- The automation event for the branch- Returns:
- a rule that represents the branch
-
getMatchingRules
public List<com.codebarrel.automation.api.config.RuleConfigBean> getMatchingRules(TenantContext context, Set<String> projectIds) Description copied from interface:AutomationConfigServiceRetrieves all enabled rules that apply to the provided event. This does NOT filter by the trigger.canHandle method- Specified by:
getMatchingRulesin interfaceAutomationConfigService- 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
-
getRules
public List<com.codebarrel.automation.api.config.RuleConfigBean> getRules(TenantContext context, String projectId) Description copied from interface:AutomationConfigServiceGet all rules for a given project.- Specified by:
getRulesin interfaceAutomationConfigService- 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
-
getRuleCount
Description copied from interface:AutomationConfigServiceReturns a count of all the rules for the tenant- Specified by:
getRuleCountin interfaceAutomationConfigService- Parameters:
context- The tenant context to look up rule count for- Returns:
- rule count
-
hasRulesInScope
Description copied from interface:AutomationConfigServiceWhether 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.- Specified by:
hasRulesInScopein interfaceAutomationConfigService- Parameters:
context- The tenant context to look up rule count forprojectId- The scope to retrieve rules for. Null = Global.
-
getEnabledRuleCount
Description copied from interface:AutomationConfigServiceCounts enabled rules on a tenant.- Specified by:
getEnabledRuleCountin interfaceAutomationConfigService- Parameters:
context- The tenant- Returns:
- count of enabled rules
-
disableAllRules
Description copied from interface:AutomationConfigServiceWill disable all rules on a particular tenant.- Specified by:
disableAllRulesin interfaceAutomationConfigService- Parameters:
tenant- The tenantdisabledAuditMessageKey- The i18n message that will be written to the audit log- Returns:
- the number of rules actually disabled
-
getRule
public Optional<com.codebarrel.automation.api.config.RuleConfigBean> getRule(TenantContext context, Long ruleId) Description copied from interface:AutomationConfigServiceRetrieve a rule by id- Specified by:
getRulein interfaceAutomationConfigService- 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
Description copied from interface:AutomationConfigServiceRetrieve rule names by rule ids- Specified by:
getRuleNamesin interfaceAutomationConfigService- Parameters:
ruleIds- The ids of rules to retrieve- Returns:
- Map of rule id to rule name
-
getScheduledTriggerConfig
public Optional<com.codebarrel.automation.api.config.ComponentConfigBean> getScheduledTriggerConfig(TenantContext context, Long ruleId) Description copied from interface:AutomationConfigServiceThis 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.- Specified by:
getScheduledTriggerConfigin interfaceAutomationConfigService- 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
public List<RuleCreationResult> bulkCreateRules(RemoteConnectUser remoteUser, TenantContext context, CreateReason reason, List<com.codebarrel.automation.api.config.RuleConfigBean> rulesToCreate) Description copied from interface:AutomationConfigServiceBulk creates a bunch of rules. Can be used for generating sample rules or imports- Specified by:
bulkCreateRulesin interfaceAutomationConfigService- 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
public io.atlassian.fugue.Either<ErrorCollection,com.codebarrel.automation.api.config.RuleConfigBean> createRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean request) Description copied from interface:AutomationConfigServiceCreates a new rule.- Specified by:
createRulein interfaceAutomationConfigService- Parameters:
remoteUser- The user making the requestcontext- The tenant context to look up rules forrequest- Data needed to create the new rule- Returns:
- The newly created rule or an error collection
-
updateRule
public io.atlassian.fugue.Either<ErrorCollection,com.codebarrel.automation.api.config.RuleConfigBean> updateRule(RemoteConnectUser remoteUser, TenantContext context, com.codebarrel.automation.api.config.RuleConfigBean request, boolean dryrun) Description copied from interface:AutomationConfigServiceUpdates the rule with the provided configuration.- Specified by:
updateRulein interfaceAutomationConfigService- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forrequest- 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
public void addLabelToRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Description copied from interface:AutomationConfigServiceAdds a rule label to the given rule- Specified by:
addLabelToRulein interfaceAutomationConfigService- 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
public void removeLabelFromRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId) Description copied from interface:AutomationConfigServiceRemoves a label from a given rule- Specified by:
removeLabelFromRulein interfaceAutomationConfigService- 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
Description copied from interface:AutomationConfigServiceThis is an 'internal' method to be called by the rule executor when an execution loop may have been detected.- Specified by:
disableRulein interfaceAutomationConfigService- 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
public void disableRuleAfterFailures(TenantContext context, Long ruleId, State failureState, int numConsecutiveFailures) Description copied from interface:AutomationConfigServiceWill 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.
- Specified by:
disableRuleAfterFailuresin interfaceAutomationConfigService
-
delete
Description copied from interface:AutomationConfigServiceDeletes the rule with the id provided.- Specified by:
deletein interfaceAutomationConfigService- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to delete
-
delete
public void delete(@Nullable RemoteConnectUser remoteUser, TenantContext context, Long ruleId, @Nullable String deletedErrorKey) Description copied from interface:AutomationConfigServiceDeletes the rule with the id provided.- Specified by:
deletein interfaceAutomationConfigService- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forruleId- The id of the rule to deletedeletedErrorKey- Reason key to display for the audit log message
-
deleteAssociatedRuleProjects
Description copied from interface:AutomationConfigServiceRemoves rules association with the given project id, also removes those rules if only one exists- Specified by:
deleteAssociatedRuleProjectsin interfaceAutomationConfigService- Parameters:
context- The project tenant context remove associated projectsprojectIds- List of project ids to delete
-
parseRulesToImport
public io.atlassian.fugue.Either<ErrorCollection,ExternalizedRuleReaderResult> parseRulesToImport(RemoteConnectUser remoteUser, TenantContext context, ExternalizedRuleReaderResult export) Description copied from interface:AutomationConfigServiceAttempts to parse and perform basic validation of the provided rule export.- Specified by:
parseRulesToImportin interfaceAutomationConfigService- Parameters:
remoteUser- 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
public void importRules(RemoteConnectUser remoteUser, TenantContext context, List<com.codebarrel.automation.api.config.RuleConfigBean> rules) Description copied from interface:AutomationConfigServicePerforms 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).- Specified by:
importRulesin interfaceAutomationConfigService- Parameters:
remoteUser- The user making the requestcontext- The project tenant context to look up rules forrules- The rules to import.
-
registerRuleChangedListener
- Specified by:
registerRuleChangedListenerin interfaceRuleChangePublisher
-
unregisterRuleChangedListener
- Specified by:
unregisterRuleChangedListenerin interfaceRuleChangePublisher
-