net.sf.aguacate.function.spi.impl.FunctionConnectorCall Maven / Gradle / Ivy
package net.sf.aguacate.function.spi.impl;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.sf.aguacate.connector.ConnectorCoupling;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.spi.AbstractFunction;
import net.sf.aguacate.util.parameter.Parameter;
import net.sf.aguacate.util.parameter.Prm;
import net.sf.aguacate.util.type.Str;
public class FunctionConnectorCall extends AbstractFunction {
private static final Logger LOGGER = LogManager.getLogger(FunctionConnectorCall.class);
private final String connectorName;
private final Parameter[] parameters;
private final String[] outputContext;
private final String outputName;
public FunctionConnectorCall(Collection methods, String name, String connectorName,
Collection parameters, List outputContext, String outputName) {
super(methods, name);
this.connectorName = connectorName;
this.parameters = Prm.toArray(parameters);
this.outputContext = Str.toArray(outputContext);
this.outputName = outputName;
}
@Override
public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
Map prms = new LinkedHashMap<>();
for (Parameter parameter : parameters) {
String name = parameter.getName();
LOGGER.trace(name);
Map ctx = parameter.calculateContext(context);
if (ctx.containsKey(name)) {
prms.put(parameter.getAliasOf(), ctx.get(name));
}
}
return new FunctionEvalResult(true, ConnectorCoupling.execute(connectorName, prms));
}
@Override
public String getOutputName() {
return outputName;
}
@Override
public String[] getOutputContext() {
return outputContext;
}
}