use of org.activiti.engine.form.StartFormData in project alfresco-remote-api by Alfresco.
the class TasksImpl method getTaskVariables.
@Override
public CollectionWithPagingInfo<TaskVariable> getTaskVariables(String taskId, Paging paging, VariableScope scope) {
// Ensure the user is allowed to get variables for the task involved.
HistoricTaskInstance taskInstance = getValidHistoricTask(taskId);
String formKey = taskInstance.getFormKey();
// Based on the scope, right variables are queried
Map<String, Object> taskvariables = new HashMap<String, Object>();
Map<String, Object> processVariables = new HashMap<String, Object>();
if (scope == VariableScope.ANY || scope == VariableScope.LOCAL) {
List<HistoricVariableInstance> variables = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().taskId(taskId).list();
if (variables != null) {
for (HistoricVariableInstance variable : variables) {
taskvariables.put(variable.getVariableName(), variable.getValue());
}
}
}
if ((scope == VariableScope.ANY || scope == VariableScope.GLOBAL) && taskInstance.getProcessInstanceId() != null) {
List<HistoricVariableInstance> variables = activitiProcessEngine.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(taskInstance.getProcessInstanceId()).excludeTaskVariables().list();
if (variables != null) {
for (HistoricVariableInstance variable : variables) {
processVariables.put(variable.getVariableName(), variable.getValue());
}
}
}
// Convert raw variables to TaskVariables
TypeDefinition taskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, false);
TypeDefinition startFormTypeDefinition = null;
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(taskInstance.getProcessDefinitionId());
if (startFormData != null) {
startFormTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(startFormData.getFormKey(), true);
} else {
// fall back
startFormTypeDefinition = taskTypeDefinition;
}
List<TaskVariable> page = restVariableHelper.getTaskVariables(taskvariables, processVariables, startFormTypeDefinition, taskTypeDefinition);
return CollectionWithPagingInfo.asPaged(paging, page, false, page.size());
}
use of org.activiti.engine.form.StartFormData in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method createProcessDefinitionRest.
protected ProcessDefinition createProcessDefinitionRest(ProcessDefinitionEntity processDefinition) {
ProcessDefinition processDefinitionRest = new ProcessDefinition(processDefinition);
String localKey = getLocalProcessDefinitionKey(processDefinition.getKey());
processDefinitionRest.setKey(localKey);
String displayId = localKey + ".workflow";
processDefinitionRest.setTitle(getLabel(displayId, "title"));
processDefinitionRest.setDescription(getLabel(displayId, "description"));
processDefinitionRest.setGraphicNotationDefined(processDefinition.isGraphicalNotationDefined());
if (processDefinition.hasStartFormKey()) {
try {
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinition.getId());
if (startFormData != null) {
processDefinitionRest.setStartFormResourceKey(startFormData.getFormKey());
}
} catch (Exception e) {
throw new ApiException("Error while retrieving start form key");
}
}
return processDefinitionRest;
}
use of org.activiti.engine.form.StartFormData in project alfresco-remote-api by Alfresco.
the class ProcessDefinitionsImpl method getStartFormModel.
@Override
public CollectionWithPagingInfo<FormModelElement> getStartFormModel(String definitionId, Paging paging) {
// first validate if user is allowed to access the process definition if workflows are deployed per tenant
if (tenantService.isEnabled() && deployWorkflowsInTenant) {
ProcessDefinitionQuery query = activitiProcessEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionId(definitionId);
query.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
org.activiti.engine.repository.ProcessDefinition processDefinition = query.singleResult();
if (processDefinition == null) {
throw new EntityNotFoundException(definitionId);
}
}
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(definitionId);
if (startFormData == null) {
throw new EntityNotFoundException(definitionId);
}
if (qNameConverter == null) {
qNameConverter = new WorkflowQNameConverter(namespaceService);
}
if (workflowFactory == null) {
workflowFactory = new WorkflowObjectFactory(qNameConverter, tenantService, messageService, dictionaryService, engineId, defaultStartTaskType);
}
// Lookup type definition for the startTask
TypeDefinition startTaskType = workflowFactory.getTaskFullTypeDefinition(startFormData.getFormKey(), true);
return getFormModelElements(startTaskType, paging);
}
use of org.activiti.engine.form.StartFormData in project alfresco-remote-api by Alfresco.
the class ProcessesImpl method updateVariableInProcess.
protected Variable updateVariableInProcess(String processId, String processDefinitionId, Variable variable) {
if (variable.getName() == null) {
throw new InvalidArgumentException("Variable name is required.");
}
// Get start-task definition for explicit typing of variables submitted at the start
String formKey = null;
StartFormData startFormData = activitiProcessEngine.getFormService().getStartFormData(processDefinitionId);
if (startFormData != null) {
formKey = startFormData.getFormKey();
}
DataTypeDefinition dataTypeDefinition = null;
TypeDefinition startTaskTypeDefinition = getWorkflowFactory().getTaskFullTypeDefinition(formKey, true);
TypeDefinitionContext context = new TypeDefinitionContext(startTaskTypeDefinition, getQNameConverter());
if (context.getPropertyDefinition(variable.getName()) != null) {
dataTypeDefinition = context.getPropertyDefinition(variable.getName()).getDataType();
if (variable.getType() != null && dataTypeDefinition.getName().toPrefixString(namespaceService).equals(variable.getType()) == false) {
throw new InvalidArgumentException("type of variable " + variable.getName() + " should be " + dataTypeDefinition.getName().toPrefixString(namespaceService));
}
} else if (context.getAssociationDefinition(variable.getName()) != null) {
dataTypeDefinition = dictionaryService.getDataType(DataTypeDefinition.NODE_REF);
}
if (dataTypeDefinition == null && variable.getType() != null) {
try {
QName dataType = QName.createQName(variable.getType(), namespaceService);
dataTypeDefinition = dictionaryService.getDataType(dataType);
} catch (InvalidQNameException iqne) {
throw new InvalidArgumentException("Unsupported type of variable: '" + variable.getType() + "'.");
}
} else if (dataTypeDefinition == null) {
// Fallback to raw value when no type has been passed and not present in model
dataTypeDefinition = dictionaryService.getDataType(restVariableHelper.extractTypeFromValue(variable.getValue()));
}
if (dataTypeDefinition == null) {
throw new InvalidArgumentException("Unsupported type of variable: '" + variable.getType() + "'.");
}
Object actualValue = null;
if ("java.util.Date".equalsIgnoreCase(dataTypeDefinition.getJavaClassName())) {
// fix for different ISO 8601 Date format classes in Alfresco (org.alfresco.util and Spring Surf)
actualValue = ISO8601DateFormat.parse((String) variable.getValue());
} else if (variable.getName().equals(WorkflowConstants.PROP_INITIATOR)) {
// update the initiator if exists
NodeRef initiator = getNodeRef((String) variable.getValue());
if (nodeService.exists(initiator)) {
actualValue = getNodeConverter().convertNode(initiator);
// Also update the initiator home reference, if one exists
NodeRef initiatorHome = (NodeRef) nodeService.getProperty(initiator, ContentModel.PROP_HOMEFOLDER);
if (initiatorHome != null) {
Variable initiatorHomeVar = new Variable();
initiatorHomeVar.setName(WorkflowConstants.PROP_INITIATOR_HOME);
initiatorHomeVar.setValue(initiatorHome);
updateVariableInProcess(processId, processDefinitionId, initiatorHomeVar);
}
} else {
throw new InvalidArgumentException("Variable value should be a valid person NodeRef.");
}
} else {
if (context.getAssociationDefinition(variable.getName()) != null) {
actualValue = convertAssociationDefinitionValue(context.getAssociationDefinition(variable.getName()), variable.getName(), variable.getValue());
} else {
actualValue = DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, variable.getValue());
}
}
activitiProcessEngine.getRuntimeService().setVariable(processId, variable.getName(), actualValue);
// Variable value needs to be of type NodeRef
if (actualValue instanceof ActivitiScriptNode) {
variable.setValue(((ActivitiScriptNode) actualValue).getNodeRef());
} else {
variable.setValue(actualValue);
}
// Set actual used type before returning
variable.setType(dataTypeDefinition.getName().toPrefixString(namespaceService));
return variable;
}
use of org.activiti.engine.form.StartFormData in project alfresco-repository by Alfresco.
the class ActivitiTypeConverter method convert.
/**
* Convert a {@link ProcessDefinition} into a {@link WorkflowDefinition}.
* @param definition ProcessDefinition
* @return WorkflowDefinition
*/
public WorkflowDefinition convert(ProcessDefinition definition) {
if (definition == null)
return null;
String defId = definition.getId();
String defName = definition.getKey();
int version = definition.getVersion();
String defaultTitle = definition.getName();
String startTaskName = null;
StartFormData startFormData = getStartFormData(defId, defName);
if (startFormData != null) {
startTaskName = startFormData.getFormKey();
}
ReadOnlyProcessDefinition def = activitiUtil.getDeployedProcessDefinition(defId);
PvmActivity startEvent = def.getInitial();
WorkflowTaskDefinition startTask = getTaskDefinition(startEvent, startTaskName, definition.getKey(), true);
return factory.createDefinition(defId, defName, version, defaultTitle, null, startTask);
}
Aggregations