use of org.activiti.engine.FormService in project carbon-business-process by wso2.
the class FormDataService method getFormData.
@GET
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getFormData() {
String taskId = uriInfo.getQueryParameters().getFirst("taskId");
String processDefinitionId = uriInfo.getQueryParameters().getFirst("processDefinitionId");
if (taskId == null && processDefinitionId == null) {
throw new ActivitiIllegalArgumentException("The taskId or processDefinitionId parameter has to be provided");
}
if (taskId != null && processDefinitionId != null) {
throw new ActivitiIllegalArgumentException("Not both a taskId and a processDefinitionId parameter can be provided");
}
FormData formData = null;
String id = null;
FormService formService = BPMNOSGIService.getFormService();
if (taskId != null) {
formData = formService.getTaskFormData(taskId);
id = taskId;
} else {
formData = formService.getStartFormData(processDefinitionId);
id = processDefinitionId;
}
if (formData == null) {
throw new ActivitiObjectNotFoundException("Could not find a form data with id '" + id + "'.", FormData.class);
}
return Response.ok().entity(new RestResponseFactory().createFormDataResponse(formData, uriInfo.getBaseUri().toString())).build();
}
use of org.activiti.engine.FormService in project carbon-business-process by wso2.
the class FormDataService method submitForm.
@POST
@Path("/")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response submitForm(SubmitFormRequest submitRequest) {
if (submitRequest == null) {
throw new ActivitiException("A request body was expected when executing the form submit.");
}
if (submitRequest.getTaskId() == null && submitRequest.getProcessDefinitionId() == null) {
throw new ActivitiIllegalArgumentException("The taskId or processDefinitionId property has to be provided");
}
Map<String, String> propertyMap = new HashMap<String, String>();
if (submitRequest.getProperties() != null) {
for (RestFormProperty formProperty : submitRequest.getProperties()) {
propertyMap.put(formProperty.getId(), formProperty.getValue());
}
}
FormService formService = BPMNOSGIService.getFormService();
Response.ResponseBuilder response = Response.ok();
if (submitRequest.getTaskId() != null) {
formService.submitTaskFormData(submitRequest.getTaskId(), propertyMap);
response.status(Response.Status.NO_CONTENT);
return response.build();
} else {
ProcessInstance processInstance = null;
if (submitRequest.getBusinessKey() != null) {
processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), submitRequest.getBusinessKey(), propertyMap);
} else {
processInstance = formService.submitStartFormData(submitRequest.getProcessDefinitionId(), propertyMap);
}
ProcessInstanceResponse processInstanceResponse = new RestResponseFactory().createProcessInstanceResponse(processInstance, uriInfo.getBaseUri().toString());
return response.entity(processInstanceResponse).build();
}
}
use of org.activiti.engine.FormService in project crnk-framework by crnk-project.
the class ActivitiModule method setupModule.
@Override
public void setupModule(ModuleContext context) {
this.moduleContext = context;
TaskService taskService = processEngine.getTaskService();
RuntimeService runtimeService = processEngine.getRuntimeService();
FormService formService = processEngine.getFormService();
resourceMapper = new ActivitiResourceMapper(context.getTypeParser(), config.getDateTimeMapper());
for (ProcessInstanceConfig processInstanceConfig : config.getProcessInstances().values()) {
context.addRepository(new ProcessInstanceResourceRepository(runtimeService, resourceMapper, processInstanceConfig.getProcessInstanceClass(), processInstanceConfig.getBaseFilters()));
for (ProcessInstanceConfig.TaskRelationshipConfig taskRel : processInstanceConfig.getTaskRelationships().values()) {
context.addRepository(new TaskRelationshipRepository(processInstanceConfig.getProcessInstanceClass(), taskRel.getTaskClass(), taskRel.getRelationshipName(), taskRel.getTaskDefinitionKey()));
}
}
for (TaskRepositoryConfig taskConfig : config.getTasks().values()) {
context.addRepository(new TaskResourceRepository(taskService, resourceMapper, taskConfig.getTaskClass(), taskConfig.getBaseFilters()));
Class<? extends FormResource> formClass = taskConfig.getFormClass();
if (formClass != null) {
context.addRepository(new FormResourceRepository(formService, taskService, resourceMapper, formClass));
context.addRepository(new FormRelationshipRepository(taskConfig.getTaskClass(), formClass));
}
}
}
use of org.activiti.engine.FormService 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();
}
Aggregations