Java Code Examples for org.drools.core.process.instance.impl.WorkItemImpl#setName()

The following examples show how to use org.drools.core.process.instance.impl.WorkItemImpl#setName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtobufProcessMarshaller.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public static WorkItem readWorkItem(MarshallerReaderContext context,
                                    JBPMMessages.WorkItem _workItem,
                                    boolean includeVariables) throws IOException {
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId( _workItem.getId() );
    workItem.setProcessInstanceId( _workItem.getProcessInstancesId() );
    workItem.setName( _workItem.getName() );
    workItem.setState( _workItem.getState() );
    workItem.setDeploymentId(_workItem.getDeploymentId());
    workItem.setNodeId(_workItem.getNodeId());
    workItem.setNodeInstanceId(_workItem.getNodeInstanceId());

    if ( includeVariables ) {
        for ( JBPMMessages.Variable _variable : _workItem.getVariableList() ) {
            try {
                Object value = unmarshallVariableValue( context, _variable );
                workItem.setParameter( _variable.getName(),
                                       value );
            } catch ( ClassNotFoundException e ) {
                throw new IllegalArgumentException( "Could not reload parameter " + _variable.getName() + " for work item " + _workItem );
            }
        }
    }

    return workItem;
}
 
Example 2
Source File: HandleMessageAction.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
public void execute(ProcessContext context) throws Exception {
    Object variable = VariableUtil.resolveVariable(variableName, context.getNodeInstance());

    if (transformation != null) {
        variable = new EventTransformerImpl(transformation).transformEvent(variable);
    }

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setName("Send Task");
    workItem.setNodeInstanceId(context.getNodeInstance().getId());
    workItem.setProcessInstanceId(context.getProcessInstance().getId());
    workItem.setNodeId(context.getNodeInstance().getNodeId());
    workItem.setParameter("MessageType", messageType);
    if (variable != null) {
        workItem.setParameter("Message", variable);
    }

    ((WorkItemManager) context.getKieRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
}
 
Example 3
Source File: AbstractProtobufProcessInstanceMarshaller.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public static WorkItem readWorkItem(MarshallerReaderContext context,
                                    JBPMMessages.WorkItem _workItem) throws IOException {
    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId( _workItem.getId() );
    workItem.setProcessInstanceId( _workItem.getProcessInstancesId() );
    workItem.setName( _workItem.getName() );
    workItem.setState( _workItem.getState() );
    workItem.setDeploymentId(_workItem.getDeploymentId());
    workItem.setNodeId(_workItem.getNodeId());
    workItem.setNodeInstanceId(_workItem.getNodeInstanceId());
    workItem.setPhaseId(_workItem.getPhaseId());
    workItem.setPhaseStatus(_workItem.getPhaseStatus());
    workItem.setStartDate(new Date(_workItem.getStartDate()));
    if (_workItem.getCompleteDate() > 0) {
        workItem.setCompleteDate(new Date(_workItem.getCompleteDate()));
    }
    
    for ( JBPMMessages.Variable _variable : _workItem.getVariableList() ) {
        try {
            Object value = ProtobufProcessMarshaller.unmarshallVariableValue( context, _variable );
            workItem.setParameter( _variable.getName(),
                                   value );
        } catch ( ClassNotFoundException e ) {
            throw new IllegalArgumentException(e);
        }
    }
    
    return workItem;
}
 
Example 4
Source File: SignalProcessInstanceAction.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public void execute(ProcessContext context) throws Exception {
    String variableName = VariableUtil.resolveVariable(this.variableName, context.getNodeInstance());
    Object variable = variableName == null ? eventDataSupplier.apply(context) : context.getVariable(variableName);

    if (transformation != null) {
        variable = new org.jbpm.process.core.event.EventTransformerImpl(transformation).transformEvent(context.getProcessInstance().getVariables());
    }
    if (DEFAULT_SCOPE.equals(scope)) {
        context.getKieRuntime().signalEvent(VariableUtil.resolveVariable(signalName, context.getNodeInstance()), variable);
    } else if (PROCESS_INSTANCE_SCOPE.equals(scope)) {
        context.getProcessInstance().signalEvent(VariableUtil.resolveVariable(signalName, context.getNodeInstance()), variable);
    } else if (EXTERNAL_SCOPE.equals(scope)) {
        WorkItemImpl workItem = new WorkItemImpl();
        workItem.setName("External Send Task");
        workItem.setNodeInstanceId(context.getNodeInstance().getId());
        workItem.setProcessInstanceId(context.getProcessInstance().getId());
        workItem.setNodeId(context.getNodeInstance().getNodeId());
        workItem.setParameter("Signal", VariableUtil.resolveVariable(signalName, context.getNodeInstance()));
        workItem.setParameter("SignalProcessInstanceId", context.getVariable("SignalProcessInstanceId"));
        workItem.setParameter("SignalWorkItemId", context.getVariable("SignalWorkItemId"));
        workItem.setParameter("SignalDeploymentId", context.getVariable("SignalDeploymentId"));
        if (variable == null) {
            workItem.setParameter("Data", variable);
        }
        ((org.drools.core.process.instance.WorkItemManager) context.getKieRuntime().getWorkItemManager()).internalExecuteWorkItem(workItem);
    }
}
 
Example 5
Source File: InputMarshaller.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
public static WorkItem readWorkItem( MarshallerReaderContext context ) throws IOException {
    ObjectInputStream stream = context.stream;

    WorkItemImpl workItem = new WorkItemImpl();
    workItem.setId( stream.readUTF() );
    workItem.setProcessInstanceId( stream.readUTF() );
    workItem.setName( stream.readUTF() );
    workItem.setState( stream.readInt() );

    //WorkItem Paramaters
    int nbVariables = stream.readInt();
    if (nbVariables > 0) {

        for (int i = 0; i < nbVariables; i++) {
            String name = stream.readUTF();
            try {
                int index = stream.readInt();
                ObjectMarshallingStrategy strategy = null;
                // Old way of retrieving strategy objects
                if (index >= 0) {
                    strategy = context.resolverStrategyFactory.getStrategy( index );
                    if (strategy == null) {
                        throw new IllegalStateException( "No strategy of with index " + index + " available." );
                    }
                }
                // New way 
                else if (index == -2) {
                    String strategyClassName = stream.readUTF();
                    // fix for backwards compatibility (5.x -> 6.x)
                    if ("org.drools.marshalling.impl.SerializablePlaceholderResolverStrategy".equals(strategyClassName)) {
                        strategyClassName = "org.drools.core.marshalling.impl.SerializablePlaceholderResolverStrategy";
                    }
                    strategy = context.resolverStrategyFactory.getStrategyObject( strategyClassName );
                    if (strategy == null) {
                        throw new IllegalStateException( "No strategy of type " + strategyClassName + " available." );
                    }
                } else {
                    throw new IllegalStateException( "Wrong index of strategy field read: " + index + "!");
                }

                Object value = strategy.read( stream );
                workItem.setParameter( name,
                                       value );
            } catch (ClassNotFoundException e) {
                throw new IllegalArgumentException(
                                                    "Could not reload variable " + name );
            }
        }
    }

    return workItem;
}