aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Dysko <igor1.dysko@orange.com>2021-06-22 14:23:34 +0200
committerIgor Dysko <igor1.dysko@orange.com>2021-06-22 14:23:34 +0200
commit847dd464a5ccb46dae990fd36173d50839f99977 (patch)
tree3454bef1e3894d17b86739434cc469e965a2cc42
parent3646ed953013eab56b29abdc57a9bf29a8a8753c (diff)
Fix bugs and vulnerabilities from sonar report
Fixed bugs and vulnerabilities. Issue-ID: AAI-3280 Signed-off-by: Igor Dysko <igor1.dysko@orange.com> Change-Id: I3f64538efc1a9ef2458847bfc60280ca76cd6919
-rw-r--r--graphgraph-fe/src/graph_settings_menu.js2
-rw-r--r--graphgraph-fe/src/requests.js16
-rw-r--r--graphgraph-fe/src/service_worker.js2
-rw-r--r--pom.xml20
-rw-r--r--src/main/java/org/onap/aai/graphgraph/ArgumentParser.java9
-rw-r--r--src/main/java/org/onap/aai/graphgraph/Config.java9
-rw-r--r--src/main/java/org/onap/aai/graphgraph/ModelExporter.java17
-rw-r--r--src/main/java/org/onap/aai/graphgraph/MoxyLoaderRepository.java2
-rw-r--r--src/main/java/org/onap/aai/graphgraph/SchemaResource.java16
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java51
-rw-r--r--src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java6
-rw-r--r--src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java7
12 files changed, 74 insertions, 83 deletions
diff --git a/graphgraph-fe/src/graph_settings_menu.js b/graphgraph-fe/src/graph_settings_menu.js
index 0a6e054..583ef8e 100644
--- a/graphgraph-fe/src/graph_settings_menu.js
+++ b/graphgraph-fe/src/graph_settings_menu.js
@@ -20,7 +20,7 @@
import React from 'react';
import GraphSettings from './graph_settings.js';
-import { Navbar, Nav } from 'react-bootstrap';
+import { Navbar } from 'react-bootstrap';
import './graph_settings_menu.css';
class GraphSettingsMenu extends React.Component {
diff --git a/graphgraph-fe/src/requests.js b/graphgraph-fe/src/requests.js
index ae41f78..ec95d04 100644
--- a/graphgraph-fe/src/requests.js
+++ b/graphgraph-fe/src/requests.js
@@ -24,32 +24,32 @@ const protocol = window.location.protocol;
export function schemas () {
return `${protocol}//${host}:${port}/schemas`;
-};
+}
export function validateSchema (schema) {
return `${protocol}//${host}:${port}/schemas/${schema}/validation`;
-};
+}
export function exportSchema (schema) {
return `${protocol}//${host}:${port}/schemas/${schema}/xmiexport`;
-};
+}
export function nodeNames (schema, edgeFilter) {
return `${protocol}//${host}:${port}/schemas/${schema}/nodes?edgeFilter=${edgeFilter}`;
-};
+}
export function basicGraph (schema, node, parentHops, cousinHops, childHops, edgeFilter) {
return `${protocol}//${host}:${port}/schemas/${schema}/graph/basic?node=${node}&parentHops=${parentHops}&cousinHops=${cousinHops}&childHops=${childHops}&edgeFilter=${edgeFilter}`;
-};
+}
export function pathGraph (schema, fromNode, toNode, edgeFilter) {
return `${protocol}//${host}:${port}/schemas/${schema}/graph/paths?fromNode=${fromNode}&toNode=${toNode}&edgeFilter=${edgeFilter}`;
-};
+}
export function nodeProperty (schema, node) {
return `${protocol}//${host}:${port}/schemas/${schema}/nodes/${node}`;
-};
+}
export function edgeProperty (schema, fromNode, toNode) {
return `${protocol}//${host}:${port}/schemas/${schema}/edges?fromNode=${fromNode}&toNode=${toNode}`;
-};
+}
diff --git a/graphgraph-fe/src/service_worker.js b/graphgraph-fe/src/service_worker.js
index 0ac740b..1df74e2 100644
--- a/graphgraph-fe/src/service_worker.js
+++ b/graphgraph-fe/src/service_worker.js
@@ -143,4 +143,4 @@ export function unregister () {
registration.unregister();
});
}
-};
+}
diff --git a/pom.xml b/pom.xml
index 7d10c5f..662d856 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,6 +37,16 @@
<dependencies>
<dependency>
+ <groupId>org.onap.aai.aai-common</groupId>
+ <artifactId>aai-core</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.onap.aai.aai-common</groupId>
+ <artifactId>aai-schema-ingest</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
@@ -106,16 +116,6 @@
</exclusions>
</dependency>
<dependency>
- <groupId>org.onap.aai.aai-common</groupId>
- <artifactId>aai-core</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.onap.aai.aai-common</groupId>
- <artifactId>aai-schema-ingest</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
diff --git a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java
index e156e39..142731c 100644
--- a/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java
+++ b/src/main/java/org/onap/aai/graphgraph/ArgumentParser.java
@@ -22,10 +22,15 @@ package org.onap.aai.graphgraph;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ArgumentParser {
- CmdLineParser parser;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ArgumentParser.class);
+
+ private CmdLineParser parser;
+
@Option(name = "-g", usage = "generates schema model for Papyrus and exits where XY is the version",
metaVar = "vXY")
private String schemaVersion;
@@ -40,7 +45,7 @@ public class ArgumentParser {
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
- System.err.println(e.getMessage());
+ LOGGER.error("Invalid arguments", e);
parser.printUsage(System.err);
}
diff --git a/src/main/java/org/onap/aai/graphgraph/Config.java b/src/main/java/org/onap/aai/graphgraph/Config.java
index 418d16f..d9d4329 100644
--- a/src/main/java/org/onap/aai/graphgraph/Config.java
+++ b/src/main/java/org/onap/aai/graphgraph/Config.java
@@ -22,7 +22,6 @@ package org.onap.aai.graphgraph;
import org.onap.aai.edges.EdgeIngestor;
import org.onap.aai.graphgraph.reader.BasicSchemaReader;
import org.onap.aai.graphgraph.reader.SchemaRepository;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@@ -43,14 +42,8 @@ public class Config {
@Value("${schema.version.list}")
String schemaVersions;
- @Autowired
- private MoxyLoaderRepository moxyLoaderRepository;
-
- @Autowired
- private EdgeIngestor edgeIngestor;
-
@Bean
- SchemaRepository createSchemaRepository() {
+ SchemaRepository createSchemaRepository(MoxyLoaderRepository moxyLoaderRepository, EdgeIngestor edgeIngestor) {
return new SchemaRepository(
Arrays.stream(schemaVersions.split(","))
.map(version -> new BasicSchemaReader(version, moxyLoaderRepository, edgeIngestor))
diff --git a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
index 24d0829..f05c39a 100644
--- a/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
+++ b/src/main/java/org/onap/aai/graphgraph/ModelExporter.java
@@ -62,7 +62,8 @@ 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 final String CAMEL_CASE_REGEX = "(?=[A-Z][a-z])";
+ private static final String VELOCITY_ASSOCIATION_NAME_FORMAT = "%s - %s (%s)";
private static final Logger LOGGER = LoggerFactory.getLogger(ModelExporter.class);
@@ -109,7 +110,7 @@ public class ModelExporter {
Map<String, String> 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.DIRECTION.toString(), Direction.OUT.toString());
edgeRuleProps.put(EdgeField.LABEL.toString(), "OXM Parent-Child");
edgeRuleProps.put(EdgeField.MULTIPLICITY.toString(), MultiplicityRule.MANY2ONE.toString());
edgeRuleProps.put(EdgeField.DEFAULT.toString(), Boolean.toString(false));
@@ -131,10 +132,8 @@ public class ModelExporter {
}
public void writeExportedModel(String result) {
- try {
- FileWriter fw = new FileWriter(AAIMODEL_UML_FILENAME);
+ try (FileWriter fw = new FileWriter(AAIMODEL_UML_FILENAME)) {
fw.write(result);
- fw.close();
} catch (IOException e) {
LOGGER.error("Writing exported model failed", e);
}
@@ -246,7 +245,7 @@ public class ModelExporter {
return new VelocityAssociation(
fromEntity.get(),
toEntity.get(),
- String.format("%s - %s (%s)", from, to, shortenLabel(label)),
+ String.format(VELOCITY_ASSOCIATION_NAME_FORMAT, from, to, shortenLabel(label)),
description,
multiplicity,
true);
@@ -254,7 +253,7 @@ public class ModelExporter {
return new VelocityAssociation(
toEntity.get(),
fromEntity.get(),
- String.format("%s - %s (%s)", to, from, shortenLabel(label)),
+ String.format(VELOCITY_ASSOCIATION_NAME_FORMAT, to, from, shortenLabel(label)),
description,
multiplicity.equals("ONE2MANY") ? "MANY2ONE" : multiplicity,
true);
@@ -262,7 +261,7 @@ public class ModelExporter {
return new VelocityAssociation(
fromEntity.get(),
toEntity.get(),
- String.format("%s - %s (%s)", from, to, shortenLabel(label)),
+ String.format(VELOCITY_ASSOCIATION_NAME_FORMAT, from, to, shortenLabel(label)),
description,
multiplicity,
false);
@@ -291,7 +290,7 @@ public class ModelExporter {
String[] split = entityName.split("\\.");
String entityNameRoot = split[split.length - 1];
- final Pattern pattern = Pattern.compile(camelCaseRegex);
+ final Pattern pattern = Pattern.compile(CAMEL_CASE_REGEX);
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/MoxyLoaderRepository.java b/src/main/java/org/onap/aai/graphgraph/MoxyLoaderRepository.java
index d2822d3..d1a476a 100644
--- a/src/main/java/org/onap/aai/graphgraph/MoxyLoaderRepository.java
+++ b/src/main/java/org/onap/aai/graphgraph/MoxyLoaderRepository.java
@@ -39,7 +39,7 @@ public class MoxyLoaderRepository {
@Autowired
private NodeIngestor nodeIngestor;
- public Map<String, MoxyLoader> moxyLoaders = new HashMap<>();
+ private Map<String, MoxyLoader> moxyLoaders = new HashMap<>();
public Map<String, MoxyLoader> getMoxyLoaders() {
return moxyLoaders;
diff --git a/src/main/java/org/onap/aai/graphgraph/SchemaResource.java b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java
index 326634d..68b26ed 100644
--- a/src/main/java/org/onap/aai/graphgraph/SchemaResource.java
+++ b/src/main/java/org/onap/aai/graphgraph/SchemaResource.java
@@ -41,26 +41,26 @@ public class SchemaResource {
@Autowired
private SchemaValidator schemaValidator;
- @RequestMapping("/schemas")
+ @GetMapping("/schemas")
public List<String> loadSchemaNames() {
return schemaRepository.getAllSchemaNames();
}
- @RequestMapping("/schemas/{schema}/nodes")
+ @GetMapping("/schemas/{schema}/nodes")
public List<NodeName> loadVertexNames(
@PathVariable("schema") String schemaName,
@RequestParam("edgeFilter") String edgeFilter) {
return schemaRepository.getSchemaReader(schemaName).getAllVertexNames(edgeFilter);
}
- @RequestMapping("/schemas/{schema}/nodes/{node}")
+ @GetMapping("/schemas/{schema}/nodes/{node}")
public List<NodeProperty> loadProperties(
@PathVariable("schema") String schemaName,
@PathVariable("node") String node) {
return schemaRepository.getSchemaReader(schemaName).getVertexProperties(node);
}
- @RequestMapping("/schemas/{schema}/edges")
+ @GetMapping("/schemas/{schema}/edges")
public List<Property> loadEdgeProperties(
@PathVariable("schema") String schemaName,
@RequestParam("fromNode") String fromNodeName,
@@ -68,7 +68,7 @@ public class SchemaResource {
return schemaRepository.getSchemaReader(schemaName).getEdgeProperties(fromNodeName, toNodeName, "edgerule");
}
- @RequestMapping("/schemas/{schema}/graph/basic")
+ @GetMapping("/schemas/{schema}/graph/basic")
public Graph loadGraph(
@PathVariable("schema") String schemaName,
@RequestParam("node") String initialNodeName,
@@ -82,7 +82,7 @@ public class SchemaResource {
return graph;
}
- @RequestMapping("/schemas/{schema}/graph/paths")
+ @GetMapping("/schemas/{schema}/graph/paths")
public Graph loadGraphWithPaths(
@PathVariable("schema") String schemaName,
@RequestParam("fromNode") String fromNode,
@@ -91,13 +91,13 @@ public class SchemaResource {
return schemaRepository.getSchemaReader(schemaName).getGraph(fromNode, toNode, edgeFilter);
}
- @RequestMapping("/schemas/{schema}/validation")
+ @GetMapping("/schemas/{schema}/validation")
public ValidationProblems validateSchema(
@PathVariable("schema") String schemaName) {
return schemaValidator.validate(schemaName);
}
- @RequestMapping(value = "/schemas/{schema}/xmiexport", produces = MediaType.TEXT_XML_VALUE)
+ @GetMapping(value = "/schemas/{schema}/xmiexport", produces = MediaType.TEXT_XML_VALUE)
@ResponseBody
public String exportSchema(
@PathVariable("schema") String schemaName) {
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 d60e955..203ef13 100644
--- a/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java
+++ b/src/main/java/org/onap/aai/graphgraph/reader/BasicSchemaReader.java
@@ -20,19 +20,6 @@
package org.onap.aai.graphgraph.reader;
import com.google.common.collect.Multimap;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.jgrapht.Graph;
import org.jgrapht.GraphPath;
import org.jgrapht.alg.shortestpath.FloydWarshallShortestPaths;
@@ -48,9 +35,19 @@ import org.onap.aai.graphgraph.dto.Property;
import org.onap.aai.introspection.Introspector;
import org.onap.aai.schema.enums.PropertyMetadata;
import org.onap.aai.setup.SchemaVersion;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.Map.Entry;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
public class BasicSchemaReader implements SchemaReader {
+ private final static Logger LOGGER = LoggerFactory.getLogger(BasicSchemaReader.class);
+
private Map<String, Introspector> allEntities;
private Graph<String, MetadataEdge> graph = new DefaultDirectedGraph<>(MetadataEdge.class);
private EdgeIngestor edgeIngestor;
@@ -78,35 +75,35 @@ public class BasicSchemaReader implements SchemaReader {
graph = createGraph(true, true);
} catch (Exception e) {
- System.out.println("Failed creation of BasicSchemaReader, version: " + getSchemaName());
- e.printStackTrace();
+ LOGGER.error("Failed creation of BasicSchemaReader, version: " + getSchemaName(), e);
}
}
private Graph<String, MetadataEdge> createGraph(boolean withParentChild, boolean withEdgeRules) {
- Graph<String, MetadataEdge> graph = new DefaultDirectedGraph<>(MetadataEdge.class);
+ Graph<String, MetadataEdge> directedGraph = new DefaultDirectedGraph<>(MetadataEdge.class);
for (Entry<String, Introspector> currentParent : allEntities.entrySet()) {
- graph.addVertex(currentParent.getKey());
+ directedGraph.addVertex(currentParent.getKey());
currentParent.getValue().getProperties().stream()
.filter(v -> allEntities.containsKey(v))
.filter(v -> !currentParent.getKey().equals(v))
.forEach(v -> {
- graph.addVertex(v);
+ directedGraph.addVertex(v);
if (withParentChild) {
- addParentChildEdge(currentParent.getKey(), v, graph);
+ addParentChildEdge(currentParent.getKey(), v, directedGraph);
}
});
}
if (!withEdgeRules) {
- return graph;
+ return directedGraph;
}
Multimap<String, EdgeRule> allRules = null;
try {
allRules = edgeIngestor.getAllRules(new SchemaVersion(getSchemaName()));
+
} catch (EdgeRuleNotFoundException e) {
- //TODO fix
+ LOGGER.error("Edge rule not found", e);
}
Objects.requireNonNull(allRules).asMap().values().stream()
@@ -114,19 +111,19 @@ public class BasicSchemaReader implements SchemaReader {
.forEach(e -> {
switch (e.getDirection()) {
case OUT:
- addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph);
+ addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), directedGraph);
break;
case IN:
- addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph);
+ addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), directedGraph);
break;
case BOTH:
- addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), graph);
- addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), graph);
+ addEdgerule(e.getFrom(), e.getTo(), e.getLabel(), directedGraph);
+ addEdgerule(e.getTo(), e.getFrom(), e.getLabel(), directedGraph);
break;
}
});
- return graph;
+ return directedGraph;
}
private void addEdgerule(String parent, String child, String label, Graph<String, MetadataEdge> graph) {
@@ -210,7 +207,7 @@ public class BasicSchemaReader implements SchemaReader {
return properties.orElse(Collections.emptyList());
} catch (EdgeRuleNotFoundException e) {
- //TODO fix
+ LOGGER.error("Edge rule not found", e);
}
}
return Collections.emptyList();
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 548d550..9a2276c 100644
--- a/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java
+++ b/src/main/java/org/onap/aai/graphgraph/reader/MetadataEdge.java
@@ -28,11 +28,7 @@ public class MetadataEdge extends DefaultEdge {
private final String source;
private final String label;
- MetadataEdge(String type, String target, String source) {
- this(type, source, target, "");
- }
-
- MetadataEdge(String type, String target, String source, String label) {
+ public MetadataEdge(String type, String target, String source, String label) {
this.type = type;
this.target = target;
this.source = source;
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 a6c404e..0e98da8 100644
--- a/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java
+++ b/src/main/java/org/onap/aai/graphgraph/velocity/VelocityEntityProperty.java
@@ -19,11 +19,11 @@
*/
package org.onap.aai.graphgraph.velocity;
-import java.util.UUID;
-
import org.eclipse.jetty.util.StringUtil;
import org.onap.aai.graphgraph.dto.Property;
+import java.util.UUID;
+
public class VelocityEntityProperty extends Property {
private final VelocityEntity entity;
@@ -34,7 +34,7 @@ public class VelocityEntityProperty extends Property {
super(propertyName, propertyValue);
this.description = propertyDescription;
this.entity = entity;
- propertyId = entity != null ? entity.getRandomId() : UUID.randomUUID().toString();
+ propertyId = VelocityId.getRandomId();
}
public String getEntityId() {
@@ -69,4 +69,5 @@ public class VelocityEntityProperty extends Property {
public String toString() {
return "VelocityEntityProperty{" + " name=" + getPropertyName() + " description=" + getDescription() + " type=" + getPropertyValue() + '}';
}
+
}