Search in sources :

Example 1 with Variable

use of io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method marshallVariablesMap.

public static Variable marshallVariablesMap(MarshallerWriteContext context, Map<String, Object> variables, boolean extractFiles) throws IOException {
    Map<String, Variable> marshalledVariables = new HashMap<String, Variable>();
    for (String key : variables.keySet()) {
        AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(key);
        Object variable = variables.get(key);
        if (variable != null) {
            ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(variable);
            Integer index = context.getStrategyIndex(strategy);
            builder.setStrategyIndex(index).setDataType(strategy.getType(variable.getClass())).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, variable)));
        }
        marshalledVariables.put(key, builder.build());
    }
    return marshallVariable(context, "variablesMap", marshalledVariables, extractFiles);
}
Also used : Variable(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable) HashMap(java.util.HashMap) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) ByteString(com.google.protobuf.ByteString)

Example 2 with Variable

use of io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method marshallVariable.

public static Variable marshallVariable(MarshallerWriteContext context, String name, Object value, boolean extractFiles) throws IOException {
    AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(name);
    if (value != null) {
        if (extractFiles && (boolean) context.env.getOrDefault("_export_", false)) {
            if (value instanceof ByteArrayFile) {
                ByteArrayFile file = ((ByteArrayFile) value);
                value = new ByteArrayFile(file.name(), file.content(), file.attributes());
            }
        }
        ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(value);
        Integer index = context.getStrategyIndex(strategy);
        builder.setStrategyIndex(index).setDataType(strategy.getType(value.getClass())).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, value)));
    }
    return builder.build();
}
Also used : Variable(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Aggregations

ObjectMarshallingStrategy (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy)2 Variable (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable)2 ByteString (com.google.protobuf.ByteString)1 ByteArrayFile (io.automatiko.engine.workflow.file.ByteArrayFile)1 HashMap (java.util.HashMap)1