diff --git a/hl7templates/goc-tests/goc-tests-runner/src/test/java/net/ihe/gazelle/goctests/interlay/ValidatorGeneratorTest.java b/hl7templates/goc-tests/goc-tests-runner/src/test/java/net/ihe/gazelle/goctests/interlay/ValidatorGeneratorTest.java index cb4edf4c54478300c29263ca442ed8285dc7628b..bf96e4546f26f98df36e61915470f8e3bde2b43e 100644 --- a/hl7templates/goc-tests/goc-tests-runner/src/test/java/net/ihe/gazelle/goctests/interlay/ValidatorGeneratorTest.java +++ b/hl7templates/goc-tests/goc-tests-runner/src/test/java/net/ihe/gazelle/goctests/interlay/ValidatorGeneratorTest.java @@ -7,6 +7,7 @@ import org.junit.Ignore; import org.junit.Test; import java.io.BufferedInputStream; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; @@ -27,7 +28,7 @@ public class ValidatorGeneratorTest { String output = "[YOUR CDA PATH]"; String mvn = "[YOUR MVN PATH]"; try { - GeneratedValidator validator = validatorGenerator.generateValidator(new URL(bbr),output,mvn); + GeneratedValidator validator = validatorGenerator.generateValidator(new File(bbr).toURI().toURL(),output,mvn); org.junit.Assert.assertTrue(validator.getValidatorBinaryPath() != null); System.out.println(validator); } catch (ValidatorGenerationException | MalformedURLException e) { diff --git a/hl7templates/hl7templates-api-jar/src/main/java/net/ihe/gazelle/tempapi/impl/ChoiceDefinitionProcessorImpl.java b/hl7templates/hl7templates-api-jar/src/main/java/net/ihe/gazelle/tempapi/impl/ChoiceDefinitionProcessorImpl.java index f59463cab9b419b3dfcf4e9531a1185b170effac..e69db691168428e966740185eaebdc8baf3d69a7 100644 --- a/hl7templates/hl7templates-api-jar/src/main/java/net/ihe/gazelle/tempapi/impl/ChoiceDefinitionProcessorImpl.java +++ b/hl7templates/hl7templates-api-jar/src/main/java/net/ihe/gazelle/tempapi/impl/ChoiceDefinitionProcessorImpl.java @@ -19,7 +19,7 @@ public abstract class ChoiceDefinitionProcessorImpl implements ChoiceDefinitionP this.processConstraints(ChoiceDefinitionUtil.getConstraints(t)); this.processDescs(t.getDesc()); //elements are processed according to the predicates type - //this.processElements(ChoiceDefinitionUtil.getElements(t)); + this.processElements(ChoiceDefinitionUtil.getElements(t)); this.processIncludes(ChoiceDefinitionUtil.getIncludes(t)); this.processMaximumMultiplicity(t.getMaximumMultiplicity()); this.processMinimumMultiplicity(t.getMinimumMultiplicity()); @@ -27,7 +27,7 @@ public abstract class ChoiceDefinitionProcessorImpl implements ChoiceDefinitionP this.processItem(t.getItem()); //Comment next line to disable processing of the unsported HL7 choices specs - this.processPredicates(ChoiceDefinitionUtil.getElements(t)); + //this.processPredicates(ChoiceDefinitionUtil.getElements(t)); } } diff --git a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/action/HL7TemplatesConverter.java b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/action/HL7TemplatesConverter.java index 5f063ee094e02cc52ba5e414959718c76991ff2e..0b3c057f264357b2d62ce75d84d0651e8aefa62a 100644 --- a/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/action/HL7TemplatesConverter.java +++ b/hl7templates/hl7templates-generator-jar/src/main/java/net/ihe/gazelle/tempgen/action/HL7TemplatesConverter.java @@ -4,6 +4,8 @@ package net.ihe.gazelle.tempgen.action; import net.ihe.gazelle.goc.uml.utils.XMIUtil; import net.ihe.gazelle.goc.xmi.XMI; import net.ihe.gazelle.goc.xmi.XMIMarshaller; +import net.ihe.gazelle.goc.xmm.OwnedRule; +import net.ihe.gazelle.goc.xmm.PackagedElement; import net.ihe.gazelle.tempgen.flatten.action.GeneralFlattenDecor; import net.ihe.gazelle.tempgen.flatten.action.RulesCleaner; import net.ihe.gazelle.tempgen.inc.action.IncludeFlattener; @@ -19,6 +21,8 @@ import javax.xml.bind.JAXBException; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author Abderrazek Boufahja @@ -138,6 +142,30 @@ public class HL7TemplatesConverter { XMI xmi = XMIUtil.createXMI(prefix); //The entrypoint to convert the decor to OCL! (new DecorAnalyzer()).process(decor, xmi, Boolean.valueOf(ignoreTemplateIdRequirements),ignoreChoicesPredicates); + //Skip incorrect OCL + clearXMI(xmi); return xmi; } + private void clearXMI(XMI xmi){ + for(PackagedElement packagedElement:xmi.getModel().getPackagedElement()){ + for(int ownedRule=0;ownedRule<packagedElement.getOwnedRule().size();ownedRule++) { + if(cleanOCL(packagedElement.getOwnedRule().get(ownedRule))==null) { + packagedElement.getOwnedRule().remove(packagedElement.getOwnedRule().get(ownedRule)); + TamlHandler.removeTAML(packagedElement.getOwnedRule().get(ownedRule)); + } + } + + } + } + + private OwnedRule cleanOCL(OwnedRule ownedRule){ + String mat= ownedRule.getSpecification().getBody(); + String matr= "\\)[A-Za-z]+"; + Pattern pattern = Pattern.compile(matr); + Matcher matcher = pattern.matcher(ownedRule.getSpecification().getBody()); + if(!matcher.find()){ + return ownedRule; + } + return null; + } }