
no.mnemonic.services.triggers.service.delegates.TriggerRuleSearchDelegate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of triggers-service Show documentation
Show all versions of triggers-service Show documentation
Implementation of the service logic
The newest version!
package no.mnemonic.services.triggers.service.delegates;
import no.mnemonic.commons.utilities.ObjectUtils;
import no.mnemonic.commons.utilities.collections.CollectionUtils;
import no.mnemonic.commons.utilities.collections.SetUtils;
import no.mnemonic.services.triggers.api.exceptions.InvalidArgumentException;
import no.mnemonic.services.triggers.api.model.v1.TriggerRule;
import no.mnemonic.services.triggers.api.request.v1.TriggerRuleSearchRequest;
import no.mnemonic.services.triggers.service.dao.TriggerRuleEntity;
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
public class TriggerRuleSearchDelegate {
private final Supplier> entitiesSupplier;
private final Function entityConverter;
private TriggerRuleSearchDelegate(Supplier> entitiesSupplier,
Function entityConverter) {
this.entitiesSupplier = ObjectUtils.notNull(entitiesSupplier, "Cannot instantiate TriggerRuleSearchDelegate without 'entitiesSupplier'.");
this.entityConverter = ObjectUtils.notNull(entityConverter, "Cannot instantiate TriggerRuleSearchDelegate without 'entityConverter'.");
}
public Iterable handle(TriggerRuleSearchRequest request) throws InvalidArgumentException {
if (request == null) throw new InvalidArgumentException("Request object is required.");
return entitiesSupplier.get().stream()
.filter(rule -> CollectionUtils.isEmpty(request.getService()) || request.getService().contains(rule.getService()))
.filter(rule -> CollectionUtils.isEmpty(request.getEvent()) || SetUtils.intersects(request.getEvent(), rule.getEvents()))
.map(entityConverter)
.collect(Collectors.toList());
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private Supplier> entitiesSupplier;
private Function entityConverter;
private Builder() {
}
public TriggerRuleSearchDelegate build() {
return new TriggerRuleSearchDelegate(entitiesSupplier, entityConverter);
}
public Builder setEntitiesSupplier(Supplier> entitiesSupplier) {
this.entitiesSupplier = entitiesSupplier;
return this;
}
public Builder setEntityConverter(Function entityConverter) {
this.entityConverter = entityConverter;
return this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy