Interface AutomationConfigService

All Superinterfaces:
RuleChangePublisher
All Known Implementing Classes:
AutomationConfigServiceImpl

public interface AutomationConfigService extends RuleChangePublisher
Service to handle CRUD operations for automation rules
  • Field Details

    • RULE_DISABLED_MSG

      static final String 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 for
      projectIds - 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 for
      event - 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 for
      projectId - 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 in
      ruleId - The id of the rule to retrieve
      Returns:
      the automation rule or empty if none exists.
    • getRuleNames

      Map<Long,String> getRuleNames(List<Long> ruleIds)
      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 in
      ruleId - 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 request
      context - The tenant context to look up rules for
      rulesToCreate - 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 request
      context - The tenant context to look up rules for
      createRequest - 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 request
      context - The project tenant context to look up rules for
      updateRequest - Data needed to update the rule
      dryrun - If true, only validate and do not save the rule
      Returns:
      The updated rule or an error collection
    • addLabelToRule

      void addLabelToRule(RemoteConnectUser remoteUser, TenantContext context, Long ruleId, Long labelId)
      Adds a rule label to the given rule
      Parameters:
      remoteUser - The user making the request
      context - The project tenant context to look up rules for
      ruleId - The id of the rule to update
      labelId - 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 request
      context - The project tenant context to look up rules for
      ruleId - The id of the rule to update
      labelId - The id of the label to remove
    • disableRule

      void disableRule(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.
      Parameters:
      context - The tenant context to look up rules for
      ruleId - The id of the rule to disable
      disabledAuditMessageKey - 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

      void delete(RemoteConnectUser remoteUser, TenantContext context, Long ruleId)
      Deletes the rule with the id provided.
      Parameters:
      remoteUser - The user making the request
      context - The project tenant context to look up rules for
      ruleId - 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 request
      context - The project tenant context to look up rules for
      ruleId - The id of the rule to delete
      reasonMessageKey - Reason key to display for the audit log message
    • deleteAssociatedRuleProjects

      void deleteAssociatedRuleProjects(TenantContext context, String... projectIds)
      Removes rules association with the given project id, also removes those rules if only one exists
      Parameters:
      context - The project tenant context remove associated projects
      projectIds - 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 request
      context - The project tenant context to look up rules for
      export - 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 request
      context - The project tenant context to look up rules for
      rules - The rules to import.
    • getRuleCount

      long getRuleCount(TenantContext context)
      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

      boolean hasRulesInScope(TenantContext context, @Nullable 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.
      Parameters:
      context - The tenant context to look up rule count for
      projectId - The scope to retrieve rules for. Null = Global.
    • getEnabledRuleCount

      long getEnabledRuleCount(TenantContext context)
      Counts enabled rules on a tenant.
      Parameters:
      context - The tenant
      Returns:
      count of enabled rules
    • disableAllRules

      int disableAllRules(TenantContext tenant, String disabledAuditMessageKey)
      Will disable all rules on a particular tenant.
      Parameters:
      tenant - The tenant
      disabledAuditMessageKey - The i18n message that will be written to the audit log
      Returns:
      the number of rules actually disabled