com.netgrif.application.engine.workflow.service.InitValueExpressionEvaluator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of application-engine Show documentation
Show all versions of application-engine Show documentation
System provides workflow management functions including user, role and data management.
package com.netgrif.application.engine.workflow.service;
import com.netgrif.application.engine.petrinet.domain.I18nString;
import com.netgrif.application.engine.petrinet.domain.dataset.ChoiceField;
import com.netgrif.application.engine.petrinet.domain.dataset.Field;
import com.netgrif.application.engine.petrinet.domain.dataset.MapOptionsField;
import com.netgrif.application.engine.petrinet.domain.dataset.logic.action.runner.CaseFieldsExpressionRunner;
import com.netgrif.application.engine.petrinet.domain.dataset.logic.action.runner.Expression;
import com.netgrif.application.engine.workflow.domain.Case;
import com.netgrif.application.engine.workflow.service.interfaces.IInitValueExpressionEvaluator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class InitValueExpressionEvaluator implements IInitValueExpressionEvaluator {
@Autowired
private CaseFieldsExpressionRunner runner;
@Override
public T evaluate(Case useCase, Field defaultField) {
return (T) evaluate(useCase, defaultField.getInitExpression());
}
@Override
public Map evaluateOptions(Case useCase, MapOptionsField field) {
Object result = evaluate(useCase, field.getExpression());
if (!(result instanceof Map)) {
throw new IllegalArgumentException("[" + useCase.getStringId() + "] Dynamic options not an instance of Map: " + field.getImportId());
}
Map map = (Map) result;
if (map.values().stream().anyMatch(it -> !(it instanceof I18nString))) {
return map.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, it -> new I18nString(it.getValue().toString()), (o1, o2) -> o1, LinkedHashMap::new));
} else {
return (Map) result;
}
}
@Override
public Set evaluateChoices(Case useCase, ChoiceField> field) {
Object result = evaluate(useCase, field.getExpression());
if (!(result instanceof Collection)) {
throw new IllegalArgumentException("[" + useCase.getStringId() + "] Dynamic choices not an instance of Collection: " + field.getImportId());
}
Collection
© 2015 - 2025 Weber Informatics LLC | Privacy Policy