use of com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class CustomVariableType method testLocalizeVariables.
@Deployment
public void testLocalizeVariables() {
// Start process instance with different types of variables
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("stringVar", "coca-cola");
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("localizeVariables", variables);
ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processInstance.getProcessDefinitionId());
dynamicBpmnService.changeLocalizationName("en-US", "stringVar", "stringVar 'en-US' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en-US", "stringVar", "stringVar 'en-US' Description", infoNode);
dynamicBpmnService.changeLocalizationName("en-AU", "stringVar", "stringVar 'en-AU' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en-AU", "stringVar", "stringVar 'en-AU' Description", infoNode);
dynamicBpmnService.changeLocalizationName("en", "stringVar", "stringVar 'en' Name", infoNode);
dynamicBpmnService.changeLocalizationDescription("en", "stringVar", "stringVar 'en' Description", infoNode);
dynamicBpmnService.saveProcessDefinitionInfo(processInstance.getProcessDefinitionId(), infoNode);
Map<String, VariableInstance> variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "es", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'es' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'es' Description", variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstances
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
List<String> variableNames = new ArrayList<String>();
variableNames.add("stringVar");
// getVariablesInstances via names
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstances(processInstance.getId(), variableNames, "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstancesLocal
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstancesLocal via names
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-US", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-US' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-AU", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en-AU' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-GB", true);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals("stringVar 'en' Name", variableInstances.get("stringVar").getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstances.get("stringVar").getLocalizedDescription());
variableInstances = runtimeService.getVariableInstancesLocal(processInstance.getId(), variableNames, "en-GB", false);
assertEquals(1, variableInstances.size());
assertEquals("stringVar", variableInstances.get("stringVar").getName());
assertEquals("coca-cola", variableInstances.get("stringVar").getValue());
assertEquals(null, variableInstances.get("stringVar").getLocalizedName());
assertEquals(null, variableInstances.get("stringVar").getLocalizedDescription());
// getVariableInstance
VariableInstance variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-US", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-US' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-AU", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-AU' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", true);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstance(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
// getVariableInstanceLocal
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-US", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-US' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-US' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-AU", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en-AU' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en-AU' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-GB", true);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals("stringVar 'en' Name", variableInstance.getLocalizedName());
assertEquals("stringVar 'en' Description", variableInstance.getLocalizedDescription());
variableInstance = runtimeService.getVariableInstanceLocal(processInstance.getId(), "stringVar", "en-GB", false);
assertNotNull(variableInstance);
assertEquals("stringVar", variableInstance.getName());
assertEquals("coca-cola", variableInstance.getValue());
assertEquals(null, variableInstance.getLocalizedName());
assertEquals(null, variableInstance.getLocalizedDescription());
}
use of com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class ScriptTaskTest method testDynamicScript.
@Deployment
public void testDynamicScript() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("a", 20, "b", 22));
assertEquals(42.0, runtimeService.getVariable(processInstance.getId(), "test"));
taskService.complete(taskService.createTaskQuery().singleResult().getId());
assertProcessEnded(processInstance.getId());
String processDefinitionId = processInstance.getProcessDefinitionId();
ObjectNode infoNode = dynamicBpmnService.changeScriptTaskScript("script1", "var sum = c + d;\nexecution.setVariable('test2', sum);");
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
processInstance = runtimeService.startProcessInstanceByKey("testDynamicScript", CollectionUtil.map("c", 10, "d", 12));
assertEquals(22.0, runtimeService.getVariable(processInstance.getId(), "test2"));
taskService.complete(taskService.createTaskQuery().singleResult().getId());
assertProcessEnded(processInstance.getId());
}
use of com.fasterxml.jackson.databind.node.ObjectNode 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 com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class DynamicBpmnServiceImpl method setElementProperty.
protected void setElementProperty(String id, String propertyName, JsonNode propertyValue, ObjectNode infoNode) {
ObjectNode bpmnNode = createOrGetBpmnNode(infoNode);
if (bpmnNode.has(id) == false) {
bpmnNode.put(id, processEngineConfiguration.getObjectMapper().createObjectNode());
}
((ObjectNode) bpmnNode.get(id)).put(propertyName, propertyValue);
}
use of com.fasterxml.jackson.databind.node.ObjectNode in project Activiti by Activiti.
the class DynamicBpmnServiceImpl method changeUserTaskFormKey.
public ObjectNode changeUserTaskFormKey(String id, String formKey) {
ObjectNode infoNode = processEngineConfiguration.getObjectMapper().createObjectNode();
changeUserTaskFormKey(id, formKey, infoNode);
return infoNode;
}
Aggregations