From 6c4672dbb3cccd6c7d8cdfde2f59a97af7cfac42 Mon Sep 17 00:00:00 2001 From: Vlastimil Starec Date: Tue, 14 Apr 2020 21:49:47 +0200 Subject: Perform repository cleanup 1. Perform whitespace cleanup in source files Changes are almost exclusively in indentation and line breaks. Some safe spelling fixes may had gotten staged too. 2. Update license file and license headers on java files Change "2019" to "2019-2020" (fix 2017-2018 in some cases). Convert to block comment format. Make "Orange Intellectual Property" consistent across headers. 3. Prepend javascript files with license headers 4. Rename frontend filenames to lowercase 5. Add missing semicolons after statements in react files Issue-ID: AAI-2861 Signed-off-by: Vlastimil Starec Change-Id: Ieee5562ce9e360da3db1f990a6cf4c1b1e56f657 --- src/main/java/org/onap/aai/graphgraph/App.java | 62 +- .../org/onap/aai/graphgraph/ArgumentParser.java | 107 ++-- src/main/java/org/onap/aai/graphgraph/Config.java | 45 +- .../java/org/onap/aai/graphgraph/CorsFilter.java | 62 +- .../org/onap/aai/graphgraph/ModelExporter.java | 415 ++++++------- .../org/onap/aai/graphgraph/SchemaResource.java | 77 ++- .../org/onap/aai/graphgraph/SchemaValidator.java | 158 ++--- .../java/org/onap/aai/graphgraph/dto/Edge.java | 45 +- .../java/org/onap/aai/graphgraph/dto/Graph.java | 45 +- .../java/org/onap/aai/graphgraph/dto/NodeName.java | 41 +- .../org/onap/aai/graphgraph/dto/NodeProperty.java | 44 +- .../java/org/onap/aai/graphgraph/dto/Property.java | 44 +- .../aai/graphgraph/dto/ValidationProblems.java | 55 +- .../aai/graphgraph/reader/BasicSchemaReader.java | 675 ++++++++++----------- .../org/onap/aai/graphgraph/reader/EdgeType.java | 60 +- .../onap/aai/graphgraph/reader/MetadataEdge.java | 112 ++-- .../onap/aai/graphgraph/reader/SchemaReader.java | 45 +- .../aai/graphgraph/reader/SchemaRepository.java | 44 +- .../graphgraph/velocity/VelocityAssociation.java | 204 +++---- .../aai/graphgraph/velocity/VelocityEntity.java | 144 +++-- .../velocity/VelocityEntityProperty.java | 96 ++- .../onap/aai/graphgraph/velocity/VelocityId.java | 51 +- src/main/resources/docker-assembly.xml | 12 +- src/main/resources/etc/auth/realm.properties | 22 +- src/main/resources/model_export.vm | 280 ++++----- src/test/java/org/onap/aai/graphgraph/AppTest.java | 38 +- 26 files changed, 1502 insertions(+), 1481 deletions(-) (limited to 'src') diff --git a/src/main/java/org/onap/aai/graphgraph/App.java b/src/main/java/org/onap/aai/graphgraph/App.java index ed1bb9a..1c6bc61 100644 --- a/src/main/java/org/onap/aai/graphgraph/App.java +++ b/src/main/java/org/onap/aai/graphgraph/App.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -40,32 +40,35 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; @SpringBootApplication -public class App{ +public class App { + public static EdgeIngestor edgeIngestor; public static Map moxyLoaders = new HashMap<>(); // TODO // this should be used properly within Spring as this is a 'static' workaround due // to some initialization issues. By all means feel free to improve and move it to Spring - public static void loadSchemes(ConfigurableApplicationContext context){ + public static void loadSchemes(ConfigurableApplicationContext context) { String version; for (int i = 10; i < 19; i++) { version = "v" + i; - moxyLoaders.put(version, new MoxyLoader(new SchemaVersion(version), (NodeIngestor) context.getBean("nodeIngestor")) ); + moxyLoaders.put(version, new MoxyLoader( + new SchemaVersion(version), (NodeIngestor) context.getBean("nodeIngestor")) + ); } } - public static void main( String[] args ) throws IOException { + public static void main(String[] args) throws IOException { ArgumentParser parser = new ArgumentParser().parseArguments(args); - if (parser.isPrintHelp()){ + if (parser.isPrintHelp()) { parser.printHelp(); return; } - SpringApplication app = new SpringApplication(App.class); + SpringApplication app = new SpringApplication(App.class); - if (parser.isRunLocally()){ + if (parser.isRunLocally()) { copyKeystore(app); } @@ -74,7 +77,7 @@ public class App{ loadSchemes(context); edgeIngestor = (EdgeIngestor) context.getBean("edgeIngestor"); - if (parser.shoudGenerateUml()){ + if (parser.shouldGenerateUrl()) { writeExportedModel(exportModel(parser.getSchemaVersion())); System.exit(0); } @@ -83,9 +86,10 @@ public class App{ private static void copyKeystore(SpringApplication app) throws IOException { Path path = Paths.get("etc/auth/aai_keystore"); if (Files.notExists(path)) { - FileUtils.copyInputStreamToFile(Objects - .requireNonNull(app.getClassLoader().getResourceAsStream("etc/auth/aai_keystore")), - path.toFile()); + FileUtils.copyInputStreamToFile( + Objects.requireNonNull(app.getClassLoader().getResourceAsStream("etc/auth/aai_keystore")), + path.toFile() + ); } } } diff --git a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java index 4405723..e156e39 100644 --- a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java +++ b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -24,51 +24,50 @@ import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; public class ArgumentParser { - @Option(name = "-g", usage = "generates schema model for Papyrus and exits where XY is the version", metaVar = "vXY") - private String schemaVersion; - - @Option(name = "-d", usage = "connect to dev version of schema-service (use JAR bundled keystore)") - private boolean runLocally; - @Option(name = "-h", usage = "print help and exit") - private boolean printHelp; + CmdLineParser parser; + @Option(name = "-g", usage = "generates schema model for Papyrus and exits where XY is the version", + metaVar = "vXY") + private String schemaVersion; + @Option(name = "-d", usage = "connect to dev version of schema-service (use JAR bundled keystore)") + private boolean runLocally; + @Option(name = "-h", usage = "print help and exit") + private boolean printHelp; - CmdLineParser parser; + public ArgumentParser parseArguments(String[] args) { + parser = new CmdLineParser(this); - public ArgumentParser parseArguments(String [] args){ - parser = new CmdLineParser(this); + try { + parser.parseArgument(args); + } catch (CmdLineException e) { + System.err.println(e.getMessage()); + parser.printUsage(System.err); + } - try { - parser.parseArgument(args); - } catch( CmdLineException e ) { - System.err.println(e.getMessage()); - parser.printUsage(System.err); + return this; } - return this; - } - - public String getSchemaVersion() { - return schemaVersion; - } + public String getSchemaVersion() { + return schemaVersion; + } - public void setSchemaVersion(String schemaVersion) { - this.schemaVersion = schemaVersion; - } + public void setSchemaVersion(String schemaVersion) { + this.schemaVersion = schemaVersion; + } - public boolean shoudGenerateUml(){ - return schemaVersion != null; - } + public boolean shouldGenerateUrl() { + return schemaVersion != null; + } - public boolean isRunLocally() { - return runLocally; - } + public boolean isRunLocally() { + return runLocally; + } - public boolean isPrintHelp() { - return printHelp; - } + public boolean isPrintHelp() { + return printHelp; + } - public void printHelp(){ - parser.printUsage(System.out); - } + public void printHelp() { + parser.printUsage(System.out); + } } diff --git a/src/main/java/org/onap/aai/graphgraph/Config.java b/src/main/java/org/onap/aai/graphgraph/Config.java index 1d4152b..bbc082f 100644 --- a/src/main/java/org/onap/aai/graphgraph/Config.java +++ b/src/main/java/org/onap/aai/graphgraph/Config.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -31,9 +31,9 @@ import org.springframework.context.annotation.Configuration; @Configuration @ComponentScan(basePackages = { - "org.onap.aai.config", - "org.onap.aai.setup", - "org.onap.aai.graphgraph" + "org.onap.aai.config", + "org.onap.aai.setup", + "org.onap.aai.graphgraph" }) public class Config { @@ -41,7 +41,7 @@ public class Config { String schemaVersions; @Bean - SchemaRepository createSchemaRepository(){ + SchemaRepository createSchemaRepository() { List readers = new LinkedList<>(); for (String s : schemaVersions.split(",")) { readers.add(new BasicSchemaReader(s)); @@ -50,4 +50,3 @@ public class Config { } } - diff --git a/src/main/java/org/onap/aai/graphgraph/CorsFilter.java b/src/main/java/org/onap/aai/graphgraph/CorsFilter.java index 448a2ea..ab97255 100644 --- a/src/main/java/org/onap/aai/graphgraph/CorsFilter.java +++ b/src/main/java/org/onap/aai/graphgraph/CorsFilter.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -30,15 +30,17 @@ import org.springframework.web.filter.OncePerRequestFilter; @Component public class CorsFilter extends OncePerRequestFilter { - @Override - protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, - final FilterChain filterChain) throws ServletException, IOException { - response.addHeader("Access-Control-Allow-Origin", "*"); - response.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, HEAD"); - response.addHeader("Access-Control-Allow-Headers", "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); - response.addHeader("Access-Control-Expose-Headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials"); - response.addHeader("Access-Control-Allow-Credentials", "true"); - response.addIntHeader("Access-Control-Max-Age", 10); - filterChain.doFilter(request, response); - } -} \ No newline at end of file + @Override + protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, + final FilterChain filterChain) throws ServletException, IOException { + response.addHeader("Access-Control-Allow-Origin", "*"); + response.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, PATCH, HEAD"); + response.addHeader("Access-Control-Allow-Headers", + "Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers"); + response.addHeader("Access-Control-Expose-Headers", + "Access-Control-Allow-Origin, Access-Control-Allow-Credentials"); + response.addHeader("Access-Control-Allow-Credentials", "true"); + response.addIntHeader("Access-Control-Max-Age", 10); + filterChain.doFilter(request, response); + } +} diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java index 36070db..047bd92 100644 --- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java +++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -54,214 +54,221 @@ import org.onap.aai.setup.SchemaVersion; public class ModelExporter { - private static final String AAIMODEL_UML_FILENAME = "aaimodel.uml"; - private static final String VELOCITY_TEMPLATE_FILENAME = "model_export.vm"; - private static final boolean OXM_ENABLED = false; - private static final String camelCaseRegex = "(?=[A-Z][a-z])"; - private static Map allEntities; - private static Multimap getEdgeRules(String schemaVersion) { - try { - Multimap allRules = App.edgeIngestor.getAllRules(new SchemaVersion(schemaVersion)); - allEntities = App.moxyLoaders.get(schemaVersion).getAllObjects(); - if (OXM_ENABLED) { - addOxmRelationships(allRules, allEntities); - } - return allRules; - } catch (EdgeRuleNotFoundException e) { - e.printStackTrace(); - } - - return null; - } + private static final String AAIMODEL_UML_FILENAME = "aaimodel.uml"; + private static final String VELOCITY_TEMPLATE_FILENAME = "model_export.vm"; + private static final boolean OXM_ENABLED = false; + private static final String camelCaseRegex = "(?=[A-Z][a-z])"; + private static Map allEntities; - private static void addOxmRelationships(Multimap allRules, - Map allEntities) { - for (Entry currentParent : allEntities.entrySet()) { - currentParent.getValue().getProperties().stream() - .filter(v -> allEntities.containsKey(v)) - .filter(v -> !currentParent.getKey().equals(v)) - .forEach(v -> { - String key = currentParent.getKey() + "|" + v; - if (!allRules.containsKey(key)) { - allRules.put(key, createEdgeRule(currentParent.getKey(), v)); + private static Multimap getEdgeRules(String schemaVersion) { + try { + Multimap allRules = App.edgeIngestor.getAllRules(new SchemaVersion(schemaVersion)); + allEntities = App.moxyLoaders.get(schemaVersion).getAllObjects(); + if (OXM_ENABLED) { + addOxmRelationships(allRules, allEntities); } - }); + return allRules; + } catch (EdgeRuleNotFoundException e) { + e.printStackTrace(); + } + + return null; } - } - private static EdgeRule createEdgeRule(String parent, String child) { - Map edgeRuleProps = new HashMap<>(); - edgeRuleProps.put(EdgeField.FROM.toString(), child); - edgeRuleProps.put(EdgeField.TO.toString(), parent); - edgeRuleProps.put(EdgeField.DIRECTION.toString(), Direction.OUT.toString()); //TODO check direction - edgeRuleProps.put(EdgeField.LABEL.toString(), "OXM Parent-Child"); - edgeRuleProps.put(EdgeField.MULTIPLICITY.toString(), MultiplicityRule.MANY2ONE.toString()); - edgeRuleProps.put(EdgeField.DEFAULT.toString(), Boolean.toString(false)); - edgeRuleProps.put(EdgeField.PRIVATE.toString(), Boolean.toString(false)); - edgeRuleProps.put(EdgeField.DELETE_OTHER_V.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.PREVENT_DELETE.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.CONTAINS.toString(), DirectionNotation.DIRECTION.toString()); - edgeRuleProps.put(EdgeField.DESCRIPTION.toString(), "fake edgerule representing parent-child"); - return new EdgeRule(edgeRuleProps); - } + private static void addOxmRelationships( + Multimap allRules, + Map allEntities) { + for (Entry currentParent : allEntities.entrySet()) { + currentParent.getValue().getProperties().stream() + .filter(v -> allEntities.containsKey(v)) + .filter(v -> !currentParent.getKey().equals(v)) + .forEach(v -> { + String key = currentParent.getKey() + "|" + v; + if (!allRules.containsKey(key)) { + allRules.put(key, createEdgeRule(currentParent.getKey(), v)); + } + }); + } + } - static String exportModel(String schemaVersion) { - Map allObjects = App.moxyLoaders.get(schemaVersion).getAllObjects(); - Template t = initVelocity(); - VelocityContext context = populateVelocityContext(schemaVersion, allObjects); - StringWriter writer = new StringWriter(); - t.merge( context, writer ); - return writer.toString(); - } + private static EdgeRule createEdgeRule(String parent, String child) { + Map edgeRuleProps = new HashMap<>(); + edgeRuleProps.put(EdgeField.FROM.toString(), child); + edgeRuleProps.put(EdgeField.TO.toString(), parent); + edgeRuleProps.put(EdgeField.DIRECTION.toString(), Direction.OUT.toString()); //TODO check direction + edgeRuleProps.put(EdgeField.LABEL.toString(), "OXM Parent-Child"); + edgeRuleProps.put(EdgeField.MULTIPLICITY.toString(), MultiplicityRule.MANY2ONE.toString()); + edgeRuleProps.put(EdgeField.DEFAULT.toString(), Boolean.toString(false)); + edgeRuleProps.put(EdgeField.PRIVATE.toString(), Boolean.toString(false)); + edgeRuleProps.put(EdgeField.DELETE_OTHER_V.toString(), DirectionNotation.DIRECTION.toString()); + edgeRuleProps.put(EdgeField.PREVENT_DELETE.toString(), DirectionNotation.DIRECTION.toString()); + edgeRuleProps.put(EdgeField.CONTAINS.toString(), DirectionNotation.DIRECTION.toString()); + edgeRuleProps.put(EdgeField.DESCRIPTION.toString(), "fake edgerule representing parent-child"); + return new EdgeRule(edgeRuleProps); + } - static void writeExportedModel(String result) { - try { - FileWriter fw = new FileWriter(AAIMODEL_UML_FILENAME); - fw.write(result); - fw.close(); - } catch (IOException e) { - e.printStackTrace(); + static String exportModel(String schemaVersion) { + Map allObjects = App.moxyLoaders.get(schemaVersion).getAllObjects(); + Template t = initVelocity(); + VelocityContext context = populateVelocityContext(schemaVersion, allObjects); + StringWriter writer = new StringWriter(); + t.merge(context, writer); + return writer.toString(); } - } - private static VelocityContext populateVelocityContext(String schemaVersion, - Map allObjects) { - VelocityContext context = new VelocityContext(); - Multimap edgeRules = getEdgeRules(schemaVersion); - Set entityList = createEntityList(edgeRules); - Set associationsList = createVelocityAssociations(entityList, edgeRules); - updateEntities(entityList, associationsList, allObjects); - context.put("entityList", entityList); - context.put("associationList", associationsList); - return context; - } + static void writeExportedModel(String result) { + try { + FileWriter fw = new FileWriter(AAIMODEL_UML_FILENAME); + fw.write(result); + fw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } - private static Template initVelocity() { - VelocityEngine ve = new VelocityEngine(); - ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); - ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); - ve.init(); - return ve.getTemplate(VELOCITY_TEMPLATE_FILENAME); - } + private static VelocityContext populateVelocityContext( + String schemaVersion, + Map allObjects) { + VelocityContext context = new VelocityContext(); + Multimap edgeRules = getEdgeRules(schemaVersion); + Set entityList = createEntityList(edgeRules); + Set associationsList = createVelocityAssociations(entityList, edgeRules); + updateEntities(entityList, associationsList, allObjects); + context.put("entityList", entityList); + context.put("associationList", associationsList); + return context; + } - private static void updateEntities(Set entityList, - Set associationsList, - Map allObjects) { - entityList.forEach(e -> { - List associations = associationsList.stream() - .filter(a -> a.getFromEntityId().equals(e.getId())).collect( - Collectors.toList()); - updateNeighbour(entityList, associations); - String description = allEntities.get(e.getName()).getMetadata(ObjectMetadata.DESCRIPTION); - e.setDescription(StringUtil.isBlank(description) ? "no description is available" : description); - }); + private static Template initVelocity() { + VelocityEngine ve = new VelocityEngine(); + ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); + ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); + ve.init(); + return ve.getTemplate(VELOCITY_TEMPLATE_FILENAME); + } - entityList.forEach(entity -> entity.setProperties(getPropertiesForEntity(allObjects.get(entity.getName()), entityList))); + private static void updateEntities( + Set entityList, + Set associationsList, + Map allObjects) { + entityList.forEach(e -> { + List associations = associationsList.stream() + .filter(a -> a.getFromEntityId().equals(e.getId())).collect( + Collectors.toList()); + updateNeighbour(entityList, associations); + String description = allEntities.get(e.getName()).getMetadata(ObjectMetadata.DESCRIPTION); + e.setDescription(StringUtil.isBlank(description) ? "no description is available" : description); + }); - } + entityList.forEach( + entity -> entity.setProperties(getPropertiesForEntity(allObjects.get(entity.getName()), entityList))); - private static void updateNeighbour( - Set entityList, List associations) { - associations.forEach(ass -> { - VelocityEntity velocityEntity = entityList.stream() - .filter(e -> e.getId().equals(ass.getToEntityId())).findFirst().get(); - velocityEntity.addNeighbours(ass); - }); - } + } - private static Set getPropertiesForEntity(Introspector introspector, - Set entityList) { - return introspector.getProperties().stream() - .map(p -> new VelocityEntityProperty( - p, - introspector.getType(p), - findVelocityEntity(introspector.getType(p), entityList))) - .collect( - Collectors.toSet()); - } + private static void updateNeighbour( + Set entityList, List associations) { + associations.forEach(ass -> { + VelocityEntity velocityEntity = entityList.stream() + .filter(e -> e.getId().equals(ass.getToEntityId())).findFirst().get(); + velocityEntity.addNeighbours(ass); + }); + } - private static Set createEntityList( - Multimap edgeRules) { - return Objects.requireNonNull(edgeRules).values().stream() - .flatMap(er -> Stream.of(er.getFrom(), er.getTo())) - .map(VelocityEntity::new) - .collect(Collectors.toSet()); - } + private static Set getPropertiesForEntity( + Introspector introspector, + Set entityList) { + return introspector.getProperties().stream() + .map(p -> new VelocityEntityProperty( + p, + introspector.getType(p), + findVelocityEntity(introspector.getType(p), entityList))) + .collect( + Collectors.toSet()); + } - private static Set createVelocityAssociations(Set entities, - Multimap edgeRules) { - return edgeRules.values().stream().flatMap(er -> { - VelocityAssociation out = createVelocityAssociation(entities, er.getFrom(), er.getTo(), - er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); - VelocityAssociation in = createVelocityAssociation(entities, er.getTo(), er.getFrom(), - er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); - switch (er.getDirection()) { - case OUT: - return Stream.of(out); - case IN: - return Stream.of(in); - case BOTH: - return Stream.of(out, in); - default: - return null; - } - }).collect(Collectors.toSet()); - } + private static Set createEntityList( + Multimap edgeRules) { + return Objects.requireNonNull(edgeRules).values().stream() + .flatMap(er -> Stream.of(er.getFrom(), er.getTo())) + .map(VelocityEntity::new) + .collect(Collectors.toSet()); + } - private static VelocityAssociation createVelocityAssociation(Set entities, - String from, String to, String label, String multiplicity, String contains) { - VelocityEntity fromEntity = entities.stream().filter(ent -> ent.getName().equals(from)) - .findFirst().get(); - VelocityEntity toEntity = entities.stream().filter(ent -> ent.getName().equals(to)).findFirst() - .get(); - switch (contains) { - case "IN": - return new VelocityAssociation( - fromEntity, - toEntity, - String.format("%s - %s (%s)", from, to, shortenLabel(label)), - multiplicity, - true); - case "OUT": - return new VelocityAssociation( - toEntity, - fromEntity, - String.format("%s - %s (%s)", to, from, shortenLabel(label)), - multiplicity.equals("ONE2MANY") ? "MANY2ONE" : multiplicity, - true); - default: - return new VelocityAssociation( - fromEntity, - toEntity, - String.format("%s - %s (%s)", from, to, shortenLabel(label)), - multiplicity, - false); + private static Set createVelocityAssociations( + Set entities, + Multimap edgeRules) { + return edgeRules.values().stream().flatMap(er -> { + VelocityAssociation out = createVelocityAssociation(entities, er.getFrom(), er.getTo(), + er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); + VelocityAssociation in = createVelocityAssociation(entities, er.getTo(), er.getFrom(), + er.getLabel(), er.getMultiplicityRule().name(), er.getContains()); + switch (er.getDirection()) { + case OUT: + return Stream.of(out); + case IN: + return Stream.of(in); + case BOTH: + return Stream.of(out, in); + default: + return null; + } + }).collect(Collectors.toSet()); } - } - private static String shortenLabel(String label) { - if (label.contains(".")) { - String[] split = label.split("\\."); - return split[split.length - 1]; + private static VelocityAssociation createVelocityAssociation( + Set entities, String from, String to, String label, String multiplicity, String contains) { + VelocityEntity fromEntity = entities.stream() + .filter(ent -> ent.getName().equals(from)).findFirst().get(); + VelocityEntity toEntity = entities.stream() + .filter(ent -> ent.getName().equals(to)).findFirst().get(); + switch (contains) { + case "IN": + return new VelocityAssociation( + fromEntity, + toEntity, + String.format("%s - %s (%s)", from, to, shortenLabel(label)), + multiplicity, + true); + case "OUT": + return new VelocityAssociation( + toEntity, + fromEntity, + String.format("%s - %s (%s)", to, from, shortenLabel(label)), + multiplicity.equals("ONE2MANY") ? "MANY2ONE" : multiplicity, + true); + default: + return new VelocityAssociation( + fromEntity, + toEntity, + String.format("%s - %s (%s)", from, to, shortenLabel(label)), + multiplicity, + false); + } } - return label; - } + private static String shortenLabel(String label) { + if (label.contains(".")) { + String[] split = label.split("\\."); + return split[split.length - 1]; + } - private static VelocityEntity findVelocityEntity(String entityName, Set entities) { - if (entityName.startsWith("java.lang")){ - return null; + return label; } - if ( ! entityName.startsWith("inventory.aai.onap.org")){ - return null; - } + private static VelocityEntity findVelocityEntity(String entityName, Set entities) { + if (entityName.startsWith("java.lang")) { + return null; + } - String[] split = entityName.split("\\."); - String entityNameRoot = split[split.length - 1]; - final Pattern pattern = Pattern.compile(camelCaseRegex); - final Matcher matcher = pattern.matcher(entityNameRoot.substring(1, entityNameRoot.length())); - String finalEntityNameRoot = (entityNameRoot.charAt(0) + matcher.replaceAll("-")).toLowerCase(); - return entities.stream().filter(e -> e.getName().equals(finalEntityNameRoot)).findFirst().orElse(null); - } -} \ No newline at end of file + if (!entityName.startsWith("inventory.aai.onap.org")) { + return null; + } + + String[] split = entityName.split("\\."); + String entityNameRoot = split[split.length - 1]; + final Pattern pattern = Pattern.compile(camelCaseRegex); + final Matcher matcher = pattern.matcher(entityNameRoot.substring(1)); + String finalEntityNameRoot = (entityNameRoot.charAt(0) + matcher.replaceAll("-")).toLowerCase(); + return entities.stream().filter(e -> e.getName().equals(finalEntityNameRoot)).findFirst().orElse(null); + } +} diff --git a/src/main/java/org/onap/aai/graphgraph/SchemaResource.java b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java index b38ef7b..577e235 100644 --- a/src/main/java/org/onap/aai/graphgraph/SchemaResource.java +++ b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -43,67 +43,66 @@ public class SchemaResource { SchemaRepository repository; @RequestMapping("/schemas") - public List loadSchemaNames() { + public List loadSchemaNames() { return repository.getAllSchemaNames(); } - @RequestMapping("/schemas/{schema}/nodes") - public List loadVertexNames(@PathVariable("schema") String schemaName, - @RequestParam("edgeFilter") String edgeFilter) { + public List loadVertexNames( + @PathVariable("schema") String schemaName, + @RequestParam("edgeFilter") String edgeFilter) { return repository.getSchemaReader(schemaName).getAllVertexNames(edgeFilter); } @RequestMapping("/schemas/{schema}/nodes/{node}") - public List loadProperties(@PathVariable("schema") String schemaName, @PathVariable("node") String node) { + public List loadProperties( + @PathVariable("schema") String schemaName, + @PathVariable("node") String node) { return repository.getSchemaReader(schemaName).getVertexProperties(node); } - @RequestMapping("/schemas/{schema}/edges") - public List loadedgeProperties ( + public List loadEdgeProperties( @PathVariable("schema") String schemaName, @RequestParam("fromNode") String fromNodeName, @RequestParam("toNode") String toNodeName) { return repository.getSchemaReader(schemaName).getEdgeProperties(fromNodeName, toNodeName, "edgerule"); } - @RequestMapping("/schemas/{schema}/graph/basic") - public Graph loadGraph ( + public Graph loadGraph( @PathVariable("schema") String schemaName, @RequestParam("node") String initialNodeName, @RequestParam("parentHops") Integer parentHops, @RequestParam("cousinHops") Integer cousinHops, @RequestParam("childHops") Integer childHops, - @RequestParam("edgeFilter") String edgeFilter) - { - Graph graph = repository.getSchemaReader(schemaName).getGraph(initialNodeName, parentHops, cousinHops, childHops, edgeFilter); - graph.setPaths(Collections.emptyList()); - return graph; + @RequestParam("edgeFilter") String edgeFilter) { + Graph graph = repository.getSchemaReader(schemaName) + .getGraph(initialNodeName, parentHops, cousinHops, childHops, edgeFilter); + graph.setPaths(Collections.emptyList()); + return graph; } - @RequestMapping("/schemas/{schema}/graph/paths") - public Graph loadGraphWithPaths ( + public Graph loadGraphWithPaths( @PathVariable("schema") String schemaName, @RequestParam("fromNode") String fromNode, @RequestParam("toNode") String toNode, - @RequestParam("edgeFilter") String edgeFilter) - { + @RequestParam("edgeFilter") String edgeFilter) { return repository.getSchemaReader(schemaName).getGraph(fromNode, toNode, edgeFilter); } @RequestMapping("/schemas/{schema}/validation") - public ValidationProblems validateSchema ( @PathVariable("schema") String schemaName) { + public ValidationProblems validateSchema( + @PathVariable("schema") String schemaName) { return new SchemaValidator().validate(schemaName); } @RequestMapping(value = "/schemas/{schema}/xmiexport", produces = MediaType.TEXT_XML_VALUE) @ResponseBody - public String exportSchema ( @PathVariable("schema") String schemaName) { + public String exportSchema( + @PathVariable("schema") String schemaName) { return ModelExporter.exportModel(schemaName); } } - diff --git a/src/main/java/org/onap/aai/graphgraph/SchemaValidator.java b/src/main/java/org/onap/aai/graphgraph/SchemaValidator.java index aa260aa..076c31e 100644 --- a/src/main/java/org/onap/aai/graphgraph/SchemaValidator.java +++ b/src/main/java/org/onap/aai/graphgraph/SchemaValidator.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -32,70 +32,74 @@ import org.onap.aai.graphgraph.dto.ValidationProblems; import org.onap.aai.graphgraph.reader.BasicSchemaReader; public class SchemaValidator { - private Graph edgerules; - private Graph oxm; - public ValidationProblems validate(String schemaVersion) { - ValidationProblems validationProblems = new ValidationProblems(); - BasicSchemaReader schema = new BasicSchemaReader(schemaVersion); - oxm = schema.getGraph("all", 0, 0, 0, "Parents"); - edgerules = schema.getGraph("all", 0, 0, 0, "Edgerules"); - checkIfDanglingEdgerules(validationProblems); - checkIfObsoleteOxm(validationProblems); - schema.getSchemaErrors().forEach(validationProblems::addProblem); - return validationProblems; - } + private Graph edgerules; + private Graph oxm; + + public ValidationProblems validate(String schemaVersion) { + ValidationProblems validationProblems = new ValidationProblems(); + BasicSchemaReader schema = new BasicSchemaReader(schemaVersion); + oxm = schema.getGraph("all", 0, 0, 0, "Parents"); + edgerules = schema.getGraph("all", 0, 0, 0, "Edgerules"); + + checkIfDanglingEdgerules(validationProblems); + checkIfObsoleteOxm(validationProblems); + schema.getSchemaErrors().forEach(validationProblems::addProblem); + return validationProblems; + } - /** - * computes nodes connected to relationship-list but not used in edgerules - * @param validationProblems - */ - private void checkIfObsoleteOxm(ValidationProblems validationProblems) { - Set relationshipListConnected = getAllNodesConnectedToRelationshipList(); - Set nodesInEdgerules = getEdgerulePairs().stream().flatMap(p -> Stream.of(p._1, p._2)) - .collect(Collectors.toSet()); - relationshipListConnected.removeAll(nodesInEdgerules); - relationshipListConnected.forEach(n -> - validationProblems.addProblem(String.format("%s is associated with relationship-list in OXM but not present in edgerules", n))); - } + /** + * computes nodes connected to relationship-list but not used in edgerules + * @param validationProblems + */ + private void checkIfObsoleteOxm(ValidationProblems validationProblems) { + Set relationshipListConnected = getAllNodesConnectedToRelationshipList(); + Set nodesInEdgerules = getEdgerulePairs().stream() + .flatMap(p -> Stream.of(p._1, p._2)) + .collect(Collectors.toSet()); + relationshipListConnected.removeAll(nodesInEdgerules); + relationshipListConnected.forEach(n -> validationProblems.addProblem( + String.format("%s is associated with relationship-list in OXM but not present in edgerules", + n))); + } - private Set> getEdgerulePairs() { - return edgerules.getEdges().stream() - .map(e -> Tuple.of(e.getSource(), e.getTarget())).collect( - Collectors.toSet()); - } + private Set> getEdgerulePairs() { + return edgerules.getEdges().stream() + .map(e -> Tuple.of(e.getSource(), e.getTarget())) + .collect(Collectors.toSet()); + } - /** - * computes edgerules which don't have the necessary connection to relationship-list in OXM - * @param validationProblems - */ - private void checkIfDanglingEdgerules( - ValidationProblems validationProblems) { - Set> edgerulePairs = getEdgerulePairs(); - edgerulePairs.removeAll(getOxmPairs()); - edgerulePairs.forEach( erp -> - validationProblems.addProblem(String.format("%s and %s are associated in edgerules but not in OXM (via relationship-list)", erp._1, erp._2))); - } + /** + * computes edgerules which don't have the necessary connection to relationship-list in OXM + * @param validationProblems + */ + private void checkIfDanglingEdgerules(ValidationProblems validationProblems) { + Set> edgerulePairs = getEdgerulePairs(); + edgerulePairs.removeAll(getOxmPairs()); + edgerulePairs.forEach(erp -> validationProblems.addProblem( + String.format("%s and %s are associated in edgerules but not in OXM (via relationship-list)", + erp._1, erp._2))); + } - private Set> getOxmPairs() { - Set> pairs = new HashSet<>(); - Set inRelationshipList = getAllNodesConnectedToRelationshipList(); + private Set> getOxmPairs() { + Set> pairs = new HashSet<>(); + Set inRelationshipList = getAllNodesConnectedToRelationshipList(); - inRelationshipList.forEach(edge1 -> - inRelationshipList.forEach(edge2 -> { - pairs.add(Tuple.of(edge1, edge2)); - })); - return pairs; - } + inRelationshipList.forEach(edge1 -> inRelationshipList + .forEach(edge2 -> pairs.add(Tuple.of(edge1, edge2)))); + return pairs; + } - private Set getAllNodesConnectedToRelationshipList() { - List edges = oxm.getEdges(); - Set inRelationshipList = edges.stream().filter(e -> e.getSource().equals("relationship-list")).map( - Edge::getTarget).collect( - Collectors.toSet()); - inRelationshipList.addAll(edges.stream().filter(e -> e.getTarget().equals("relationship-list")) - .map(Edge::getSource).collect( - Collectors.toSet())); - return inRelationshipList; - } + private Set getAllNodesConnectedToRelationshipList() { + List edges = oxm.getEdges(); + Set inRelationshipList = edges.stream() + .filter(e -> e.getSource().equals("relationship-list")) + .map(Edge::getTarget) + .collect(Collectors.toSet()); + inRelationshipList.addAll(edges.stream() + .filter(e -> e.getTarget().equals("relationship-list")) + .map(Edge::getSource) + .collect(Collectors.toSet())); + return inRelationshipList; + } } diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Edge.java b/src/main/java/org/onap/aai/graphgraph/dto/Edge.java index 5154e5b..c3ba8df 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/Edge.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/Edge.java @@ -1,26 +1,25 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; import java.util.Arrays; -import java.util.Collections; import java.util.List; public class Edge { @@ -49,14 +48,14 @@ public class Edge { return source; } - public List getNodeNames() { - return Arrays.asList(new NodeName(source), new NodeName(target)); - } - public void setSource(String source) { this.source = source; } + public List getNodeNames() { + return Arrays.asList(new NodeName(source), new NodeName(target)); + } + public String getTarget() { return target; } diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Graph.java b/src/main/java/org/onap/aai/graphgraph/dto/Graph.java index 83e5977..7d5f957 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/Graph.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/Graph.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; @@ -23,12 +23,15 @@ import java.util.Collections; import java.util.List; public class Graph { + private List nodeNames; private List edges; private List> paths; private List startNodeProperties; - public Graph(List nodeNames, List edges, List> pathsList, List startNodeProperties) { + public Graph( + List nodeNames, List edges, + List> pathsList, List startNodeProperties) { this.nodeNames = nodeNames; this.edges = edges; this.paths = pathsList; @@ -36,8 +39,8 @@ public class Graph { } public static Graph emptyGraph() { - return new Graph(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), - Collections.emptyList()); + return new Graph( + Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); } public List getStartNodeProperties() { diff --git a/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java b/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java index 992609c..013f1aa 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/NodeName.java @@ -1,25 +1,26 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; public class NodeName { + private String id; public NodeName(String name) { @@ -56,8 +57,6 @@ public class NodeName { @Override public String toString() { - return "NodeName{" + - "id='" + id + '\'' + - '}'; + return "NodeName{" + "id='" + id + '\'' + '}'; } } diff --git a/src/main/java/org/onap/aai/graphgraph/dto/NodeProperty.java b/src/main/java/org/onap/aai/graphgraph/dto/NodeProperty.java index 93b04cf..0daa9f4 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/NodeProperty.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/NodeProperty.java @@ -1,33 +1,35 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; public class NodeProperty extends Property { + private String description; private String type; private boolean key; private boolean index; private boolean required; - public NodeProperty(String propertyName, - String description, String type, boolean key, boolean index, boolean required) { + public NodeProperty( + String propertyName, String description, String type, + boolean key, boolean index, boolean required) { super(propertyName, ""); this.description = description; this.type = type; @@ -92,7 +94,7 @@ public class NodeProperty extends Property { @Override public int hashCode() { - return getPropertyName().hashCode(); + return getPropertyName().hashCode(); } @Override diff --git a/src/main/java/org/onap/aai/graphgraph/dto/Property.java b/src/main/java/org/onap/aai/graphgraph/dto/Property.java index add7dc1..a08b0ec 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/Property.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/Property.java @@ -1,25 +1,26 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; -public class Property implements Comparable{ +public class Property implements Comparable { + private String propertyName; private String propertyValue; @@ -59,7 +60,6 @@ public class Property implements Comparable{ return false; } return propertyValue.equals(property.propertyValue); - } @Override @@ -71,8 +71,8 @@ public class Property implements Comparable{ @Override public int compareTo(Property o) { - if (o.getPropertyName().equals(getPropertyName()) && o.getPropertyValue() != null - && getPropertyValue() != null) { + if (o.getPropertyName().equals(getPropertyName()) + && o.getPropertyValue() != null && getPropertyValue() != null) { return getPropertyValue().compareTo(o.getPropertyValue()); } diff --git a/src/main/java/org/onap/aai/graphgraph/dto/ValidationProblems.java b/src/main/java/org/onap/aai/graphgraph/dto/ValidationProblems.java index 9b031d0..976058d 100644 --- a/src/main/java/org/onap/aai/graphgraph/dto/ValidationProblems.java +++ b/src/main/java/org/onap/aai/graphgraph/dto/ValidationProblems.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.dto; @@ -23,17 +23,18 @@ import java.util.LinkedList; import java.util.List; public class ValidationProblems { + private List problems = new LinkedList<>(); - public List getProblems() { - return problems; - } + public List getProblems() { + return problems; + } - public void setProblems(List problems) { - this.problems = problems; - } + public void setProblems(List problems) { + this.problems = problems; + } - public void addProblem(String problem) { - problems.add(problem); - } + public void addProblem(String problem) { + problems.add(problem); + } } diff --git a/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java b/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java index b2d766b..7f903f7 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.reader; @@ -50,357 +50,356 @@ import org.onap.aai.setup.SchemaVersion; public class BasicSchemaReader implements SchemaReader { - private Map allEntities; - private Graph graph = new DefaultDirectedGraph<>(MetadataEdge.class); - private EdgeIngestor edgeIngestor; - private String version; - private List schemaErrors = new LinkedList<>(); + private Map allEntities; + private Graph graph = new DefaultDirectedGraph<>(MetadataEdge.class); + private EdgeIngestor edgeIngestor; + private String version; + private List schemaErrors = new LinkedList<>(); - public List getSchemaErrors() { - return schemaErrors; - } + public BasicSchemaReader(String version) { + this.version = version; + } - public BasicSchemaReader(String version) { - this.version = version; - } + public List getSchemaErrors() { + return schemaErrors; + } - private void init() { - if (allEntities != null) { - return; + private void init() { + if (allEntities != null) { + return; + } + allEntities = App.moxyLoaders.get(getSchemaName()).getAllObjects(); + edgeIngestor = App.edgeIngestor; + graph = createGraph(true, true); } - allEntities = App.moxyLoaders.get(getSchemaName()).getAllObjects(); - edgeIngestor = App.edgeIngestor; - graph = createGraph(true, true); - } - - private Graph createGraph(boolean withParentChild, boolean withEdgeRules) { - Graph graph = new DefaultDirectedGraph<>(MetadataEdge.class); - for (Entry currentParent : allEntities.entrySet()) { - graph.addVertex(currentParent.getKey()); - currentParent.getValue().getProperties().stream() - .filter(v -> allEntities.containsKey(v)) - .filter(v -> !currentParent.getKey().equals(v)) - .forEach(v -> { - graph.addVertex(v); - if (withParentChild) { - addParentChildEdge(currentParent.getKey(), v, graph); - } - }); + + private Graph createGraph(boolean withParentChild, boolean withEdgeRules) { + Graph graph = new DefaultDirectedGraph<>(MetadataEdge.class); + for (Entry currentParent : allEntities.entrySet()) { + graph.addVertex(currentParent.getKey()); + currentParent.getValue().getProperties().stream() + .filter(v -> allEntities.containsKey(v)) + .filter(v -> !currentParent.getKey().equals(v)) + .forEach(v -> { + graph.addVertex(v); + if (withParentChild) { + addParentChildEdge(currentParent.getKey(), v, graph); + } + }); + } + + if (!withEdgeRules) { + return graph; + } + + Multimap allRules = null; + try { + allRules = edgeIngestor.getAllRules(new SchemaVersion(getSchemaName())); + } catch (EdgeRuleNotFoundException e) { + //TODO fix + } + + allRules.asMap().values().stream() + .flatMap(e -> e.stream()) + .forEach(e -> { + switch (e.getDirection()) { + case OUT: + addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph); + break; + case IN: + addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph); + break; + case BOTH: + addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph); + addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph); + break; + } + }); + + return graph; + } + + private void addEdgerule(String parent, String child, String label, Graph graph) { + //shortening labels, long edge names are unreadable in the UI + if (label.contains(".")) { + String[] split = label.split("\\."); + label = split[split.length - 1]; + } + checkVertexExist(graph, parent); + checkVertexExist(graph, child); + + graph.addEdge(child, parent, + new MetadataEdge(EdgeType.EDGE_RULE.getTypeName(), child, parent, label)); + } + + private void checkVertexExist(Graph graph, String vertex) { + if (!graph.vertexSet().contains(vertex)) { + graph.addVertex(vertex); + schemaErrors.add(String.format("Schema is inconsistent, missing node %s", vertex)); + } + } + + private void addParentChildEdge(String parent, String child, Graph graph) { + graph.addEdge(parent, child, + new MetadataEdge(EdgeType.PARENT.getTypeName(), parent, child, EdgeType.PARENT.getTypeName())); + graph.addEdge(child, parent, + new MetadataEdge(EdgeType.CHILD.getTypeName(), child, parent, EdgeType.CHILD.getTypeName())); + } + + @Override + public String getSchemaName() { + return version; + } + + @Override + public List getAllVertexNames(String edgeFilter) { + init(); + + return createGraph( + isParentChildFilter(edgeFilter), + isEdgeRulesFilter(edgeFilter)).edgeSet().stream() + .flatMap(e -> Arrays.asList(e.getSource(), e.getTarget()).stream()) + .sorted().distinct() + .map(NodeName::new) + .collect(Collectors.toList()); } - if (!withEdgeRules) { - return graph; + @Override + public List getVertexProperties(String nodeName) { + init(); + + if (!allEntities.containsKey(nodeName)) { + return Collections.emptyList(); + } + Introspector introspector = allEntities.get(nodeName); + List properties = introspector.getProperties().stream().sorted().collect(Collectors.toList()); + + return properties.stream() + .map(p -> new NodeProperty( + p, + introspector.getPropertyMetadata(p).getOrDefault( + PropertyMetadata.DESCRIPTION, "no description available"), + introspector.getType(p), + introspector.getAllKeys().contains(p), + introspector.getIndexedProperties().contains(p), + introspector.getRequiredProperties().contains(p))) + .collect(Collectors.toList()); + } + + @Override + public List getEdgeProperties(String fromNode, String toNode, String type) { + init(); + if (type.equals(EdgeType.EDGE_RULE.getTypeName())) { + try { + List rules = edgeIngestor.getAllRules(new SchemaVersion(getSchemaName())) + .asMap().values().stream() + .flatMap(Collection::stream) + .filter(identifyEdgeRule(fromNode, toNode)) + .collect(Collectors.toList()); + + Optional> properties = rules.stream().map(this::edgeRuleProperties).findFirst(); + return properties.orElse(Collections.emptyList()); + + } catch (EdgeRuleNotFoundException e) { + //TODO fix + } + } + return Collections.emptyList(); } - Multimap allRules = null; - try { - allRules = edgeIngestor.getAllRules(new SchemaVersion(getSchemaName())); - } catch (EdgeRuleNotFoundException e) { - //TODO fix + private Predicate identifyEdgeRule(String fromNode, String toNode) { + return e -> { + switch (e.getDirection()) { + case OUT: + return e.getFrom().equals(fromNode) && e.getTo().equals(toNode); + case IN: + return e.getFrom().equals(toNode) && e.getTo().equals(fromNode); + case BOTH: + return e.getFrom().equals(toNode) && e.getTo().equals(fromNode) + || e.getFrom().equals(fromNode) && e.getTo().equals(toNode); + default: + return false; + } + }; } - allRules.asMap().values().stream().flatMap(e -> e.stream()).forEach(e -> { - switch (e.getDirection()) { - case OUT: - addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph); - break; - case IN: - addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph); - break; - case BOTH: - addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph); - addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph); - break; - } - }); - - return graph; - } - - private void addEdgerule(String parent, String child, String label, - Graph graph) { - //shortening labels, long edge names are unreadable in the UI - if (label.contains(".")) { - String[] split = label.split("\\."); - label = split[split.length - 1]; + private List edgeRuleProperties(EdgeRule r) { + List ps = new LinkedList<>(); + ps.add(new Property("Multiplicity", r.getMultiplicityRule().name())); + ps.add(new Property("Is default edge", String.valueOf(r.isDefault()))); + ps.add(new Property("Description", r.getDescription())); + ps.add(new Property("Is private edge", String.valueOf(r.isPrivateEdge()))); + ps.add(new Property("Contains", r.getContains())); + ps.add(new Property("Prevent delete", r.getPreventDelete())); + ps.add(new Property("Label", r.getLabel())); + ps.add(new Property("Delete other v", r.getDeleteOtherV())); + return ps; } - checkVertexExist(graph, parent); - checkVertexExist(graph, child); - graph.addEdge(child, parent, - new MetadataEdge(EdgeType.EDGE_RULE.getTypeName(), child, parent, label)); - } + @Override + public org.onap.aai.graphgraph.dto.Graph getGraph( + String initialNode, int parentHops, int cousinHops, int childHops, String edgeFilter) { + init(); + + Optional anyVertex = graph.vertexSet().stream().findFirst(); + if (!anyVertex.isPresent()) { + return org.onap.aai.graphgraph.dto.Graph.emptyGraph(); + } + Set edges = computeAllEdges( + anyVertex.get(), isParentChildFilter(edgeFilter), isEdgeRulesFilter(edgeFilter)); + + if (!"all".equals(initialNode)) { + Set subGraphVertices = computeNodes(initialNode, parentHops, EdgeType.CHILD.getTypeName()); + subGraphVertices.addAll(computeNodes(initialNode, childHops, EdgeType.PARENT.getTypeName())); + subGraphVertices.addAll(computeNodes(initialNode, cousinHops, EdgeType.EDGE_RULE.getTypeName())); + edges = filterEdges(edges, subGraphVertices); + } - private void checkVertexExist(Graph graph, String vertex) { - if (! graph.vertexSet().contains(vertex)) { - graph.addVertex(vertex); - schemaErrors.add(String.format("Schema is inconsistent, missing node %s", vertex)); + return new org.onap.aai.graphgraph.dto.Graph(new LinkedList<>(computeNodeNames(edges)), + new LinkedList<>(edges), Collections.emptyList(), getVertexProperties(initialNode)); } - } - - private void addParentChildEdge(String parent, String child, Graph graph) { - graph.addEdge(parent, child, - new MetadataEdge(EdgeType.PARENT.getTypeName(), parent, child, EdgeType.PARENT.getTypeName())); - graph.addEdge(child, parent, - new MetadataEdge(EdgeType.CHILD.getTypeName(), child, parent, EdgeType.CHILD.getTypeName())); - } - - @Override - public String getSchemaName() { - return version; - } - - @Override - public List getAllVertexNames(String edgeFilter) { - init(); - - return createGraph(isParentChildFilter(edgeFilter), isEdgeRulesFilter(edgeFilter)) - .edgeSet().stream().flatMap(e -> Arrays.asList(e.getSource(), e.getTarget()).stream()) - .sorted() - .distinct() - .map(NodeName::new).collect( - Collectors.toList()); - } - - @Override - public List getVertexProperties(String nodeName) { - init(); - - if (!allEntities.containsKey(nodeName)) { - return Collections.emptyList(); + + private boolean isParentChildFilter(String edgeFilter) { + return "Parents".equals(edgeFilter); } - Introspector introspector = allEntities.get(nodeName); - List properties = introspector.getProperties().stream() - .sorted() - .collect(Collectors.toList()); - - List result = properties.stream().map( p -> - new NodeProperty( - p, - introspector.getPropertyMetadata(p) - .getOrDefault(PropertyMetadata.DESCRIPTION,"no description available"), - introspector.getType(p), - introspector.getAllKeys().contains(p), - introspector.getIndexedProperties().contains(p), - introspector.getRequiredProperties().contains(p)) - ).collect(Collectors.toList()); - - return result; - } - - @Override - public List getEdgeProperties(String fromNode, String toNode, String type) { - init(); - if (type.equals(EdgeType.EDGE_RULE.getTypeName())) { - try { - List rules = edgeIngestor.getAllRules(new SchemaVersion(getSchemaName())) - .asMap() - .values() - .stream() - .flatMap(Collection::stream) - .filter(identifyEdgeRule(fromNode, toNode)) - .collect(Collectors.toList()); - - Optional> properties = rules.stream().map(this::edgeRuleProperties) - .findFirst(); - return properties.orElse(Collections.emptyList()); - - } catch (EdgeRuleNotFoundException e) { - //TODO fix - } + private boolean isEdgeRulesFilter(String edgeFilter) { + return "Edgerules".equals(edgeFilter); } - return Collections.emptyList(); - } - - private Predicate identifyEdgeRule(String fromNode, String toNode) { - return e -> { - switch (e.getDirection()) { - case OUT: - return e.getFrom().equals(fromNode) && e.getTo().equals(toNode); - case IN: - return e.getFrom().equals(toNode) && e.getTo().equals(fromNode); - case BOTH: - return e.getFrom().equals(toNode) && e.getTo().equals(fromNode) - || e.getFrom().equals(fromNode) && e.getTo().equals(toNode); - default: - return false; - } - }; - } - - private List edgeRuleProperties(EdgeRule r) { - List ps = new LinkedList<>(); - ps.add(new Property("Multiplicity", r.getMultiplicityRule().name())); - ps.add(new Property("Is default edge", String.valueOf(r.isDefault()))); - ps.add(new Property("Description", r.getDescription())); - ps.add(new Property("Is private edge", String.valueOf(r.isPrivateEdge()))); - ps.add(new Property("Contains", r.getContains())); - ps.add(new Property("Prevent delete", r.getPreventDelete())); - ps.add(new Property("Label", r.getLabel())); - ps.add(new Property("Delete other v", r.getDeleteOtherV())); - return ps; - } - - @Override - public org.onap.aai.graphgraph.dto.Graph getGraph(String initialNode, int parentHops, - int cousinHops, int childHops, String edgeFilter) { - init(); - - Optional anyVertex = graph.vertexSet().stream().findFirst(); - if (!anyVertex.isPresent()) { - return org.onap.aai.graphgraph.dto.Graph.emptyGraph(); + + private Set filterEdgesStrict(Set edges, Set subGraphVertices) { + return edges.stream() + .filter(e -> subGraphVertices.contains(e.getSource()) && subGraphVertices.contains(e.getTarget())) + .collect(Collectors.toSet()); } - Set edges = computeAllEdges(anyVertex.get(), isParentChildFilter(edgeFilter), - isEdgeRulesFilter(edgeFilter)); - - if (!"all".equals(initialNode)) { - Set subGraphVertices = computeNodes(initialNode, parentHops, EdgeType.CHILD.getTypeName()); - subGraphVertices.addAll(computeNodes(initialNode, childHops, EdgeType.PARENT.getTypeName())); - subGraphVertices.addAll(computeNodes(initialNode, cousinHops, EdgeType.EDGE_RULE.getTypeName())); - edges = filterEdges(edges, subGraphVertices); + + private Set filterEdges(Set edges, Set subGraphVertices) { + return edges.stream() + .filter(e -> subGraphVertices.contains(e.getSource()) || subGraphVertices.contains(e.getTarget())) + .filter(e -> !e.getType().equals(EdgeType.EDGE_RULE.getTypeName())) + .collect(Collectors.toSet()); } - return new org.onap.aai.graphgraph.dto.Graph(new LinkedList<>(computeNodeNames(edges)), - new LinkedList<>(edges), Collections.emptyList(), getVertexProperties(initialNode)); - } - - private boolean isParentChildFilter(String edgeFilter) { - return "Parents".equals(edgeFilter); - } - - private boolean isEdgeRulesFilter(String edgeFilter) { - return "Edgerules".equals(edgeFilter); - } - - private Set filterEdgesStrict(Set edges, Set subGraphVertices) { - return edges.stream().filter( - e -> subGraphVertices.contains(e.getSource()) && subGraphVertices.contains(e.getTarget())) - .collect( - Collectors.toSet()); - } - - private Set filterEdges(Set edges, Set subGraphVertices) { - return edges.stream().filter(e -> - subGraphVertices.contains(e.getSource()) || subGraphVertices.contains(e.getTarget())) - .filter(e -> !e.getType().equals(EdgeType.EDGE_RULE.getTypeName())) - .collect(Collectors.toSet()); - } - - private Set computeNodeNames(Set edges) { - return edges.stream().flatMap(e -> e.getNodeNames().stream()).collect( - Collectors.toSet()); - } - - private Set computeAllEdges(String initial, boolean parentChild, boolean edgeRules) { - Set result = new HashSet<>(); - List toQuery = new LinkedList<>(); - toQuery.add(initial); - final List toVisit = new LinkedList<>(); - Set visited = new HashSet<>(); - - while (!toQuery.isEmpty()) { - for (String v : toQuery) { - visited.add(v); - - graph.edgesOf(v).forEach(edge -> { - String neighbour = edge.getTarget(); - toVisit.add(neighbour); - - if (EdgeType.CHILD.isType(edge.getType()) && parentChild) { - result.add(new Edge(neighbour, edge.getSource(), EdgeType.PARENT.getTypeName(), - createTooltip(neighbour, edge.getSource(), EdgeType.PARENT.getTypeName(), edge.getLabel()))); - } - - if (EdgeType.EDGE_RULE.isType(edge.getType()) && edgeRules) { - result.add(new Edge(edge.getSource(), neighbour, edge.getLabel(), - createTooltip(neighbour, edge.getSource(), EdgeType.EDGE_RULE.getTypeName(), - edge.getLabel()))); - } - }); - } - toQuery.clear(); - toQuery.addAll( - toVisit.stream().filter(s -> !visited.contains(s)).collect(Collectors.toList())); + private Set computeNodeNames(Set edges) { + return edges.stream() + .flatMap(e -> e.getNodeNames().stream()) + .collect(Collectors.toSet()); } - return result; + private Set computeAllEdges(String initial, boolean parentChild, boolean edgeRules) { + Set result = new HashSet<>(); + List toQuery = new LinkedList<>(); + toQuery.add(initial); + final List toVisit = new LinkedList<>(); + Set visited = new HashSet<>(); + + while (!toQuery.isEmpty()) { + for (String v : toQuery) { + visited.add(v); + + graph.edgesOf(v).forEach(edge -> { + String neighbour = edge.getTarget(); + toVisit.add(neighbour); + + if (EdgeType.CHILD.isType(edge.getType()) && parentChild) { + result.add(new Edge( + neighbour, edge.getSource(), EdgeType.PARENT.getTypeName(), createTooltip( + neighbour, edge.getSource(), EdgeType.PARENT.getTypeName(), edge.getLabel()))); + } + + if (EdgeType.EDGE_RULE.isType(edge.getType()) && edgeRules) { + result.add(new Edge( + edge.getSource(), neighbour, edge.getLabel(), createTooltip( + neighbour, edge.getSource(), EdgeType.EDGE_RULE.getTypeName(), edge.getLabel()))); + } + }); + } + toQuery.clear(); + toQuery.addAll(toVisit.stream().filter(s -> !visited.contains(s)).collect(Collectors.toList())); + } + + return result; + + } - } + private Set computeNodes(String vertex, int hops, String relationshipName) { + List toQuery = new LinkedList<>(); + toQuery.add(vertex); - private Set computeNodes(String vertex, int hops, String relationshipName) { - List toQuery = new LinkedList<>(); - toQuery.add(vertex); + Set visited = new HashSet<>(); + int i = 0; - Set visited = new HashSet<>(); - int i = 0; + final List toVisit = new LinkedList<>(); + while (!toQuery.isEmpty() && hops > i) { + i++; + toVisit.clear(); - final List toVisit = new LinkedList<>(); - while (!toQuery.isEmpty() && hops > i) { - i++; - toVisit.clear(); + for (String v : toQuery) { + visited.add(v); + graph.edgesOf(v).stream() + .filter(e -> e.getType().equals(relationshipName)) + .map(MetadataEdge::getTarget) + .forEach(toVisit::add); + } - for (String v : toQuery) { - visited.add(v); - graph.edgesOf(v).stream().filter(e -> e.getType().equals(relationshipName)).map( - MetadataEdge::getTarget).forEach(toVisit::add); - } + toQuery.clear(); + toQuery.addAll(toVisit.stream().filter(v -> !visited.contains(v)).collect(Collectors.toList())); + } - toQuery.clear(); - toQuery - .addAll(toVisit.stream().filter(v -> !visited.contains(v)).collect(Collectors.toList())); + return visited; } - return visited; - } - - - @Override - public org.onap.aai.graphgraph.dto.Graph getGraph(String fromNode, String toNode, - String edgeFilter) { - init(); - Graph tempGraph = createGraph(isParentChildFilter(edgeFilter), isEdgeRulesFilter(edgeFilter)); - List> paths = new LinkedList<>(); - FloydWarshallShortestPaths shortestPaths; - - while (true) { - shortestPaths = new FloydWarshallShortestPaths<>(tempGraph); - GraphPath p = shortestPaths.getPath(fromNode, toNode); - if (p == null || p.getEdgeList() == null || p.getEdgeList().isEmpty()) { - break; - } - String previous = fromNode; - List path = new LinkedList<>(); - for (MetadataEdge e : p.getEdgeList()) { - if (e.getTarget().equals(previous)) { - previous = e.getSource(); - path.add(new NodeName(e.getTarget())); - } else { - previous = e.getTarget(); - path.add(new NodeName(e.getSource())); + @Override + public org.onap.aai.graphgraph.dto.Graph getGraph(String fromNode, String toNode, String edgeFilter) { + init(); + Graph tempGraph = createGraph( + isParentChildFilter(edgeFilter), isEdgeRulesFilter(edgeFilter)); + List> paths = new LinkedList<>(); + FloydWarshallShortestPaths shortestPaths; + + while (true) { + shortestPaths = new FloydWarshallShortestPaths<>(tempGraph); + GraphPath p = shortestPaths.getPath(fromNode, toNode); + if (p == null || p.getEdgeList() == null || p.getEdgeList().isEmpty()) { + break; + } + String previous = fromNode; + List path = new LinkedList<>(); + for (MetadataEdge e : p.getEdgeList()) { + if (e.getTarget().equals(previous)) { + previous = e.getSource(); + path.add(new NodeName(e.getTarget())); + } else { + previous = e.getTarget(); + path.add(new NodeName(e.getSource())); + } + } + path.add(new NodeName(previous)); + paths.add(path); + tempGraph.removeEdge(p.getEdgeList().get(p.getLength() - 1)); //remove last edge from path } - } - path.add(new NodeName(previous)); - paths.add(path); - tempGraph.removeEdge(p.getEdgeList().get(p.getLength() - 1)); //remove last edge from path + + Set edges = computeAllEdges(fromNode, isParentChildFilter(edgeFilter), isEdgeRulesFilter(edgeFilter)); + edges = filterEdgesStrict( + edges, + paths.stream() + .flatMap(Collection::stream) + .map(NodeName::getId) + .collect(Collectors.toSet())); + return new org.onap.aai.graphgraph.dto.Graph( + new LinkedList<>(computeNodeNames(edges)), new LinkedList<>(edges), + paths, getVertexProperties(fromNode)); } - Set edges = computeAllEdges(fromNode, isParentChildFilter(edgeFilter), - isEdgeRulesFilter(edgeFilter)); - edges = filterEdgesStrict(edges, - paths.stream().flatMap(Collection::stream).map(NodeName::getId).collect( - Collectors.toSet())); - return new org.onap.aai.graphgraph.dto.Graph(new LinkedList<>(computeNodeNames(edges)), - new LinkedList<>(edges), paths, getVertexProperties(fromNode)); - } - - private List createTooltip(String target, String v, String type, String label) { - List properties = new LinkedList<>(); - properties.add(new Property("From", target)); - properties.add(new Property("To", v)); - properties.add(new Property("Type", type)); - properties.add(new Property("Relationship", label)); - properties.addAll(getEdgeProperties(v, target, EdgeType.EDGE_RULE.isType(type) ? EdgeType.EDGE_RULE.getTypeName() : EdgeType.PARENT.getTypeName())); - return properties; - } + private List createTooltip(String target, String v, String type, String label) { + List properties = new LinkedList<>(); + properties.add(new Property("From", target)); + properties.add(new Property("To", v)); + properties.add(new Property("Type", type)); + properties.add(new Property("Relationship", label)); + properties.addAll(getEdgeProperties( + v, target, + EdgeType.EDGE_RULE.isType(type) ? EdgeType.EDGE_RULE.getTypeName() : EdgeType.PARENT.getTypeName())); + return properties; + } } diff --git a/src/main/java/org/onap/aai/graphgraph/reader/EdgeType.java b/src/main/java/org/onap/aai/graphgraph/reader/EdgeType.java index 1250474..fd2614c 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/EdgeType.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/EdgeType.java @@ -1,38 +1,40 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.reader; public enum EdgeType { - EDGE_RULE("edgerule"), PARENT("parent"), CHILD("child"); + EDGE_RULE("edgerule"), + PARENT("parent"), + CHILD("child"); - private final String name; + private final String name; - EdgeType(String s) { - name = s; - } + EdgeType(String s) { + name = s; + } - public String getTypeName() { - return this.name; - } + public String getTypeName() { + return this.name; + } - public boolean isType(String o){ - return name.equals(o); - } + public boolean isType(String o) { + return name.equals(o); + } } diff --git a/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java b/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java index fb8e53f..2dea403 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.reader; @@ -23,49 +23,49 @@ import org.jgrapht.graph.DefaultEdge; public class MetadataEdge extends DefaultEdge { - private final String type; - private final String target; - private final String source; - private final String label; + private final String type; + private final String target; + private final String source; + private final String label; - MetadataEdge(String type, String source, String target) { - this.source = source; - this.target = target; - this.type = type; - this.label = ""; - } + MetadataEdge(String type, String source, String target) { + this.source = source; + this.target = target; + this.type = type; + this.label = ""; + } - MetadataEdge(String type, String target, String source, String label) { - this.type = type; - this.target = target; - this.source = source; - this.label = label; - } + MetadataEdge(String type, String target, String source, String label) { + this.type = type; + this.target = target; + this.source = source; + this.label = label; + } - public String getLabel() { - return label; - } + public String getLabel() { + return label; + } - @Override - public String getTarget() { - return target; - } + @Override + public String getTarget() { + return target; + } - @Override - public String getSource() { - return source; - } + @Override + public String getSource() { + return source; + } - public String getType() { - return type; - } + public String getType() { + return type; + } - @Override - public String toString() { - return "MetadataEdge{" + - "type='" + type + '\'' + - ", target='" + target + '\'' + - ", source='" + source + '\'' + - '}'; - } + @Override + public String toString() { + return "MetadataEdge{" + + "type='" + type + '\'' + + ", target='" + target + '\'' + + ", source='" + source + '\'' + + '}'; + } } diff --git a/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java b/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java index a924e63..38e1bf6 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/SchemaReader.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.reader; @@ -27,11 +27,16 @@ import org.onap.aai.graphgraph.dto.Property; import java.util.List; public interface SchemaReader { + String getSchemaName(); + List getAllVertexNames(String edgeFilter); + List getVertexProperties(String nodeName); + List getEdgeProperties(String fromNode, String toNode, String type); - Graph getGraph(String initialNode, int parentHops, int cousinHops, int childHops, - String edgeFilter); + + Graph getGraph(String initialNode, int parentHops, int cousinHops, int childHops, String edgeFilter); + Graph getGraph(String fromNode, String toNode, String edgeFilter); } diff --git a/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java b/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java index f49a669..5764c50 100644 --- a/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java +++ b/src/main/java/org/onap/aai/graphgraph/reader/SchemaRepository.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.reader; @@ -24,20 +24,22 @@ import java.util.Optional; import java.util.stream.Collectors; public class SchemaRepository { + private List readers; public SchemaRepository(List readers) { this.readers = readers; } - public List getAllSchemaNames(){ + public List getAllSchemaNames() { return readers.stream().map(SchemaReader::getSchemaName).collect(Collectors.toList()); } - public SchemaReader getSchemaReader(String schemaName){ + public SchemaReader getSchemaReader(String schemaName) { Optional reader = readers.stream().filter(r -> schemaName.equals(r.getSchemaName())).findFirst(); - if(!reader.isPresent()) + if (!reader.isPresent()) { throw new IllegalArgumentException("Schema " + schemaName + " not found"); + } return reader.get(); } diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java index 697fad1..dda37b5 100644 --- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java +++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityAssociation.java @@ -1,115 +1,113 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.velocity; public class VelocityAssociation extends VelocityId { - private final String name; - private final VelocityEntity fromEntity; - private final VelocityEntity toEntity; - private final String fromId = getRandomId(); - private final String toId = getRandomId(); - private final String multiplicity; - private final boolean isComposition; - - public VelocityAssociation(VelocityEntity fromEntity, - VelocityEntity toEntity, String name, String multiplicity, boolean isComposition) { - this.fromEntity = fromEntity; - this.toEntity = toEntity; - this.name = name; - this.multiplicity = multiplicity; - this.isComposition = isComposition; - } - - public String getFromEntityName(){ - return fromEntity.getName(); - } - - public String getToEntityName(){ - return toEntity.getName(); - } - - public String getFromEntityId(){ - return fromEntity.getId(); - } - - public String getToEntityId(){ - return toEntity.getId(); - } - - public String getFromId() { - return fromId; - } - - public String getToId() { - return toId; - } - - public String getName() { - return name; - } - - public String getMultiplicity() { - return multiplicity.toUpperCase(); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + private final String name; + private final VelocityEntity fromEntity; + private final VelocityEntity toEntity; + private final String fromId = getRandomId(); + private final String toId = getRandomId(); + private final String multiplicity; + private final boolean isComposition; + + public VelocityAssociation(VelocityEntity fromEntity, + VelocityEntity toEntity, String name, String multiplicity, boolean isComposition) { + this.fromEntity = fromEntity; + this.toEntity = toEntity; + this.name = name; + this.multiplicity = multiplicity; + this.isComposition = isComposition; } - if (o == null || getClass() != o.getClass()) { - return false; + + public String getFromEntityName() { + return fromEntity.getName(); + } + + public String getToEntityName() { + return toEntity.getName(); + } + + public String getFromEntityId() { + return fromEntity.getId(); } - VelocityAssociation that = (VelocityAssociation) o; + public String getToEntityId() { + return toEntity.getId(); + } + + public String getFromId() { + return fromId; + } + + public String getToId() { + return toId; + } - if (!name.equals(that.name)) { - return false; + public String getName() { + return name; } - if (!fromEntity.equals(that.fromEntity)) { - return false; + + public String getMultiplicity() { + return multiplicity.toUpperCase(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + VelocityAssociation that = (VelocityAssociation) o; + + if (!name.equals(that.name)) { + return false; + } + if (!fromEntity.equals(that.fromEntity)) { + return false; + } + return toEntity.equals(that.toEntity); + } + + public boolean getIsComposition() { + return isComposition; + } + + @Override + public String toString() { + return "VelocityAssociation{" + + "name='" + name + '\'' + + ", fromEntity=" + fromEntity + + ", toEntity=" + toEntity + + '}'; + } + + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + fromEntity.hashCode(); + result = 31 * result + toEntity.hashCode(); + return result; } - return toEntity.equals(that.toEntity); - } - - public boolean getIsComposition() { - return isComposition; - } - - @Override - public String toString() { - return "VelocityAssociation{" + - "name='" + name + '\'' + - ", fromEntity=" + fromEntity + - ", toEntity=" + toEntity + - '}'; - } - - @Override - public int hashCode() { - int result = name.hashCode(); - result = 31 * result + fromEntity.hashCode(); - result = 31 * result + toEntity.hashCode(); - return result; - - - } } diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java index 99f94f3..424c0e6 100644 --- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java +++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntity.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.velocity; @@ -24,75 +24,73 @@ import java.util.List; import java.util.Set; public class VelocityEntity extends VelocityId { - private String name; - private String description; - private List neighbours = new LinkedList<>(); - private Set properties; - public Set getProperties() { - return properties; - } + private String name; + private String description; + private List neighbours = new LinkedList<>(); + private Set properties; - public void setProperties(Set properties) { - this.properties = properties; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } + public VelocityEntity(String name) { + this.name = name; + } - public VelocityEntity(String name) { - this.name = name; - } + public Set getProperties() { + return properties; + } - public String getName() { - return name; - } + public void setProperties(Set properties) { + this.properties = properties; + } - public void setName(String name) { - this.name = name; - } + public String getDescription() { + return description; + } - public List getNeighbours() { - return neighbours; - } + public void setDescription(String description) { + this.description = description; + } - public void setNeighbours(List neighbours) { - this.neighbours = neighbours; - } + public String getName() { + return name; + } - public void addNeighbours(VelocityAssociation neighbour) { - neighbours.add(neighbour); - } + public void setName(String name) { + this.name = name; + } + public List getNeighbours() { + return neighbours; + } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; + public void setNeighbours(List neighbours) { + this.neighbours = neighbours; } - if (o == null || getClass() != o.getClass()) { - return false; + + public void addNeighbours(VelocityAssociation neighbour) { + neighbours.add(neighbour); } - VelocityEntity that = (VelocityEntity) o; + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } - return name.equals(that.name); - } + VelocityEntity that = (VelocityEntity) o; - @Override - public int hashCode() { - return name.hashCode(); - } + return name.equals(that.name); + } - @Override - public String toString() { - return "VelocityEntity{" + - "name='" + name + '\'' + - '}'; - } + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public String toString() { + return "VelocityEntity{" + "name='" + name + '\'' + '}'; + } } diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java index e8dec9f..2c65ae3 100644 --- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java +++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.velocity; @@ -24,35 +24,33 @@ import org.onap.aai.graphgraph.dto.Property; public class VelocityEntityProperty extends Property { - private final VelocityEntity entity; - private final String propertyId; - public VelocityEntityProperty(String propertyName, String propertyValue, VelocityEntity entity) { - super(propertyName, propertyValue); - this.entity = entity; - propertyId = entity != null ? entity.getRandomId() : UUID.randomUUID().toString(); - } - - public String getEntityId() { - return entity.getId(); - } - - public String getEntityName() { - return entity.getName(); - } - - public boolean hasEntity(){ - return entity != null; - } - - public String getPropertyId() { - return propertyId; - } - - @Override - public String toString() { - return "VelocityEntityProperty{" + - " name=" + getPropertyName() + - " type=" + getPropertyValue() + - '}'; - } + private final VelocityEntity entity; + private final String propertyId; + + public VelocityEntityProperty(String propertyName, String propertyValue, VelocityEntity entity) { + super(propertyName, propertyValue); + this.entity = entity; + propertyId = entity != null ? entity.getRandomId() : UUID.randomUUID().toString(); + } + + public String getEntityId() { + return entity.getId(); + } + + public String getEntityName() { + return entity.getName(); + } + + public boolean hasEntity() { + return entity != null; + } + + public String getPropertyId() { + return propertyId; + } + + @Override + public String toString() { + return "VelocityEntityProperty{" + " name=" + getPropertyName() + " type=" + getPropertyValue() + '}'; + } } diff --git a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityId.java b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityId.java index fc44a5e..9b59c82 100644 --- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityId.java +++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityId.java @@ -1,34 +1,35 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2019 Orange Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph.velocity; import java.util.UUID; public abstract class VelocityId { - private String id = getRandomId(); - public String getId() { - return id; - } + private String id = getRandomId(); + + public String getId() { + return id; + } - public String getRandomId() { - return UUID.randomUUID().toString(); - } + public String getRandomId() { + return UUID.randomUUID().toString(); + } } diff --git a/src/main/resources/docker-assembly.xml b/src/main/resources/docker-assembly.xml index afd1970..54a87af 100644 --- a/src/main/resources/docker-assembly.xml +++ b/src/main/resources/docker-assembly.xml @@ -1,6 +1,6 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> distribution jar @@ -13,11 +13,11 @@ - - + + target/${project.artifactId}-${project.version}.${project.packaging} / false - - \ No newline at end of file + + diff --git a/src/main/resources/etc/auth/realm.properties b/src/main/resources/etc/auth/realm.properties index f0e0172..3ba96bc 100644 --- a/src/main/resources/etc/auth/realm.properties +++ b/src/main/resources/etc/auth/realm.properties @@ -1,13 +1,13 @@ # format : username: password[,rolename ...] # default username/password: AAI/AAI, MSO/MSO, ModelLoader/ModelLoader... -AAI:OBF:1gfr1ev31gg7,admin -MSO:OBF:1jzx1lz31k01,admin -SDNC:OBF:1itr1i0l1i151isv,admin -DCAE:OBF:1g8u1f9d1f991g8w,admin -POLICY:OBF:1mk61i171ima1im41i0j1mko,admin -ASDC:OBF:1f991j0u1j001f9d,admin -VID:OBF:1jm91i0v1jl9,admin -APPC:OBF:1f991ksf1ksf1f9d,admin -ModelLoader:OBF:1qvu1v2h1sov1sar1wfw1j7j1wg21saj1sov1v1x1qxw,admin -AaiUI:OBF:1gfr1p571unz1p4j1gg7,admin -OOF:OBF:1img1ke71ily,admin +AAI=OBF:1gfr1ev31gg7,admin +MSO=OBF:1jzx1lz31k01,admin +SDNC=OBF:1itr1i0l1i151isv,admin +DCAE=OBF:1g8u1f9d1f991g8w,admin +POLICY=OBF:1mk61i171ima1im41i0j1mko,admin +ASDC=OBF:1f991j0u1j001f9d,admin +VID=OBF:1jm91i0v1jl9,admin +APPC=OBF:1f991ksf1ksf1f9d,admin +ModelLoader=OBF:1qvu1v2h1sov1sar1wfw1j7j1wg21saj1sov1v1x1qxw,admin +AaiUI=OBF:1gfr1p571unz1p4j1gg7,admin +OOF=OBF:1img1ke71ily,admin diff --git a/src/main/resources/model_export.vm b/src/main/resources/model_export.vm index c461d59..ae92fab 100644 --- a/src/main/resources/model_export.vm +++ b/src/main/resources/model_export.vm @@ -5,148 +5,148 @@ - + #foreach($association in $associationList) - - -
- - - #if($association.multiplicity == "ONE2MANY" || $association.multiplicity == - "MANY2MANY") - - - #else - - - #end - - #if( ! $association.isComposition) - - #if($association.multiplicity == "MANY2ONE" || $association.multiplicity == - "MANY2MANY") - - - #else - - - #end - - #end - + + +
+ + + #if($association.multiplicity == "ONE2MANY" || $association.multiplicity == + "MANY2MANY") + + + #else + + + #end + + #if( ! $association.isComposition) + + #if($association.multiplicity == "MANY2ONE" || $association.multiplicity == + "MANY2MANY") + + + #else + + + #end + + #end + #end - - + + #foreach($entity in $entityList) - - - $entity.description - - #foreach($association in $entity.neighbours) - #if( $association.isComposition) - - #if($association.multiplicity == "MANY2ONE" || $association.multiplicity == - "MANY2MANY") - - - #else - - - #end - - #end - #end - #foreach($prop in $entity.properties) - #if($prop.propertyValue.contains("java.lang")) - - #if($prop.propertyValue == "java.lang.String") - - #end# - #if($prop.propertyValue == "java.lang.Long") - - #end - #if($prop.propertyValue == "java.lang.Boolean") - - #end - #if($prop.propertyValue == "java.lang.Integer") - - #end - - #elseif(! $prop.hasEntity) - #* *# - #else - - #end - #end - - #end - - - -
-
-
-
-
- - - - - - - - -
-
-
-
-
- - - - - - - - -#foreach($association in $associationList) - -#if( ! $association.isComposition) - -#end -#end -#foreach($entity in $entityList) - - #foreach($association in $entity.neighbours) + + + $entity.description + + #foreach($association in $entity.neighbours) #if( $association.isComposition) - + + #if($association.multiplicity == "MANY2ONE" || $association.multiplicity == + "MANY2MANY") + + + #else + + + #end + #end - #end - #foreach($prop in $entity.properties) - - #end -#end - \ No newline at end of file + #end + #foreach($prop in $entity.properties) + #if($prop.propertyValue.contains("java.lang")) + + #if($prop.propertyValue == "java.lang.String") + + #end# + #if($prop.propertyValue == "java.lang.Long") + + #end + #if($prop.propertyValue == "java.lang.Boolean") + + #end + #if($prop.propertyValue == "java.lang.Integer") + + #end + + #elseif(! $prop.hasEntity) + #* *# + #else + + #end + #end + + #end + + + +
+
+
+
+
+ + + + + + + + +
+
+
+
+
+ + + + + + + + + #foreach($association in $associationList) + + #if( ! $association.isComposition) + + #end + #end + #foreach($entity in $entityList) + + #foreach($association in $entity.neighbours) + #if( $association.isComposition) + + #end + #end + #foreach($prop in $entity.properties) + + #end + #end + diff --git a/src/test/java/org/onap/aai/graphgraph/AppTest.java b/src/test/java/org/onap/aai/graphgraph/AppTest.java index 7879fc3..5393d26 100644 --- a/src/test/java/org/onap/aai/graphgraph/AppTest.java +++ b/src/test/java/org/onap/aai/graphgraph/AppTest.java @@ -1,21 +1,21 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= +/* + ============LICENSE_START======================================================= + org.onap.aai + ================================================================================ + Copyright © 2019-2020 Orange Intellectual Property. All rights reserved. + ================================================================================ + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + ============LICENSE_END========================================================= */ package org.onap.aai.graphgraph; @@ -26,7 +26,7 @@ import org.junit.Test; /** * Unit test for simple App. */ -public class AppTest +public class AppTest { /** * Rigorous Test :-) -- cgit 1.2.3-korg