From 70b6a2551ea9caa2a84febfb3930dab53ac624c9 Mon Sep 17 00:00:00 2001 From: Malte Brunnlieb Date: Mon, 21 Aug 2017 14:59:28 +0200 Subject: [PATCH 01/69] #399 set next development version --- cobigen/cobigen-xmlplugin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cobigen/cobigen-xmlplugin/pom.xml b/cobigen/cobigen-xmlplugin/pom.xml index b4afa62678..0cd888c05d 100644 --- a/cobigen/cobigen-xmlplugin/pom.xml +++ b/cobigen/cobigen-xmlplugin/pom.xml @@ -4,7 +4,7 @@ 4.0.0 cobigen-xmlplugin CobiGen - XML Plug-In - 3.1.0 + 3.2.0-SNAPSHOT jar From a14a0befc72693a1bb3f92d4247f9cf079a3b69b Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Fri, 20 Oct 2017 10:22:03 +0200 Subject: [PATCH 02/69] XPath working added & tests added --- .../xmlplugin/inputreader/XmlInputReader.java | 2 + .../cobigen/xmlplugin/matcher/XmlMatcher.java | 102 +++++++++++++++++- .../cobigen/xmlplugin/model/EntityDef.java | 17 +++ .../integrationtest/XPathGenerationTest.java | 50 +++++++++ .../uml-basic-test/context.xml | 8 ++ .../integrationtest/uml-basic-test/uml.xml | 15 +++ .../uml-basic-test/uml_test/templates.xml | 9 ++ .../${variables.className}.java2.ftl | 23 ++++ .../uml_test/templates/java/DocXPath.txt.ftl | 1 + 9 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/model/EntityDef.java create mode 100644 cobigen/cobigen-xmlplugin/src/test/java/com/capgemini/cobigen/xmlplugin/integrationtest/XPathGenerationTest.java create mode 100644 cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/context.xml create mode 100644 cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml.xml create mode 100644 cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates.xml create mode 100644 cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/${variables.className}.java2.ftl create mode 100644 cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/java/DocXPath.txt.ftl diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index fc2b438d5b..2c29e47b99 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -41,6 +41,8 @@ public Map createModel(Object input) { Document doc = (Document) input; Element rootElement = doc.getDocumentElement(); Map model = new HashMap<>(); + // JAIME: one option for the Xpath + model.put("doc", doc); model.put(rootElement.getNodeName(), deriveSubModel(rootElement)); return new HashMap<>(model); } else { diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index dc2e0523cc..c2826e9650 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -4,9 +4,18 @@ import java.util.List; import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; +import org.w3c.dom.NodeList; import com.capgemini.cobigen.api.exception.InvalidConfigurationException; import com.capgemini.cobigen.api.extension.MatcherInterpreter; @@ -31,7 +40,9 @@ public class XmlMatcher implements MatcherInterpreter { */ private enum MatcherType { /** Document's root name */ - NODENAME, + NODENAME, // ELEMENT + /** Xpath expression group assignment */ + XPATH } /** @@ -43,7 +54,9 @@ private enum VariableType { /** Constant variable assignment */ CONSTANT, /** Regular expression group assignment */ - REGEX + REGEX, + /** Xpath expression group assignment */ + XPATH } @Override @@ -59,6 +72,42 @@ public boolean matches(MatcherTo matcher) { return documentRootName != null && !documentRootName.equals("") && matcher.getValue().matches(documentRootName); } + break; + case XPATH: + // TODO #112 + Object targetXpath = matcher.getTarget(); + + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = builderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + + } + + if (targetXpath instanceof Document) { + Document document = ((Document) targetXpath); + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = matcher.getValue(); + + System.out.println("Expresion Xpath:\t" + expression); + System.out.println("I AM IN matches"); + + NodeList nodeList; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); + } + return nodeList.item(0).getFirstChild().getNodeValue() != null; + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return false; } } catch (IllegalArgumentException e) { LOG.info("Matcher type '{}' not registered --> no match!", matcher.getType()); @@ -72,9 +121,10 @@ public Map resolveVariables(MatcherTo matcher, List resolvedVariables; switch (matcherType) { case NODENAME: - Map resolvedVariables = new HashMap<>(); + resolvedVariables = new HashMap<>(); for (VariableAssignmentTo va : variableAssignments) { VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); switch (variableType) { @@ -86,6 +136,52 @@ public Map resolveVariables(MatcherTo matcher, List(); + for (VariableAssignmentTo va : variableAssignments) { + resolvedVariables.put(va.getVarName(), resultXpath); + } + return resolvedVariables; + } + // resolvedVariables = new HashMap<>(); + // resolvedVariables.put(matcher.getType(), matcher.getValue()); + // return resolvedVariables; default: break; } diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/model/EntityDef.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/model/EntityDef.java new file mode 100644 index 0000000000..902eaac27a --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/model/EntityDef.java @@ -0,0 +1,17 @@ +package com.capgemini.cobigen.xmlplugin.model; + +/** + * Definition that stores the configuration of an XMI definition schema + */ +public class EntityDef { + + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/cobigen/cobigen-xmlplugin/src/test/java/com/capgemini/cobigen/xmlplugin/integrationtest/XPathGenerationTest.java b/cobigen/cobigen-xmlplugin/src/test/java/com/capgemini/cobigen/xmlplugin/integrationtest/XPathGenerationTest.java new file mode 100644 index 0000000000..8799c8b0ff --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/java/com/capgemini/cobigen/xmlplugin/integrationtest/XPathGenerationTest.java @@ -0,0 +1,50 @@ +package com.capgemini.cobigen.xmlplugin.integrationtest; + +import static com.capgemini.cobigen.test.assertj.CobiGenAsserts.assertThat; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.File; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.util.List; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.capgemini.cobigen.api.CobiGen; +import com.capgemini.cobigen.api.to.GenerationReportTo; +import com.capgemini.cobigen.api.to.TemplateTo; +import com.capgemini.cobigen.impl.CobiGenFactory; + +/** + * + */ +public class XPathGenerationTest { + + @Rule + public TemporaryFolder tmpFolder = new TemporaryFolder(); + + /** + * Testing basic Xpath Access + * @throws Exception + * test fails + */ + @Test + public void testXpathAccess() throws Exception { + Path cobigenConfigFolder = new File("src/test/resources/testdata/integrationtest/uml-basic-test").toPath(); + Path input = cobigenConfigFolder.resolve("uml.xml"); + + CobiGen cobigen = CobiGenFactory.create(cobigenConfigFolder.toUri()); + Object compliantInput = cobigen.read("xml", input, Charset.forName("UTF-8")); + List matchingTemplates = cobigen.getMatchingTemplates(compliantInput); + assertThat(matchingTemplates).isNotNull().hasSize(1); + + File targetFolder = tmpFolder.newFolder("testXpathAccess"); + GenerationReportTo report = cobigen.generate(compliantInput, matchingTemplates.get(0), targetFolder.toPath()); + assertThat(report).isSuccessful(); + + assertThat(targetFolder.toPath().resolve("DocXPath.txt")).hasContent("Bill"); + } + +} diff --git a/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/context.xml b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/context.xml new file mode 100644 index 0000000000..0addf55ed3 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/context.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml.xml b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml.xml new file mode 100644 index 0000000000..b1d2a12c36 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates.xml b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates.xml new file mode 100644 index 0000000000..d3d31bf3a8 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/${variables.className}.java2.ftl b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/${variables.className}.java2.ftl new file mode 100644 index 0000000000..e3c17a84fe --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/${variables.className}.java2.ftl @@ -0,0 +1,23 @@ +package main.java.umlTest; + +<#list doc["xmi:XMI"].Children as parent> + + +<#list .vars['xmi:XMI'].Children as parent> +<#if parent._nodeName_ == "uml:Model"> + // ${parent._at_name} + <#list parent.Children as firstChild> + // ${firstChild._at_name} + <#list firstChild.Children as secondChild> +public class ${secondChild._at_name} { + // CLASS NAME: ${secondChild._at_name} + + + + + +public int x; + +public String y; + +} diff --git a/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/java/DocXPath.txt.ftl b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/java/DocXPath.txt.ftl new file mode 100644 index 0000000000..2cabc391a8 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/test/resources/testdata/integrationtest/uml-basic-test/uml_test/templates/java/DocXPath.txt.ftl @@ -0,0 +1 @@ +${doc["XMI/Model/packagedElement/packagedElement/@name"]} From 8e9957732fe081e86a31ce35977c0a6e750b612f Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Fri, 20 Oct 2017 12:34:42 +0200 Subject: [PATCH 03/69] Refactoring code, improving XPath in variable assignment --- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 57 +++++++++---------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index c2826e9650..63555e5fcf 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -40,7 +40,7 @@ public class XmlMatcher implements MatcherInterpreter { */ private enum MatcherType { /** Document's root name */ - NODENAME, // ELEMENT + NODENAME, /** Xpath expression group assignment */ XPATH } @@ -74,7 +74,7 @@ public boolean matches(MatcherTo matcher) { } break; case XPATH: - // TODO #112 + // #112 Object targetXpath = matcher.getTarget(); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); @@ -82,8 +82,8 @@ public boolean matches(MatcherTo matcher) { try { builder = builderFactory.newDocumentBuilder(); } catch (ParserConfigurationException e) { + LOG.info("Document builder initialization failed!"); e.printStackTrace(); - } if (targetXpath instanceof Document) { @@ -104,6 +104,7 @@ public boolean matches(MatcherTo matcher) { return nodeList.item(0).getFirstChild().getNodeValue() != null; } catch (XPathExpressionException e) { // TODO Auto-generated catch block + LOG.info("Matcher Xpath expression is not correct!"); e.printStackTrace(); } } @@ -148,40 +149,34 @@ public Map resolveVariables(MatcherTo matcher, List(); for (VariableAssignmentTo va : variableAssignments) { - resolvedVariables.put(va.getVarName(), resultXpath); + Document document = ((Document) targetXpath); + String resultXpath = "Error_See_XMLMatcher"; + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = va.getValue(); + + System.out.println("Expresion Xpath:\t" + expression); + System.out.println("I AM IN resolveVariables"); + + NodeList nodeList; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + resultXpath = nodeList.item(i).getFirstChild().getNodeValue(); + + resolvedVariables.put(va.getVarName(), resultXpath); + System.out.println(resultXpath); + } + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } return resolvedVariables; } - // resolvedVariables = new HashMap<>(); - // resolvedVariables.put(matcher.getType(), matcher.getValue()); - // return resolvedVariables; default: break; } From c42bcd1af87bb91580c113a4ed94c34207b2b504 Mon Sep 17 00:00:00 2001 From: richter-cg Date: Fri, 20 Oct 2017 13:34:02 +0200 Subject: [PATCH 04/69] Extracing the logic for XPath --- .../cobigen-eclipse-test/.classpath | 5 - cobigen-eclipse/cobigen-eclipse/.classpath | 19 ---- .../cobigen/xmlplugin/matcher/XPathLogic.java | 107 ++++++++++++++++++ .../cobigen/xmlplugin/matcher/XmlMatcher.java | 78 +------------ 4 files changed, 111 insertions(+), 98 deletions(-) create mode 100644 cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java diff --git a/cobigen-eclipse/cobigen-eclipse-test/.classpath b/cobigen-eclipse/cobigen-eclipse-test/.classpath index 88ee6df2f4..98ddc48ed2 100644 --- a/cobigen-eclipse/cobigen-eclipse-test/.classpath +++ b/cobigen-eclipse/cobigen-eclipse-test/.classpath @@ -3,10 +3,5 @@ - - - - - diff --git a/cobigen-eclipse/cobigen-eclipse/.classpath b/cobigen-eclipse/cobigen-eclipse/.classpath index 07dd246344..46cec6ed2a 100644 --- a/cobigen-eclipse/cobigen-eclipse/.classpath +++ b/cobigen-eclipse/cobigen-eclipse/.classpath @@ -3,24 +3,5 @@ - - - - - - - - - - - - - - - - - - - diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java new file mode 100644 index 0000000000..7c0d7e3179 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -0,0 +1,107 @@ +package com.capgemini.cobigen.xmlplugin.matcher; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.slf4j.Logger; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +import com.capgemini.cobigen.api.to.MatcherTo; +import com.capgemini.cobigen.api.to.VariableAssignmentTo; + +/** + * + */ +public class XPathLogic { + + public boolean matchesXPath(MatcherTo matcher, Logger LOG) { + // #112 + Object targetXpath = matcher.getTarget(); + + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = builderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + LOG.info("Document builder initialization failed!"); + e.printStackTrace(); + } + + if (targetXpath instanceof Document) { + Document document = ((Document) targetXpath); + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = matcher.getValue(); + + System.out.println("Expresion Xpath:\t" + expression); + System.out.println("I AM IN matches"); + + NodeList nodeList; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); + } + return nodeList.item(0).getFirstChild().getNodeValue() != null; + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + LOG.info("Matcher Xpath expression is not correct!"); + e.printStackTrace(); + } + } + return false; + } + + public Map resolveVariablesXPath(MatcherTo matcher, Map resolvedVariables, + List variableAssignments) { + // TODO #112 + Object targetXpath = matcher.getTarget(); + + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = builderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + + } + if (targetXpath instanceof Document) { + resolvedVariables = new HashMap<>(); + for (VariableAssignmentTo va : variableAssignments) { + Document document = ((Document) targetXpath); + String resultXpath = "Error_See_XMLMatcher"; + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = va.getValue(); + + System.out.println("Expresion Xpath:\t" + expression); + System.out.println("I AM IN resolveVariables"); + + NodeList nodeList; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + resultXpath = nodeList.item(i).getFirstChild().getNodeValue(); + + resolvedVariables.put(va.getVarName(), resultXpath); + System.out.println(resultXpath); + } + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + return resolvedVariables; + } + } +} diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 63555e5fcf..194a626b27 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -33,6 +33,8 @@ public class XmlMatcher implements MatcherInterpreter { */ private static final Logger LOG = LoggerFactory.getLogger(XmlMatcher.class); + private XPathLogic logic = new XPathLogic(); + /** * Currently supported matcher types * @@ -74,41 +76,7 @@ public boolean matches(MatcherTo matcher) { } break; case XPATH: - // #112 - Object targetXpath = matcher.getTarget(); - - DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = null; - try { - builder = builderFactory.newDocumentBuilder(); - } catch (ParserConfigurationException e) { - LOG.info("Document builder initialization failed!"); - e.printStackTrace(); - } - - if (targetXpath instanceof Document) { - Document document = ((Document) targetXpath); - - XPath xPath = XPathFactory.newInstance().newXPath(); - String expression = matcher.getValue(); - - System.out.println("Expresion Xpath:\t" + expression); - System.out.println("I AM IN matches"); - - NodeList nodeList; - try { - nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); - } - return nodeList.item(0).getFirstChild().getNodeValue() != null; - } catch (XPathExpressionException e) { - // TODO Auto-generated catch block - LOG.info("Matcher Xpath expression is not correct!"); - e.printStackTrace(); - } - } - return false; + return logic.matchesXPath(matcher, LOG); } } catch (IllegalArgumentException e) { LOG.info("Matcher type '{}' not registered --> no match!", matcher.getType()); @@ -138,45 +106,7 @@ public Map resolveVariables(MatcherTo matcher, List(); - for (VariableAssignmentTo va : variableAssignments) { - Document document = ((Document) targetXpath); - String resultXpath = "Error_See_XMLMatcher"; - - XPath xPath = XPathFactory.newInstance().newXPath(); - String expression = va.getValue(); - - System.out.println("Expresion Xpath:\t" + expression); - System.out.println("I AM IN resolveVariables"); - - NodeList nodeList; - try { - nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - resultXpath = nodeList.item(i).getFirstChild().getNodeValue(); - - resolvedVariables.put(va.getVarName(), resultXpath); - System.out.println(resultXpath); - } - } catch (XPathExpressionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return resolvedVariables; - } + default: break; } From ca076569056e3cc828842ef7a485166bbecf283a Mon Sep 17 00:00:00 2001 From: richter-cg Date: Fri, 20 Oct 2017 13:45:28 +0200 Subject: [PATCH 05/69] . --- .../cobigen/xmlplugin/matcher/XPathLogic.java | 4 ++-- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 13 +++---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index 7c0d7e3179..585e193afd 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -62,7 +62,7 @@ public boolean matchesXPath(MatcherTo matcher, Logger LOG) { return false; } - public Map resolveVariablesXPath(MatcherTo matcher, Map resolvedVariables, + public Map resolveVariablesXPath(MatcherTo matcher, List variableAssignments) { // TODO #112 Object targetXpath = matcher.getTarget(); @@ -76,7 +76,7 @@ public Map resolveVariablesXPath(MatcherTo matcher, Map(); + Map resolvedVariables = new HashMap<>(); for (VariableAssignmentTo va : variableAssignments) { Document document = ((Document) targetXpath); String resultXpath = "Error_See_XMLMatcher"; diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 194a626b27..07dd0b615c 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -4,18 +4,9 @@ import java.util.List; import java.util.Map; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; -import org.w3c.dom.NodeList; import com.capgemini.cobigen.api.exception.InvalidConfigurationException; import com.capgemini.cobigen.api.extension.MatcherInterpreter; @@ -106,7 +97,9 @@ public Map resolveVariables(MatcherTo matcher, List Date: Fri, 20 Oct 2017 14:00:26 +0200 Subject: [PATCH 06/69] Not tested yet --- .../java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index 585e193afd..404d205566 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -103,5 +103,6 @@ public Map resolveVariablesXPath(MatcherTo matcher, } return resolvedVariables; } + return null; } } From 680246b4395ab565d995b1cce4defff0fe5b88b1 Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Mon, 23 Oct 2017 14:15:59 +0200 Subject: [PATCH 07/69] Trying to make multiple file generation possible --- .../xmlplugin/inputreader/XmlInputReader.java | 10 ++++++- .../cobigen/xmlplugin/matcher/XPathLogic.java | 26 ++++++++++--------- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 24 +++++++++++++---- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index 2c29e47b99..3dadfa544a 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -41,8 +41,10 @@ public Map createModel(Object input) { Document doc = (Document) input; Element rootElement = doc.getDocumentElement(); Map model = new HashMap<>(); + // JAIME: one option for the Xpath model.put("doc", doc); + model.put(rootElement.getNodeName(), deriveSubModel(rootElement)); return new HashMap<>(model); } else { @@ -57,7 +59,13 @@ public Map createModel(Object input) { */ @Override public boolean combinesMultipleInputObjects(Object input) { - return false; + if (input instanceof Document) { + Document doc = (Document) input; + if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { + return true; + } + } + return true; } /** diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index 404d205566..e35df58c94 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -46,13 +46,18 @@ public boolean matchesXPath(MatcherTo matcher, Logger LOG) { System.out.println("Expresion Xpath:\t" + expression); System.out.println("I AM IN matches"); - NodeList nodeList; + NodeList nodeList = null; try { nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); + if (nodeList == null) { + return false; + } else { + return true; } - return nodeList.item(0).getFirstChild().getNodeValue() != null; + // for (int i = 0; i < nodeList.getLength(); i++) { + // System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); + // } + // return nodeList.item(0).getFirstChild().getNodeValue() != null; } catch (XPathExpressionException e) { // TODO Auto-generated catch block LOG.info("Matcher Xpath expression is not correct!"); @@ -86,16 +91,13 @@ public Map resolveVariablesXPath(MatcherTo matcher, System.out.println("Expresion Xpath:\t" + expression); System.out.println("I AM IN resolveVariables"); + System.out.println(document.hasAttributes() + " " + document.getNodeValue()); - NodeList nodeList; + String entity = new String(); try { - nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - resultXpath = nodeList.item(i).getFirstChild().getNodeValue(); - - resolvedVariables.put(va.getVarName(), resultXpath); - System.out.println(resultXpath); - } + entity = (String) xPath.compile("[" + expression + "]").evaluate(document, XPathConstants.STRING); + System.out.println(entity); + resolvedVariables.put(va.getVarName(), entity); } catch (XPathExpressionException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 07dd0b615c..7611c2a601 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -35,7 +35,7 @@ private enum MatcherType { /** Document's root name */ NODENAME, /** Xpath expression group assignment */ - XPATH + XPATH, UML } /** @@ -56,9 +56,10 @@ private enum VariableType { public boolean matches(MatcherTo matcher) { try { MatcherType matcherType = Enum.valueOf(MatcherType.class, matcher.getType().toUpperCase()); + Object target = matcher.getTarget(); switch (matcherType) { case NODENAME: - Object target = matcher.getTarget(); + if (target instanceof Document) { String documentRootName = ((Document) target).getDocumentElement().getNodeName(); // return documentRootName.equals(matcher.getValue()); @@ -68,7 +69,14 @@ public boolean matches(MatcherTo matcher) { break; case XPATH: return logic.matchesXPath(matcher, LOG); + + case UML: + if (target instanceof Document) { + return ((Document) target).getDocumentElement().getNodeName().equals(matcher.getValue()); + } + break; } + } catch (IllegalArgumentException e) { LOG.info("Matcher type '{}' not registered --> no match!", matcher.getType()); } @@ -94,11 +102,17 @@ public Map resolveVariables(MatcherTo matcher, List(); + for (VariableAssignmentTo va : variableAssignments) { + VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); + switch (variableType) { + case XPATH: + resolvedVariables.putAll(logic.resolveVariablesXPath(matcher, variableAssignments)); + } + return resolvedVariables; } default: break; From add06e6481f0ee70a79dcf66f619fd0d3643fa84 Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Tue, 24 Oct 2017 12:45:49 +0200 Subject: [PATCH 08/69] Fixing bugs, Multiple input objects does not work :( --- .../xmlplugin/inputreader/XmlInputReader.java | 12 ++--- .../cobigen/xmlplugin/matcher/XPathLogic.java | 53 ++++++++----------- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 6 ++- 3 files changed, 30 insertions(+), 41 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index 3dadfa544a..787175925b 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -59,13 +59,11 @@ public Map createModel(Object input) { */ @Override public boolean combinesMultipleInputObjects(Object input) { - if (input instanceof Document) { - Document doc = (Document) input; - if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { - return true; - } - } - return true; + /* + * if (input instanceof Document) { Document doc = (Document) input; if + * (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { return true; } } + */ + return false; } /** diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index e35df58c94..27ec73afad 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -1,9 +1,5 @@ package com.capgemini.cobigen.xmlplugin.matcher; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -49,15 +45,14 @@ public boolean matchesXPath(MatcherTo matcher, Logger LOG) { NodeList nodeList = null; try { nodeList = (NodeList) xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); + } if (nodeList == null) { return false; } else { return true; } - // for (int i = 0; i < nodeList.getLength(); i++) { - // System.out.println(nodeList.item(i).getFirstChild().getNodeValue()); - // } - // return nodeList.item(0).getFirstChild().getNodeValue() != null; } catch (XPathExpressionException e) { // TODO Auto-generated catch block LOG.info("Matcher Xpath expression is not correct!"); @@ -67,10 +62,10 @@ public boolean matchesXPath(MatcherTo matcher, Logger LOG) { return false; } - public Map resolveVariablesXPath(MatcherTo matcher, - List variableAssignments) { + public String resolveVariablesXPath(MatcherTo matcher, VariableAssignmentTo va) { // TODO #112 Object targetXpath = matcher.getTarget(); + String entity = new String("Error_XPATH_SeeXpathLogic"); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; @@ -81,29 +76,23 @@ public Map resolveVariablesXPath(MatcherTo matcher, } if (targetXpath instanceof Document) { - Map resolvedVariables = new HashMap<>(); - for (VariableAssignmentTo va : variableAssignments) { - Document document = ((Document) targetXpath); - String resultXpath = "Error_See_XMLMatcher"; - - XPath xPath = XPathFactory.newInstance().newXPath(); - String expression = va.getValue(); - - System.out.println("Expresion Xpath:\t" + expression); - System.out.println("I AM IN resolveVariables"); - System.out.println(document.hasAttributes() + " " + document.getNodeValue()); - - String entity = new String(); - try { - entity = (String) xPath.compile("[" + expression + "]").evaluate(document, XPathConstants.STRING); - System.out.println(entity); - resolvedVariables.put(va.getVarName(), entity); - } catch (XPathExpressionException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + Document document = ((Document) targetXpath); + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = va.getValue(); + + System.out.println("Expresion Xpath:\t" + expression); + System.out.println("I AM IN resolveVariables"); + System.out.println(document.hasAttributes() + " " + document.getNodeValue()); + + try { + entity = (String) xPath.compile(expression).evaluate(document, XPathConstants.STRING); + System.out.println("Entity resolvedVaribales: " + entity); + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - return resolvedVariables; + return entity; } return null; } diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 7611c2a601..1a48424200 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -35,7 +35,9 @@ private enum MatcherType { /** Document's root name */ NODENAME, /** Xpath expression group assignment */ - XPATH, UML + XPATH, + /** UML expression group assignment */ + UML } /** @@ -110,7 +112,7 @@ public Map resolveVariables(MatcherTo matcher, List Date: Wed, 25 Oct 2017 11:34:52 +0200 Subject: [PATCH 09/69] first idea of how to get the class names. --- .../xmlplugin/inputreader/XmiClassReader.java | 30 +++++++++++++++++++ .../xmlplugin/inputreader/XmlInputReader.java | 24 ++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java new file mode 100644 index 0000000000..9f884fe4a7 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java @@ -0,0 +1,30 @@ +package com.capgemini.cobigen.xmlplugin.inputreader; + +import java.util.List; + +/** + * Extracts class names out of xmi files to generate multiple classes out of one source file. + */ +public class XmiClassReader { + // TODO get the right input file + // something like: + // Path cobigenConfigFolder = new + // File("src/test/resources/testdata/integrationtest/uml-basic-test").toPath(); + // Path input = cobigenConfigFolder.resolve("uml.xml"); + + // parsing the xmi: + // 1: cobigen uses JAXB: ask Ruben if we can use this parser to get all nodenames (class names) + // 2: use XPath to get every occurrence of packagedElement like + // "XMI/Model/packagedElement/packagedElement/@name" + // some kind of iteration is needed. + + // return all extracted Names as List + + /** + * + * @return a list of objects wich represent the name of every class in the given xmi. + */ + List getClassNames() { + return null; + } +} diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index 787175925b..a2e6bd5bf4 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -59,10 +59,13 @@ public Map createModel(Object input) { */ @Override public boolean combinesMultipleInputObjects(Object input) { - /* - * if (input instanceof Document) { Document doc = (Document) input; if - * (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { return true; } } - */ + + if (input instanceof Document) { + Document doc = (Document) input; + if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { + return true; + } + } return false; } @@ -73,6 +76,12 @@ public boolean combinesMultipleInputObjects(Object input) { */ @Override public List getInputObjects(Object input, Charset inputCharset) { + if (input instanceof Document) { + Document doc = (Document) input; + if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { + return true; + } + } return new LinkedList<>(); } @@ -83,6 +92,13 @@ public List getInputObjects(Object input, Charset inputCharset) { */ @Override public List getInputObjectsRecursively(Object input, Charset inputCharset) { + if (input instanceof Document) { + Document doc = (Document) input; + if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { + // no recursive call, needs to be adapted. + return getInputObjects(input, inputCharset); + } + } return new LinkedList<>(); } From 8fd74b49ee7848afb55558f8328af9b0490fb0e4 Mon Sep 17 00:00:00 2001 From: richter-cg Date: Wed, 25 Oct 2017 11:43:43 +0200 Subject: [PATCH 10/69] typo --- .../cobigen/xmlplugin/inputreader/XmiClassReader.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java index 9f884fe4a7..4d9b77b461 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java @@ -22,9 +22,10 @@ public class XmiClassReader { /** * - * @return a list of objects wich represent the name of every class in the given xmi. + * @return a list of objects which represent the name of every class in the given xmi. */ List getClassNames() { return null; } + } From b83d0deb0d63055a3776d53027927876d69fb8fc Mon Sep 17 00:00:00 2001 From: richter-cg Date: Wed, 25 Oct 2017 11:51:50 +0200 Subject: [PATCH 11/69] added function to retrieve the input document. --- .../xmlplugin/inputreader/XmiClassReader.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java index 4d9b77b461..9023fe4a80 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java @@ -2,6 +2,10 @@ import java.util.List; +import org.w3c.dom.Document; + +import com.capgemini.cobigen.api.to.MatcherTo; + /** * Extracts class names out of xmi files to generate multiple classes out of one source file. */ @@ -28,4 +32,12 @@ List getClassNames() { return null; } + Document getInput(MatcherTo matcher) { + Object targetXpath = matcher.getTarget(); + if (targetXpath instanceof Document) { + return ((Document) targetXpath); + } + return null; + } + } From 84a9f3226a30bd2e9bcf939d2a4b617fda8bbbc0 Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Wed, 25 Oct 2017 14:37:36 +0200 Subject: [PATCH 12/69] Code changes made by Ruben --- .../xmlplugin/inputreader/XmiClassReader.java | 29 ++++++- .../xmlplugin/inputreader/XmlInputReader.java | 43 +++++++--- .../cobigen/xmlplugin/matcher/XPathLogic.java | 1 + .../cobigen/xmlplugin/matcher/XmlMatcher.java | 86 +++++++++++-------- 4 files changed, 106 insertions(+), 53 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java index 9023fe4a80..045732b083 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java @@ -1,8 +1,16 @@ package com.capgemini.cobigen.xmlplugin.inputreader; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + import org.w3c.dom.Document; +import org.w3c.dom.NodeList; import com.capgemini.cobigen.api.to.MatcherTo; @@ -28,8 +36,25 @@ public class XmiClassReader { * * @return a list of objects which represent the name of every class in the given xmi. */ - List getClassNames() { - return null; + List getClassNames(Document doc) { + List classesNames = new ArrayList(); + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "XMI/Model/packagedElement/packagedElement[@type='uml:Class']/@name"; + + System.out.println("I AM IN XmiClassReader"); + NodeList nodeList = null; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(doc, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + classesNames.add(nodeList.item(i).getFirstChild().getNodeValue()); + } + System.out.println("Classes Names List: " + Arrays.toString(classesNames.toArray())); + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // combine xpath with input + return classesNames; } Document getInput(MatcherTo matcher) { diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index a2e6bd5bf4..32281effe3 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -12,6 +12,10 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -59,7 +63,6 @@ public Map createModel(Object input) { */ @Override public boolean combinesMultipleInputObjects(Object input) { - if (input instanceof Document) { Document doc = (Document) input; if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { @@ -76,13 +79,32 @@ public boolean combinesMultipleInputObjects(Object input) { */ @Override public List getInputObjects(Object input, Charset inputCharset) { - if (input instanceof Document) { - Document doc = (Document) input; - if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { - return true; + + List list = new LinkedList<>(); + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "XMI/Model/packagedElement"; + + NodeList nodeList = null; + try { + nodeList = (NodeList) xPath.compile(expression).evaluate(input, XPathConstants.NODESET); + for (int i = 0; i < nodeList.getLength(); i++) { + list.add(nodeList.item(i)); } + } catch (XPathExpressionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - return new LinkedList<>(); + // + // if (input instanceof Document) { + // Document doc = (Document) input; + // System.out.println("Root Tag: " + doc.getFirstChild().getNodeName()); + // + // if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { + // XmiClassReader xmiClassReader = new XmiClassReader(); + // return xmiClassReader.getClassNames(doc); + // } + // } + return list; } /** @@ -92,14 +114,7 @@ public List getInputObjects(Object input, Charset inputCharset) { */ @Override public List getInputObjectsRecursively(Object input, Charset inputCharset) { - if (input instanceof Document) { - Document doc = (Document) input; - if (doc.getFirstChild().getNodeName().equals("xmi:XMI")) { - // no recursive call, needs to be adapted. - return getInputObjects(input, inputCharset); - } - } - return new LinkedList<>(); + return getInputObjects(input, inputCharset); } /** diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index 27ec73afad..3f8f9b32df 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -75,6 +75,7 @@ public String resolveVariablesXPath(MatcherTo matcher, VariableAssignmentTo va) e.printStackTrace(); } + System.out.println(targetXpath.getClass()); if (targetXpath instanceof Document) { Document document = ((Document) targetXpath); diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 1a48424200..a992ff6c29 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -12,7 +12,6 @@ import com.capgemini.cobigen.api.extension.MatcherInterpreter; import com.capgemini.cobigen.api.to.MatcherTo; import com.capgemini.cobigen.api.to.VariableAssignmentTo; -import com.google.common.collect.Maps; /** * {@link MatcherInterpreter} for XML matcher configurations. @@ -35,9 +34,7 @@ private enum MatcherType { /** Document's root name */ NODENAME, /** Xpath expression group assignment */ - XPATH, - /** UML expression group assignment */ - UML + COSA, UML } /** @@ -69,10 +66,13 @@ public boolean matches(MatcherTo matcher) { && matcher.getValue().matches(documentRootName); } break; - case XPATH: - return logic.matchesXPath(matcher, LOG); + case COSA: + System.out.println("el matcher " + matcher.getTarget().getClass().getSimpleName()); + return matcher.getTarget().getClass().getSimpleName().toLowerCase() + .equals(matcher.getValue().toLowerCase()); case UML: + System.out.println("el container " + ((Document) target).getDocumentElement().getNodeName()); if (target instanceof Document) { return ((Document) target).getDocumentElement().getNodeName().equals(matcher.getValue()); } @@ -89,40 +89,52 @@ public boolean matches(MatcherTo matcher) { public Map resolveVariables(MatcherTo matcher, List variableAssignments) throws InvalidConfigurationException { - try { - MatcherType matcherType = Enum.valueOf(MatcherType.class, matcher.getType().toUpperCase()); - Map resolvedVariables; - switch (matcherType) { - case NODENAME: - resolvedVariables = new HashMap<>(); - for (VariableAssignmentTo va : variableAssignments) { - VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); - switch (variableType) { - case CONSTANT: - resolvedVariables.put(va.getVarName(), va.getValue()); - break; - case REGEX: - // TODO #64 - } - return resolvedVariables; - } + System.out.println("llegas aki"); + Map resolvedVariables = new HashMap<>(); + for (VariableAssignmentTo va : variableAssignments) { + VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); + switch (variableType) { case XPATH: - resolvedVariables = new HashMap<>(); - for (VariableAssignmentTo va : variableAssignments) { - VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); - switch (variableType) { - case XPATH: - resolvedVariables.put(va.getVarName(), logic.resolveVariablesXPath(matcher, va)); - } - return resolvedVariables; - } - default: - break; + System.out.println("la variables es xpath con value: " + va.getValue()); + resolvedVariables.put(va.getVarName(), logic.resolveVariablesXPath(matcher, va)); } - } catch (IllegalArgumentException e) { - LOG.warn("Matcher type '{}' not registered --> no match!", matcher.getType()); + } - return Maps.newHashMap(); + return resolvedVariables; + // try { + // MatcherType matcherType = Enum.valueOf(MatcherType.class, matcher.getType().toUpperCase()); + // Map resolvedVariables; + // switch (matcherType) { + // case NODENAME: + // resolvedVariables = new HashMap<>(); + // for (VariableAssignmentTo va : variableAssignments) { + // VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); + // switch (variableType) { + // case CONSTANT: + // resolvedVariables.put(va.getVarName(), va.getValue()); + // break; + // case REGEX: + // // TODO #64 + // } + // return resolvedVariables; + // } + // case XPATH: + // resolvedVariables = new HashMap<>(); + // for (VariableAssignmentTo va : variableAssignments) { + // VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); + // switch (variableType) { + // case XPATH: + // resolvedVariables.put(va.getVarName(), logic.resolveVariablesXPath(matcher, va)); + // } + // return resolvedVariables; + // } + // default: + // break; + // } + // } catch (IllegalArgumentException e) { + // LOG.warn("Matcher type '{}' not registered --> no match!", matcher.getType()); + // } + // return Maps.newHashMap(); } } From eb6ad60b0d4a177c1833de717bea8bd6b32422ce Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Thu, 26 Oct 2017 13:46:37 +0200 Subject: [PATCH 13/69] First working version of the multiple file generation --- .../xmlplugin/inputreader/XmlInputReader.java | 45 ++++++++++++++----- .../cobigen/xmlplugin/matcher/XPathLogic.java | 4 +- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 4 ++ 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index 32281effe3..875909747f 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -80,20 +80,46 @@ public boolean combinesMultipleInputObjects(Object input) { @Override public List getInputObjects(Object input, Charset inputCharset) { - List list = new LinkedList<>(); XPath xPath = XPathFactory.newInstance().newXPath(); - String expression = "XMI/Model/packagedElement"; + String expression = "XMI/Model/packagedElement/packagedElement[@type='uml:Class']"; + Document newXmlDocument = null; - NodeList nodeList = null; + NodeList list = null; try { - nodeList = (NodeList) xPath.compile(expression).evaluate(input, XPathConstants.NODESET); - for (int i = 0; i < nodeList.getLength(); i++) { - list.add(nodeList.item(i)); - } - } catch (XPathExpressionException e) { + list = (NodeList) xPath.evaluate(expression, input, XPathConstants.NODESET); + } catch (XPathExpressionException e1) { // TODO Auto-generated catch block - e.printStackTrace(); + e1.printStackTrace(); + } + + List docsList = new LinkedList<>(); + for (int i = 0; i < list.getLength(); i++) { + try { + newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Element root = newXmlDocument.createElement("xmi:XMI"); + String finalExpression = expression + "[" + i + "]"; + + Node node = list.item(i); + newXmlDocument.appendChild(root); + Node copyNode = newXmlDocument.importNode(node, true); + root.appendChild(copyNode); + docsList.add(newXmlDocument); } + return docsList; + /* + * List list = new LinkedList<>(); XPath xPath = XPathFactory.newInstance().newXPath(); String + * expression = "XMI/Model/packagedElement"; + * + * NodeList nodeList = null; try { nodeList = (NodeList) xPath.compile(expression).evaluate(input, + * XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { + * list.add(nodeList.item(i)); } } catch (XPathExpressionException e) { // TODO Auto-generated catch + * block e.printStackTrace(); } + */ // // if (input instanceof Document) { // Document doc = (Document) input; @@ -104,7 +130,6 @@ public List getInputObjects(Object input, Charset inputCharset) { // return xmiClassReader.getClassNames(doc); // } // } - return list; } /** diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java index 3f8f9b32df..edd212e34b 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XPathLogic.java @@ -84,10 +84,10 @@ public String resolveVariablesXPath(MatcherTo matcher, VariableAssignmentTo va) System.out.println("Expresion Xpath:\t" + expression); System.out.println("I AM IN resolveVariables"); - System.out.println(document.hasAttributes() + " " + document.getNodeValue()); try { - entity = (String) xPath.compile(expression).evaluate(document, XPathConstants.STRING); + NodeList list = (NodeList) xPath.evaluate(expression, document, XPathConstants.NODESET); + entity = list.item(0).getNodeValue(); System.out.println("Entity resolvedVaribales: " + entity); } catch (XPathExpressionException e) { // TODO Auto-generated catch block diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index a992ff6c29..0b1b85121c 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -97,6 +97,10 @@ public Map resolveVariables(MatcherTo matcher, List Date: Thu, 26 Oct 2017 14:02:24 +0200 Subject: [PATCH 14/69] Fixing gibberish on the code --- .../xmlplugin/inputreader/XmlInputReader.java | 3 +-- .../cobigen/xmlplugin/matcher/XmlMatcher.java | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java index 875909747f..6c37e59d1a 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmlInputReader.java @@ -102,7 +102,6 @@ public List getInputObjects(Object input, Charset inputCharset) { } Element root = newXmlDocument.createElement("xmi:XMI"); - String finalExpression = expression + "[" + i + "]"; Node node = list.item(i); newXmlDocument.appendChild(root); @@ -114,7 +113,7 @@ public List getInputObjects(Object input, Charset inputCharset) { /* * List list = new LinkedList<>(); XPath xPath = XPathFactory.newInstance().newXPath(); String * expression = "XMI/Model/packagedElement"; - * + * * NodeList nodeList = null; try { nodeList = (NodeList) xPath.compile(expression).evaluate(input, * XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { * list.add(nodeList.item(i)); } } catch (XPathExpressionException e) { // TODO Auto-generated catch diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java index 0b1b85121c..172d3581b2 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/matcher/XmlMatcher.java @@ -34,7 +34,7 @@ private enum MatcherType { /** Document's root name */ NODENAME, /** Xpath expression group assignment */ - COSA, UML + DOCUMENT, UML } /** @@ -66,13 +66,13 @@ public boolean matches(MatcherTo matcher) { && matcher.getValue().matches(documentRootName); } break; - case COSA: - System.out.println("el matcher " + matcher.getTarget().getClass().getSimpleName()); + case DOCUMENT: + System.out.println("The matcher " + matcher.getTarget().getClass().getSimpleName()); return matcher.getTarget().getClass().getSimpleName().toLowerCase() .equals(matcher.getValue().toLowerCase()); case UML: - System.out.println("el container " + ((Document) target).getDocumentElement().getNodeName()); + System.out.println("The container " + ((Document) target).getDocumentElement().getNodeName()); if (target instanceof Document) { return ((Document) target).getDocumentElement().getNodeName().equals(matcher.getValue()); } @@ -89,13 +89,13 @@ public boolean matches(MatcherTo matcher) { public Map resolveVariables(MatcherTo matcher, List variableAssignments) throws InvalidConfigurationException { - System.out.println("llegas aki"); + System.out.println("Gets to this point"); Map resolvedVariables = new HashMap<>(); for (VariableAssignmentTo va : variableAssignments) { VariableType variableType = Enum.valueOf(VariableType.class, va.getType().toUpperCase()); switch (variableType) { case XPATH: - System.out.println("la variables es xpath con value: " + va.getValue()); + System.out.println("The variable is Xpath with value: " + va.getValue()); resolvedVariables.put(va.getVarName(), logic.resolveVariablesXPath(matcher, va)); break; case CONSTANT: From 1e1b9418e6d44f447c48f3aed8e3146807fdc3e0 Mon Sep 17 00:00:00 2001 From: richter-cg Date: Fri, 27 Oct 2017 09:04:25 +0200 Subject: [PATCH 15/69] added getinputObjects --- .../xmlplugin/inputreader/XmiClassReader.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java index 045732b083..56e76d1598 100644 --- a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/inputreader/XmiClassReader.java @@ -1,15 +1,21 @@ package com.capgemini.cobigen.xmlplugin.inputreader; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedList; import java.util.List; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.capgemini.cobigen.api.to.MatcherTo; @@ -57,6 +63,40 @@ List getClassNames(Document doc) { return classesNames; } + public List getInputObjects(Object input, Charset inputCharset) { + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "XMI/Model/packagedElement/packagedElement[@type='uml:Class']"; + Document newXmlDocument = null; + + NodeList list = null; + try { + list = (NodeList) xPath.evaluate(expression, input, XPathConstants.NODESET); + } catch (XPathExpressionException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + List docsList = new LinkedList<>(); + for (int i = 0; i < list.getLength(); i++) { + try { + newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Element root = newXmlDocument.createElement("xmi:XMI"); + + Node node = list.item(i); + newXmlDocument.appendChild(root); + Node copyNode = newXmlDocument.importNode(node, true); + root.appendChild(copyNode); + docsList.add(newXmlDocument); + } + return docsList; + } + Document getInput(MatcherTo matcher) { Object targetXpath = matcher.getTarget(); if (targetXpath instanceof Document) { From f5895107aa6d5e5f77ab2ba5e7d68a5caa0a6fe6 Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Fri, 27 Oct 2017 10:01:10 +0200 Subject: [PATCH 16/69] Adding main class for testing --- .../cobigen/xmlplugin/appTesting/App.java | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/appTesting/App.java diff --git a/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/appTesting/App.java b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/appTesting/App.java new file mode 100644 index 0000000000..069ddb3fa3 --- /dev/null +++ b/cobigen/cobigen-xmlplugin/src/main/java/com/capgemini/cobigen/xmlplugin/appTesting/App.java @@ -0,0 +1,100 @@ +package com.capgemini.cobigen.xmlplugin.appTesting; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; +import org.xml.sax.SAXException; + +/** + * Hello world! + * + */ +public class App { + + private static Document document; + + private static Document newXmlDocument; + + public static void main(String[] args) throws XPathExpressionException { + + DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = null; + try { + builder = builderFactory.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + + } + + try { + document = builder.parse(new FileInputStream( + "c:\\Users\\jdiazgon\\Documents\\repositorios\\interns-uml-plugin\\master\\RestaurantAsDiagram\\restaurantUseCaseSequence.xml")); + + } catch (SAXException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "XMI/Model/packagedElement/packagedElement[@type='uml:Class']"; + + NodeList list = (NodeList) xPath.evaluate(expression, document, XPathConstants.NODESET); + + List docsList = new LinkedList<>(); + for (int i = 0; i < list.getLength(); i++) { + try { + newXmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + } catch (ParserConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + Element root = newXmlDocument.createElement("xmi:XMI"); + + Node node = list.item(i); + newXmlDocument.appendChild(root); + Node copyNode = newXmlDocument.importNode(node, true); + root.appendChild(copyNode); + docsList.add(newXmlDocument); + } + printXmlDocument((Document) docsList.get(3)); + + list = (NodeList) xPath.evaluate("XMI/packagedElement/@name", docsList.get(1), XPathConstants.NODESET); + System.out.println("Result: " + list.item(0).getNodeValue()); + + /* + * System.out.println("Expresion Xpath:\t" + expression); NodeList nodeList = (NodeList) + * xPath.compile(expression).evaluate(document, XPathConstants.NODESET); + * System.out.println(nodeList.getLength()); for (int i = 0; i < nodeList.getLength(); i++) { + * System.out.println(nodeList.item(i)); expression = "packagedElement[@type='uml:Class']/@name"; + * NodeList nodeList2 = (NodeList) xPath.compile(expression).evaluate(nodeList.item(i), + * XPathConstants.NODESET); for (int j = 0; j < nodeList2.getLength(); j++) { + * System.out.println(nodeList2.item(j)); } } + */ + + } + + public static void printXmlDocument(Document document) { + DOMImplementationLS domImplementationLS = (DOMImplementationLS) document.getImplementation(); + LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); + String string = lsSerializer.writeToString(document); + System.out.println(string); + } +} From 886b782d4932e42d6379995dda359cc724ffd4e0 Mon Sep 17 00:00:00 2001 From: Diaz Gonzalez Date: Fri, 27 Oct 2017 10:52:42 +0200 Subject: [PATCH 17/69] Adding templates folder --- cobigen/templs/CobiGen_Templates/.gitignore | 1 + .../META-INF/LICENSE.CobiGen | 1 + .../named_queries/NamedQueries.java.ftl | 18 + .../constants/named_queries/templates.bak.xml | 17 + .../constants/named_queries/templates.xml | 11 + .../PermissionConstants.java.ftl | 25 + .../security_permissions/templates.bak.xml | 17 + .../security_permissions/templates.xml | 11 + cobigen/templs/CobiGen_Templates/context.xml | 9 + .../crud_angular_client_app/functions.ftl | 57 ++ .../crud_angular_client_app/templates.xml | 44 ++ .../templates/cobigen.properties | 1 + ...les.component}addDialog.component.html.ftl | 11 + ...ables.component}addDialog.component.ts.ftl | 41 ++ ...bles.component}dataGrid.component.html.ftl | 71 ++ ...iables.component}dataGrid.component.ts.ftl | 210 ++++++ ...ariables.component}dataGrid.service.ts.ftl | 53 ++ .../src/app/BusinessOperations.ts.ftl | 33 + .../templates/src/app/app.module.ts.ftl | 80 +++ .../templates/src/app/app.routing.ts.ftl | 6 + .../src/app/home/home.component.html.ftl | 24 + .../templates/src/assets/i18n/en.json.ftl | 48 ++ .../templates/src/assets/i18n/es.json.ftl | 48 ++ .../templates/src/assets/serverPath.ts.ftl | 1 + .../crud_java_server_app/functions.ftl | 76 ++ .../crud_java_server_app/templates.xml | 87 +++ .../AbstractGenericEntityUtils.java.ftl | 99 +++ .../api/${variables.entityName}.java.ftl | 10 + .../${variables.entityName}Entity.java.ftl | 48 ++ ...entityName}EntityRegistrationBean.java.ftl | 57 ++ .../dao/${variables.entityName}Dao.java.ftl | 20 + .../repo/${variables.entityName}Repo.java.ftl | 25 + ...${variables.entityName}RepoCustom.java.ftl | 10 + .../${variables.entityName}RepoImpl.java.ftl | 101 +++ .../${variables.entityName}DaoImpl.java.ftl | 75 ++ .../${variables.component#cap_first}.java.ftl | 44 ++ .../to/${variables.entityName}Cto.java.ftl | 48 ++ .../to/${variables.entityName}Eto.java.ftl | 86 +++ ...ables.entityName}SearchCriteriaTo.java.ftl | 28 + ...ariables.component#cap_first}Impl.java.ftl | 89 +++ ...bles.component#cap_first}RepoImpl.java.ftl | 76 ++ ...s.component#cap_first}RestService.java.ftl | 67 ++ ...s.component#cap_first}SoapService.java.ftl | 40 ++ ...mponent#cap_first}RestServiceImpl.java.ftl | 45 ++ ...mponent#cap_first}SoapServiceImpl.java.ftl | 72 ++ .../common/api/ApplicationEntity.java.ftl | 11 + .../common/api/to/AbstractCto.java.ftl | 20 + .../common/api/to/AbstractEto.java.ftl | 20 + .../api/to/PaginatedListToWrapper.java.ftl | 56 ++ .../base/AbstractBeanMapperSupport.java.ftl | 24 + .../api/ApplicationPersistenceEntity.java.ftl | 25 + .../api/dao/ApplicationDao.java.ftl | 14 + .../base/dao/ApplicationDaoImpl.java.ftl | 29 + .../base/AbstractComponentFacade.java.ftl | 107 +++ .../base/AbstractGenericEntityUtils.java.ftl | 99 +++ .../impl/config/ServiceConfig.java.ftl | 141 ++++ .../WebApplicationContextLocator.java.ftl | 26 + .../functions.ftl | 52 ++ .../templates.xml | 32 + .../${variables.component#cap_first}.java.ftl | 11 + .../UcFind${variables.entityName}.java.ftl | 28 + .../UcManage${variables.entityName}.java.ftl | 26 + ...Abstract${variables.entityName}Uc.java.ftl | 26 + ...ariables.component#cap_first}Impl.java.ftl | 57 ++ ...UcFind${variables.entityName}Impl.java.ftl | 46 ++ ...Manage${variables.entityName}Impl.java.ftl | 50 ++ .../base/AbstractBeanMapperSupport.java.ftl | 24 + .../base/AbstractGenericEntityUtils.java.ftl | 99 +++ .../general/logic/base/AbstractUc.java.ftl | 18 + .../crud_nested_java_server_app/functions.ftl | 76 ++ .../crud_nested_java_server_app/templates.xml | 47 ++ .../${variables.component#cap_first}.java.ftl | 46 ++ .../to/${variables.entityName}Cto.java.ftl | 70 ++ .../to/${variables.entityName}Eto.java.ftl | 86 +++ ...ables.entityName}SearchCriteriaTo.java.ftl | 28 + ...ariables.component#cap_first}Impl.java.ftl | 98 +++ ...s.component#cap_first}RestService.java.ftl | 67 ++ ...s.component#cap_first}SoapService.java.ftl | 46 ++ ...mponent#cap_first}RestServiceImpl.java.ftl | 45 ++ ...mponent#cap_first}SoapServiceImpl.java.ftl | 77 ++ .../common/api/ApplicationEntity.java.ftl | 11 + .../common/api/to/AbstractCto.java.ftl | 20 + .../common/api/to/AbstractEto.java.ftl | 20 + .../api/to/PaginatedListToWrapper.java.ftl | 56 ++ .../base/AbstractBeanMapperSupport.java.ftl | 24 + .../impl/config/ServiceConfig.java.ftl | 141 ++++ .../WebApplicationContextLocator.java.ftl | 26 + .../crud_sencha_client_app/methods.ftl | 148 ++++ .../crud_sencha_client_app/templates.xml | 65 ++ .../app/Application.js.ftl | 24 + .../${variables.domain}/app/Config.js.ftl | 6 + .../app/ConfigDevelopment.js.ftl | 2 + ...iables.etoName#cap_first}Controller.js.ftl | 80 +++ .../app/controller/main/MainController.js.ftl | 14 + .../${variables.etoName#cap_first}.js.ftl | 12 + .../${variables.etoName#cap_first}Crud.js.ftl | 68 ++ ...{variables.etoName#cap_first}CrudVC.js.ftl | 63 ++ ...{variables.etoName#cap_first}CrudVM.js.ftl | 32 + .../${variables.etoName#cap_first}List.js.ftl | 72 ++ ...{variables.etoName#cap_first}ListVC.js.ftl | 74 ++ ...{variables.etoName#cap_first}ListVM.js.ftl | 28 + ...{variables.etoName#cap_first}_en_EN.js.ftl | 55 ++ ...{variables.etoName#cap_first}_es_ES.js.ftl | 55 ++ ...${variables.domain#cap_first}Status.js.ftl | 23 + ...variables.domain#cap_first}StatusVC.js.ftl | 41 ++ .../app/view/main/Content.js.ftl | 20 + .../app/view/main/Header.js.ftl | 69 ++ .../app/view/main/HeaderVC.js.ftl | 13 + .../app/view/main/Home.js.ftl | 11 + .../app/view/main/LeftSidePanel.js.ftl | 27 + .../app/view/main/Menu.js.ftl | 27 + .../app/view/main/i18n/Main_en_EN.js.ftl | 27 + .../app/view/main/i18n/Main_es_ES.js.ftl | 27 + .../embeddables/functions.ftl | 51 ++ .../embeddables/templates.xml | 27 + .../api/${variables.entityName}.java.ftl | 42 ++ ...${variables.entityName}Embeddable.java.ftl | 44 ++ .../to/${variables.entityName}Eto.java.ftl | 82 +++ ...ables.entityName}SearchCriteriaTo.java.ftl | 28 + .../common/api/to/AbstractEto.java.ftl | 20 + cobigen/templs/CobiGen_Templates/logback.xml | 24 + cobigen/templs/CobiGen_Templates/pom.xml | 34 + .../restaurantUseCaseSequence.xml | 666 ++++++++++++++++++ .../sencha_architect_project/functions.ftl | 65 ++ .../sencha_architect_project/templates.xml | 30 + .../${variables.domain}.xds.ftl | 43 ++ .../app.js.ftl | 14 + .../index.html.ftl | 13 + .../metadata/Application.ftl | 13 + ...variables.etoName#cap_first}Controller.ftl | 124 ++++ .../model/${variables.etoName#cap_first}.ftl | 29 + .../view/${variables.etoName#cap_first}s.ftl | 223 ++++++ ...bles.etoName#cap_first}sViewController.ftl | 78 ++ ...variables.etoName#cap_first}sViewModel.ftl | 55 ++ .../src/main/java/constants/pojo/Field.java | 50 ++ .../src/main/java/utils/IDGenerator.java | 122 ++++ .../src/main/java/utils/JavaUtil.java | 323 +++++++++ .../src/main/java/utils/OaspUtil.java | 342 +++++++++ .../src/test/java/utils/JavaUtilTest.java | 291 ++++++++ .../src/test/java/utils/OaspUtilTest.java | 173 +++++ .../test/java/utils/resources/TestClass.java | 26 + .../test/java/utils/resources/TestEntity.java | 5 + .../resources/dataaccess/api/DeepEntity.java | 5 + .../src/test/resources/logback.xml | 14 + .../TestAllTemplatesEntityInput/logback.xml | 14 + .../TestAllTemplatesEntityInput/pom.xml | 53 ++ .../generator/dataaccess/api/InputEntity.java | 25 + .../TestAllTemplatesEtoInput/logback.xml | 14 + .../TestAllTemplatesEtoInput/pom.xml | 53 ++ .../generator/logic/api/to/InputEto.java | 25 + .../test/resources/testinput/InputEntity.java | 38 + .../testdata_builder/ObjectBuilder.java.ftl | 55 ++ .../ObjectBuilder_customFunctions.java.ftl | 22 + ...ObjectBuilder_fillMandatoryFields.java.ftl | 22 + .../ObjectBuilder_persistable.java.ftl | 45 ++ .../testdata_builder/P.java.ftl | 13 + .../testdata_builder/makros.ftl | 41 ++ .../testdata_builder/templates.xml | 25 + cobigen/templs/CobiGen_Templates/uml.xml | 15 + .../CobiGen_Templates/uml_test/functions.ftl | 57 ++ .../CobiGen_Templates/uml_test/templates.xml | 18 + .../java/${variables.className}.java.ftl | 8 + .../Testfiles/restaurantUseCaseSequence.xml | 325 +++++++++ .../templs/CobiGen_Test/src/Testfiles/uml.xml | 15 + .../src/main/java/umlTest/Bill.java | 12 + .../CobiGen_Test/src/restaurantExport.xml | 309 ++++++++ cobigen/templs/README.md | 7 + 167 files changed, 9416 insertions(+) create mode 100644 cobigen/templs/CobiGen_Templates/.gitignore create mode 100644 cobigen/templs/CobiGen_Templates/META-INF/LICENSE.CobiGen create mode 100644 cobigen/templs/CobiGen_Templates/constants/named_queries/NamedQueries.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/constants/named_queries/templates.bak.xml create mode 100644 cobigen/templs/CobiGen_Templates/constants/named_queries/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/constants/security_permissions/PermissionConstants.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/constants/security_permissions/templates.bak.xml create mode 100644 cobigen/templs/CobiGen_Templates/constants/security_permissions/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/context.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/cobigen.properties create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/${variables.component}dataGrid/${variables.component}addDialog/${variables.component}addDialog.component.html.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/${variables.component}dataGrid/${variables.component}addDialog/${variables.component}addDialog.component.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/${variables.component}dataGrid/${variables.component}dataGrid.component.html.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/${variables.component}dataGrid/${variables.component}dataGrid.component.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/${variables.component}dataGrid/shared/${variables.component}dataGrid.service.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/BusinessOperations.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/app.module.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/app.routing.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/app/home/home.component.html.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/assets/i18n/en.json.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/assets/i18n/es.json.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_angular_client_app/templates/src/assets/serverPath.ts.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/AbstractGenericEntityUtils.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Entity.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}EntityRegistrationBean.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/dao/${variables.entityName}Dao.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}Repo.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}RepoCustom.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/repo/${variables.entityName}RepoImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/impl/dao/${variables.entityName}DaoImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}RepoImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractCto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractEto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/PaginatedListToWrapper.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/ApplicationPersistenceEntity.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/api/dao/ApplicationDao.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/dataaccess/base/dao/ApplicationDaoImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractComponentFacade.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/logic/base/AbstractGenericEntityUtils.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcFind${variables.entityName}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/api/usecase/UcManage${variables.entityName}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/base/usecase/Abstract${variables.entityName}Uc.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcFind${variables.entityName}Impl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/usecase/UcManage${variables.entityName}Impl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractGenericEntityUtils.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_java_server_app_complex/templates/java/${variables.rootPackage}/general/logic/base/AbstractUc.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/${variables.component#cap_first}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Cto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/logic/impl/${variables.component#cap_first}Impl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/rest/${variables.component#cap_first}RestService.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/api/soap/${variables.component#cap_first}SoapService.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/rest/${variables.component#cap_first}RestServiceImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/${variables.component}/service/impl/soap/${variables.component#cap_first}SoapServiceImpl.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/common/api/ApplicationEntity.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractCto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/AbstractEto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/common/api/to/PaginatedListToWrapper.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/common/base/AbstractBeanMapperSupport.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/ServiceConfig.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_nested_java_server_app/templates/java/${variables.rootPackage}/general/service/impl/config/WebApplicationContextLocator.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/methods.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/Application.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/Config.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/ConfigDevelopment.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/controller/${variables.etoName#lower_case}/${variables.etoName#cap_first}Controller.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/controller/main/MainController.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/model/${variables.etoName#lower_case}/${variables.etoName#cap_first}.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}Crud.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}CrudVC.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}CrudVM.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}List.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}ListVC.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/${variables.etoName#cap_first}ListVM.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/i18n/${variables.etoName#cap_first}_en_EN.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/${variables.etoName#lower_case}/i18n/${variables.etoName#cap_first}_es_ES.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/${variables.domain#cap_first}Status.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/${variables.domain#cap_first}StatusVC.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/Content.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/Header.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/HeaderVC.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/Home.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/LeftSidePanel.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/Menu.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/i18n/Main_en_EN.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/crud_sencha_client_app/templates/${variables.domain}/app/view/main/i18n/Main_es_ES.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates/java/${variables.rootPackage}/${variables.component}/common/api/${variables.entityName}.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates/java/${variables.rootPackage}/${variables.component}/dataaccess/api/${variables.entityName}Embeddable.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}Eto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates/java/${variables.rootPackage}/${variables.component}/logic/api/to/${variables.entityName}SearchCriteriaTo.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/embeddables/templates/java/${variables.rootPackage}/general/common/api/to/AbstractEto.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/logback.xml create mode 100644 cobigen/templs/CobiGen_Templates/pom.xml create mode 100644 cobigen/templs/CobiGen_Templates/restaurantUseCaseSequence.xml create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/${variables.domain}.xds.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/app.js.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/index.html.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/Application.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/controller/${variables.etoName#cap_first}Controller.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/model/${variables.etoName#cap_first}.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/view/${variables.etoName#cap_first}s.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/view/${variables.etoName#cap_first}sViewController.ftl create mode 100644 cobigen/templs/CobiGen_Templates/sencha_architect_project/templates/${variables.domain}_architect_project/metadata/view/${variables.etoName#cap_first}sViewModel.ftl create mode 100644 cobigen/templs/CobiGen_Templates/src/main/java/constants/pojo/Field.java create mode 100644 cobigen/templs/CobiGen_Templates/src/main/java/utils/IDGenerator.java create mode 100644 cobigen/templs/CobiGen_Templates/src/main/java/utils/JavaUtil.java create mode 100644 cobigen/templs/CobiGen_Templates/src/main/java/utils/OaspUtil.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/java/utils/JavaUtilTest.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/java/utils/OaspUtilTest.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/java/utils/resources/TestClass.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/java/utils/resources/TestEntity.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/java/utils/resources/dataaccess/api/DeepEntity.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/logback.xml create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/logback.xml create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/pom.xml create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEntityInput/src/main/java/io/github/devonfw/cobigen/generator/dataaccess/api/InputEntity.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/logback.xml create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/pom.xml create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testdata/templatetest/TestAllTemplatesEtoInput/src/main/java/io/github/devonfw/cobigen/generator/logic/api/to/InputEto.java create mode 100644 cobigen/templs/CobiGen_Templates/src/test/resources/testinput/InputEntity.java create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/ObjectBuilder.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/ObjectBuilder_customFunctions.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/ObjectBuilder_fillMandatoryFields.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/ObjectBuilder_persistable.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/P.java.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/makros.ftl create mode 100644 cobigen/templs/CobiGen_Templates/testdata_builder/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/uml.xml create mode 100644 cobigen/templs/CobiGen_Templates/uml_test/functions.ftl create mode 100644 cobigen/templs/CobiGen_Templates/uml_test/templates.xml create mode 100644 cobigen/templs/CobiGen_Templates/uml_test/templates/java/${variables.className}.java.ftl create mode 100644 cobigen/templs/CobiGen_Test/src/Testfiles/restaurantUseCaseSequence.xml create mode 100644 cobigen/templs/CobiGen_Test/src/Testfiles/uml.xml create mode 100644 cobigen/templs/CobiGen_Test/src/main/java/umlTest/Bill.java create mode 100644 cobigen/templs/CobiGen_Test/src/restaurantExport.xml create mode 100644 cobigen/templs/README.md diff --git a/cobigen/templs/CobiGen_Templates/.gitignore b/cobigen/templs/CobiGen_Templates/.gitignore new file mode 100644 index 0000000000..b83d22266a --- /dev/null +++ b/cobigen/templs/CobiGen_Templates/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/cobigen/templs/CobiGen_Templates/META-INF/LICENSE.CobiGen b/cobigen/templs/CobiGen_Templates/META-INF/LICENSE.CobiGen new file mode 100644 index 0000000000..346e51a909 --- /dev/null +++ b/cobigen/templs/CobiGen_Templates/META-INF/LICENSE.CobiGen @@ -0,0 +1 @@ +The usage of this software is subject to the terms and conditions of the Capgemini CobiGen License Agreement. To the extent that CobiGen contains software licensed under open source licenses, the respective license terms apply. The rights for using the open source software are granted directly by the respective owner of those rights as set forth in the corresponding open source license terms. To the extent CobiGen contains Capgemini proprietary code, non-transferrable use rights are granted by Capgemini as set forth in the CobiGen License Agreement. \ No newline at end of file diff --git a/cobigen/templs/CobiGen_Templates/constants/named_queries/NamedQueries.java.ftl b/cobigen/templs/CobiGen_Templates/constants/named_queries/NamedQueries.java.ftl new file mode 100644 index 0000000000..f10c44db3b --- /dev/null +++ b/cobigen/templs/CobiGen_Templates/constants/named_queries/NamedQueries.java.ftl @@ -0,0 +1,18 @@ +<#macro toCamelCase points> +${points?replace(".a","A")?replace(".b","B")?replace(".c","C")?replace(".d","D")?replace(".e","E")?replace(".f","F")?replace(".g","G")?replace(".h","H")?replace(".i","I")?replace(".j","J")?replace(".k","K")?replace(".l","L")?replace(".m","M")?replace(".n","N")?replace(".o","O")?replace(".p","P")?replace(".q","Q")?replace(".r","R")?replace(".s","S")?replace(".t","T")?replace(".u","U")?replace(".v","V")?replace(".w","W")?replace(".x","X")?replace(".y","Y")?replace(".z","Z")} +<#macro toUnderScore points> +${points?upper_case?replace('.', '_')} +package ${variables.rootPackage}.general.common.api.constants; + +/** + * Constants of the named queries defined in NamedQueries.xml. + */ +public abstract class NamedQueries { + +<#list .vars['entity-mappings'].Children as namedQuery> +<#if namedQuery._nodeName_ == "named-query"> +public static final String <@toUnderScore points=namedQuery._at_name/> = "${namedQuery._at_name}"; + + + +} diff --git a/cobigen/templs/CobiGen_Templates/constants/named_queries/templates.bak.xml b/cobigen/templs/CobiGen_Templates/constants/named_queries/templates.bak.xml new file mode 100644 index 0000000000..a3a82c00b6 --- /dev/null +++ b/cobigen/templs/CobiGen_Templates/constants/named_queries/templates.bak.xml @@ -0,0 +1,17 @@ + + + + + +