Search in sources :

Example 61 with ProcessEngineException

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

the class AddCommentCmd method execute.

public Comment execute(CommandContext commandContext) {
    if (processInstanceId == null && taskId == null) {
        throw new ProcessEngineException("Process instance id and task id is null");
    }
    ensureNotNull("Message", message);
    String userId = commandContext.getAuthenticatedUserId();
    CommentEntity comment = new CommentEntity();
    comment.setUserId(userId);
    comment.setType(CommentEntity.TYPE_COMMENT);
    comment.setTime(ClockUtil.getCurrentTime());
    comment.setTaskId(taskId);
    comment.setProcessInstanceId(processInstanceId);
    comment.setAction(Event.ACTION_ADD_COMMENT);
    String eventMessage = message.replaceAll("\\s+", " ");
    if (eventMessage.length() > 163) {
        eventMessage = eventMessage.substring(0, 160) + "...";
    }
    comment.setMessage(eventMessage);
    comment.setFullMessage(message);
    commandContext.getCommentManager().insert(comment);
    return comment;
}
Also used : ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) CommentEntity(org.camunda.bpm.engine.impl.persistence.entity.CommentEntity)

Example 62 with ProcessEngineException

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

the class DetermineHistoryLevelCmd method execute.

@Override
public HistoryLevel execute(final CommandContext commandContext) {
    final Integer databaseHistoryLevel = HistoryLevelSetupCommand.databaseHistoryLevel(commandContext);
    HistoryLevel result = null;
    if (databaseHistoryLevel != null) {
        for (final HistoryLevel historyLevel : historyLevels) {
            if (historyLevel.getId() == databaseHistoryLevel) {
                result = historyLevel;
                break;
            }
        }
        if (result != null) {
            return result;
        } else {
            // if a custom non-null value is not registered, throw an exception.
            throw new ProcessEngineException(String.format("The configured history level with id='%s' is not registered in this config.", databaseHistoryLevel));
        }
    } else {
        return null;
    }
}
Also used : HistoryLevel(org.camunda.bpm.engine.impl.history.HistoryLevel) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 63 with ProcessEngineException

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

the class JavaSerializationTest method testStandaloneTaskVariable.

public void testStandaloneTaskVariable() {
    Task task = taskService.newTask();
    task.setName("gonzoTask");
    taskService.saveTask(task);
    String taskId = task.getId();
    try {
        taskService.setVariable(taskId, "instrument", Variables.serializedObjectValue("trumpet").serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
        fail("Exception is expected.");
    } catch (ProcessEngineException ex) {
        assertEquals("ENGINE-17007 Cannot set variable with name instrument. Java serialization format is prohibited", ex.getMessage());
    } finally {
        taskService.deleteTask(taskId, true);
    }
}
Also used : Task(org.camunda.bpm.engine.task.Task) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 64 with ProcessEngineException

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

the class JavaSerializationTest method testJavaSerializedValuesAreProhibitedForTransient.

@Deployment(resources = ONE_TASK_PROCESS)
public void testJavaSerializedValuesAreProhibitedForTransient() throws JSONException {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    try {
        // request object to be serialized as Java
        runtimeService.setVariable(instance.getId(), "simpleBean", serializedObjectValue("").serializationDataFormat(Variables.SerializationDataFormats.JAVA).create());
        fail("Exception is expected.");
    } catch (ProcessEngineException ex) {
        assertEquals("ENGINE-17007 Cannot set variable with name simpleBean. Java serialization format is prohibited", ex.getMessage());
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

Example 65 with ProcessEngineException

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

the class JsonSerializationTest method testFailingSerialization.

@Deployment(resources = ONE_TASK_PROCESS)
public void testFailingSerialization() {
    ProcessInstance instance = runtimeService.startProcessInstanceByKey("oneTaskProcess");
    FailingSerializationBean failingBean = new FailingSerializationBean("a String", 42, true);
    try {
        runtimeService.setVariable(instance.getId(), "simpleBean", objectValue(failingBean).serializationDataFormat(JSON_FORMAT_NAME));
        fail("exception expected");
    } catch (ProcessEngineException e) {
    // happy path
    }
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) Deployment(org.camunda.bpm.engine.test.Deployment)

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