diff options
author | Liard Samuel <samuel.liard@orange.com> | 2021-06-30 19:06:16 +0200 |
---|---|---|
committer | Samuel Liard <samuel.liard@gmail.com> | 2021-07-02 09:30:45 +0200 |
commit | a2f7d11ca0bd58ec6c252111ddd3d5dfac0e4c70 (patch) | |
tree | 2c12ab019a9456d928da715198b4bb91b3678b36 /aai-schema-ingest | |
parent | fe71e2611b2bfecc65ef121631360b4c32ca129e (diff) |
Fix all blocker sonar issues and some checkstyle
Issue-ID: AAI-3362
Signed-off-by: sliard <samuel.liard@gmail.com>
Change-Id: I365be3e8afe75b54f5a65deadb054df73857274e
Diffstat (limited to 'aai-schema-ingest')
4 files changed, 48 insertions, 31 deletions
diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java index 002ec1ee..207f7e0a 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java @@ -239,8 +239,9 @@ public class EdgeIngestor { public Multimap<String, EdgeRule> getRules(EdgeRuleQuery q) throws EdgeRuleNotFoundException { Multimap<String, EdgeRule> found = null; - if (q.getVersion().isPresent()) { - found = extractRules(q.getFilter(), q.getVersion().get()); + Optional<SchemaVersion> versionOpt = q.getVersion(); + if (versionOpt.isPresent()) { + found = extractRules(q.getFilter(), versionOpt.get()); } else { found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); } @@ -287,8 +288,9 @@ public class EdgeIngestor { */ public EdgeRule getRule(EdgeRuleQuery q) throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { Multimap<String, EdgeRule> found = null; - if (q.getVersion().isPresent()) { - found = extractRules(q.getFilter(), q.getVersion().get()); + Optional<SchemaVersion> versionOpt = q.getVersion(); + if (versionOpt.isPresent()) { + found = extractRules(q.getFilter(), versionOpt.get()); } else { found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); } @@ -361,8 +363,9 @@ public class EdgeIngestor { * @return boolean */ public boolean hasRule(EdgeRuleQuery q) { - if (q.getVersion().isPresent()) { - return !extractRules(q.getFilter(), q.getVersion().get()).isEmpty(); + Optional<SchemaVersion> versionOpt = q.getVersion(); + if (versionOpt.isPresent()) { + return !extractRules(q.getFilter(), versionOpt.get()).isEmpty(); } else { return !extractRules(q.getFilter(), schemaVersions.getDefaultVersion()).isEmpty(); } @@ -418,7 +421,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any cousin relationships in the current version. - * + * * @param nodeType * @return boolean */ @@ -428,7 +431,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any cousin relationships in the given version. - * + * * @param nodeType * @return boolean */ @@ -479,7 +482,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any child relationships (ie it contains another node type) in the current * version. - * + * * @param nodeType * @return boolean */ @@ -490,7 +493,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any child relationships (ie it contains another node type) in the given * version. - * + * * @param nodeType * @return boolean */ @@ -541,7 +544,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the * current version. - * + * * @param nodeType * @return boolean */ @@ -552,7 +555,7 @@ public class EdgeIngestor { /** * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the * given version. - * + * * @param nodeType * @return boolean */ diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java index 139eb625..014a4442 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java @@ -22,23 +22,24 @@ package org.onap.aai.nodes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.CaseFormat; - -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.annotation.PostConstruct; import javax.xml.XMLConstants; import javax.xml.bind.JAXBException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; - import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; @@ -46,6 +47,8 @@ import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; import org.onap.aai.setup.Translator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; @@ -76,7 +79,7 @@ public class NodeIngestor { /** * Instantiates the NodeIngestor bean. - * + * * @param translatorSet */ @@ -158,6 +161,8 @@ public class NodeIngestor { throws ParserConfigurationException, IOException, SAXException { Set<String> types = new HashSet<>(); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); @@ -191,6 +196,8 @@ public class NodeIngestor { InputStream inputStream = inputStreams.get(0); inputStream.reset(); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); return masterDocBuilder.parse(inputStream); @@ -199,6 +206,8 @@ public class NodeIngestor { private Document createCombinedSchema(List<InputStream> inputStreams, SchemaVersion version) throws ParserConfigurationException, SAXException, IOException { final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java index 4ee93fad..10f1f542 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java @@ -20,15 +20,15 @@ package org.onap.aai.setup; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.onap.aai.restclient.RestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.io.*; -import java.util.*; - -import javax.ws.rs.HttpMethod; - -import org.onap.aai.restclient.RestClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; @@ -82,7 +82,10 @@ public class SchemaServiceTranslator extends Translator { ResponseEntity<Resource> schemaResponse = restClient.getGetResource(content, uri, headersMap); verifySchemaServiceResponse(schemaResponse.getStatusCode()); LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode()); - inputStreams.add(schemaResponse.getBody().getInputStream()); + Resource resultBody = schemaResponse.getBody(); + if (resultBody != null) { + inputStreams.add(resultBody.getInputStream()); + } return inputStreams; } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java index 024525b9..6181c52d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java @@ -1,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -43,7 +43,7 @@ import org.xml.sax.SAXException; * Default duplicate rules for A&AI - * node types may never have a duplicate definition * within the same Version's file set. - * + * * Finds all duplicates and what files they're in. * */ @@ -51,13 +51,15 @@ public class DefaultDuplicateNodeDefinitionValidationModule implements Duplicate /* * (non-Javadoc) - * + * * @see org.onap.aai.nodes.validation.DuplicateNodeDefinitionValidationModule#findDuplicates(java.util.List) */ @Override public String findDuplicates(List<String> files, SchemaVersion v) { try { final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + docFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); |