Search in sources :

Example 16 with FormProperty

use of org.activiti.engine.form.FormProperty in project crnk-framework by crnk-project.

the class ActivitiResourceMapper method mapToResource.

public <T extends FormResource> T mapToResource(Class<T> resourceClass, TaskFormData formData) {
    T resource = io.crnk.core.engine.internal.utils.ClassUtils.newInstance(resourceClass);
    Map<String, Object> formPropertyMap = new HashMap<>();
    List<FormProperty> formProperties = formData.getFormProperties();
    for (FormProperty formProperty : formProperties) {
        formPropertyMap.put(formProperty.getId(), formProperty.getValue());
    }
    copyInternal(resource, null, formPropertyMap, true, Optional.empty());
    resource.setId(formData.getTask().getId());
    return resource;
}
Also used : HashMap(java.util.HashMap) FormProperty(org.activiti.engine.form.FormProperty)

Example 17 with FormProperty

use of org.activiti.engine.form.FormProperty in project carbon-business-process by wso2.

the class ProcessDefinitionFormPropertyService method getStartFormProperties.

@GET
@Path("/{processDefinitionId}/properties")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getStartFormProperties(@PathParam("processDefinitionId") String processDefinitionId) {
    FormService formService = BPMNOSGIService.getFormService();
    StartFormData startFormData = formService.getStartFormData(processDefinitionId);
    FormPropertyResponseCollection formPropertyResponseCollection = new FormPropertyResponseCollection();
    if (startFormData != null) {
        List<FormProperty> properties = startFormData.getFormProperties();
        List<FormPropertyResponse> formPropertyResponseList = new ArrayList<>();
        for (FormProperty property : properties) {
            // ObjectNode propertyJSON = objectMapper.createObjectNode();
            FormPropertyResponse formPropertyResponse = new FormPropertyResponse();
            formPropertyResponse.setId(property.getId());
            formPropertyResponse.setName(property.getName());
            if (property.getValue() != null) {
                formPropertyResponse.setValue(property.getValue());
            } else {
                formPropertyResponse.setValue(null);
            }
            if (property.getType() != null) {
                formPropertyResponse.setType(property.getType().getName());
                if (property.getType() instanceof EnumFormType) {
                    @SuppressWarnings("unchecked") Map<String, String> valuesMap = (Map<String, String>) property.getType().getInformation("values");
                    if (valuesMap != null) {
                        List<FormPropertyEnumDataHolder> formPropertyEnumDataHoldersList = new ArrayList<>();
                        for (String key : valuesMap.keySet()) {
                            FormPropertyEnumDataHolder formPropertyEnumDataHolder = new FormPropertyEnumDataHolder();
                            formPropertyEnumDataHolder.setId(key);
                            formPropertyEnumDataHolder.setName(valuesMap.get(key));
                            formPropertyEnumDataHoldersList.add(formPropertyEnumDataHolder);
                        }
                        formPropertyResponse.setEnumValues(formPropertyEnumDataHoldersList);
                    }
                }
            } else {
                formPropertyResponse.setType("String");
            }
            formPropertyResponse.setRequired(property.isRequired());
            formPropertyResponse.setReadable(property.isReadable());
            formPropertyResponse.setWritable(property.isWritable());
            formPropertyResponseList.add(formPropertyResponse);
        }
        formPropertyResponseCollection.setData(formPropertyResponseList);
    }
    return Response.ok().entity(formPropertyResponseCollection).build();
}
Also used : FormPropertyEnumDataHolder(org.wso2.carbon.bpmn.rest.model.form.FormPropertyEnumDataHolder) FormProperty(org.activiti.engine.form.FormProperty) FormService(org.activiti.engine.FormService) FormPropertyResponse(org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponse) ArrayList(java.util.ArrayList) EnumFormType(org.activiti.engine.impl.form.EnumFormType) FormPropertyResponseCollection(org.wso2.carbon.bpmn.rest.model.form.FormPropertyResponseCollection) StartFormData(org.activiti.engine.form.StartFormData) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 18 with FormProperty

use of org.activiti.engine.form.FormProperty in project carbon-business-process by wso2.

the class RestResponseFactory method createFormDataResponse.

