Search in sources :

Example 1 with ObjectMarshallingStrategy

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method marshallVariablesContainer.

public static VariableContainer marshallVariablesContainer(MarshallerWriteContext context, Map<String, Object> variables) throws IOException {
    AutomatikoMessages.VariableContainer.Builder vcbuilder = AutomatikoMessages.VariableContainer.newBuilder();
    for (String key : variables.keySet()) {
        AutomatikoMessages.Variable.Builder builder = AutomatikoMessages.Variable.newBuilder().setName(key);
        if (variables.get(key) != null) {
            ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(variables.get(key));
            Integer index = context.getStrategyIndex(strategy);
            builder.setStrategyIndex(index).setValue(ByteString.copyFrom(strategy.marshal(context.strategyContext.get(strategy), context, variables.get(key))));
        }
        vcbuilder.addVariable(builder.build());
    }
    return vcbuilder.build();
}
Also used : Variable(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable) VariableContainer(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.VariableContainer) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) ByteString(com.google.protobuf.ByteString)

Example 2 with ObjectMarshallingStrategy

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.

the class PersisterHelper method writeStrategiesIndex.

public static void writeStrategiesIndex(MarshallerWriteContext context, AutomatikoMessages.Header.Builder _header) throws IOException {
    for (Entry<ObjectMarshallingStrategy, Integer> entry : context.usedStrategies.entrySet()) {
        Builder _strat = AutomatikoMessages.Header.StrategyIndex.newBuilder().setId(entry.getValue().intValue()).setName(entry.getKey().getName());
        Context ctx = context.strategyContext.get(entry.getKey());
        if (ctx != null) {
            Output os = ByteString.newOutput();
            ctx.write(new ObjectOutputStream(os));
            _strat.setData(os.toByteString());
            os.close();
        }
        _header.addStrategy(_strat.build());
    }
}
Also used : Context(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context) ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy) Builder(io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header.StrategyIndex.Builder) Output(com.google.protobuf.ByteString.Output) ObjectOutputStream(java.io.ObjectOutputStream)

Example 3 with ObjectMarshallingStrategy

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy 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 4 with ObjectMarshallingStrategy

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy 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)

Example 5 with ObjectMarshallingStrategy

use of io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy in project automatiko-engine by automatiko-io.

the class ProtobufProcessMarshaller method unmarshallVariableValue.

public static Object unmarshallVariableValue(MarshallerReaderContext context, AutomatikoMessages.Variable _variable) throws IOException, ClassNotFoundException {
    if (_variable.getValue() == null || _variable.getValue().isEmpty()) {
        return null;
    }
    ObjectMarshallingStrategy strategy = context.usedStrategies.get(_variable.getStrategyIndex());
    Object value = strategy.unmarshal(_variable.getDataType(), context.strategyContexts.get(strategy), context, _variable.getValue().toByteArray(), null);
    return value;
}
Also used : ObjectMarshallingStrategy(io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy)

Aggregations

ObjectMarshallingStrategy (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy)6 Variable (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Variable)3 ByteString (com.google.protobuf.ByteString)2 Context (io.automatiko.engine.api.marshalling.ObjectMarshallingStrategy.Context)2 Output (com.google.protobuf.ByteString.Output)1 ByteArrayFile (io.automatiko.engine.workflow.file.ByteArrayFile)1 Builder (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.Header.StrategyIndex.Builder)1 VariableContainer (io.automatiko.engine.workflow.marshalling.impl.AutomatikoMessages.VariableContainer)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1