use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class TerminateEndEventTest method testParseTerminateEndEventDefinitionWithExtensions.
public void testParseTerminateEndEventDefinitionWithExtensions() {
org.activiti.engine.repository.Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.parseExtensionElements.bpmn20.xml").deploy();
ProcessDefinition processDefinitionQuery = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
BpmnModel bpmnModel = this.processEngineConfiguration.getProcessDefinitionCache().get(processDefinitionQuery.getId()).getBpmnModel();
Map<String, List<ExtensionElement>> extensionElements = bpmnModel.getProcesses().get(0).findFlowElementsOfType(EndEvent.class).get(0).getExtensionElements();
assertThat(extensionElements).hasSize(1);
List<ExtensionElement> strangeProperties = extensionElements.get("strangeProperty");
assertThat(strangeProperties).hasSize(1);
ExtensionElement strangeProperty = strangeProperties.get(0);
assertThat(strangeProperty.getNamespace()).isEqualTo("http://activiti.org/bpmn");
assertThat(strangeProperty.getElementText()).isEqualTo("value");
assertThat(strangeProperty.getAttributes()).hasSize(1);
ExtensionAttribute id = strangeProperty.getAttributes().get("id").get(0);
assertThat(id.getName()).isEqualTo("id");
assertThat(id.getValue()).isEqualTo("strangeId");
repositoryService.deleteDeployment(deployment.getId());
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BaseBpmnXMLConverter method parseExtensionElement.
@SuppressWarnings("unchecked")
protected ExtensionElement parseExtensionElement(XMLStreamReader xtr) throws Exception {
ExtensionElement extensionElement = new ExtensionElement();
extensionElement.setName(xtr.getLocalName());
if (StringUtils.isNotEmpty(xtr.getNamespaceURI())) {
extensionElement.setNamespace(xtr.getNamespaceURI());
}
if (StringUtils.isNotEmpty(xtr.getPrefix())) {
extensionElement.setNamespacePrefix(xtr.getPrefix());
}
BpmnXMLUtil.addCustomAttributes(xtr, extensionElement, defaultElementAttributes);
boolean readyWithExtensionElement = false;
while (!readyWithExtensionElement && xtr.hasNext()) {
xtr.next();
if (xtr.isCharacters() || XMLStreamReader.CDATA == xtr.getEventType()) {
if (StringUtils.isNotEmpty(xtr.getText().trim())) {
extensionElement.setElementText(xtr.getText().trim());
}
} else if (xtr.isStartElement()) {
ExtensionElement childExtensionElement = parseExtensionElement(xtr);
extensionElement.addChildElement(childExtensionElement);
} else if (xtr.isEndElement() && extensionElement.getName().equalsIgnoreCase(xtr.getLocalName())) {
readyWithExtensionElement = true;
}
}
return extensionElement;
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class CustomSequenceFlowBpmnParseHandler method executeParse.
protected void executeParse(BpmnParse bpmnParse, SequenceFlow flow) {
// Do the regular stuff
super.executeParse(bpmnParse, flow);
// Add extension element conditions
Map<String, List<ExtensionElement>> extensionElements = flow.getExtensionElements();
if (extensionElements.containsKey("activiti_custom_condition")) {
List<ExtensionElement> conditionsElements = extensionElements.get("activiti_custom_condition");
CustomSetConditionsExecutionListener customFlowListener = new CustomSetConditionsExecutionListener();
customFlowListener.setFlowId(flow.getId());
for (ExtensionElement conditionElement : conditionsElements) {
customFlowListener.addCondition(conditionElement.getElementText());
}
ActivitiListener activitiListener = new ActivitiListener();
activitiListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_INSTANCE);
activitiListener.setInstance(customFlowListener);
activitiListener.setEvent("start");
flow.getSourceFlowElement().getExecutionListeners().add(activitiListener);
}
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class BpmnDeployer method createLocalizationValues.
protected void createLocalizationValues(String processDefinitionId, Process process) {
if (process == null) {
return;
}
CommandContext commandContext = Context.getCommandContext();
DynamicBpmnService dynamicBpmnService = commandContext.getProcessEngineConfiguration().getDynamicBpmnService();
ObjectNode infoNode = dynamicBpmnService.getProcessDefinitionInfo(processDefinitionId);
boolean localizationValuesChanged = false;
List<ExtensionElement> localizationElements = process.getExtensionElements().get("localization");
if (localizationElements != null) {
for (ExtensionElement localizationElement : localizationElements) {
if (BpmnXMLConstants.ACTIVITI_EXTENSIONS_PREFIX.equals(localizationElement.getNamespacePrefix())) {
String locale = localizationElement.getAttributeValue(null, "locale");
String name = localizationElement.getAttributeValue(null, "name");
String documentation = null;
List<ExtensionElement> documentationElements = localizationElement.getChildElements().get("documentation");
if (documentationElements != null) {
for (ExtensionElement documentationElement : documentationElements) {
documentation = StringUtils.trimToNull(documentationElement.getElementText());
break;
}
}
String processId = process.getId();
if (!isEqualToCurrentLocalizationValue(locale, processId, "name", name, infoNode)) {
dynamicBpmnService.changeLocalizationName(locale, processId, name, infoNode);
localizationValuesChanged = true;
}
if (documentation != null && !isEqualToCurrentLocalizationValue(locale, processId, "description", documentation, infoNode)) {
dynamicBpmnService.changeLocalizationDescription(locale, processId, documentation, infoNode);
localizationValuesChanged = true;
}
break;
}
}
}
boolean isFlowElementLocalizationChanged = localizeFlowElements(process.getFlowElements(), infoNode);
boolean isDataObjectLocalizationChanged = localizeDataObjectElements(process.getDataObjects(), infoNode);
if (isFlowElementLocalizationChanged || isDataObjectLocalizationChanged) {
localizationValuesChanged = true;
}
if (localizationValuesChanged) {
dynamicBpmnService.saveProcessDefinitionInfo(processDefinitionId, infoNode);
}
}
use of org.activiti.bpmn.model.ExtensionElement in project Activiti by Activiti.
the class UserTaskJsonConverter method convertElementToJson.
@Override
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
UserTask userTask = (UserTask) baseElement;
String assignee = userTask.getAssignee();
if (StringUtils.isNotEmpty(assignee) || CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) || CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
ObjectNode assignmentNode = objectMapper.createObjectNode();
ObjectNode assignmentValuesNode = objectMapper.createObjectNode();
List<ExtensionElement> idmAssigneeList = userTask.getExtensionElements().get("activiti-idm-assignee");
List<ExtensionElement> idmAssigneeFieldList = userTask.getExtensionElements().get("activiti-idm-assignee-field");
if (CollectionUtils.isNotEmpty(idmAssigneeList) || CollectionUtils.isNotEmpty(idmAssigneeFieldList) || CollectionUtils.isNotEmpty(userTask.getExtensionElements().get("activiti-idm-candidate-user")) || CollectionUtils.isNotEmpty(userTask.getExtensionElements().get("activiti-idm-candidate-group"))) {
assignmentValuesNode.put("type", "idm");
ObjectNode idmNode = objectMapper.createObjectNode();
assignmentValuesNode.set("idm", idmNode);
List<ExtensionElement> canCompleteList = userTask.getExtensionElements().get("initiator-can-complete");
if (CollectionUtils.isNotEmpty(canCompleteList)) {
assignmentValuesNode.put("initiatorCanCompleteTask", Boolean.valueOf(canCompleteList.get(0).getElementText()));
}
if (StringUtils.isNotEmpty(userTask.getAssignee())) {
ObjectNode assigneeNode = objectMapper.createObjectNode();
if (userTask.getAssignee().contains("${taskAssignmentBean.assignTaskToAssignee(")) {
idmNode.set("assigneeField", assigneeNode);
idmNode.put("type", "user");
fillProperty("id", "activiti-idm-assignee-field", assigneeNode, userTask);
fillProperty("name", "assignee-field-info-name", assigneeNode, userTask);
} else {
assigneeNode.put("id", userTask.getAssignee());
idmNode.set("assignee", assigneeNode);
idmNode.put("type", "user");
fillProperty("externalId", "assignee-info-externalid", assigneeNode, userTask);
fillProperty("email", "assignee-info-email", assigneeNode, userTask);
fillProperty("firstName", "assignee-info-firstname", assigneeNode, userTask);
fillProperty("lastName", "assignee-info-lastname", assigneeNode, userTask);
}
}
List<ExtensionElement> idmCandidateUserList = userTask.getExtensionElements().get("activiti-idm-candidate-user");
if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers()) && CollectionUtils.isNotEmpty(idmCandidateUserList)) {
List<String> candidateUserIds = new ArrayList<String>();
if (userTask.getCandidateUsers().size() == 1 && userTask.getCandidateUsers().get(0).contains("${taskAssignmentBean.assignTaskToCandidateUsers(")) {
idmNode.put("type", "users");
String candidateUsersString = userTask.getCandidateUsers().get(0);
candidateUsersString = candidateUsersString.replace("${taskAssignmentBean.assignTaskToCandidateUsers('", "");
candidateUsersString = candidateUsersString.replace("', execution)}", "");
List<String> candidateFieldIds = new ArrayList<String>();
String[] candidateUserArray = candidateUsersString.split(",");
for (String candidate : candidateUserArray) {
if (candidate.contains("field(")) {
candidateFieldIds.add(candidate.trim().substring(6, candidate.length() - 1));
} else {
candidateUserIds.add(candidate.trim());
}
}
if (candidateFieldIds.size() > 0) {
ArrayNode candidateUserFieldsNode = objectMapper.createArrayNode();
idmNode.set("candidateUserFields", candidateUserFieldsNode);
for (String fieldId : candidateFieldIds) {
ObjectNode fieldNode = objectMapper.createObjectNode();
fieldNode.put("id", fieldId);
candidateUserFieldsNode.add(fieldNode);
fillProperty("name", "user-field-info-name-" + fieldId, fieldNode, userTask);
}
}
} else {
for (String candidateUser : userTask.getCandidateUsers()) {
candidateUserIds.add(candidateUser);
}
}
if (candidateUserIds.size() > 0) {
ArrayNode candidateUsersNode = objectMapper.createArrayNode();
idmNode.set("candidateUsers", candidateUsersNode);
idmNode.put("type", "users");
for (String candidateUser : candidateUserIds) {
ObjectNode candidateUserNode = objectMapper.createObjectNode();
candidateUserNode.put("id", candidateUser);
candidateUsersNode.add(candidateUserNode);
fillProperty("externalId", "user-info-externalid-" + candidateUser, candidateUserNode, userTask);
fillProperty("email", "user-info-email-" + candidateUser, candidateUserNode, userTask);
fillProperty("firstName", "user-info-firstname-" + candidateUser, candidateUserNode, userTask);
fillProperty("lastName", "user-info-lastname-" + candidateUser, candidateUserNode, userTask);
}
}
}
List<ExtensionElement> idmCandidateGroupList = userTask.getExtensionElements().get("activiti-idm-candidate-group");
if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups()) && CollectionUtils.isNotEmpty(idmCandidateGroupList)) {
List<String> candidateGroupIds = new ArrayList<String>();
if (userTask.getCandidateGroups().size() == 1 && userTask.getCandidateGroups().get(0).contains("${taskAssignmentBean.assignTaskToCandidateGroups(")) {
idmNode.put("type", "groups");
String candidateGroupsString = userTask.getCandidateGroups().get(0);
candidateGroupsString = candidateGroupsString.replace("${taskAssignmentBean.assignTaskToCandidateGroups('", "");
candidateGroupsString = candidateGroupsString.replace("', execution)}", "");
List<String> candidateFieldIds = new ArrayList<String>();
String[] candidateGroupArray = candidateGroupsString.split(",");
for (String candidate : candidateGroupArray) {
if (candidate.contains("field(")) {
candidateFieldIds.add(candidate.trim().substring(6, candidate.length() - 1));
} else {
candidateGroupIds.add(candidate.trim());
}
}
if (candidateFieldIds.size() > 0) {
ArrayNode candidateGroupFieldsNode = objectMapper.createArrayNode();
idmNode.set("candidateGroupFields", candidateGroupFieldsNode);
for (String fieldId : candidateFieldIds) {
ObjectNode fieldNode = objectMapper.createObjectNode();
fieldNode.put("id", fieldId);
candidateGroupFieldsNode.add(fieldNode);
fillProperty("name", "group-field-info-name-" + fieldId, fieldNode, userTask);
}
}
} else {
for (String candidateGroup : userTask.getCandidateGroups()) {
candidateGroupIds.add(candidateGroup);
}
}
if (candidateGroupIds.size() > 0) {
ArrayNode candidateGroupsNode = objectMapper.createArrayNode();
idmNode.set("candidateGroups", candidateGroupsNode);
idmNode.put("type", "groups");
for (String candidateGroup : candidateGroupIds) {
ObjectNode candidateGroupNode = objectMapper.createObjectNode();
candidateGroupNode.put("id", candidateGroup);
candidateGroupsNode.add(candidateGroupNode);
fillProperty("externalId", "group-info-externalid-" + candidateGroup, candidateGroupNode, userTask);
fillProperty("name", "group-info-name-" + candidateGroup, candidateGroupNode, userTask);
}
}
}
} else {
assignmentValuesNode.put("type", "static");
if (StringUtils.isNotEmpty(assignee)) {
assignmentValuesNode.put(PROPERTY_USERTASK_ASSIGNEE, assignee);
}
if (CollectionUtils.isNotEmpty(userTask.getCandidateUsers())) {
ArrayNode candidateArrayNode = objectMapper.createArrayNode();
for (String candidateUser : userTask.getCandidateUsers()) {
ObjectNode candidateNode = objectMapper.createObjectNode();
candidateNode.put("value", candidateUser);
candidateArrayNode.add(candidateNode);
}
assignmentValuesNode.set(PROPERTY_USERTASK_CANDIDATE_USERS, candidateArrayNode);
}
if (CollectionUtils.isNotEmpty(userTask.getCandidateGroups())) {
ArrayNode candidateArrayNode = objectMapper.createArrayNode();
for (String candidateGroup : userTask.getCandidateGroups()) {
ObjectNode candidateNode = objectMapper.createObjectNode();
candidateNode.put("value", candidateGroup);
candidateArrayNode.add(candidateNode);
}
assignmentValuesNode.set(PROPERTY_USERTASK_CANDIDATE_GROUPS, candidateArrayNode);
}
}
assignmentNode.set("assignment", assignmentValuesNode);
propertiesNode.set(PROPERTY_USERTASK_ASSIGNMENT, assignmentNode);
}
if (userTask.getPriority() != null) {
setPropertyValue(PROPERTY_USERTASK_PRIORITY, userTask.getPriority().toString(), propertiesNode);
}
if (StringUtils.isNotEmpty(userTask.getFormKey())) {
if (formKeyMap != null && formKeyMap.containsKey(userTask.getFormKey())) {
ObjectNode formRefNode = objectMapper.createObjectNode();
ModelInfo modelInfo = formKeyMap.get(userTask.getFormKey());
formRefNode.put("id", modelInfo.getId());
formRefNode.put("name", modelInfo.getName());
formRefNode.put("key", modelInfo.getKey());
propertiesNode.set(PROPERTY_FORM_REFERENCE, formRefNode);
} else {
setPropertyValue(PROPERTY_FORMKEY, userTask.getFormKey(), propertiesNode);
}
}
setPropertyValue(PROPERTY_USERTASK_DUEDATE, userTask.getDueDate(), propertiesNode);
setPropertyValue(PROPERTY_USERTASK_CATEGORY, userTask.getCategory(), propertiesNode);
addFormProperties(userTask.getFormProperties(), propertiesNode);
}
Aggregations