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

no.mnemonic.services.triggers.service.delegates.TriggerActionDefinitionSearchDelegate Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package no.mnemonic.services.triggers.service.delegates;

import no.mnemonic.commons.utilities.ObjectUtils;
import no.mnemonic.commons.utilities.collections.ListUtils;
import no.mnemonic.services.triggers.api.exceptions.InvalidArgumentException;
import no.mnemonic.services.triggers.api.model.v1.TriggerActionDefinition;
import no.mnemonic.services.triggers.api.request.v1.TriggerActionDefinitionSearchRequest;
import no.mnemonic.services.triggers.service.dao.TriggerActionDefinitionEntity;

import java.util.Collection;
import java.util.function.Function;
import java.util.function.Supplier;

public class TriggerActionDefinitionSearchDelegate {

  private final Supplier> entitiesSupplier;
  private final Function entityConverter;

  private TriggerActionDefinitionSearchDelegate(Supplier> entitiesSupplier,
                                                Function entityConverter) {
    this.entitiesSupplier = ObjectUtils.notNull(entitiesSupplier, "Cannot instantiate TriggerActionDefinitionSearchDelegate without 'entitiesSupplier'.");
    this.entityConverter = ObjectUtils.notNull(entityConverter, "Cannot instantiate TriggerActionDefinitionSearchDelegate without 'entityConverter'.");
  }

  public Iterable handle(TriggerActionDefinitionSearchRequest request) throws InvalidArgumentException {
    if (request == null) throw new InvalidArgumentException("Request object is required.");

    // No filter options have been defined yet, just return everything.
    return ListUtils.list(entitiesSupplier.get(), entityConverter);
  }

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

  public static class Builder {
    private Supplier> entitiesSupplier;
    private Function entityConverter;

    private Builder() {
    }

    public TriggerActionDefinitionSearchDelegate build() {
      return new TriggerActionDefinitionSearchDelegate(entitiesSupplier, entityConverter);
    }

    public Builder setEntitiesSupplier(Supplier> entitiesSupplier) {
      this.entitiesSupplier = entitiesSupplier;
      return this;
    }

    public Builder setEntityConverter(Function entityConverter) {
      this.entityConverter = entityConverter;
      return this;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy