Search in sources :

Example 1 with RepositoryService

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

the class ProcessApplicationDeploymentService method performDeployment.

protected void performDeployment() throws StartException {
    ManagedReference reference = null;
    try {
        // get process engine
        ProcessEngine processEngine = processEngineInjector.getValue();
        // get the process application component
        ProcessApplicationInterface processApplication = null;
        ComponentView componentView = paComponentViewInjector.getOptionalValue();
        if (componentView != null) {
            reference = componentView.createInstance();
            processApplication = (ProcessApplicationInterface) reference.getInstance();
        } else {
            processApplication = noViewProcessApplication.getValue();
        }
        // get the application name
        String processApplicationName = processApplication.getName();
        // build the deployment
        final RepositoryService repositoryService = processEngine.getRepositoryService();
        final ProcessApplicationDeploymentBuilder deploymentBuilder = repositoryService.createDeployment(processApplication.getReference());
        // enable duplicate filtering
        deploymentBuilder.enableDuplicateFiltering(PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_DEPLOY_CHANGED_ONLY, false));
        // enable resuming of previous versions:
        if (PropertyHelper.getBooleanProperty(processArchive.getProperties(), ProcessArchiveXml.PROP_IS_RESUME_PREVIOUS_VERSIONS, true)) {
            enableResumingOfPreviousVersions(deploymentBuilder);
        }
        // set the name for the deployment
        String deploymentName = processArchive.getName();
        if (deploymentName == null || deploymentName.isEmpty()) {
            deploymentName = processApplicationName;
        }
        deploymentBuilder.name(deploymentName);
        // set the tenant id for the deployment
        String tenantId = processArchive.getTenantId();
        if (tenantId != null && !tenantId.isEmpty()) {
            deploymentBuilder.tenantId(tenantId);
        }
        // add deployment resources
        for (Entry<String, byte[]> resource : deploymentMap.entrySet()) {
            deploymentBuilder.addInputStream(resource.getKey(), new ByteArrayInputStream(resource.getValue()));
        }
        // let the process application component add resources to the deployment.
        processApplication.createDeployment(processArchive.getName(), deploymentBuilder);
        Collection<String> resourceNames = deploymentBuilder.getResourceNames();
        if (!resourceNames.isEmpty()) {
            logDeploymentSummary(resourceNames, deploymentName, processApplicationName);
            // perform the actual deployment
            deployment = Tccl.runUnderClassloader(new Tccl.Operation<ProcessApplicationDeployment>() {

                public ProcessApplicationDeployment run() {
                    return deploymentBuilder.deploy();
                }
            }, module.getClassLoader());
        } else {
            LOGGER.info("Not creating a deployment for process archive '" + processArchive.getName() + "': no resources provided.");
        }
    } catch (Exception e) {
        throw new StartException("Could not register process application with shared process engine ", e);
    } finally {
        if (reference != null) {
            reference.release();
        }
    }
}
Also used : ManagedReference(org.jboss.as.naming.ManagedReference) ProcessApplicationInterface(org.camunda.bpm.application.ProcessApplicationInterface) StartException(org.jboss.msc.service.StartException) ProcessApplicationDeploymentBuilder(org.camunda.bpm.engine.repository.ProcessApplicationDeploymentBuilder) ComponentView(org.jboss.as.ee.component.ComponentView) ByteArrayInputStream(java.io.ByteArrayInputStream) StartException(org.jboss.msc.service.StartException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 2 with RepositoryService

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

the class ProcessDefinitionSuspensionStateDto method updateSuspensionState.

public void updateSuspensionState(ProcessEngine engine) {
    if (processDefinitionId != null && processDefinitionKey != null) {
        String message = "Only one of processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    }
    RepositoryService repositoryService = engine.getRepositoryService();
    Date delayedExecutionDate = null;
    if (executionDate != null && !executionDate.equals("")) {
        delayedExecutionDate = DateTimeUtil.parseDate(executionDate);
    }
    if (processDefinitionId != null) {
        // activate/suspend process definition by id
        if (getSuspended()) {
            repositoryService.suspendProcessDefinitionById(processDefinitionId, includeProcessInstances, delayedExecutionDate);
        } else {
            repositoryService.activateProcessDefinitionById(processDefinitionId, includeProcessInstances, delayedExecutionDate);
        }
    } else if (processDefinitionKey != null) {
        // activate/suspend process definition by key
        if (getSuspended()) {
            repositoryService.suspendProcessDefinitionByKey(processDefinitionKey, includeProcessInstances, delayedExecutionDate);
        } else {
            repositoryService.activateProcessDefinitionByKey(processDefinitionKey, includeProcessInstances, delayedExecutionDate);
        }
    } else {
        String message = "Either processDefinitionId or processDefinitionKey should be set to update the suspension state.";
        throw new InvalidRequestException(Status.BAD_REQUEST, message);
    }
}
Also used : InvalidRequestException(org.camunda.bpm.engine.rest.exception.InvalidRequestException) Date(java.util.Date) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 3 with RepositoryService

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

the class ProcessDefinitionRestServiceImpl method deleteProcessDefinitionsByKey.

@Override
public void deleteProcessDefinitionsByKey(String processDefinitionKey, boolean cascade, boolean skipCustomListeners) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeleteProcessDefinitionsBuilder builder = repositoryService.deleteProcessDefinitions().byKey(processDefinitionKey);
    deleteProcessDefinitions(builder, cascade, skipCustomListeners);
}
Also used : DeleteProcessDefinitionsBuilder(org.camunda.bpm.engine.repository.DeleteProcessDefinitionsBuilder) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 4 with RepositoryService

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

the class ProcessDefinitionRestServiceImpl method deleteProcessDefinitionsByKeyAndTenantId.

@Override
public void deleteProcessDefinitionsByKeyAndTenantId(String processDefinitionKey, boolean cascade, boolean skipCustomListeners, String tenantId) {
    RepositoryService repositoryService = processEngine.getRepositoryService();
    DeleteProcessDefinitionsBuilder builder = repositoryService.deleteProcessDefinitions().byKey(processDefinitionKey).withTenantId(tenantId);
    deleteProcessDefinitions(builder, cascade, skipCustomListeners);
}
Also used : DeleteProcessDefinitionsBuilder(org.camunda.bpm.engine.repository.DeleteProcessDefinitionsBuilder) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 5 with RepositoryService

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

the class CaseDefinitionResourceImpl method getCaseDefinition.

@Override
public CaseDefinitionDto getCaseDefinition() {
    RepositoryService repositoryService = engine.getRepositoryService();
    CaseDefinition definition = null;
    try {
        definition = repositoryService.getCaseDefinition(caseDefinitionId);
    } 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 CaseDefinitionDto.fromCaseDefinition(definition);
}
Also used : NotValidException(org.camunda.bpm.engine.exception.NotValidException) CaseDefinition(org.camunda.bpm.engine.repository.CaseDefinition) 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)

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