use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class ExecutionVariableDataResource method getVariableData.
@RequestMapping(value = "/runtime/executions/{executionId}/variables/{variableName}/data", method = RequestMethod.GET)
@ResponseBody
public byte[] getVariableData(@PathVariable("executionId") String executionId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request, HttpServletResponse response) {
try {
byte[] result = null;
Execution execution = getExecutionFromRequest(executionId);
RestVariable variable = getVariableFromRequest(execution, variableName, scope, true);
if (RestResponseFactory.BYTE_ARRAY_VARIABLE_TYPE.equals(variable.getType())) {
result = (byte[]) variable.getValue();
response.setContentType("application/octet-stream");
} else if (RestResponseFactory.SERIALIZABLE_VARIABLE_TYPE.equals(variable.getType())) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream outputStream = new ObjectOutputStream(buffer);
outputStream.writeObject(variable.getValue());
outputStream.close();
result = buffer.toByteArray();
response.setContentType("application/x-java-serialized-object");
} else {
throw new ActivitiObjectNotFoundException("The variable does not have a binary data stream.", null);
}
return result;
} catch (IOException ioe) {
throw new ActivitiException("Error getting variable " + variableName, ioe);
}
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class TaskAttachmentCollectionResource method createBinaryAttachment.
protected AttachmentResponse createBinaryAttachment(MultipartHttpServletRequest request, Task task, HttpServletResponse response) {
String name = null;
String description = null;
String type = null;
Map<String, String[]> paramMap = request.getParameterMap();
for (String parameterName : paramMap.keySet()) {
if (paramMap.get(parameterName).length > 0) {
if (parameterName.equalsIgnoreCase("name")) {
name = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("description")) {
description = paramMap.get(parameterName)[0];
} else if (parameterName.equalsIgnoreCase("type")) {
type = paramMap.get(parameterName)[0];
}
}
}
if (name == null) {
throw new ActivitiIllegalArgumentException("Attachment name is required.");
}
if (request.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
MultipartFile file = request.getFileMap().values().iterator().next();
if (file == null) {
throw new ActivitiIllegalArgumentException("Attachment content is required.");
}
try {
Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name, description, file.getInputStream());
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createAttachmentResponse(createdAttachment);
} catch (Exception e) {
throw new ActivitiException("Error creating attachment response", e);
}
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class UserTaskActivityBehavior method execute.
public void execute(ActivityExecution execution) throws Exception {
TaskEntity task = TaskEntity.createAndInsert(execution);
task.setExecution(execution);
Expression activeNameExpression = null;
Expression activeDescriptionExpression = null;
Expression activeDueDateExpression = null;
Expression activePriorityExpression = null;
Expression activeCategoryExpression = null;
Expression activeFormKeyExpression = null;
Expression activeSkipExpression = null;
Expression activeAssigneeExpression = null;
Expression activeOwnerExpression = null;
Set<Expression> activeCandidateUserExpressions = null;
Set<Expression> activeCandidateGroupExpressions = null;
if (Context.getProcessEngineConfiguration().isEnableProcessDefinitionInfoCache()) {
ObjectNode taskElementProperties = Context.getBpmnOverrideElementProperties(userTaskId, execution.getProcessDefinitionId());
activeNameExpression = getActiveValue(taskDefinition.getNameExpression(), DynamicBpmnConstants.USER_TASK_NAME, taskElementProperties);
taskDefinition.setNameExpression(activeNameExpression);
activeDescriptionExpression = getActiveValue(taskDefinition.getDescriptionExpression(), DynamicBpmnConstants.USER_TASK_DESCRIPTION, taskElementProperties);
taskDefinition.setDescriptionExpression(activeDescriptionExpression);
activeDueDateExpression = getActiveValue(taskDefinition.getDueDateExpression(), DynamicBpmnConstants.USER_TASK_DUEDATE, taskElementProperties);
taskDefinition.setDueDateExpression(activeDueDateExpression);
activePriorityExpression = getActiveValue(taskDefinition.getPriorityExpression(), DynamicBpmnConstants.USER_TASK_PRIORITY, taskElementProperties);
taskDefinition.setPriorityExpression(activePriorityExpression);
activeCategoryExpression = getActiveValue(taskDefinition.getCategoryExpression(), DynamicBpmnConstants.USER_TASK_CATEGORY, taskElementProperties);
taskDefinition.setCategoryExpression(activeCategoryExpression);
activeFormKeyExpression = getActiveValue(taskDefinition.getFormKeyExpression(), DynamicBpmnConstants.USER_TASK_FORM_KEY, taskElementProperties);
taskDefinition.setFormKeyExpression(activeFormKeyExpression);
activeSkipExpression = getActiveValue(taskDefinition.getSkipExpression(), DynamicBpmnConstants.TASK_SKIP_EXPRESSION, taskElementProperties);
taskDefinition.setSkipExpression(activeSkipExpression);
activeAssigneeExpression = getActiveValue(taskDefinition.getAssigneeExpression(), DynamicBpmnConstants.USER_TASK_ASSIGNEE, taskElementProperties);
taskDefinition.setAssigneeExpression(activeAssigneeExpression);
activeOwnerExpression = getActiveValue(taskDefinition.getOwnerExpression(), DynamicBpmnConstants.USER_TASK_OWNER, taskElementProperties);
taskDefinition.setOwnerExpression(activeOwnerExpression);
activeCandidateUserExpressions = getActiveValueSet(taskDefinition.getCandidateUserIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_USERS, taskElementProperties);
taskDefinition.setCandidateUserIdExpressions(activeCandidateUserExpressions);
activeCandidateGroupExpressions = getActiveValueSet(taskDefinition.getCandidateGroupIdExpressions(), DynamicBpmnConstants.USER_TASK_CANDIDATE_GROUPS, taskElementProperties);
taskDefinition.setCandidateGroupIdExpressions(activeCandidateGroupExpressions);
} else {
activeNameExpression = taskDefinition.getNameExpression();
activeDescriptionExpression = taskDefinition.getDescriptionExpression();
activeDueDateExpression = taskDefinition.getDueDateExpression();
activePriorityExpression = taskDefinition.getPriorityExpression();
activeCategoryExpression = taskDefinition.getCategoryExpression();
activeFormKeyExpression = taskDefinition.getFormKeyExpression();
activeSkipExpression = taskDefinition.getSkipExpression();
activeAssigneeExpression = taskDefinition.getAssigneeExpression();
activeOwnerExpression = taskDefinition.getOwnerExpression();
activeCandidateUserExpressions = taskDefinition.getCandidateUserIdExpressions();
activeCandidateGroupExpressions = taskDefinition.getCandidateGroupIdExpressions();
}
task.setTaskDefinition(taskDefinition);
if (activeNameExpression != null) {
String name = null;
try {
name = (String) activeNameExpression.getValue(execution);
} catch (ActivitiException e) {
name = activeNameExpression.getExpressionText();
LOGGER.warn("property not found in task name expression " + e.getMessage());
}
task.setName(name);
}
if (activeDescriptionExpression != null) {
String description = null;
try {
description = (String) activeDescriptionExpression.getValue(execution);
} catch (ActivitiException e) {
description = activeDescriptionExpression.getExpressionText();
LOGGER.warn("property not found in task description expression " + e.getMessage());
}
task.setDescription(description);
}
if (activeDueDateExpression != null) {
Object dueDate = activeDueDateExpression.getValue(execution);
if (dueDate != null) {
if (dueDate instanceof Date) {
task.setDueDate((Date) dueDate);
} else if (dueDate instanceof String) {
BusinessCalendar businessCalendar = Context.getProcessEngineConfiguration().getBusinessCalendarManager().getBusinessCalendar(taskDefinition.getBusinessCalendarNameExpression().getValue(execution).toString());
task.setDueDate(businessCalendar.resolveDuedate((String) dueDate));
} else {
throw new ActivitiIllegalArgumentException("Due date expression does not resolve to a Date or Date string: " + activeDueDateExpression.getExpressionText());
}
}
}
if (activePriorityExpression != null) {
final Object priority = activePriorityExpression.getValue(execution);
if (priority != null) {
if (priority instanceof String) {
try {
task.setPriority(Integer.valueOf((String) priority));
} catch (NumberFormatException e) {
throw new ActivitiIllegalArgumentException("Priority does not resolve to a number: " + priority, e);
}
} else if (priority instanceof Number) {
task.setPriority(((Number) priority).intValue());
} else {
throw new ActivitiIllegalArgumentException("Priority expression does not resolve to a number: " + activePriorityExpression.getExpressionText());
}
}
}
if (activeCategoryExpression != null) {
final Object category = activeCategoryExpression.getValue(execution);
if (category != null) {
if (category instanceof String) {
task.setCategory((String) category);
} else {
throw new ActivitiIllegalArgumentException("Category expression does not resolve to a string: " + activeCategoryExpression.getExpressionText());
}
}
}
if (activeFormKeyExpression != null) {
final Object formKey = activeFormKeyExpression.getValue(execution);
if (formKey != null) {
if (formKey instanceof String) {
task.setFormKey((String) formKey);
} else {
throw new ActivitiIllegalArgumentException("FormKey expression does not resolve to a string: " + activeFormKeyExpression.getExpressionText());
}
}
}
boolean skipUserTask = SkipExpressionUtil.isSkipExpressionEnabled(execution, activeSkipExpression) && SkipExpressionUtil.shouldSkipFlowElement(execution, activeSkipExpression);
if (!skipUserTask) {
handleAssignments(activeAssigneeExpression, activeOwnerExpression, activeCandidateUserExpressions, activeCandidateGroupExpressions, task, execution);
}
task.fireEvent(TaskListener.EVENTNAME_CREATE);
// All properties set, now firing 'create' events
if (Context.getProcessEngineConfiguration().getEventDispatcher().isEnabled()) {
Context.getProcessEngineConfiguration().getEventDispatcher().dispatchEvent(ActivitiEventBuilder.createEntityEvent(ActivitiEventType.TASK_CREATED, task));
}
if (skipUserTask) {
task.complete(null, false);
}
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class BpmnDeployer method addMessageEventSubscriptions.
@SuppressWarnings("unchecked")
protected void addMessageEventSubscriptions(ProcessDefinitionEntity processDefinition) {
CommandContext commandContext = Context.getCommandContext();
List<EventSubscriptionDeclaration> eventDefinitions = (List<EventSubscriptionDeclaration>) processDefinition.getProperty(BpmnParse.PROPERTYNAME_EVENT_SUBSCRIPTION_DECLARATION);
if (eventDefinitions != null) {
Set<String> messageNames = new HashSet<String>();
for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
if (eventDefinition.getEventType().equals("message") && eventDefinition.isStartEvent()) {
if (!messageNames.contains(eventDefinition.getEventName())) {
messageNames.add(eventDefinition.getEventName());
} else {
throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName() + "': there are multiple message event subscriptions for the message with name '" + eventDefinition.getEventName() + "'.");
}
// look for subscriptions for the same name in db:
List<EventSubscriptionEntity> subscriptionsForSameMessageName = commandContext.getEventSubscriptionEntityManager().findEventSubscriptionsByName(MessageEventHandler.EVENT_HANDLER_TYPE, eventDefinition.getEventName(), processDefinition.getTenantId());
// also look for subscriptions created in the session:
List<MessageEventSubscriptionEntity> cachedSubscriptions = commandContext.getDbSqlSession().findInCache(MessageEventSubscriptionEntity.class);
for (MessageEventSubscriptionEntity cachedSubscription : cachedSubscriptions) {
if (eventDefinition.getEventName().equals(cachedSubscription.getEventName()) && !subscriptionsForSameMessageName.contains(cachedSubscription)) {
subscriptionsForSameMessageName.add(cachedSubscription);
}
}
// remove subscriptions deleted in the same command
subscriptionsForSameMessageName = commandContext.getDbSqlSession().pruneDeletedEntities(subscriptionsForSameMessageName);
for (EventSubscriptionEntity eventSubscriptionEntity : subscriptionsForSameMessageName) {
// no process instance-id = it's a message start event
if (StringUtils.isEmpty(eventSubscriptionEntity.getProcessInstanceId())) {
throw new ActivitiException("Cannot deploy process definition '" + processDefinition.getResourceName() + "': there already is a message event subscription for the message with name '" + eventDefinition.getEventName() + "'.");
}
}
MessageEventSubscriptionEntity newSubscription = new MessageEventSubscriptionEntity();
newSubscription.setEventName(eventDefinition.getEventName());
newSubscription.setActivityId(eventDefinition.getActivityId());
newSubscription.setConfiguration(processDefinition.getId());
newSubscription.setProcessDefinitionId(processDefinition.getId());
if (processDefinition.getTenantId() != null) {
newSubscription.setTenantId(processDefinition.getTenantId());
}
newSubscription.insert();
}
}
}
}
use of org.activiti.engine.ActivitiException in project Activiti by Activiti.
the class ExclusiveGatewayActivityBehavior method leave.
/**
* The default behaviour of BPMN, taking every outgoing sequence flow
* (where the condition evaluates to true), is not valid for an exclusive
* gateway.
*
* Hence, this behaviour is overriden and replaced by the correct behavior:
* selecting the first sequence flow which condition evaluates to true
* (or which hasn't got a condition) and leaving the activity through that
* sequence flow.
*
* If no sequence flow is selected (ie all conditions evaluate to false),
* then the default sequence flow is taken (if defined).
*/
@Override
protected void leave(ActivityExecution execution) {
if (log.isDebugEnabled()) {
log.debug("Leaving activity '{}'", execution.getActivity().getId());
}
PvmTransition outgoingSeqFlow = null;
String defaultSequenceFlow = (String) execution.getActivity().getProperty("default");
Iterator<PvmTransition> transitionIterator = execution.getActivity().getOutgoingTransitions().iterator();
while (outgoingSeqFlow == null && transitionIterator.hasNext()) {
PvmTransition seqFlow = transitionIterator.next();
Expression skipExpression = seqFlow.getSkipExpression();
if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpression)) {
Condition condition = (Condition) seqFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION);
if ((condition == null && (defaultSequenceFlow == null || !defaultSequenceFlow.equals(seqFlow.getId()))) || (condition != null && condition.evaluate(seqFlow.getId(), execution))) {
if (log.isDebugEnabled()) {
log.debug("Sequence flow '{}'selected as outgoing sequence flow.", seqFlow.getId());
}
outgoingSeqFlow = seqFlow;
}
} else if (SkipExpressionUtil.shouldSkipFlowElement(execution, skipExpression)) {
outgoingSeqFlow = seqFlow;
}
}
if (outgoingSeqFlow != null) {
execution.take(outgoingSeqFlow);
} else {
if (defaultSequenceFlow != null) {
PvmTransition defaultTransition = execution.getActivity().findOutgoingTransition(defaultSequenceFlow);
if (defaultTransition != null) {
execution.take(defaultTransition);
} else {
throw new ActivitiException("Default sequence flow '" + defaultSequenceFlow + "' not found");
}
} else {
//No sequence flow could be found, not even a default one
throw new ActivitiException("No outgoing sequence flow of the exclusive gateway '" + execution.getActivity().getId() + "' could be selected for continuing the process");
}
}
}
Aggregations