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;
}
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;
}
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;
}
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;
}
Aggregations