Search in sources :

Example 16 with StartFormData

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());
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HashMap(java.util.HashMap) StartFormData(org.activiti.engine.form.StartFormData) TaskVariable(org.alfresco.rest.workflow.api.model.TaskVariable) HistoricVariableInstance(org.activiti.engine.history.HistoricVariableInstance) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 17 with StartFormData

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;
}
Also used : StartFormData(org.activiti.engine.form.StartFormData) ProcessDefinition(org.alfresco.rest.workflow.api.model.ProcessDefinition) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException) IOException(java.io.IOException) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) ApiException(org.alfresco.rest.framework.core.exceptions.ApiException)

Example 18 with StartFormData

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);
}
Also used : WorkflowQNameConverter(org.alfresco.repo.workflow.WorkflowQNameConverter) StartFormData(org.activiti.engine.form.StartFormData) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) WorkflowObjectFactory(org.alfresco.repo.workflow.WorkflowObjectFactory) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition)

Example 19 with StartFormData

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;
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Variable(org.alfresco.rest.workflow.api.model.Variable) ActivitiScriptNode(org.alfresco.repo.workflow.activiti.ActivitiScriptNode) InvalidQNameException(org.alfresco.service.namespace.InvalidQNameException) QName(org.alfresco.service.namespace.QName) StartFormData(org.activiti.engine.form.StartFormData) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition) TypeDefinition(org.alfresco.service.cmr.dictionary.TypeDefinition) DataTypeDefinition(org.alfresco.service.cmr.dictionary.DataTypeDefinition)

Example 20 with StartFormData

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);
}
Also used : StartFormData(org.activiti.engine.form.StartFormData) WorkflowTaskDefinition(org.alfresco.service.cmr.workflow.WorkflowTaskDefinition) ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) PvmActivity(org.activiti.engine.impl.pvm.PvmActivity)

Aggregations

StartFormData (org.activiti.engine.form.StartFormData)23 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)8 HashMap (java.util.HashMap)7 FormProperty (org.activiti.engine.form.FormProperty)7 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)7 Map (java.util.Map)5 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)4 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)4 QName (org.alfresco.service.namespace.QName)4 ArrayList (java.util.ArrayList)3 TaskFormData (org.activiti.engine.form.TaskFormData)3 ReadOnlyProcessDefinition (org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition)3 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)3 Deployment (org.activiti.engine.test.Deployment)3 WorkflowTaskDefinition (org.alfresco.service.cmr.workflow.WorkflowTaskDefinition)3 InvalidQNameException (org.alfresco.service.namespace.InvalidQNameException)3 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2