diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/onap/aai/graphgraph/App.java | 28 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/graphgraph/ArgumentParser.java | 24 | ||||
-rw-r--r-- | src/main/java/org/onap/aai/graphgraph/ModelExporter.java | 39 | ||||
-rw-r--r-- | src/main/resources/application.properties | 2 |
4 files changed, 77 insertions, 16 deletions
diff --git a/src/main/java/org/onap/aai/graphgraph/App.java b/src/main/java/org/onap/aai/graphgraph/App.java index 33172ca..58e0d66 100644 --- a/src/main/java/org/onap/aai/graphgraph/App.java +++ b/src/main/java/org/onap/aai/graphgraph/App.java @@ -21,8 +21,14 @@ package org.onap.aai.graphgraph; import static org.onap.aai.graphgraph.ModelExporter.exportModel; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; +import java.util.Objects; +import org.apache.commons.io.FileUtils; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.introspection.MoxyLoader; import org.onap.aai.nodes.NodeIngestor; @@ -48,9 +54,20 @@ public class App{ } } - public static void main( String[] args ) { + public static void main( String[] args ) throws IOException { ArgumentParser parser = new ArgumentParser().parseArguments(args); + + if (parser.isPrintHelp()){ + parser.printHelp(); + return; + } + SpringApplication app = new SpringApplication(App.class); + + if (parser.isRunLocally()){ + copyKeystore(app); + } + app.addInitializers(new PropertyPasswordConfiguration()); ConfigurableApplicationContext context = app.run(args); loadSchemes(context); @@ -61,4 +78,13 @@ public class App{ System.exit(0); } } + + 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()); + } + } } diff --git a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java index 4940a25..4405723 100644 --- a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java +++ b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java @@ -24,11 +24,19 @@ import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Option; public class ArgumentParser { - @Option(name = "-g", usage = "schema to be generated", metaVar = "schema") + @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){ - CmdLineParser parser = new CmdLineParser(this); + parser = new CmdLineParser(this); try { parser.parseArgument(args); @@ -51,4 +59,16 @@ public class ArgumentParser { public boolean shoudGenerateUml(){ return schemaVersion != null; } + + public boolean isRunLocally() { + return runLocally; + } + + public boolean isPrintHelp() { + return printHelp; + } + + public void printHelp(){ + parser.printUsage(System.out); + } } diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java index 0410250..3180c4c 100644 --- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java +++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java @@ -24,7 +24,6 @@ import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -151,17 +150,33 @@ public class ModelExporter { private static Set<VelocityAssociation> createVelocityAssociations(Set<VelocityEntity> entities, Multimap<String, EdgeRule> edgeRules) { - Set<VelocityAssociation> result = new HashSet<>(); - result.addAll(edgeRules.values().stream().map(er -> - new VelocityAssociation( - findVelocityEntity(er.getFrom(), entities), - findVelocityEntity(er.getTo(), entities), - String.format("%s - %s (label: %s)", er.getFrom(), er.getTo(), er.getLabel()), - er.getMultiplicityRule().name(), - er.getLabel().equals("org.onap.relationships.inventory.BelongsTo") - )).collect(Collectors.toSet())); - - return result; + return edgeRules.values().stream().flatMap(er -> { + VelocityAssociation out = createVelocityAssociation(entities, er.getFrom(), er.getTo(), + er.getLabel(), er.getMultiplicityRule().name()); + VelocityAssociation in = createVelocityAssociation(entities, er.getTo(), er.getFrom(), + er.getLabel(), er.getMultiplicityRule().name()); + 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 VelocityAssociation createVelocityAssociation(Set<VelocityEntity> entities, + String from, String to, String label, String multiplicity) { + return new VelocityAssociation( + findVelocityEntity(from, entities), + findVelocityEntity(to, entities), + String.format("%s - %s (label: %s)", from, to, label), + multiplicity, + label.equals("org.onap.relationships.inventory.BelongsTo") + ); } private static VelocityEntity findVelocityEntity(String from, Set<VelocityEntity> entities) { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 060041a..9094f48 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -7,7 +7,7 @@ schema.source.name=onap schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ schema.edges.location=${server.local.startpath}/schema/${schema.source.name}/dbedgerules/ -server.local.startpath=${graphgraph.startpath} +server.local.startpath=${graphgraph.startpath:./} schema.ingest.file=${server.local.startpath}/application.properties # Schema Version Related Attributes |