public FormDataResponse createFormDataResponse(FormData formData, String baseUri) {
    FormDataResponse result = new FormDataResponse();
    result.setDeploymentId(formData.getDeploymentId());
    result.setFormKey(formData.getFormKey());
    if (formData.getFormProperties() != null) {
        for (FormProperty formProp : formData.getFormProperties()) {
            RestFormProperty restFormProp = new RestFormProperty();
            restFormProp.setId(formProp.getId());
            restFormProp.setName(formProp.getName());
            if (formProp.getType() != null) {
                restFormProp.setType(formProp.getType().getName());
            }
            restFormProp.setValue(formProp.getValue());
            restFormProp.setReadable(formProp.isReadable());
            restFormProp.setRequired(formProp.isRequired());
            restFormProp.setWritable(formProp.isWritable());
            if ("enum".equals(restFormProp.getType())) {
                Object values = formProp.getType().getInformation("values");
                if (values != null) {
                    @SuppressWarnings("unchecked") Map<String, String> enumValues = (Map<String, String>) values;
                    for (String enumId : enumValues.keySet()) {
                        RestEnumFormProperty enumProperty = new RestEnumFormProperty();
                        enumProperty.setId(enumId);
                        enumProperty.setName(enumValues.get(enumId));
                        restFormProp.addEnumValue(enumProperty);
                    }
                }
            } else if ("date".equals(restFormProp.getType())) {
                restFormProp.setDatePattern((String) formProp.getType().getInformation("datePattern"));
            }
            result.addFormProperty(restFormProp);
        }
    }
    RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
    if (formData instanceof StartFormData) {
        StartFormData startFormData = (StartFormData) formData;
        if (startFormData.getProcessDefinition() != null) {
            result.setProcessDefinitionId(startFormData.getProcessDefinition().getId());
            result.setProcessDefinitionUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION, startFormData.getProcessDefinition().getId()));
        }
    } else if (formData instanceof TaskFormData) {
        TaskFormData taskFormData = (TaskFormData) formData;
        if (taskFormData.getTask() != null) {
            result.setTaskId(taskFormData.getTask().getId());
            result.setTaskUrl(urlBuilder.buildUrl(RestUrls.URL_TASK, taskFormData.getTask().getId()));
        }
    }
    return result;
}
Also used : RestEnumFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestEnumFormProperty) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) RestEnumFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestEnumFormProperty) FormProperty(org.activiti.engine.form.FormProperty) StartFormData(org.activiti.engine.form.StartFormData) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) TaskFormData(org.activiti.engine.form.TaskFormData) Map(java.util.Map) FormDataResponse(org.wso2.carbon.bpmn.rest.model.form.FormDataResponse)

Example 19 with FormProperty

use of org.activiti.engine.form.FormProperty in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method toResource.

private WorkflowTaskInstanceDto toResource(TaskInfo task, BasePermission[] permission) {
    if (task == null) {
        return null;
    }
    WorkflowTaskInstanceDto dto = new WorkflowTaskInstanceDto();
    dto.setId(task.getId());
    dto.setName(task.getName());
    dto.setProcessDefinitionId(task.getProcessDefinitionId());
    dto.setPriority(task.getPriority());
    dto.setAssignee(task.getAssignee());
    dto.setCreated(task.getCreateTime());
    dto.setFormKey(task.getFormKey());
    dto.setDescription(task.getDescription());
    dto.setProcessInstanceId(task.getProcessInstanceId());
    Map<String, Object> taskVariables = task.getTaskLocalVariables();
    Map<String, Object> processVariables = task.getProcessVariables();
    // Add applicant username to task dto (for easier work)
    if (processVariables != null && processVariables.containsKey(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER)) {
        dto.setApplicant(processVariables.get(WorkflowProcessInstanceService.APPLICANT_IDENTIFIER).toString());
    }
    dto.setVariables(processVariables);
    convertToDtoVariables(dto, taskVariables);
    dto.setDefinition(workflowTaskDefinitionService.searchTaskDefinitionById(task.getProcessDefinitionId(), task.getTaskDefinitionKey()));
    if (!Strings.isNullOrEmpty(task.getProcessDefinitionId())) {
        WorkflowProcessDefinitionDto processDefinition = workflowProcessDefinitionService.get(task.getProcessDefinitionId());
        if (processDefinition != null) {
            dto.setProcessDefinitionKey(processDefinition.getKey());
        }
    }
    TaskFormData taskFormData = formService.getTaskFormData(task.getId());
    // Add form data (it means form properties and value from WF)
    List<FormProperty> formProperties = taskFormData.getFormProperties();
    // Search and add identity links to dto (It means all user
    // (assigned/candidates/group) for this task)
    List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
    if (identityLinks != null) {
        List<IdentityLinkDto> identityLinksDtos = new ArrayList<>(identityLinks.size());
        identityLinks.forEach((il) -> {
            identityLinksDtos.add(toResource(il));
        });
        dto.getIdentityLinks().addAll(identityLinksDtos);
    }
    // Check if the logged user can complete this task
    boolean canExecute = this.canExecute(dto, permission);
    if (formProperties != null && !formProperties.isEmpty()) {
        formProperties.forEach((property) -> {
            resovleFormProperty(property, dto, canExecute);
        });
    }
    return dto;
}
Also used : FormProperty(org.activiti.engine.form.FormProperty) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ArrayList(java.util.ArrayList) TaskFormData(org.activiti.engine.form.TaskFormData) IdentityLink(org.activiti.engine.task.IdentityLink) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)

Example 20 with FormProperty

use of org.activiti.engine.form.FormProperty in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowTaskInstanceService method resovleFormProperty.

/**
 * Convert form property and add to result dto
 *
 * @param property
 * @param dto
 * @param canExecute
 */
