Search in sources :

Example 1 with DataObjectImpl

use of org.activiti.engine.impl.DataObjectImpl in project Activiti by Activiti.

the class GetDataObjectCmd method execute.

public DataObject execute(CommandContext commandContext) {
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("executionId is null");
    }
    if (dataObjectName == null) {
        throw new ActivitiIllegalArgumentException("dataObjectName is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }
    DataObject dataObject = null;
    VariableInstance variableEntity = null;
    if (isLocal) {
        variableEntity = execution.getVariableInstanceLocal(dataObjectName, false);
    } else {
        variableEntity = execution.getVariableInstance(dataObjectName, false);
    }
    String localizedName = null;
    String localizedDescription = null;
    if (variableEntity != null) {
        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(variableEntity.getExecutionId());
        while (!executionEntity.isScope()) {
            executionEntity = executionEntity.getParent();
        }
        BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(executionEntity.getProcessDefinitionId());
        ValuedDataObject foundDataObject = null;
        if (executionEntity.getParentId() == null) {
            for (ValuedDataObject dataObjectDefinition : bpmnModel.getMainProcess().getDataObjects()) {
                if (dataObjectDefinition.getName().equals(variableEntity.getName())) {
                    foundDataObject = dataObjectDefinition;
                    break;
                }
            }
        } else {
            SubProcess subProcess = (SubProcess) bpmnModel.getFlowElement(execution.getActivityId());
            for (ValuedDataObject dataObjectDefinition : subProcess.getDataObjects()) {
                if (dataObjectDefinition.getName().equals(variableEntity.getName())) {
                    foundDataObject = dataObjectDefinition;
                    break;
                }
            }
        }
        if (locale != null && foundDataObject != null) {
            ObjectNode languageNode = Context.getLocalizationElementProperties(locale, foundDataObject.getId(), execution.getProcessDefinitionId(), withLocalizationFallback);
            if (variableEntity != null && languageNode != null) {
                JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                if (nameNode != null) {
                    localizedName = nameNode.asText();
                }
                JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                if (descriptionNode != null) {
                    localizedDescription = descriptionNode.asText();
                }
            }
        }
        if (foundDataObject != null) {
            dataObject = new DataObjectImpl(variableEntity.getName(), variableEntity.getValue(), foundDataObject.getDocumentation(), foundDataObject.getType(), localizedName, localizedDescription, foundDataObject.getId());
        }
    }
    return dataObject;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) DataObjectImpl(org.activiti.engine.impl.DataObjectImpl) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) DataObject(org.activiti.engine.runtime.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 2 with DataObjectImpl

use of org.activiti.engine.impl.DataObjectImpl in project Activiti by Activiti.

the class GetTaskDataObjectsCmd method execute.

public Map<String, DataObject> execute(CommandContext commandContext) {
    if (taskId == null) {
        throw new ActivitiIllegalArgumentException("taskId is null");
    }
    TaskEntity task = commandContext.getTaskEntityManager().findById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
    }
    Map<String, DataObject> dataObjects = null;
    Map<String, VariableInstance> variables = null;
    if (variableNames == null) {
        variables = task.getVariableInstances();
    } else {
        variables = task.getVariableInstances(variableNames, false);
    }
    if (variables != null) {
        dataObjects = new HashMap<>(variables.size());
        for (Entry<String, VariableInstance> entry : variables.entrySet()) {
            VariableInstance variableEntity = entry.getValue();
            String localizedName = null;
            String localizedDescription = null;
            ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(variableEntity.getExecutionId());
            while (!executionEntity.isScope()) {
                executionEntity = executionEntity.getParent();
            }
            BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(executionEntity.getProcessDefinitionId());
            ValuedDataObject foundDataObject = null;
            if (executionEntity.getParentId() == null) {
                for (ValuedDataObject dataObject : bpmnModel.getMainProcess().getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            } else {
                SubProcess subProcess = (SubProcess) bpmnModel.getFlowElement(executionEntity.getActivityId());
                for (ValuedDataObject dataObject : subProcess.getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            }
            if (locale != null && foundDataObject != null) {
                ObjectNode languageNode = Context.getLocalizationElementProperties(locale, foundDataObject.getId(), task.getProcessDefinitionId(), withLocalizationFallback);
                if (languageNode != null) {
                    JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                    if (nameNode != null) {
                        localizedName = nameNode.asText();
                    }
                    JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                    if (descriptionNode != null) {
                        localizedDescription = descriptionNode.asText();
                    }
                }
            }
            if (foundDataObject != null) {
                dataObjects.put(variableEntity.getName(), new DataObjectImpl(variableEntity.getName(), variableEntity.getValue(), foundDataObject.getDocumentation(), foundDataObject.getType(), localizedName, localizedDescription, foundDataObject.getId()));
            }
        }
    }
    return dataObjects;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) DataObjectImpl(org.activiti.engine.impl.DataObjectImpl) DataObject(org.activiti.engine.runtime.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 3 with DataObjectImpl

use of org.activiti.engine.impl.DataObjectImpl in project Activiti by Activiti.

the class GetDataObjectsCmd method execute.

public Map<String, DataObject> execute(CommandContext commandContext) {
    // Verify existance of execution
    if (executionId == null) {
        throw new ActivitiIllegalArgumentException("executionId is null");
    }
    ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
    if (execution == null) {
        throw new ActivitiObjectNotFoundException("execution " + executionId + " doesn't exist", Execution.class);
    }
    Map<String, VariableInstance> variables = null;
    if (dataObjectNames == null || dataObjectNames.isEmpty()) {
        // Fetch all
        if (isLocal) {
            variables = execution.getVariableInstancesLocal();
        } else {
            variables = execution.getVariableInstances();
        }
    } else {
        // Fetch specific collection of variables
        if (isLocal) {
            variables = execution.getVariableInstancesLocal(dataObjectNames, false);
        } else {
            variables = execution.getVariableInstances(dataObjectNames, false);
        }
    }
    Map<String, DataObject> dataObjects = null;
    if (variables != null) {
        dataObjects = new HashMap<>(variables.size());
        for (Entry<String, VariableInstance> entry : variables.entrySet()) {
            String name = entry.getKey();
            VariableInstance variableEntity = (VariableInstance) entry.getValue();
            ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(variableEntity.getExecutionId());
            while (!executionEntity.isScope()) {
                executionEntity = executionEntity.getParent();
            }
            BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(execution.getProcessDefinitionId());
            ValuedDataObject foundDataObject = null;
            if (executionEntity.getParentId() == null) {
                for (ValuedDataObject dataObject : bpmnModel.getMainProcess().getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            } else {
                SubProcess subProcess = (SubProcess) bpmnModel.getFlowElement(execution.getActivityId());
                for (ValuedDataObject dataObject : subProcess.getDataObjects()) {
                    if (dataObject.getName().equals(variableEntity.getName())) {
                        foundDataObject = dataObject;
                        break;
                    }
                }
            }
            String localizedName = null;
            String localizedDescription = null;
            if (locale != null && foundDataObject != null) {
                ObjectNode languageNode = Context.getLocalizationElementProperties(locale, foundDataObject.getId(), execution.getProcessDefinitionId(), withLocalizationFallback);
                if (languageNode != null) {
                    JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                    if (nameNode != null) {
                        localizedName = nameNode.asText();
                    }
                    JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                    if (descriptionNode != null) {
                        localizedDescription = descriptionNode.asText();
                    }
                }
            }
            if (foundDataObject != null) {
                dataObjects.put(name, new DataObjectImpl(variableEntity.getName(), variableEntity.getValue(), foundDataObject.getDocumentation(), foundDataObject.getType(), localizedName, localizedDescription, foundDataObject.getId()));
            }
        }
    }
    return dataObjects;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) DataObjectImpl(org.activiti.engine.impl.DataObjectImpl) DataObject(org.activiti.engine.runtime.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Example 4 with DataObjectImpl

use of org.activiti.engine.impl.DataObjectImpl in project Activiti by Activiti.

the class GetTaskDataObjectCmd method execute.

public DataObject execute(CommandContext commandContext) {
    if (taskId == null) {
        throw new ActivitiIllegalArgumentException("taskId is null");
    }
    if (variableName == null) {
        throw new ActivitiIllegalArgumentException("variableName is null");
    }
    TaskEntity task = commandContext.getTaskEntityManager().findById(taskId);
    if (task == null) {
        throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
    }
    DataObject dataObject = null;
    VariableInstance variableEntity = task.getVariableInstance(variableName, false);
    String localizedName = null;
    String localizedDescription = null;
    if (variableEntity != null) {
        ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(variableEntity.getExecutionId());
        while (!executionEntity.isScope()) {
            executionEntity = executionEntity.getParent();
        }
        BpmnModel bpmnModel = ProcessDefinitionUtil.getBpmnModel(executionEntity.getProcessDefinitionId());
        ValuedDataObject foundDataObject = null;
        if (executionEntity.getParentId() == null) {
            for (ValuedDataObject dataObjectDefinition : bpmnModel.getMainProcess().getDataObjects()) {
                if (dataObjectDefinition.getName().equals(variableEntity.getName())) {
                    foundDataObject = dataObjectDefinition;
                    break;
                }
            }
        } else {
            SubProcess subProcess = (SubProcess) bpmnModel.getFlowElement(executionEntity.getActivityId());
            for (ValuedDataObject dataObjectDefinition : subProcess.getDataObjects()) {
                if (dataObjectDefinition.getName().equals(variableEntity.getName())) {
                    foundDataObject = dataObjectDefinition;
                    break;
                }
            }
        }
        if (locale != null && foundDataObject != null) {
            ObjectNode languageNode = Context.getLocalizationElementProperties(locale, foundDataObject.getId(), task.getProcessDefinitionId(), withLocalizationFallback);
            if (languageNode != null) {
                JsonNode nameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
                if (nameNode != null) {
                    localizedName = nameNode.asText();
                }
                JsonNode descriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
                if (descriptionNode != null) {
                    localizedDescription = descriptionNode.asText();
                }
            }
        }
        if (foundDataObject != null) {
            dataObject = new DataObjectImpl(variableEntity.getName(), variableEntity.getValue(), foundDataObject.getDocumentation(), foundDataObject.getType(), localizedName, localizedDescription, foundDataObject.getId());
        }
    }
    return dataObject;
}
Also used : SubProcess(org.activiti.bpmn.model.SubProcess) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) BpmnModel(org.activiti.bpmn.model.BpmnModel) DataObjectImpl(org.activiti.engine.impl.DataObjectImpl) DataObject(org.activiti.engine.runtime.DataObject) ValuedDataObject(org.activiti.bpmn.model.ValuedDataObject) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) VariableInstance(org.activiti.engine.impl.persistence.entity.VariableInstance)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 SubProcess (org.activiti.bpmn.model.SubProcess)4 ValuedDataObject (org.activiti.bpmn.model.ValuedDataObject)4 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)4 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)4 DataObjectImpl (org.activiti.engine.impl.DataObjectImpl)4 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)4 VariableInstance (org.activiti.engine.impl.persistence.entity.VariableInstance)4 DataObject (org.activiti.engine.runtime.DataObject)4 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)2