diff options
author | 2020-03-24 13:08:36 +0100 | |
---|---|---|
committer | 2020-04-21 11:29:53 +0200 | |
commit | 6915f57d07f466a6dd54be693b2af2cec9b8e0c1 (patch) | |
tree | 7c1309f6575aee88434fca15b2001e72f81a46bc /aai-schema-ingest/src/main/java/org | |
parent | 71d81fa49428fcd2080844482e4e1205a9481ae4 (diff) |
AAI-common sonar fixes
Issue-ID: AAI-2786
Change-Id: Ia37e660886fce56c8ab5c53888fcbf265692a359
Signed-off-by: David Brilla <david.brilla@tieto.com>
Diffstat (limited to 'aai-schema-ingest/src/main/java/org')
5 files changed, 32 insertions, 42 deletions
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java index af4d8e8e..ad7c3718 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java @@ -44,7 +44,6 @@ import org.springframework.context.annotation.PropertySource; @Configuration public class EdgesConfiguration { - private static final String CONFIG_TRANSLATOR = "config"; private static final String SCHEMA_SERVICE_TRANSLATOR = "schema-service"; @Autowired(required = false) diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java index 0bb36a2d..2e6847d2 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java @@ -47,7 +47,6 @@ import org.springframework.context.annotation.PropertySource; @Configuration public class NodesConfiguration { - private static final String CONFIG_TRANSLATOR = "config"; private static final String SCHEMA_SERVICE_TRANSLATOR = "schema-service"; private static final Logger LOGGER = LoggerFactory.getLogger(NodesConfiguration.class); diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java index 529c0684..c46ab78d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java @@ -23,7 +23,6 @@ package org.onap.aai.config; import org.onap.aai.restclient.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; @@ -48,19 +47,19 @@ public class RestConfiguration { * In the below cases bean name and method names are different because all of them qualify as restClient */ @Bean(name = "restClient") - @ConditionalOnProperty(name = "schema.service.client", havingValue = "two-way-ssl", matchIfMissing = true) + @ConditionalOnProperty(name = "schema.service.client", havingValue = TWO_WAY_SSL, matchIfMissing = true) public RestClient getSchemaServiceTwoWayClient() { return new SchemaServiceRestClient(); } @Bean(name = "restClient") - @ConditionalOnProperty(name = "schema.service.client", havingValue = "no-auth") + @ConditionalOnProperty(name = "schema.service.client", havingValue = NO_AUTH) public RestClient getSchemaServiceNoAuthClient() { return new SchemaServiceNoAuthClient(); } @Bean(name = "restClient") - @ConditionalOnProperty(name = "schema.service.client", havingValue = "one-way-ssl") + @ConditionalOnProperty(name = "schema.service.client", havingValue = ONE_WAY_SSL) public RestClient getSchemaServiceOneWayClient() { return new SchemaServiceOneWayClient(); } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java index 68def753..8861c5cc 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java @@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.structure.Direction; import org.onap.aai.edges.enums.*; import java.util.EnumMap; -import java.util.HashMap; import java.util.Map; /** @@ -77,7 +76,7 @@ public class EdgeRule { this.label = edgeRule.label; this.direction = Direction.valueOf(edgeRule.direction.toString()); this.multiplicityRule = MultiplicityRule.valueOf(edgeRule.multiplicityRule.toString()); - this.edgeFields = new HashMap<>(edgeRule.edgeFields); + this.edgeFields = new EnumMap<>(edgeRule.edgeFields); this.isDefaultEdge = edgeRule.isDefaultEdge; this.description = edgeRule.description; this.isPrivateEdge = edgeRule.isPrivateEdge; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java index fc58dbb6..8ecbe2a3 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java @@ -22,9 +22,7 @@ package org.onap.aai.edges; -import static com.jayway.jsonpath.Criteria.where; -import static com.jayway.jsonpath.Filter.filter; - +import com.jayway.jsonpath.Criteria; import com.jayway.jsonpath.Filter; import com.jayway.jsonpath.Predicate; @@ -54,10 +52,11 @@ public class EdgeRuleQuery { private EdgeType type; private boolean isPrivate; + private static final String TO_ONLY = "ToOnly"; + private static final String FROM_ONLY = "FromOnly"; + public static class Builder { - private static final String TO_ONLY = "ToOnly"; - private static final String FROM_ONLY = "FromOnly"; // required private String nodeA; @@ -168,7 +167,7 @@ public class EdgeRuleQuery { // will cover from A to B case List<Predicate> criteriaFromTo = new ArrayList<>(); // Special logic to allow for A to B case only - if (("FromOnly").equals(builder.getSecondNodeType())) { + if ((FROM_ONLY).equals(builder.getSecondNodeType())) { criteriaFromTo.add(buildToFromPart(builder.getFirstNodeType(), null)); } else { criteriaFromTo.add(buildToFromPart(builder.getFirstNodeType(), builder.getSecondNodeType())); @@ -176,7 +175,7 @@ public class EdgeRuleQuery { // will cover from B to A case - must be separate bc jsonpath won't let me OR predicates >:C List<Predicate> criteriaToFrom = new ArrayList<>(); // Special logic to allow for B to A case only - if (("ToOnly").equals(builder.getFirstNodeType())) { + if ((TO_ONLY).equals(builder.getFirstNodeType())) { criteriaToFrom.add(buildToFromPart(null, builder.getSecondNodeType())); } else { criteriaToFrom.add(buildToFromPart(builder.getSecondNodeType(), builder.getFirstNodeType())); @@ -192,7 +191,7 @@ public class EdgeRuleQuery { criteriaFromTo.add(typePred); criteriaToFrom.add(typePred); } - Predicate privatePredicate = where("private").is(String.valueOf(isPrivate)); + Predicate privatePredicate = Criteria.where("private").is(String.valueOf(isPrivate)); if (isPrivate) { criteriaFromTo.add(privatePredicate); @@ -204,12 +203,12 @@ public class EdgeRuleQuery { criteriaFromTo.add(directionPred); criteriaToFrom.add(directionPred); } - if (("ToOnly").equals(builder.getFirstNodeType())) { - this.filter = filter(criteriaToFrom); - } else if (("FromOnly").equals(builder.getSecondNodeType())) { - this.filter = filter(criteriaFromTo); + if ((TO_ONLY).equals(builder.getFirstNodeType())) { + this.filter = Filter.filter(criteriaToFrom); + } else if ((FROM_ONLY).equals(builder.getSecondNodeType())) { + this.filter = Filter.filter(criteriaFromTo); } else { - this.filter = filter(criteriaFromTo).or(filter(criteriaToFrom)); + this.filter = Filter.filter(criteriaFromTo).or(Filter.filter(criteriaToFrom)); } } @@ -221,44 +220,44 @@ public class EdgeRuleQuery { Predicate p; if (to == null) { - p = where(EdgeField.FROM.toString()).is(from); + p = Criteria.where(EdgeField.FROM.toString()).is(from); } else if (from == null) { - p = where(EdgeField.TO.toString()).is(to); + p = Criteria.where(EdgeField.TO.toString()).is(to); } else { - p = where(EdgeField.FROM.toString()).is(from).and(EdgeField.TO.toString()).is(to); + p = Criteria.where(EdgeField.FROM.toString()).is(from).and(EdgeField.TO.toString()).is(to); } return p; } private Predicate addLabel(String label) { - return where(EdgeField.LABEL.toString()).is(label); + return Criteria.where(EdgeField.LABEL.toString()).is(label); } private Predicate addType(EdgeType type) { if (type == EdgeType.COUSIN) { - return where(EdgeProperty.CONTAINS.toString()).is(AAIDirection.NONE.toString()); + return Criteria.where(EdgeProperty.CONTAINS.toString()).is(AAIDirection.NONE.toString()); } else { // equals TREE - return where(EdgeProperty.CONTAINS.toString()).ne(AAIDirection.NONE.toString()); + return Criteria.where(EdgeProperty.CONTAINS.toString()).ne(AAIDirection.NONE.toString()); } } private Predicate addDirection(AAIDirection direction) { if (direction == AAIDirection.OUT) { - return where(EdgeField.DIRECTION.toString()).in(AAIDirection.OUT.toString(), AAIDirection.BOTH.toString()); + return Criteria.where(EdgeField.DIRECTION.toString()).in(AAIDirection.OUT.toString(), AAIDirection.BOTH.toString()); } else if (direction == AAIDirection.IN) { - return where(EdgeField.DIRECTION.toString()).in(AAIDirection.IN.toString(), AAIDirection.BOTH.toString()); + return Criteria.where(EdgeField.DIRECTION.toString()).in(AAIDirection.IN.toString(), AAIDirection.BOTH.toString()); } else if (direction == AAIDirection.BOTH) { - return where(EdgeField.DIRECTION.toString()).is(AAIDirection.BOTH.toString()); + return Criteria.where(EdgeField.DIRECTION.toString()).is(AAIDirection.BOTH.toString()); } else if (direction == AAIDirection.NONE) { - return where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); + return Criteria.where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); } - return where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); + return Criteria.where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); } /** * Provides the JsonPath filter for actually querying the edge rule schema files - * + * * @return Filter */ public Filter getFilter() { @@ -284,7 +283,7 @@ public class EdgeRuleQuery { /** * So the Ingestor knows which version of the rules to search - * + * * @return the Version */ public Optional<SchemaVersion> getVersion() { @@ -315,9 +314,7 @@ public class EdgeRuleQuery { sb.append(", isPrivate: "); sb.append(isPrivate); - if (v.isPresent()) { - sb.append(", for version: ").append(v.get().toString()).append("."); - } + v.ifPresent(schemaVersion -> sb.append(", for version: ").append(schemaVersion.toString()).append(".")); return sb.toString(); } @@ -335,11 +332,8 @@ public class EdgeRuleQuery { @Override public int hashCode() { - if (v.isPresent()) { - return Objects.hash(v.get(), nodeA, nodeB, label, direction, type, isPrivate); - } else { - return Objects.hash(nodeA, nodeB, label, direction, type, isPrivate); - } + return v.map(schemaVersion -> Objects.hash(schemaVersion, nodeA, nodeB, label, direction, type, isPrivate)) + .orElseGet(() -> Objects.hash(nodeA, nodeB, label, direction, type, isPrivate)); } } |