All Downloads are FREE. Search and download functionalities are using the official Maven repository.

no.mnemonic.services.triggers.api.model.v1.TriggerRule Maven / Gradle / Ivy

There is a newer version: 0.0.22
Show newest version
package no.mnemonic.services.triggers.api.model.v1;

import no.mnemonic.commons.utilities.ObjectUtils;
import no.mnemonic.commons.utilities.collections.MapUtils;
import no.mnemonic.commons.utilities.collections.SetUtils;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class TriggerRule {

  private final UUID id;
  private final String service;
  private final Set events;
  private final Set organizations;
  private final Set scopes;
  private final AccessMode accessMode;
  private final String expression;
  private final TriggerActionDefinition.Info triggerAction;
  private final Map triggerParameters;

  private TriggerRule(UUID id, String service, Set events, Set organizations, Set scopes,
                      AccessMode accessMode, String expression, TriggerActionDefinition.Info triggerAction,
                      Map triggerParameters) {
    this.id = id;
    this.service = service;
    this.events = ObjectUtils.ifNotNull(events, Collections::unmodifiableSet);
    this.organizations = ObjectUtils.ifNotNull(organizations, Collections::unmodifiableSet);
    this.scopes = ObjectUtils.ifNotNull(scopes, Collections::unmodifiableSet);
    this.accessMode = accessMode;
    this.expression = expression;
    this.triggerAction = triggerAction;
    this.triggerParameters = ObjectUtils.ifNotNull(triggerParameters, Collections::unmodifiableMap);
  }

  public UUID getId() {
    return id;
  }

  public String getService() {
    return service;
  }

  public Set getEvents() {
    return events;
  }

  public Set getOrganizations() {
    return organizations;
  }

  public Set getScopes() {
    return scopes;
  }

  public AccessMode getAccessMode() {
    return accessMode;
  }

  public String getExpression() {
    return expression;
  }

  public TriggerActionDefinition.Info getTriggerAction() {
    return triggerAction;
  }

  public Map getTriggerParameters() {
    return triggerParameters;
  }

  public static Builder builder() {
    return new Builder();
  }

  public static class Builder {
    private UUID id;
    private String service;
    private Set events;
    private Set organizations;
    private Set scopes;
    private AccessMode accessMode;
    private String expression;
    private TriggerActionDefinition.Info triggerAction;
    private Map triggerParameters;

    private Builder() {
    }

    public TriggerRule build() {
      return new TriggerRule(id, service, events, organizations, scopes, accessMode, expression, triggerAction, triggerParameters);
    }

    public Builder setId(UUID id) {
      this.id = id;
      return this;
    }

    public Builder setService(String service) {
      this.service = service;
      return this;
    }

    public Builder setEvents(Set events) {
      this.events = events;
      return this;
    }

    public Builder addEvent(String event) {
      this.events = SetUtils.addToSet(this.events, event);
      return this;
    }

    public Builder setOrganizations(Set organizations) {
      this.organizations = organizations;
      return this;
    }

    public Builder addOrganization(OrganizationInfo organization) {
      this.organizations = SetUtils.addToSet(this.organizations, organization);
      return this;
    }

    public Builder setScopes(Set scopes) {
      this.scopes = scopes;
      return this;
    }

    public Builder addScope(String scope) {
      this.scopes = SetUtils.addToSet(this.scopes, scope);
      return this;
    }

    public Builder setAccessMode(AccessMode accessMode) {
      this.accessMode = accessMode;
      return this;
    }

    public Builder setExpression(String expression) {
      this.expression = expression;
      return this;
    }

    public Builder setTriggerAction(TriggerActionDefinition.Info triggerAction) {
      this.triggerAction = triggerAction;
      return this;
    }

    public Builder setTriggerParameters(Map triggerParameters) {
      this.triggerParameters = triggerParameters;
      return this;
    }

    public Builder addTriggerParameter(String parameterName, String parameterValue) {
      this.triggerParameters = MapUtils.addToMap(this.triggerParameters, parameterName, parameterValue);
      return this;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy