Search in sources :

Example 1 with FormService

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();
}
Also used : FormData(org.activiti.engine.form.FormData) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) FormService(org.activiti.engine.FormService) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with FormService

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();
    }
}
Also used : ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) Response(javax.ws.rs.core.Response) ActivitiException(org.activiti.engine.ActivitiException) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) FormService(org.activiti.engine.FormService) ProcessInstanceResponse(org.wso2.carbon.bpmn.rest.model.runtime.ProcessInstanceResponse) RestFormProperty(org.wso2.carbon.bpmn.rest.model.form.RestFormProperty) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 3 with FormService

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));
        }
    }
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) FormService(org.activiti.engine.FormService) ProcessInstanceResourceRepository(io.crnk.activiti.internal.repository.ProcessInstanceResourceRepository) TaskResourceRepository(io.crnk.activiti.internal.repository.TaskResourceRepository) FormResourceRepository(io.crnk.activiti.internal.repository.FormResourceRepository) FormRelationshipRepository(io.crnk.activiti.internal.repository.FormRelationshipRepository) TaskRelationshipRepository(io.crnk.activiti.internal.repository.TaskRelationshipRepository)

Example 4 with FormService

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

Aggregations

FormService (org.activiti.engine.FormService)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 GET (javax.ws.rs.GET)2 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)2 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)2 FormRelationshipRepository (io.crnk.activiti.internal.repository.FormRelationshipRepository)1 FormResourceRepository (io.crnk.activiti.internal.repository.FormResourceRepository)1 ProcessInstanceResourceRepository (io.crnk.activiti.internal.repository.ProcessInstanceResourceRepository)1 TaskRelationshipRepository (io.crnk.activiti.internal.repository.TaskRelationshipRepository)1 TaskResourceRepository (io.crnk.activiti.internal.repository.TaskResourceRepository)1 ActivitiResourceMapper (io.crnk.activiti.mapper.ActivitiResourceMapper)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 POST (javax.ws.rs.POST)1 Response (javax.ws.rs.core.Response)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 RuntimeService (org.activiti.engine.RuntimeService)1