@SuppressWarnings("unchecked")
private void resovleFormProperty(FormProperty property, WorkflowTaskInstanceDto dto, boolean canExecute) {
    FormType formType = property.getType();
    if (formType instanceof DecisionFormType) {
        // task
        if (!canExecute) {
            return;
        }
        DecisionFormTypeDto decisionDto = (DecisionFormTypeDto) ((DecisionFormType) formType).convertFormValueToModelValue(property.getValue());
        if (decisionDto != null) {
            decisionDto.setId(property.getId());
            setDecisionReasonRequired(decisionDto);
            dto.getDecisions().add(decisionDto);
        }
    } else if (formType instanceof TaskHistoryFormType) {
        WorkflowFilterDto filterDto = new WorkflowFilterDto();
        filterDto.setProcessInstanceId(dto.getProcessInstanceId());
        List<WorkflowHistoricTaskInstanceDto> tasks = historicTaskInstanceService.find(filterDto, PageRequest.of(0, 50)).getContent();
        List<WorkflowHistoricTaskInstanceDto> history = tasks.stream().filter(workflowHistoricTaskInstanceDto -> workflowHistoricTaskInstanceDto.getEndTime() != null).sorted((o1, o2) -> {
            if (o1.getEndTime().before(o2.getEndTime())) {
                return -1;
            } else if (o1.getEndTime().after(o2.getEndTime())) {
                return 1;
            }
            return 0;
        }).collect(Collectors.toList());
        dto.getFormData().add(historyToResource(property, history));
    } else if (formType instanceof AbstractFormType) {
        // To rest will be add only component form type marked as "exportable to rest".
        if (formType instanceof AbstractComponentFormType && !((AbstractComponentFormType) formType).isExportableToRest()) {
            return;
        }
        Object values = formType.getInformation("values");
        if (values instanceof Map<?, ?>) {
            dto.getFormData().add(toResource(property, (Map<String, String>) values));
        } else {
            dto.getFormData().add(toResource(property, null));
        }
    }
}
Also used : DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) Date(java.util.Date) FormDataDto(eu.bcvsolutions.idm.core.workflow.model.dto.FormDataDto) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) SecurityService(eu.bcvsolutions.idm.core.security.api.service.SecurityService) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) AbstractBaseDtoService(eu.bcvsolutions.idm.core.rest.AbstractBaseDtoService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) Pageable(org.springframework.data.domain.Pageable) TaskQuery(org.activiti.engine.task.TaskQuery) IdentityLink(org.activiti.engine.task.IdentityLink) ImmutableMap(com.google.common.collect.ImmutableMap) FormType(org.activiti.engine.form.FormType) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) UUID(java.util.UUID) TaskInfo(org.activiti.engine.task.TaskInfo) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) AbstractFormType(org.activiti.engine.form.AbstractFormType) List(java.util.List) PageImpl(org.springframework.data.domain.PageImpl) WorkflowProcessDefinitionService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessDefinitionService) TaskService(org.activiti.engine.TaskService) HashMap(java.util.HashMap) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) LookupService(eu.bcvsolutions.idm.core.api.service.LookupService) Service(org.springframework.stereotype.Service) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) TaskFormData(org.activiti.engine.form.TaskFormData) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowHistoricTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowHistoricTaskInstanceService) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) Task(org.activiti.engine.task.Task) FormService(org.activiti.engine.FormService) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) FormProperty(org.activiti.engine.form.FormProperty) WorkflowTaskDefinitionService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskDefinitionService) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) WorkflowProcessDefinitionDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto) DecisionFormTypeDto(eu.bcvsolutions.idm.core.workflow.model.dto.DecisionFormTypeDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) Assert(org.springframework.util.Assert) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) AbstractComponentFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.AbstractComponentFormType) FormType(org.activiti.engine.form.FormType) TaskHistoryFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.TaskHistoryFormType) AbstractFormType(org.activiti.engine.form.AbstractFormType) DecisionFormType(eu.bcvsolutions.idm.core.workflow.domain.formtype.DecisionFormType) List(java.util.List) ArrayList(java.util.ArrayList) AbstractFormType(org.activiti.engine.form.AbstractFormType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) DecisionFormTypeDto(eu.bcvsolutions.idm.core.workflow.model.dto.DecisionFormTypeDto)

Aggregations

FormProperty (org.activiti.engine.form.FormProperty)21 TaskFormData (org.activiti.engine.form.TaskFormData)10 HashMap (java.util.HashMap)9 StartFormData (org.activiti.engine.form.StartFormData)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 Deployment (org.activiti.engine.test.Deployment)6 LinkedHashMap (java.util.LinkedHashMap)4 Task (org.activiti.engine.task.Task)4 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)3 WorkflowProcessDefinitionDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessDefinitionDto)3 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)3 EnumFormType (org.activiti.engine.impl.form.EnumFormType)3 IdentityLink (org.activiti.engine.task.IdentityLink)3 Field (com.vaadin.ui.Field)2 FormService (org.activiti.engine.FormService)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1