org.flowable.cmmn.model.CmmnModel Maven / Gradle / Ivy
The newest version!
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.flowable.cmmn.model;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
/**
* @author Joram Barrez
*/
public class CmmnModel {
protected String id;
protected String name;
protected String targetNamespace;
protected String expressionLanguage;
protected String exporter;
protected String exporterVersion;
protected String author;
protected Date creationDate;
protected Map> definitionsAttributes = new LinkedHashMap<>();
protected List cases = new ArrayList<>();
protected List processes = new ArrayList<>();
protected List decisions = new ArrayList<>();
protected List associations = new ArrayList<>();
protected List textAnnotations = new ArrayList<>();
protected Map criterionMap = new LinkedHashMap<>();
protected Map criterionTechnicalIdMap = new HashMap<>();
protected Map locationMap = new LinkedHashMap<>();
protected Map labelLocationMap = new LinkedHashMap<>();
protected Map> flowLocationMap = new LinkedHashMap<>();
protected Map edgeMap = new LinkedHashMap<>();
protected Map namespaceMap = new LinkedHashMap<>();
public void addCase(Case caze) {
cases.add(caze);
}
public Case getPrimaryCase() {
return cases.get(0);
}
public Case getCaseById(String id) {
for (Case caze : cases) {
if (id.equals(caze.getId())) {
return caze;
}
}
return null;
}
public void addProcess(Process process) {
processes.add(process);
}
public Process getProcessById(String id) {
for (Process process : processes) {
if (id.equals(process.getId())) {
return process;
}
}
return null;
}
public void addDecision(Decision decision) {
decisions.add(decision);
}
public Decision getDecisionById(String id) {
for (Decision decision : decisions) {
if (id.equals(decision.getId())) {
return decision;
}
}
return null;
}
public Collection getDecisions() {
return decisions;
}
public PlanItemDefinition findPlanItemDefinition(String id) {
PlanItemDefinition foundPlanItemDefinition = null;
for (Case caseModel : cases) {
foundPlanItemDefinition = caseModel.getPlanModel().findPlanItemDefinitionInStageOrUpwards(id);
if (foundPlanItemDefinition != null) {
break;
}
}
if (foundPlanItemDefinition == null) {
for (Case caseModel : cases) {
for (Stage stage : caseModel.getPlanModel().findPlanItemDefinitionsOfType(Stage.class, true)) {
foundPlanItemDefinition = stage.findPlanItemDefinitionInStageOrUpwards(id);
if (foundPlanItemDefinition != null) {
break;
}
}
if (foundPlanItemDefinition != null) {
break;
}
}
}
return foundPlanItemDefinition;
}
public PlanItem findPlanItem(String id) {
PlanItem foundPlanItem = null;
for (Case caseModel : cases) {
foundPlanItem = caseModel.getPlanModel().findPlanItemInPlanFragmentOrUpwards(id);
if (foundPlanItem != null) {
break;
}
}
if (foundPlanItem == null) {
for (Case caseModel : cases) {
for (Stage stage : caseModel.getPlanModel().findPlanItemDefinitionsOfType(Stage.class, true)) {
foundPlanItem = stage.findPlanItemInPlanFragmentOrUpwards(id);
if (foundPlanItem != null) {
break;
}
}
if (foundPlanItem != null) {
break;
}
}
}
return foundPlanItem;
}
public PlanItem findPlanItemByPlanItemDefinitionId(String id) {
PlanItem foundPlanItem = null;
for (Case caseModel : cases) {
foundPlanItem = caseModel.getPlanModel().findPlanItemForPlanItemDefinitionInPlanFragmentOrDownwards(id);
if (foundPlanItem != null) {
break;
}
}
if (foundPlanItem == null) {
for (Case caseModel : cases) {
for (Stage stage : caseModel.getPlanModel().findPlanItemDefinitionsOfType(Stage.class, true)) {
foundPlanItem = stage.findPlanItemForPlanItemDefinitionInPlanFragmentOrDownwards(id);
if (foundPlanItem != null) {
break;
}
}
if (foundPlanItem != null) {
break;
}
}
}
return foundPlanItem;
}
public void addAssociation(Association association) {
associations.add(association);
}
public TextAnnotation findTextAnnotation(String id) {
for (TextAnnotation textAnnotation : textAnnotations) {
if (id.equals(textAnnotation.getId())) {
return textAnnotation;
}
}
return null;
}
public void addTextAnnotation(TextAnnotation textAnnotation) {
textAnnotations.add(textAnnotation);
}
public void addCriterion(String key, Criterion criterion) {
criterionMap.put(key, criterion);
}
public Criterion getCriterion(String key) {
return criterionMap.get(key);
}
public void addCriterionTechnicalId(String technicalId, String id) {
criterionTechnicalIdMap.put(technicalId, id);
}
public String getCriterionId(String technicalId) {
return criterionTechnicalIdMap.get(technicalId);
}
public void addGraphicInfo(String key, GraphicInfo graphicInfo) {
locationMap.put(key, graphicInfo);
}
public GraphicInfo getGraphicInfo(String key) {
return locationMap.get(key);
}
public void removeGraphicInfo(String key) {
locationMap.remove(key);
}
public List getFlowLocationGraphicInfo(String key) {
return flowLocationMap.get(key);
}
public void removeFlowGraphicInfoList(String key) {
flowLocationMap.remove(key);
}
public Map getLocationMap() {
return locationMap;
}
public Map> getFlowLocationMap() {
return flowLocationMap;
}
public CmmnDiEdge getEdgeInfo(String key) {
return edgeMap.get(key);
}
public void addEdgeInfo(String key, CmmnDiEdge edgeInfo) {
edgeMap.put(key, edgeInfo);
}
public Map getEdgeMap() {
return edgeMap;
}
public GraphicInfo getLabelGraphicInfo(String key) {
return labelLocationMap.get(key);
}
public void addLabelGraphicInfo(String key, GraphicInfo graphicInfo) {
labelLocationMap.put(key, graphicInfo);
}
public void removeLabelGraphicInfo(String key) {
labelLocationMap.remove(key);
}
public Map getLabelLocationMap() {
return labelLocationMap;
}
public void addFlowGraphicInfoList(String key, List graphicInfoList) {
flowLocationMap.put(key, graphicInfoList);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTargetNamespace() {
return targetNamespace;
}
public void setTargetNamespace(String targetNamespace) {
this.targetNamespace = targetNamespace;
}
public String getExpressionLanguage() {
return expressionLanguage;
}
public void setExpressionLanguage(String expressionLanguage) {
this.expressionLanguage = expressionLanguage;
}
public String getExporter() {
return exporter;
}
public void setExporter(String exporter) {
this.exporter = exporter;
}
public String getExporterVersion() {
return exporterVersion;
}
public void setExporterVersion(String exporterVersion) {
this.exporterVersion = exporterVersion;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
public List getCases() {
return cases;
}
public void setCases(List cases) {
this.cases = cases;
}
public List getProcesses() {
return processes;
}
public void setProcesses(List processes) {
this.processes = processes;
}
public List getAssociations() {
return associations;
}
public void setAssociations(List associations) {
this.associations = associations;
}
public List getTextAnnotations() {
return textAnnotations;
}
public void setTextAnnotations(List textAnnotations) {
this.textAnnotations = textAnnotations;
}
public void addNamespace(String prefix, String uri) {
namespaceMap.put(prefix, uri);
}
public boolean containsNamespacePrefix(String prefix) {
return namespaceMap.containsKey(prefix);
}
public String getNamespace(String prefix) {
return namespaceMap.get(prefix);
}
public Map getNamespaces() {
return namespaceMap;
}
public Map> getDefinitionsAttributes() {
return definitionsAttributes;
}
public String getDefinitionsAttributeValue(String namespace, String name) {
List attributes = getDefinitionsAttributes().get(name);
if (attributes != null && !attributes.isEmpty()) {
for (ExtensionAttribute attribute : attributes) {
if (namespace.equals(attribute.getNamespace())) {
return attribute.getValue();
}
}
}
return null;
}
public void addDefinitionsAttribute(ExtensionAttribute attribute) {
if (attribute != null && StringUtils.isNotEmpty(attribute.getName())) {
List attributeList = null;
if (!this.definitionsAttributes.containsKey(attribute.getName())) {
attributeList = new ArrayList<>();
this.definitionsAttributes.put(attribute.getName(), attributeList);
}
this.definitionsAttributes.get(attribute.getName()).add(attribute);
}
}
public void setDefinitionsAttributes(Map> attributes) {
this.definitionsAttributes = attributes;
}
}