Search in sources :

Example 6 with RepositoryService

use of org.camunda.bpm.engine.RepositoryService in project camunda-bpm-platform by camunda.

the class DecisionRequirementsDefinitionResourceImpl method getDecisionRequirementsDefinition.

@Override
public DecisionRequirementsDefinitionDto getDecisionRequirementsDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    DecisionRequirementsDefinition definition = null;
    try {
        definition = repositoryService.getDecisionRequirementsDefinition(decisionRequirementsDefinitionId);
    } catch (NotFoundException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e, e.getMessage());
    } catch (NotValidException e) {
        throw new InvalidRequestException(Status.BAD_REQUEST, e, e.getMessage());
    } catch (ProcessEngineException e) {
        throw new RestException(Status.INTERNAL_SERVER_ERROR, e);
    }
    return DecisionRequirementsDefinitionDto.fromDecisionRequirementsDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) DecisionRequirementsDefinition(org.camunda.bpm.engine.repository.DecisionRequirementsDefinition) RestException(org.camunda.bpm.engine.rest.exception.RestException) NotFoundException(org.camunda.bpm.engine.exception.NotFoundException) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 7 with RepositoryService

use of org.camunda.bpm.engine.RepositoryService in project camunda-bpm-platform by camunda.

the class DeploymentResourcesResourceImpl method getDeploymentResourceData.

public Response getDeploymentResourceData(String resourceId) {
    RepositoryService repositoryService = engine.getRepositoryService();
    InputStream resourceAsStream = repositoryService.getResourceAsStreamById(deploymentId, resourceId);
    if (resourceAsStream != null) {
        DeploymentResourceDto resource = getDeploymentResource(resourceId);
        String name = resource.getName();
        String filename = null;
        String mediaType = null;
        if (name != null) {
            name = name.replace("\\", "/");
            String[] filenameParts = name.split("/");
            if (filenameParts.length > 0) {
                int idx = filenameParts.length - 1;
                filename = filenameParts[idx];
            }
            String[] extensionParts = name.split("\\.");
            if (extensionParts.length > 0) {
                int idx = extensionParts.length - 1;
                String extension = extensionParts[idx];
                if (extension != null) {
                    mediaType = MEDIA_TYPE_MAPPING.get(extension);
                }
            }
        }
        if (filename == null) {
            filename = "data";
        }
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_OCTET_STREAM;
        }
        return Response.ok(resourceAsStream, mediaType).header("Content-Disposition", "attachment; filename=" + filename).build();
    } else {
        throw new InvalidRequestException(Status.NOT_FOUND, "Deployment resource '" + resourceId + "' for deployment id '" + deploymentId + "' does not exist.");
    }
}
Also used : InputStream(java.io.InputStream) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) DeploymentResourceDto(org.camunda.bpm.engine.rest.dto.repository.DeploymentResourceDto) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 8 with RepositoryService

use of org.camunda.bpm.engine.RepositoryService in project camunda-bpm-platform by camunda.

the class ProcessDefinitionResourceImpl method getProcessDefinition.

@Override
public ProcessDefinitionDto getProcessDefinition() {
    RepositoryService repoService = engine.getRepositoryService();
    ProcessDefinition definition;
    try {
        definition = repoService.getProcessDefinition(processDefinitionId);
    } catch (ProcessEngineException e) {
        throw new InvalidRequestException(Status.NOT_FOUND, e, "No matching definition with id " + processDefinitionId);
    }
    ProcessDefinitionDto result = ProcessDefinitionDto.fromProcessDefinition(definition);
    return result;
}
Also used : ProcessDefinition(org.camunda.bpm.engine.repository.ProcessDefinition) InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) ProcessDefinitionDto(org.camunda.bpm.engine.rest.dto.repository.ProcessDefinitionDto) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 9 with RepositoryService

use of org.camunda.bpm.engine.RepositoryService in project camunda-bpm-platform by camunda.

the class DeploymentResourceImpl method tryToRedeploy.

protected DeploymentWithDefinitions tryToRedeploy(RedeploymentDto redeployment) {
    RepositoryService repositoryService = getProcessEngine().getRepositoryService();
    DeploymentBuilder builder = repositoryService.createDeployment();
    builder.nameFromDeployment(deploymentId);
    String tenantId = getDeployment().getTenantId();
    if (tenantId != null) {
        builder.tenantId(tenantId);
    }
    if (redeployment != null) {
        builder = addRedeploymentResources(builder, redeployment);
    } else {
        builder.addDeploymentResources(deploymentId);
    }
    return builder.deployWithResult();
}
Also used : DeploymentBuilder(org.camunda.bpm.engine.repository.DeploymentBuilder) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 10 with RepositoryService

use of org.camunda.bpm.engine.RepositoryService in project camunda-bpm-platform by camunda.

the class DeployProcessArchiveStep method performOperationStep.

@Override
public void performOperationStep(DeploymentOperation operationContext) {
    final PlatformServiceContainer serviceContainer = operationContext.getServiceContainer();
    final AbstractProcessApplication processApplication = operationContext.getAttachment(Attachments.PROCESS_APPLICATION);
    final ClassLoader processApplicationClassloader = processApplication.getProcessApplicationClassloader();
    ProcessEngine processEngine = getProcessEngine(serviceContainer);
    // start building deployment map
    Map<String, byte[]> deploymentMap = new HashMap<String, byte[]>();
    // add all processes listed in the processes.xml
    List<String> listedProcessResources = processArchive.getProcessResourceNames();
    for (String processResource : listedProcessResources) {
        InputStream resourceAsStream = null;
        try {
            resourceAsStream = processApplicationClassloader.getResourceAsStream(processResource);
            byte[] bytes = IoUtil.readInputStream(resourceAsStream, processResource);
            deploymentMap.put(processResource, bytes);
        } finally {
            IoUtil.closeSilently(resourceAsStream);
        }
    }
    // scan for additional process definitions if not turned off
    if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_SCAN_FOR_PROCESS_DEFINITIONS, true)) {
        String paResourceRoot = processArchive.getProperties().get(ProcessArchiveXml.PROP_RESOURCE_ROOT_PATH);
        String[] additionalResourceSuffixes = StringUtil.split(processArchive.getProperties().get(ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES), ProcessArchiveXml.PROP_ADDITIONAL_RESOURCE_SUFFIXES_SEPARATOR);
        deploymentMap.putAll(findResources(processApplicationClassloader, paResourceRoot, additionalResourceSuffixes));
    }
    // perform process engine deployment
    RepositoryService repositoryService = processEngine.getRepositoryService();
    ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());
    // set the name for the deployment
    String deploymentName = processArchive.getName();
    if (deploymentName == null || deploymentName.isEmpty()) {
        deploymentName = processApplication.getName();
    }
    deploymentBuilder.name(deploymentName);
    // set the tenant id for the deployment
    String tenantId = processArchive.getTenantId();
    if (tenantId != null && !tenantId.isEmpty()) {
        deploymentBuilder.tenantId(tenantId);
    }
    // enable duplicate filtering
    deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));
    if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
        enableResumingOfPreviousVersions(deploymentBuilder);
    }
    // add all resources obtained through the processes.xml and through scanning
    for (Entry<String, byte[]> deploymentResource : deploymentMap.entrySet()) {
        deploymentBuilder.addInputStream(deploymentResource.getKey(), new ByteArrayInputStream(deploymentResource.getValue()));
    }
    // allow the process application to add additional resources to the deployment
    processApplication.createDeployment(processArchive.getName(), deploymentBuilder);
    Collection<String> deploymentResourceNames = deploymentBuilder.getResourceNames();
    if (!deploymentResourceNames.isEmpty()) {
        LOG.deploymentSummary(deploymentResourceNames, deploymentName);
        // perform the process engine deployment
        deployment = deploymentBuilder.deploy();
        // add attachment
        Map<String, DeployedProcessArchive> processArchiveDeploymentMap = operationContext.getAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP);
        if (processArchiveDeploymentMap == null) {
            processArchiveDeploymentMap = new HashMap<String, DeployedProcessArchive>();
            operationContext.addAttachment(Attachments.PROCESS_ARCHIVE_DEPLOYMENT_MAP, processArchiveDeploymentMap);
        }
        processArchiveDeploymentMap.put(processArchive.getName(), new DeployedProcessArchive(deployment));
    } else {
        LOG.notCreatingPaDeployment(processApplication.getName());
    }
}
Also used : DeployedProcessArchive(org.camunda.bpm.container.impl.deployment.util.DeployedProcessArchive) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ProcessApplicationDeploymentBuilder(org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder) AbstractProcessApplication(org.camunda.bpm.application.AbstractProcessApplication) ByteArrayInputStream(java.io.ByteArrayInputStream) PlatformServiceContainer(org.camunda.bpm.container.impl.spi.PlatformServiceContainer) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Aggregations

RepositoryService (org.camunda.bpm.engine.RepositoryService)57 Test (org.junit.Test)24 AbstractFoxPlatformIntegrationTest (org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)23 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)13 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)10 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)9 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)8 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)6 ProcessApplicationService (org.camunda.bpm.ProcessApplicationService)5 ProcessApplicationDeploymentInfo (org.camunda.bpm.application.ProcessApplicationDeploymentInfo)5 ProcessApplicationInfo (org.camunda.bpm.application.ProcessApplicationInfo)5 CommandContext (org.camunda.bpm.engine.impl.interceptor.CommandContext)5 ProcessApplicationReference (org.camunda.bpm.application.ProcessApplicationReference)4 RuntimeService (org.camunda.bpm.engine.RuntimeService)4 Deployment (org.camunda.bpm.engine.repository.Deployment)4 ProcessDefinitionQuery (org.camunda.bpm.engine.repository.ProcessDefinitionQuery)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)3 NotValidException (org.camunda.bpm.engine.exception.NotValidException)3