Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 52705958 authored by Achraf Achkari's avatar Achraf Achkari
Browse files

Fix Datatype issue with IPS

parent 921915da
No related branches found
No related tags found
2 merge requests!2Release GOC,!1Release GOC
package net.ihe.gazelle.goc.scripts;
import net.ihe.gazelle.goc.umlmodel.model.ModelUMLDesc;
import net.ihe.gazelle.goc.umlmodel.model.ModelsDefinition;
import net.ihe.gazelle.model.CdaepsosModelRetriever;
import org.apache.commons.io.FileUtils;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import java.io.*;
import java.net.URL;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CreateResourcesForTestEpsos {
public static void main(String[] args) throws IOException{
Properties properties = new Properties();
InputStream inputStream = CreateResourcesForTestEpsos.class.getResourceAsStream("/env.properties");
properties.load(inputStream);
String workspacePath = properties.getProperty("TEMP_TESTS_WORKSPACE");
System.out.println("Creating resources for tests...");
CdaepsosModelRetriever modelRetriever = new CdaepsosModelRetriever();
Map<String, URL> resources = modelRetriever.retrieveResources();
Map<String, URL> models = modelRetriever.retrieveModels();
Map<String, URL> profiles = modelRetriever.retrieveUMLProfiles();
ModelsDefinition modelsDefinition;
try {
modelsDefinition = getModelsDefinitionFromResources(resources);
} catch (JAXBException e){
throw new IOException(e);
}
for (ModelUMLDesc modelDescription : modelsDefinition.getUMLModelsDescription().getModelUMLDesc()) {
String modelPath = modelDescription.getRelativeXMIPath().replace("../", "");
String subModelName = modelPath.substring(modelPath.lastIndexOf("/")+1);
String folderName = modelPath.substring(0, modelPath.lastIndexOf("/"));
createFolder(workspacePath + "/" + folderName);
if (models.get(subModelName) == null) {
throw new IOException("Didn't found model in resources : " + subModelName);
}
writeContentInFile(models.get(subModelName), workspacePath + "/" + modelPath);
}
createFolder(new File(workspacePath) + "/hl7templates-resources/cdaepsos");
for (String key : resources.keySet()) {
writeContentInFile(resources.get(key), new File(workspacePath) + "/hl7templates-resources/cdaepsos" + "/" + key);
}
createFolder(new File(workspacePath) + "/hl7templates-resources/uml/profiles");
for (String key : profiles.keySet()) {
writeContentInFile(profiles.get(key), new File(workspacePath) + "/hl7templates-resources/uml/profiles" + "/" + key);
}
String pathResources = workspacePath + "/hl7templates-resources" + File.separator + "cdaepsos/modelsDefinition.xml";
try {
String content = readDoc(pathResources);
String folderOutputformatted = workspacePath.endsWith("/")?workspacePath.substring(0, workspacePath.length()-1):workspacePath;
String replaceBy = updateWorkspacePath(content, folderOutputformatted);
printDoc(replaceBy, pathResources);
} catch (IOException e) {
throw e;
}
String source = workspacePath + "/hl7templates-resources";
File srcDir = new File(source);
String destination = workspacePath + "hl7templates/hl7templates-resources";
File destDir = new File(destination);
try {
FileUtils.copyDirectory(srcDir, destDir);
} catch (IOException e) {
e.printStackTrace();
}
}
private static ModelsDefinition getModelsDefinitionFromResources(Map<String, URL> resources) throws JAXBException {
ModelsDefinition modelsDefinition;
JAXBContext jxb = JAXBContext.newInstance(ModelsDefinition.class);
Unmarshaller um = jxb.createUnmarshaller();
modelsDefinition = (ModelsDefinition) um.unmarshal(resources.get("modelsDefinition.xml"));
return modelsDefinition;
}
private static void createFolder(String folderToCreatePath) throws IOException {
File folderToCreate = new File(folderToCreatePath);
if (folderToCreate.exists()){
System.out.println("Folder " + folderToCreate.getAbsolutePath() + " already exists.");
} else if (!folderToCreate.mkdirs()){
throw new IOException("Cannot create folder " + folderToCreate.getAbsolutePath());
}
}
private static void writeContentInFile(URL resourceURL, String fileOutputPath) throws IOException{
try (InputStream resourceInputStream = resourceURL.openStream()) {
if (resourceInputStream == null) {
throw new IOException("Didn't found resource : " + resourceURL);
}
byte[] buffer = new byte[resourceInputStream.available()];
File fileOutput = new File(fileOutputPath);
try (OutputStream outStream = new FileOutputStream(fileOutput)){
while (true) {
final int length = resourceInputStream.read(buffer);
if (length <= 0) {
break;
}
outStream.write(buffer, 0, length);
}
}
}
}
public static String readDoc(String name) throws IOException {
BufferedReader scanner = new BufferedReader(new FileReader(name));
StringBuilder res = new StringBuilder();
try {
String line = scanner.readLine();
while (line != null) {
res.append(line + "\n");
line = scanner.readLine();
}
} finally {
scanner.close();
}
return res.toString();
}
public static void printDoc(String doc, String name) throws IOException {
try (FileWriter fw = new FileWriter(new File(name))){
fw.append(doc);
fw.close();
}
}
private static String updateWorkspacePath(String modelsDefinitionContent, String workspacePath) throws IOException{
if (modelsDefinitionContent != null) {
String regex = "<path>(.*?)</path>";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(modelsDefinitionContent);
String tobeReplaced = "";
if(matcher.find()) {
String stringUMLPath = matcher.group(1);
tobeReplaced = extractWorkspace(stringUMLPath);
}
return modelsDefinitionContent.replace(tobeReplaced, workspacePath);
}
return null;
}
private static String extractWorkspace(String modelPath) throws IOException{
String[] paths = modelPath.split("/");
for (String path : paths) {
if (path.contains("-model")) {
return modelPath.substring(0, modelPath.indexOf(path)-1);
}
}
throw new IOException("ModelDefinition does not define correct path to a model : " + modelPath);
}
}
......@@ -46,7 +46,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8 -DHL7TEMP_RESOURCES_PATH=../hl7templates-resources/</argLine>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
<dependencies>
<dependency>
......
......@@ -155,18 +155,7 @@ public class AssertAnalyzer extends AssertProcessorImpl {
OwnedRule ownedRule = OwnedRuleUtil.initOwnedRule();
ownedRule.setConstrainedElement(this.currentPackagedElement.getId());
//Specific OCL of SEQUOIA's OCL (disabled so far, till fixing assertions issue)
String specification = this.generateOCLConstraint();
// if(this.currentAssert != null && this.currentAssert.getParentObject() != null
// && this.currentAssert.getParentObject() instanceof RuleDefinition
// && ((RuleDefinition)this.currentAssert.getParentObject()).getItem() != null
// && ((RuleDefinition) this.currentAssert.getParentObject()).getItem().getLabel().equals("CONF:1198-30804")) {
// specification = "self.value->forAll(not oclIsKindOf(CD)) or self.value->forAll(aa | CommonOperationsStatic::validateByXPATHV2(aa, '@codeSystem=\\u00272.16.840.1.113883.6.96\\u0027') )";
// System.out.println("SPEC: "+specification);
// }
// else{
// specification = this.generateOCLConstraint();
// }
String comment = this.generateCommentConstraint();
ownedRule.getSpecification().setBody(specification);
ownedRule.getOwnedComment().setBody(comment);
......@@ -280,7 +269,7 @@ public class AssertAnalyzer extends AssertProcessorImpl {
String formattedXPATH = this.getFormatedXPATH(xpath);
String prefix = getPrefixRule(contextRule,parent);
// TODO: 22/07/2021 Make following processes independent to support both at same time
// replace invalid XSLT functions with a matchingValueSet()
res = getCleanedXPATHValidation(contextRule,parent,formattedXPATH);
......
......@@ -452,7 +452,6 @@ public class ChoiceDefinitionAnalyzer extends ChoiceDefinitionProcessorImpl {
ORRules(generalOwnedRule,subGeneralOwnedRule);
}
generalOwnedRule.getSpecification().setBody(generalOwnedRule.getSpecification().getBody()+")");
//TODO: Comment should be improved later for choices
String templateName = ChoiceDefinitionUtil.getParentTemplateDefinition(currentChoiceDefinition).getDisplayName();
DParent dparent = RuleDefinitionUtil.getDParentOfTheParent((RuleDefinition)currentChoiceDefinition.getParentObject());
String parentPath = DPathExtractor.createPathFromDParent(dparent);
......
......@@ -200,6 +200,7 @@ public class RDVocabularyAnalyzer implements ConstraintGenerator {
}
private String getTypeKeyword(RuleDefinition ruleDefinition){
if(generateConstraintOwnedRuleType(ruleDefinition) == null) return "";
switch (generateConstraintOwnedRuleType(ruleDefinition)){
case ERROR:
return "SHALL";
......
......@@ -60,7 +60,8 @@ public final class DTUtils {
}
public static String getUMLDatatype(String dataType){
String dt = getRealDatatype(dataType);
String cleanedDT = cleanDTforIPS(dataType);
String dt = getRealDatatype(cleanedDT);
if (dt != null) {
dt = dt.replace("_", "");
}
......@@ -111,6 +112,12 @@ public final class DTUtils {
return !realDTConstrained.equals(typeRD) && UMLLoader.verifyTheParentOfType1IsType2(realDTConstrained, typeRD);
}
public static String cleanDTforIPS(String datatype){
if(datatype == null)
return null;
return datatype.replace(".IPS","");
}
/**
* example : CE.EPSOS -&gt; true
* CD -&gt; false
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment