Search in sources :

Example 1 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getForm.

@Override
public WorkflowFormTO getForm(final String workflowId) {
    Task task;
    try {
        task = engine.getTaskService().createTaskQuery().processInstanceId(workflowId).singleResult();
    } catch (FlowableException e) {
        throw new WorkflowException("While reading form for workflow instance " + workflowId, e);
    }
    TaskFormData formData;
    try {
        formData = engine.getFormService().getTaskFormData(task.getId());
    } catch (FlowableException e) {
        LOG.debug("No form found for task {}", task.getId(), e);
        formData = null;
    }
    WorkflowFormTO result = null;
    if (formData != null && !formData.getFormProperties().isEmpty()) {
        result = getFormTO(task);
    }
    return result;
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) TaskFormData(org.flowable.engine.form.TaskFormData) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO)

Example 2 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getHistoricFormTO.

protected WorkflowFormTO getHistoricFormTO(final String processInstanceId, final String taskId, final String formKey, final List<HistoricFormPropertyEntity> props) {
    WorkflowFormTO formTO = new WorkflowFormTO();
    User user = userDAO.findByWorkflowId(processInstanceId);
    if (user == null) {
        throw new NotFoundException("User with workflow id " + processInstanceId);
    }
    formTO.setUsername(user.getUsername());
    formTO.setTaskId(taskId);
    formTO.setKey(formKey);
    formTO.setUserTO(engine.getRuntimeService().getVariable(processInstanceId, USER_TO, UserTO.class));
    formTO.setUserPatch(engine.getRuntimeService().getVariable(processInstanceId, USER_PATCH, UserPatch.class));
    props.stream().map(prop -> {
        WorkflowFormPropertyTO propertyTO = new WorkflowFormPropertyTO();
        propertyTO.setId(prop.getPropertyId());
        propertyTO.setName(prop.getPropertyId());
        propertyTO.setValue(prop.getPropertyValue());
        return propertyTO;
    }).forEachOrdered(propertyTO -> {
        formTO.getProperties().add(propertyTO);
    });
    return formTO;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) Pair(org.apache.commons.lang3.tuple.Pair) DomainProcessEngine(org.apache.syncope.core.workflow.flowable.spring.DomainProcessEngine) Map(java.util.Map) AbstractUserWorkflowAdapter(org.apache.syncope.core.workflow.java.AbstractUserWorkflowAdapter) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) JsonNode(com.fasterxml.jackson.databind.JsonNode) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) FormType(org.flowable.engine.form.FormType) Resource(javax.annotation.Resource) Set(java.util.Set) Model(org.flowable.engine.repository.Model) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Query(org.flowable.engine.common.api.query.Query) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WorkflowFormPropertyType(org.apache.syncope.common.lib.types.WorkflowFormPropertyType) FormProperty(org.flowable.engine.form.FormProperty) WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) WorkflowDefinitionFormat(org.apache.syncope.core.workflow.api.WorkflowDefinitionFormat) TaskFormData(org.flowable.engine.form.TaskFormData) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) HashMap(java.util.HashMap) BeanUtils(org.apache.syncope.core.spring.BeanUtils) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) ModelDataJsonConstants(org.flowable.editor.constants.ModelDataJsonConstants) OutputStream(java.io.OutputStream) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) User(org.apache.syncope.core.persistence.api.entity.user.User) IOException(java.io.IOException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Collections(java.util.Collections) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) InputStream(java.io.InputStream) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) HistoricFormPropertyEntity(org.flowable.engine.impl.persistence.entity.HistoricFormPropertyEntity) Transactional(org.springframework.transaction.annotation.Transactional) User(org.apache.syncope.core.persistence.api.entity.user.User) UserTO(org.apache.syncope.common.lib.to.UserTO) WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) UserPatch(org.apache.syncope.common.lib.patch.UserPatch)

Example 3 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getForms.

protected <T extends Query<?, ?>, U extends Object> List<WorkflowFormTO> getForms(final Query<T, U> query) {
    List<WorkflowFormTO> forms = new ArrayList<>();
    query.list().forEach(obj -> {
        try {
            if (obj instanceof HistoricTaskInstance) {
                forms.add(getFormTO((HistoricTaskInstance) obj));
            } else if (obj instanceof Task) {
                forms.add(getFormTO((Task) obj));
            } else {
                throw new FlowableException("Failure retrieving form", new IllegalArgumentException("Invalid task type"));
            }
        } catch (FlowableException e) {
            LOG.debug("No form found for task {}", obj, e);
        }
    });
    return forms;
}
Also used : Task(org.flowable.task.api.Task) FlowableException(org.flowable.engine.common.api.FlowableException) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO)

Example 4 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getFormTO.

