Skip to content

Commit

Permalink
Merge pull request #19 from rte-france/17_CardinalityErrors
Browse files Browse the repository at this point in the history
See #17: Cardinality errors are correctly catched forcing the rule association
  • Loading branch information
picaultj authored Apr 30, 2020
2 parents 091d75a + 7a14883 commit 2c427dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
20 changes: 14 additions & 6 deletions src/main/java/ocl/Validation.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,35 @@ private List<EvaluationResult> getErrors(Diagnostic diagnostics, HashMap<String,
level,
object.eClass().getName(),
(object.eClass().getEStructuralFeature("mRID") != null) ? String.valueOf(object.eGet(object.eClass().getEStructuralFeature("mRID"))) : null,
name
name, null
));
}
}
} else {
// it is for sure a problem of cardinality, we set it by default to IncorrectAttributeOrRoleCard,
// later on we check anyway if it exists in UMLRestrictionRules file
msg = childDiagnostic.getMessage();
matcher = pattern.matcher(msg);
while (matcher.find()) {
String ruleName = matcher.group(1);
if (!excludeRuleName(ruleName)) {
if(rules.get(ruleName)==null){
ruleName = "IncorrectAttributeOrRoleCard";
}
String severity = rules.get(ruleName) == null ? "UNKOWN" : rules.get(ruleName).getSeverity();
int level = rules.get(ruleName) == null ? 0 : rules.get(ruleName).getLevel();
results.add(new EvaluationResult(severity,
EvaluationResult evaluationResult = new EvaluationResult(severity,
ruleName,
level,
object.eClass().getName(),
(object.eClass().getEStructuralFeature("mRID") != null) ? String.valueOf(object.eGet(object.eClass().getEStructuralFeature("mRID"))) : null,
null
));
null, null
);
if(rules.get(ruleName)!=null){
evaluationResult.setSpecificMessage(matcher.group(1)+" of "+object.eClass().getName()+" is required.");
}
results.add(evaluationResult);

}
}
}
Expand Down Expand Up @@ -230,7 +240,6 @@ public static void main(String[] args) throws IOException, SAXException, ParserC
ZipEntry entry = entries.nextElement();
InputStream xmlStream = zip.getInputStream(entry);
List<EvaluationResult> res = validation.getErrors(validation.evaluate(xmlStream,entry.getName()), rules);

OutputStream zipout = Files.newOutputStream(Paths.get(file.getParentFile().getAbsolutePath() + File.separator +entry.getName().replace("xmi","json") +".zip"));
ZipOutputStream zipOutputStream = new ZipOutputStream(zipout);
String json = new Gson().toJson(res);
Expand All @@ -241,7 +250,6 @@ public static void main(String[] args) throws IOException, SAXException, ParserC
zipOutputStream.close();
file.delete();
res=null;

xmlStream.close();

}
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/ocl/util/EvaluationResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,28 @@ public void setLevel(Integer level) {
this.level = level;
}

public String getSpecificMessage(){return specificMessage;}

public void setSpecificMessage(String specificMessage){this.specificMessage=specificMessage;}

private String type;
private String id;
private String name;
private Integer level;
private String specificMessage;

public EvaluationResult(String severity, String rule, Integer level, String type, String id, String name) {
public EvaluationResult(String severity, String rule, Integer level, String type, String id, String name, String specificMessage) {
this.severity = severity;
this.rule = rule;
this.type = type;
this.id = id;
this.name = name;
this.level = level;
this.specificMessage=specificMessage;
}

public String toString(){
String s = String.format("%-40s %-5s: %-25s %-37s %-30s", this.rule, this.level, this.type, (id!=null)?id:"", (name!=null)?name:"");
String s = String.format("%-40s %-5s: %-25s %-37s %-30s %-40s", this.rule, this.level, this.type, (id!=null)?id:"", (name!=null)?name:"", (specificMessage!=null)?specificMessage:"");
return s;
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/ocl/util/XLSWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ else if (severity.equalsIgnoreCase("WARNING"))
String name = res.getName();
cell.setCellValue(name==null?"":name);
cell = row.createCell(colNum++);
String message = res.getName();

if (rules.get(infringedRule)==null)
cell.setCellValue("");
else
cell.setCellValue(rules.get(infringedRule).getMessage());
else {
String message = res.getSpecificMessage()!=null? rules.get(infringedRule).getMessage() + " " + res.getSpecificMessage():rules.get(infringedRule).getMessage() ;
cell.setCellValue(message);
}

}
sheet.setAutoFilter(new CellRangeAddress(0, 0, 0, colNum-1));
Expand Down

0 comments on commit 2c427dc

Please sign in to comment.