Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #183 from viadee/issue179
Browse files Browse the repository at this point in the history
Resolved issue #179
  • Loading branch information
sdibernardo authored Jul 30, 2020
2 parents 846f4c6 + 633569f commit f19c935
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 36 deletions.
3 changes: 1 addition & 2 deletions src/main/java/de/viadee/bpm/vPAV/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,8 @@ public class Runner {
/**
* Main method which represents lifecycle of the validation process. Calls main
* functions
*
*/
public void viadeeProcessApplicationValidator() {

// 1
rules = readConfig();

Expand Down Expand Up @@ -582,6 +580,7 @@ public FileScanner getFileScanner() {

public void setFileScanner(FileScanner fileScanner) {
this.fileScanner = fileScanner;
RuntimeConfig.getInstance().setFileScanner(fileScanner);
}

public Map<String, String> getWrongCheckersMap() {
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/de/viadee/bpm/vPAV/RuntimeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,18 @@
*/
package de.viadee.bpm.vPAV;

import de.viadee.bpm.vPAV.config.model.RuleSet;
import de.viadee.bpm.vPAV.constants.ConfigConstants;
import org.springframework.context.ApplicationContext;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.*;
import java.util.logging.Logger;
import java.util.stream.Stream;

import org.springframework.context.ApplicationContext;

import de.viadee.bpm.vPAV.config.model.RuleSet;
import de.viadee.bpm.vPAV.constants.ConfigConstants;

public class RuntimeConfig {

private static RuntimeConfig instance;
Expand All @@ -62,6 +57,8 @@ public class RuntimeConfig {

private ResourceBundle resourceBundle;

private FileScanner fileScanner;

private boolean test = false;

private static Logger LOGGER = Logger.getLogger(RuntimeConfig.class.getName());
Expand Down Expand Up @@ -211,4 +208,12 @@ private void setResourceBundle(ResourceBundle resourceBundle) {
this.resourceBundle = resourceBundle;
}

public FileScanner getFileScanner() {
return fileScanner;
}

public void setFileScanner(FileScanner fileScanner) {
this.fileScanner = fileScanner;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;

/**
* Checks, whether a business rule task with dmn implementation is valid
*
*/
public class DmnTaskChecker extends AbstractElementChecker {

Expand Down Expand Up @@ -82,6 +82,7 @@ public Collection<CheckerIssue> check(final BpmnElement element) {
String.format(Messages.getString("DmnTaskChecker.0"), //$NON-NLS-1$
CheckName.checkName(bpmnElement))));
} else {

issues.addAll(checkDMNFile(element, implementation.getValue()));
}
}
Expand All @@ -93,10 +94,8 @@ public Collection<CheckerIssue> check(final BpmnElement element) {
/**
* Check if the referenced DMN in a BusinessRuleTask exists
*
* @param element
* BpmnElement
* @param dmnName
* Name of DMN-File
* @param element BpmnElement
* @param dmnName Name of DMN-File
* @return issues
*/
private Collection<CheckerIssue> checkDMNFile(final BpmnElement element, final String dmnName) {
Expand All @@ -107,6 +106,17 @@ private Collection<CheckerIssue> checkDMNFile(final BpmnElement element, final S

// If a dmn path has been found, check the correctness
URL urlDMN = RuntimeConfig.getInstance().getClassLoader().getResource(dmnPath);
if (urlDMN == null) {
// Trying to retrieve the dmn filename by dmn id if the native reference doesn't result in a match
if (RuntimeConfig.getInstance().getFileScanner().getDecisionRefToPathMap().containsKey(dmnName)) {
String dmnFileName = RuntimeConfig.getInstance()
.getFileScanner().getDecisionRefToPathMap().get(dmnName);
//Set new dmn url if retrieval by dmn id was successfull
if (dmnFileName != null) {
urlDMN = RuntimeConfig.getInstance().getClassLoader().getResource(dmnFileName);
}
}
}

if (urlDMN == null) {
// Throws an error, if the class was not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
*/
package de.viadee.bpm.vPAV.processing.checker;

import de.viadee.bpm.vPAV.FileScanner;
import de.viadee.bpm.vPAV.IssueService;
import de.viadee.bpm.vPAV.Runner;
import de.viadee.bpm.vPAV.RuntimeConfig;
import de.viadee.bpm.vPAV.config.model.Rule;
import de.viadee.bpm.vPAV.config.model.RuleSet;
import de.viadee.bpm.vPAV.config.reader.ConfigReaderException;
import de.viadee.bpm.vPAV.config.reader.XmlConfigReader;
import de.viadee.bpm.vPAV.processing.CheckName;
import de.viadee.bpm.vPAV.processing.code.flow.BpmnElement;
import de.viadee.bpm.vPAV.processing.code.flow.ControlFlowGraph;
Expand Down Expand Up @@ -75,6 +80,7 @@ public static void setup() throws MalformedURLException {
ClassLoader cl = new URLClassLoader(classUrls);
RuntimeConfig.getInstance().setClassLoader(cl);
RuntimeConfig.getInstance().getResource("en_US");
RuntimeConfig.getInstance().setTest(true);
}

/**
Expand Down Expand Up @@ -104,11 +110,16 @@ public void testCorrectDMN() {

/**
* Case: DMN task with wrong DMN-File
*
*/

@Test
public void testDMNTaskWithWrongDMN() {
public void testDMNTaskWithWrongDMN() throws ConfigReaderException {
// Load rule set.
XmlConfigReader reader = new XmlConfigReader();
RuleSet rules = reader.read("ruleSets/ruleSetChild.xml");

FileScanner fileScanner = new FileScanner(rules);
RuntimeConfig.getInstance().setFileScanner(fileScanner);
final String PATH = BASE_PATH + "DmnTaskCheckerTest_wrongDMNReference.bpmn";
checker = new DmnTaskChecker(rule);

Expand All @@ -135,11 +146,16 @@ public void testDMNTaskWithWrongDMN() {

/**
* Case: read referenced DMN
*
*/

@Test
public void testReadReferencedDMNFile() {
public void testReadReferencedDMNFile() throws ConfigReaderException {
// Load rule set.
XmlConfigReader reader = new XmlConfigReader();
RuleSet rules = reader.read("ruleSets/ruleSetChild.xml");

FileScanner fileScanner = new FileScanner(rules);
RuntimeConfig.getInstance().setFileScanner(fileScanner);
final String PATH = BASE_PATH + "DmnTaskCheckerTest_ReadReferencedDMN.bpmn";
checker = new DmnTaskChecker(rule);

Expand Down
30 changes: 15 additions & 15 deletions src/test/resources/DmnTaskCheckerTest_ReadReferencedDMN.bpmn
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.8.0">
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.1.1">
<bpmn:process id="Process_1" isExecutable="false">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1m3rdh2</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:sequenceFlow id="SequenceFlow_1m3rdh2" sourceRef="StartEvent_1" targetRef="Task_00f37fo" />
<bpmn:businessRuleTask id="Task_00f37fo" camunda:decisionRef="table">
<bpmn:businessRuleTask id="Task_00f37fo" camunda:decisionRef="definitions">
<bpmn:incoming>SequenceFlow_1m3rdh2</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0nvw4dw</bpmn:outgoing>
</bpmn:businessRuleTask>
Expand All @@ -16,16 +16,23 @@
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0nvw4dw_di" bpmnElement="SequenceFlow_0nvw4dw">
<di:waypoint x="440" y="120" />
<di:waypoint x="585" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="512.5" y="99" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_1m3rdh2_di" bpmnElement="SequenceFlow_1m3rdh2">
<di:waypoint xsi:type="dc:Point" x="209" y="120" />
<di:waypoint xsi:type="dc:Point" x="340" y="120" />
<di:waypoint x="209" y="120" />
<di:waypoint x="340" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="274.5" y="99" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="173" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="BusinessRuleTask_1fidosk_di" bpmnElement="Task_00f37fo">
<dc:Bounds x="340" y="80" width="100" height="80" />
</bpmndi:BPMNShape>
Expand All @@ -35,13 +42,6 @@
<dc:Bounds x="603" y="142" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_0nvw4dw_di" bpmnElement="SequenceFlow_0nvw4dw">
<di:waypoint xsi:type="dc:Point" x="440" y="120" />
<di:waypoint xsi:type="dc:Point" x="585" y="120" />
<bpmndi:BPMNLabel>
<dc:Bounds x="512.5" y="99" width="0" height="12" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>

0 comments on commit f19c935

Please sign in to comment.