Search in sources :

Example 6 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class EditorProcessDefinitionDetailPanel method deployModelerModel.

protected void deployModelerModel(final ObjectNode modelNode) {
    BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
    String processName = modelData.getName() + ".bpmn20.xml";
    Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
    ExplorerApp.get().getViewManager().showDeploymentPage(deployment.getId());
}
Also used : Deployment(org.activiti.engine.repository.Deployment) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter)

Example 7 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class SecureScriptingBaseTest method shutdownProcessEngine.

@After
public void shutdownProcessEngine() {
    for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        repositoryService.deleteDeployment(deployment.getId(), true);
    }
    this.taskService = null;
    this.repositoryService = null;
    this.runtimeService = null;
    this.processEngine.close();
    this.processEngine = null;
}
Also used : Deployment(org.activiti.engine.repository.Deployment) After(org.junit.After)

Example 8 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class SimpleWorkflowResource method createWorkflow.

@RequestMapping(value = "/simple-workflow", method = RequestMethod.POST, produces = "application/json")
public SimpleWorkflowSuccessResponse createWorkflow(@RequestBody String json) {
    // Convert json to simple workflow definition
    SimpleWorkflowJsonConverter jsonConverter = new SimpleWorkflowJsonConverter();
    WorkflowDefinition workflowDefinition = jsonConverter.readWorkflowDefinition(json.getBytes());
    WorkflowDefinitionConversionFactory conversionFactory = new WorkflowDefinitionConversionFactory();
    WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(workflowDefinition);
    conversion.convert();
    // Deploy process
    BpmnModel bpmnModel = conversion.getBpmnModel();
    Deployment deployment = repositoryService.createDeployment().addBpmnModel(bpmnModel.getProcesses().get(0).getName() + ".bpmn20.xml", bpmnModel).deploy();
    // Fetch process definition id
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    return new SimpleWorkflowSuccessResponse(processDefinition.getId());
}
Also used : WorkflowDefinitionConversion(org.activiti.workflow.simple.converter.WorkflowDefinitionConversion) WorkflowDefinitionConversionFactory(org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Deployment(org.activiti.engine.repository.Deployment) SimpleWorkflowJsonConverter(org.activiti.workflow.simple.converter.json.SimpleWorkflowJsonConverter) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) BpmnModel(org.activiti.bpmn.model.BpmnModel) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class BaseDeploymentResourceDataResource method getDeploymentResourceData.

protected byte[] getDeploymentResourceData(String deploymentId, String resourceId, HttpServletResponse response) {
    if (deploymentId == null) {
        throw new ActivitiIllegalArgumentException("No deployment id provided");
    }
    if (resourceId == null) {
        throw new ActivitiIllegalArgumentException("No resource id provided");
    }
    // Check if deployment exists
    Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
    if (deployment == null) {
        throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
    }
    List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
    if (resourceList.contains(resourceId)) {
        final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
        String contentType = contentTypeResolver.resolveContentType(resourceId);
        response.setContentType(contentType);
        try {
            return IOUtils.toByteArray(resourceStream);
        } catch (Exception e) {
            throw new ActivitiException("Error converting resource stream", e);
        }
    } else {
        // Resource not found in deployment
        throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
    }
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) InputStream(java.io.InputStream) Deployment(org.activiti.engine.repository.Deployment) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException)

Example 10 with Deployment

use of org.activiti.engine.repository.Deployment in project Activiti by Activiti.

the class DeploymentCollectionResource method uploadDeployment.

@RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json")
public DeploymentResponse uploadDeployment(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {
    if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
    }
    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
    if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
    }
    MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
    try {
        DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
        String fileName = file.getOriginalFilename();
        if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
            fileName = file.getName();
        }
        if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
            deploymentBuilder.addInputStream(fileName, file.getInputStream());
        } else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
            deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
        } else {
            throw new ActivitiIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
        }
        deploymentBuilder.name(fileName);
        if (tenantId != null) {
            deploymentBuilder.tenantId(tenantId);
        }
        Deployment deployment = deploymentBuilder.deploy();
        response.setStatus(HttpStatus.CREATED.value());
        return restResponseFactory.createDeploymentResponse(deployment);
    } catch (Exception e) {
        if (e instanceof ActivitiException) {
            throw (ActivitiException) e;
        }
        throw new ActivitiException(e.getMessage(), e);
    }
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) ZipInputStream(java.util.zip.ZipInputStream) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Deployment(org.activiti.engine.repository.Deployment) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Deployment (org.activiti.engine.repository.Deployment)66 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)12 BpmnModel (org.activiti.bpmn.model.BpmnModel)10 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 ActivitiException (org.activiti.engine.ActivitiException)7 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)6 HttpGet (org.apache.http.client.methods.HttpGet)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 InputStream (java.io.InputStream)3 HashSet (java.util.HashSet)3 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 ProcessEngine (org.activiti.engine.ProcessEngine)3 RuntimeService (org.activiti.engine.RuntimeService)3 DeploymentBuilder (org.activiti.engine.repository.DeploymentBuilder)3 Task (org.activiti.engine.task.Task)3