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