All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.viadee.bpm.vPAV.processing.code.flow.BpmnElement Maven / Gradle / Ivy

Go to download

The tool checks Camunda projects for consistency and discovers errors in process-driven applications. Called as a Maven plugin or JUnit test, it discovers esp. inconsistencies of a given BPMN model in the classpath and the sourcecode of an underlying java project, such as a delegate reference to a non-existing java class or a non-existing Spring bean.

There is a newer version: 3.0.8
Show newest version
/**
 * BSD 3-Clause License
 *
 * Copyright © 2019, viadee Unternehmensberatung AG
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice, this
 *   list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from
 *   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package de.viadee.bpm.vPAV.processing.code.flow;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import de.viadee.bpm.vPAV.processing.model.data.AnomalyContainer;
import de.viadee.bpm.vPAV.processing.model.data.InOutState;
import de.viadee.bpm.vPAV.processing.model.data.ProcessVariableOperation;
import org.camunda.bpm.model.bpmn.instance.BaseElement;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Represents an BPMN element
 *
 */
public class BpmnElement implements AnalysisElement {

	private String processDefinition;

	private BaseElement baseElement;

	private ControlFlowGraph controlFlowGraph;

	private LinkedHashMap operations;
	private LinkedHashMap defined;
	private LinkedHashMap used;
	private LinkedHashMap killed;
	private LinkedHashMap inUsed;
	private LinkedHashMap inUnused;
	private LinkedHashMap outUsed;
	private LinkedHashMap outUnused;

	private LinkedHashMap predecessors;
	private LinkedHashMap successors;

	private List sourceCodeAnomalies;

	public BpmnElement(final String processDefinition, final BaseElement element,
			final ControlFlowGraph controlFlowGraph) {
		this.processDefinition = processDefinition;
		this.baseElement = element;
		this.controlFlowGraph = controlFlowGraph;
		this.operations = new LinkedHashMap<>();

		this.predecessors = new LinkedHashMap<>();
		this.successors = new LinkedHashMap<>();

		this.operations = new LinkedHashMap<>();
		this.processVariables = ArrayListMultimap.create();
		this.defined = new LinkedHashMap<>();
		this.used = new LinkedHashMap<>();
		this.killed = new LinkedHashMap<>();
		this.inUsed = new LinkedHashMap<>();
		this.inUnused = new LinkedHashMap<>();
		this.outUsed = new LinkedHashMap<>();
		this.outUnused = new LinkedHashMap<>();

		this.sourceCodeAnomalies = new ArrayList<>();
	}

	/**
	 * Sets the process variables of this element
	 *
	 * @param variables
	 *            Collection of variables
	 */
	public void setProcessVariables(final ListMultimap variables) {
		variables.entries().forEach(e -> addOperation(e.getValue()));
		this.processVariables.putAll(variables);
	}

	/**
	 * Puts process variable operations into correct sets
	 *
	 * @param processVariableOperation
	 *            Current operation
	 */
	private void addOperation(final ProcessVariableOperation processVariableOperation) {
		this.operations.put(processVariableOperation.getId(), processVariableOperation);
		switch (processVariableOperation.getOperation()) {
		case WRITE:
			defined.put(processVariableOperation.getId(), processVariableOperation);
			break;
		case READ:
			used.put(processVariableOperation.getId(), processVariableOperation);
			break;
		case DELETE:
			killed.put(processVariableOperation.getId(), processVariableOperation);
			break;
		}
	}

	private Map in = new HashMap();

	private Map out = new HashMap();

	/* in interface for call activity */
	private Collection inCa;

	/* out interface for call activity */
	private Collection outCa;

	private ListMultimap processVariables;

	private List getSourceCodeAnomalies() {
		return sourceCodeAnomalies;
	}

	public String getProcessDefinition() {
		return processDefinition;
	}

	public ListMultimap getProcessVariables() {
		return processVariables;
	}

	public void setProcessVariable(final String variableName, final ProcessVariableOperation variableObject) {
		processVariables.put(variableName, variableObject);
	}

	public Map getIn() {
		return in;
	}

	public Map getOut() {
		return out;
	}

	public void setInCa(final Collection in) {
		this.inCa = in;
	}

	public void setOutCa(final Collection out) {
		this.outCa = out;
	}

	public Map> getAnomalies() {
		final Map> anomalyMap = new HashMap<>();
		anomalyMap.put(this, getSourceCodeAnomalies());
		return anomalyMap;
	}

	public BaseElement getBaseElement() {
		return baseElement;
	}

	public void addSourceCodeAnomaly(AnomalyContainer anomaly) {
		sourceCodeAnomalies.add(anomaly);
	}

	public ControlFlowGraph getControlFlowGraph() {
		return controlFlowGraph;
	}

	public LinkedHashMap getInUsed() {
		return inUsed;
	}

	public LinkedHashMap getInUnused() {
		return inUnused;
	}

	public LinkedHashMap getOutUsed() {
		return outUsed;
	}

	public LinkedHashMap getOutUnused() {
		return outUnused;
	}

	public void setInUsed(LinkedHashMap inUsedB) {
		this.inUsed = inUsedB;
	}

	public void setInUnused(LinkedHashMap inUnusedB) {
		this.inUnused = inUnusedB;
	}

	public void setOutUsed(LinkedHashMap outUsed) {
		this.outUsed = outUsed;
	}

	public void setOutUnused(LinkedHashMap outUnused) {
		this.outUnused = outUnused;
	}

	public LinkedHashMap getUsed() {
		return used;
	}

	public LinkedHashMap getKilled() {
		return killed;
	}

	public LinkedHashMap getDefined() {
		return defined;
	}

	@Override
	public void setDefined(LinkedHashMap defined) {
		this.defined = defined;
	}

	@Override
	public void addDefined(LinkedHashMap defined) {
		this.defined.putAll(defined);
	}

	@Override
	public String getId() {
		return this.getBaseElement().getId();
	}

	@Override
	public LinkedHashMap getOperations() {
		return operations;
	}

	@Override
	public void setPredecessors(LinkedHashMap predecessors) {
		this.predecessors = predecessors;
	}

	@Override
	public void addPredecessor(AnalysisElement predecessor) {
		this.predecessors.put(predecessor.getId(), predecessor);
	}

	@Override
	public List getPredecessors() {
		return this.predecessors.values().stream().map(BpmnElementDecorator::new).collect(Collectors.toList());
	}

	@Override
	public List getSuccessors() {
		return this.successors.values().stream().map(BpmnElementDecorator::new).collect(Collectors.toList());
	}

	@Override
	public void setSuccessors(LinkedHashMap successors) {
		this.successors = successors;
	}

	@Override
	public void addSuccessor(AnalysisElement successor) {
		this.successors.put(successor.getId(), successor);
	}

	@Override
	public void clearPredecessors() {
		this.predecessors.clear();
	}

	@Override
	public void removePredecessor(String predecessor) {
		this.predecessors.remove(predecessor);
	}

	@Override
	public int hashCode() {
		return baseElement.getId().hashCode();
	}

	@Override
	public boolean equals(Object o) {
		return o instanceof BpmnElement && this.hashCode() == o.hashCode();
	}

	@Override
	public String toString() {
		return baseElement.getId();
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy