From 583288aa1d1871c171c0d939a67a10d81029a0c4 Mon Sep 17 00:00:00 2001 From: Fiete Ostkamp Date: Thu, 15 Feb 2024 17:10:02 +0100 Subject: Enable dependency injection for some aai-common classes - minor refactorings in SchemaServiceTranslator - annotate the other classes with @Component to make them available for dependency injection Issue-ID: AAI-3780 Signed-off-by: Fiete Ostkamp Change-Id: Ia48743b81de36e1da3e71eee8821baa526c86885 --- .../onap/aai/setup/SchemaServiceTranslator.java | 31 +++++++++------------- .../edges/CousinDefaultingValidationModule.java | 2 ++ .../edges/DefaultEdgeFieldsValidationModule.java | 2 ++ .../edges/SingleContainmentValidationModule.java | 2 ++ .../edges/UniqueLabelValidationModule.java | 2 ++ 5 files changed, 21 insertions(+), 18 deletions(-) (limited to 'aai-schema-ingest/src') 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 27148a44..680bdd12 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 @@ -23,6 +23,7 @@ package org.onap.aai.setup; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,15 +49,12 @@ public class SchemaServiceTranslator extends Translator { private static final Logger LOGGER = LoggerFactory.getLogger(SchemaServiceTranslator.class); - private static final String SchemaServiceClientType = "schema.service"; - @Value("${schema.service.nodes.endpoint}") private String nodeSchemaUri; @Value("${schema.service.edges.endpoint}") private String edgeSchemaUri; - @Qualifier("restClient") @Autowired private RestClient restClient; @@ -73,21 +71,20 @@ public class SchemaServiceTranslator extends Translator { @Override public List getVersionNodeStream(SchemaVersion version) throws IOException { - List inputStreams = new ArrayList<>(); - String content = ""; - String uri = nodeSchemaUri + version.toString(); - Map headersMap = new HashMap<>(); - + final Map headersMap = new HashMap<>(); headersMap.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML.toString()); headersMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML.toString()); + final String content = ""; + final String uri = nodeSchemaUri + version.toString(); ResponseEntity schemaResponse = restClient.getGetResource(content, uri, headersMap); + verifySchemaServiceResponse(schemaResponse.getStatusCode()); LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode()); + Resource resultBody = schemaResponse.getBody(); - if (resultBody != null) { - inputStreams.add(resultBody.getInputStream()); - } - return inputStreams; + return resultBody != null + ? Collections.singletonList(resultBody.getInputStream()) + : Collections.emptyList(); } @Override @@ -95,16 +92,14 @@ public class SchemaServiceTranslator extends Translator { /* * Call Schema MS to get versions using RestTemplate */ - List inputStreams = new ArrayList<>(); - String content = ""; - String uri = edgeSchemaUri + version.toString(); - Map headersMap = new HashMap<>(); + final String content = ""; + final String uri = edgeSchemaUri + version.toString(); + final Map headersMap = new HashMap<>(); ResponseEntity schemaResponse = restClient.getGetRequest(content, uri, headersMap); verifySchemaServiceResponse(schemaResponse.getStatusCode()); LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode()); - inputStreams.add(schemaResponse.getBody()); - return inputStreams; + return Collections.singletonList(schemaResponse.getBody()); } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java index 73337a49..688a6b96 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java @@ -28,11 +28,13 @@ import org.onap.aai.edges.EdgeRuleQuery; import org.onap.aai.edges.EdgeRuleQuery.Builder; import org.onap.aai.edges.enums.EdgeField; import org.onap.aai.edges.enums.EdgeType; +import org.springframework.stereotype.Component; /** * Validates that in the collection of cousin rules between a given node type pair, * there is exactly 1 set default=true. */ +@Component public class CousinDefaultingValidationModule { /** diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java index 1229cf49..5d81c60e 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java @@ -29,12 +29,14 @@ import java.util.Map; import java.util.Map.Entry; import org.onap.aai.edges.enums.EdgeField; +import org.springframework.stereotype.Component; /** * Default core A&AI edge field validation * All fields in EdgeField enum are required EXCEPT description * */ +@Component public class DefaultEdgeFieldsValidationModule implements EdgeFieldsValidationModule { /* diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java index 5f6a9646..1f18eb67 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java @@ -28,12 +28,14 @@ import java.util.Map; import org.onap.aai.edges.EdgeRuleQuery; import org.onap.aai.edges.enums.EdgeType; +import org.springframework.stereotype.Component; /** * Validates that the given node type pair has at most one containment relationship * in their edge rules. * */ +@Component public class SingleContainmentValidationModule { /** diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java index 82dc1694..162a11cf 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java @@ -27,11 +27,13 @@ import java.util.*; import org.onap.aai.edges.EdgeRuleQuery; import org.onap.aai.edges.EdgeRuleQuery.Builder; import org.onap.aai.edges.enums.EdgeField; +import org.springframework.stereotype.Component; /** * Applies label validation rules * */ +@Component public class UniqueLabelValidationModule { /** -- cgit 1.2.3-korg