Search in sources :

Example 46 with ProcessEngineException

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

the class JobRestServiceInteractionTest method deleteLockedJob.

@Test
public void deleteLockedJob() {
    String jobId = MockProvider.EXAMPLE_JOB_ID;
    String expectedMessage = "Cannot delete job when the job is being executed. Try again later.";
    doThrow(new ProcessEngineException(expectedMessage)).when(mockManagementService).deleteJob(jobId);
    given().pathParam("id", jobId).then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).body("type", equalTo(RestException.class.getSimpleName())).body("message", equalTo(expectedMessage)).when().delete(SINGLE_JOB_RESOURCE_URL);
    verify(mockManagementService).deleteJob(jobId);
    verifyNoMoreInteractions(mockManagementService);
}
Also used : RestException(org.camunda.bpm.engine.rest.exception.RestException) Matchers.anyString(org.mockito.Matchers.anyString) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Test(org.junit.Test)

Example 47 with ProcessEngineException

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

the class PurgeDatabaseAndCacheCmd method purgeDatabase.

private DatabasePurgeReport purgeDatabase(CommandContext commandContext) {
    DbEntityManager dbEntityManager = commandContext.getDbEntityManager();
    // For MySQL and MariaDB we have to disable foreign key check,
    // to delete the table data as bulk operation (execution, incident etc.)
    // The flag will be reset by the DBEntityManager after flush.
    dbEntityManager.setIgnoreForeignKeysForNextFlush(true);
    List<String> tablesNames = dbEntityManager.getTableNamesPresentInDatabase();
    String databaseTablePrefix = commandContext.getProcessEngineConfiguration().getDatabaseTablePrefix().trim();
    // for each table
    DatabasePurgeReport databasePurgeReport = new DatabasePurgeReport();
    for (String tableName : tablesNames) {
        String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, EMPTY_STRING);
        if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
            // Check if table contains data
            Map<String, String> param = new HashMap<String, String>();
            param.put(TABLE_NAME, tableName);
            Long count = (Long) dbEntityManager.selectOne(SELECT_TABLE_COUNT, param);
            if (count > 0) {
                databasePurgeReport.addPurgeInformation(tableName, count);
                // Get corresponding entity classes for the table, which contains data
                List<Class<? extends DbEntity>> entities = commandContext.getTableDataManager().getEntities(tableName);
                if (entities.isEmpty()) {
                    throw new ProcessEngineException("No mapped implementation of " + DbEntity.class.getName() + " was found for: " + tableName);
                }
                // Delete the table data as bulk operation with the first entity
                Class<? extends DbEntity> entity = entities.get(0);
                DbBulkOperation deleteBulkOp = new DbBulkOperation(DbOperationType.DELETE_BULK, entity, DELETE_TABLE_DATA, param);
                dbEntityManager.getDbOperationManager().addOperation(deleteBulkOp);
            }
        }
    }
    return databasePurgeReport;
}
Also used : HashMap(java.util.HashMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 48 with ProcessEngineException

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

the class DeleteJobCmd method execute.

public Object execute(CommandContext commandContext) {
    ensureNotNull("jobId", jobId);
    JobEntity job = commandContext.getJobManager().findJobById(jobId);
    ensureNotNull("No job found with id '" + jobId + "'", "job", job);
    for (CommandChecker checker : commandContext.getProcessEngineConfiguration().getCommandCheckers()) {
        checker.checkUpdateJob(job);
    }
    // In that case, we can't allow to delete the job.
    if (job.getLockOwner() != null || job.getLockExpirationTime() != null) {
        throw new ProcessEngineException("Cannot delete job when the job is being executed. Try again later.");
    }
    job.delete();
    return null;
}
Also used : JobEntity(org.camunda.bpm.engine.impl.persistence.entity.JobEntity) CommandChecker(org.camunda.bpm.engine.impl.cfg.CommandChecker) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 49 with ProcessEngineException

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

the class MscManagedProcessEngineController method addProcessEnginePlugins.

protected void addProcessEnginePlugins(JtaProcessEngineConfiguration processEngineConfiguration) {
    // add process engine plugins:
    List<ProcessEnginePluginXml> pluginConfigurations = processEngineMetadata.getPluginConfigurations();
    for (ProcessEnginePluginXml pluginXml : pluginConfigurations) {
        // create plugin instance
        ProcessEnginePlugin plugin = null;
        String pluginClassName = pluginXml.getPluginClass();
        try {
            plugin = (ProcessEnginePlugin) createInstance(pluginClassName);
        } catch (ClassCastException e) {
            throw new ProcessEngineException("Process engine plugin '" + pluginClassName + "' does not implement interface " + ProcessEnginePlugin.class.getName() + "'.");
        }
        // apply configured properties
        Map<String, String> properties = pluginXml.getProperties();
        PropertyHelper.applyProperties(plugin, properties);
        // add to configuration
        processEngineConfiguration.getProcessEnginePlugins().add(plugin);
    }
}
Also used : ProcessEnginePluginXml(org.camunda.bpm.container.impl.metadata.spi.ProcessEnginePluginXml) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEnginePlugin(org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin)

Example 50 with ProcessEngineException

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

the class MscRuntimeContainerDelegate method registerProcessEngine.

// RuntimeContainerDelegate implementation /////////////////////////////
public void registerProcessEngine(ProcessEngine processEngine) {
    if (processEngine == null) {
        throw new ProcessEngineException("Cannot register process engine with Msc Runtime Container: process engine is 'null'");
    }
    ServiceName serviceName = ServiceNames.forManagedProcessEngine(processEngine.getName());
    if (serviceContainer.getService(serviceName) == null) {
        MscManagedProcessEngine processEngineRegistration = new MscManagedProcessEngine(processEngine);
        // install the service asynchronously.
        childTarget.addService(serviceName, processEngineRegistration).setInitialMode(Mode.ACTIVE).addDependency(ServiceNames.forMscRuntimeContainerDelegate(), MscRuntimeContainerDelegate.class, processEngineRegistration.getRuntimeContainerDelegateInjector()).install();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Aggregations

ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)611 Test (org.junit.Test)185 Deployment (org.camunda.bpm.engine.test.Deployment)138 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)79 HashMap (java.util.HashMap)62 RestException (org.camunda.bpm.engine.rest.exception.RestException)62 Matchers.anyString (org.mockito.Matchers.anyString)60 TaskQuery (org.camunda.bpm.engine.task.TaskQuery)57 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)47 InvalidRequestException (org.camunda.bpm.engine.rest.exception.InvalidRequestException)41 Task (org.camunda.bpm.engine.task.Task)40 ArrayList (java.util.ArrayList)39 ProcessDefinition (org.camunda.bpm.engine.repository.ProcessDefinition)36 Matchers.containsString (org.hamcrest.Matchers.containsString)35 CaseExecutionQuery (org.camunda.bpm.engine.runtime.CaseExecutionQuery)24 MigrationPlan (org.camunda.bpm.engine.migration.MigrationPlan)22 AuthorizationException (org.camunda.bpm.engine.AuthorizationException)21 CaseInstanceQuery (org.camunda.bpm.engine.runtime.CaseInstanceQuery)21 NotValidException (org.camunda.bpm.engine.exception.NotValidException)19 NotFoundException (org.camunda.bpm.engine.exception.NotFoundException)18