protected WorkflowFormTO getFormTO(final HistoricTaskInstance task) {
    final List<HistoricFormPropertyEntity> props = new ArrayList<>();
    engine.getHistoryService().createHistoricDetailQuery().taskId(task.getId()).list().stream().filter(historicDetail -> (historicDetail instanceof HistoricFormPropertyEntity)).forEachOrdered(historicDetail -> {
        props.add((HistoricFormPropertyEntity) historicDetail);
    });
    WorkflowFormTO formTO = getHistoricFormTO(task.getProcessInstanceId(), task.getId(), task.getFormKey(), props);
    BeanUtils.copyProperties(task, formTO);
    HistoricActivityInstance historicActivityInstance = engine.getHistoryService().createHistoricActivityInstanceQuery().executionId(task.getExecutionId()).activityType("userTask").activityName(task.getName()).singleResult();
    if (historicActivityInstance != null) {
        formTO.setCreateTime(historicActivityInstance.getStartTime());
        formTO.setDueDate(historicActivityInstance.getEndTime());
    }
    return formTO;
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) WorkflowException(org.apache.syncope.core.workflow.api.WorkflowException) Autowired(org.springframework.beans.factory.annotation.Autowired) UserPatch(org.apache.syncope.common.lib.patch.UserPatch) ResourceOperation(org.apache.syncope.common.lib.types.ResourceOperation) StringUtils(org.apache.commons.lang3.StringUtils) Pair(org.apache.commons.lang3.tuple.Pair) DomainProcessEngine(org.apache.syncope.core.workflow.flowable.spring.DomainProcessEngine) Map(java.util.Map) AbstractUserWorkflowAdapter(org.apache.syncope.core.workflow.java.AbstractUserWorkflowAdapter) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) JsonNode(com.fasterxml.jackson.databind.JsonNode) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) FormType(org.flowable.engine.form.FormType) Resource(javax.annotation.Resource) Set(java.util.Set) Model(org.flowable.engine.repository.Model) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) Deployment(org.flowable.engine.repository.Deployment) Task(org.flowable.task.api.Task) Collectors(java.util.stream.Collectors) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Query(org.flowable.engine.common.api.query.Query) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WorkflowFormPropertyType(org.apache.syncope.common.lib.types.WorkflowFormPropertyType) FormProperty(org.flowable.engine.form.FormProperty) WorkflowFormPropertyTO(org.apache.syncope.common.lib.to.WorkflowFormPropertyTO) WorkflowDefinitionFormat(org.apache.syncope.core.workflow.api.WorkflowDefinitionFormat) TaskFormData(org.flowable.engine.form.TaskFormData) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) BpmnXMLConverter(org.flowable.bpmn.converter.BpmnXMLConverter) HashMap(java.util.HashMap) BeanUtils(org.apache.syncope.core.spring.BeanUtils) WorkflowResult(org.apache.syncope.core.provisioning.api.WorkflowResult) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) FlowableException(org.flowable.engine.common.api.FlowableException) BpmnModel(org.flowable.bpmn.model.BpmnModel) ModelDataJsonConstants(org.flowable.editor.constants.ModelDataJsonConstants) OutputStream(java.io.OutputStream) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance) WorkflowDefinitionTO(org.apache.syncope.common.lib.to.WorkflowDefinitionTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) User(org.apache.syncope.core.persistence.api.entity.user.User) IOException(java.io.IOException) InvalidEntityException(org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntityException) PasswordPatch(org.apache.syncope.common.lib.patch.PasswordPatch) UserTO(org.apache.syncope.common.lib.to.UserTO) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) Collections(java.util.Collections) BpmnJsonConverter(org.flowable.editor.language.json.converter.BpmnJsonConverter) InputStream(java.io.InputStream) ParsingValidationException(org.apache.syncope.core.persistence.api.attrvalue.validation.ParsingValidationException) HistoricFormPropertyEntity(org.flowable.engine.impl.persistence.entity.HistoricFormPropertyEntity) Transactional(org.springframework.transaction.annotation.Transactional) ArrayList(java.util.ArrayList) HistoricFormPropertyEntity(org.flowable.engine.impl.persistence.entity.HistoricFormPropertyEntity) WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO) HistoricActivityInstance(org.flowable.engine.history.HistoricActivityInstance)

Example 5 with WorkflowFormTO

use of org.apache.syncope.common.lib.to.WorkflowFormTO in project syncope by apache.

the class FlowableUserWorkflowAdapter method getFormTO.

protected WorkflowFormTO getFormTO(final Task task, final TaskFormData fd) {
    WorkflowFormTO formTO = getFormTO(task.getProcessInstanceId(), task.getId(), fd.getFormKey(), fd.getFormProperties());
    BeanUtils.copyProperties(task, formTO);
    return formTO;
}
Also used : WorkflowFormTO(org.apache.syncope.common.lib.to.WorkflowFormTO)

Aggregations

WorkflowFormTO (org.apache.syncope.common.lib.to.WorkflowFormTO)16 UserTO (org.apache.syncope.common.lib.to.UserTO)11 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)8 Test (org.junit.jupiter.api.Test)8 UserPatch (org.apache.syncope.common.lib.patch.UserPatch)7 ArrayList (java.util.ArrayList)5 PasswordPatch (org.apache.syncope.common.lib.patch.PasswordPatch)5 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)5 Map (java.util.Map)4 WorkflowFormPropertyTO (org.apache.syncope.common.lib.to.WorkflowFormPropertyTO)4 NotFoundException (org.apache.syncope.core.persistence.api.dao.NotFoundException)4 FlowableException (org.flowable.engine.common.api.FlowableException)4 Task (org.flowable.task.api.Task)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 Collections (java.util.Collections)3