Only load SchemaService related beans in aai-common when schema.translator.list=schem... 69/137369/2
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>
Mon, 26 Feb 2024 13:03:09 +0000 (14:03 +0100)
committerFiete Ostkamp <fiete.ostkamp@telekom.de>
Mon, 26 Feb 2024 13:08:47 +0000 (13:08 +0000)
- conditionally load schema-service related config, otherwise use the ConfigTranslator
- this prepares locally running traversal via mvn spring-boot:run

Issue-ID: AAI-3787
Change-Id: I9415802fb708933e8596b62e7540fa8a156e4cd6
Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
aai-core/src/main/java/org/onap/aai/config/SchemaConfiguration.java
aai-core/src/test/java/org/onap/aai/AbstractConfigTranslator.java
aai-rest/src/main/java/org/onap/aai/restclient/AAIRestClient.java
aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java
aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java
aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java
aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java
aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java
aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java

index 885790c..9247bc7 100644 (file)
@@ -66,13 +66,6 @@ public class SchemaConfiguration {
         return nodesConfiguration.nodeIngestor();
     }
 
-    @Bean(name = "configTranslator")
-    @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
-    public ConfigTranslator configTranslator(SchemaLocationsBean schemaLocationsBean,
-            SchemaConfigVersions schemaVersions) {
-        return new AAIConfigTranslator(schemaLocationsBean, schemaVersions);
-    }
-
     @Bean
     @ConditionalOnProperty(name = "schema.translator.list", havingValue = "config", matchIfMissing = true)
     public SchemaErrorStrategy schemaErrorStrategy() {
index 19b8220..3df799b 100644 (file)
@@ -45,7 +45,7 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator {
      */
     @Override
     public Map<SchemaVersion, List<String>> getNodeFiles() {
-        String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
+        String prefix = schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
 
         String suffix = ".xml";
 
@@ -65,7 +65,7 @@ public abstract class AbstractConfigTranslator extends ConfigTranslator {
 
         List<String> container = new ArrayList<>();
         String directoryName =
-                bean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP;
+                schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP;
 
         File[] files = new File(directoryName).listFiles();
         for (File f : files) {
index 05d5ec0..393c663 100644 (file)
@@ -26,12 +26,16 @@ import java.util.Map;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.stereotype.Component;
 import org.springframework.util.MultiValueMap;
 
 @Component(value = ClientType.AAI)
+@ConditionalOnExpression("${aai-rest-client.enabled:false}")
 public class AAIRestClient extends TwoWaySSLRestClient {
 
     private static Logger logger = LoggerFactory.getLogger(AAIRestClient.class);
index cdd8749..701fd17 100644 (file)
 package org.onap.aai.config;
 
 import org.onap.aai.setup.*;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.PropertySource;
 
 @Configuration
-@ConditionalOnExpression("'${schema.translator.list}'.contains('schema-service')")
+@ConditionalOnProperty(name = "schema.translator.list", havingValue = "schema-service", matchIfMissing = false)
 @PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true)
 @PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true)
 public class SchemaServiceConfiguration {
index 8949891..66ffcf8 100644 (file)
@@ -4,6 +4,8 @@
  * ================================================================================
  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Modifications Copyright © 2024 DEUTSCHE TELEKOM AG.
+ * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -24,23 +26,24 @@ import java.io.File;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.TreeMap;
 import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import org.springframework.stereotype.Component;
+
 /**
  * <b>AAIConfigTranslator</b> is responsible for looking at the
  * schema files and edge files based on the available versions
  * Also has the ability to exclude them based on the node.exclusion.pattern
  */
+@Component
 public class AAIConfigTranslator extends ConfigTranslator {
 
-    private static final String FILESEP =
-            (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
-
-    public AAIConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
-        super(bean, schemaVersions);
+    public AAIConfigTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaConfigVersions) {
+        super(schemaLocationsBean, schemaConfigVersions);
     }
 
     /*
@@ -61,8 +64,8 @@ public class AAIConfigTranslator extends ConfigTranslator {
     }
 
     private List<String> getVersionNodeFiles(SchemaVersion v) {
-        return getVersionFiles(bean.getNodeDirectory(), v, () -> bean.getNodesInclusionPattern().stream(),
-                () -> bean.getNodesExclusionPattern().stream());
+        return getVersionFiles(schemaLocationsBean.getNodeDirectory(), v, () -> schemaLocationsBean.getNodesInclusionPattern().stream(),
+                () -> schemaLocationsBean.getNodesExclusionPattern().stream());
     }
 
     /*
@@ -84,18 +87,25 @@ public class AAIConfigTranslator extends ConfigTranslator {
 
     private List<String> getVersionEdgeFiles(SchemaVersion v) {
 
-        return getVersionFiles(bean.getEdgeDirectory(), v, () -> bean.getEdgesInclusionPattern().stream(),
-                () -> bean.getEdgesExclusionPattern().stream());
+        return getVersionFiles(schemaLocationsBean.getEdgeDirectory(), v, () -> schemaLocationsBean.getEdgesInclusionPattern().stream(),
+                () -> schemaLocationsBean.getEdgesExclusionPattern().stream());
     }
 
     private List<String> getVersionFiles(String startDirectory, SchemaVersion schemaVersion,
-            Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) {
-
-        List<String> container;
-        final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP;
-        container = Arrays.stream(new File(directoryName).listFiles()).map(File::getName)
-                .filter(name -> inclusionPattern.get().anyMatch(name::matches)).map(name -> directoryName + name)
-                .filter(name -> exclusionPattern.get().noneMatch(name::matches)).collect(Collectors.toList());
+           Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) {
+
+       final File versionDirectory = new File(startDirectory + "/" + schemaVersion.toString());
+       final List<String> container = Arrays.stream(versionDirectory.listFiles())
+           .filter(Objects::nonNull)    
+           .map(File::getName)
+           .filter(versionFileName -> inclusionPattern
+               .get()
+               .anyMatch(versionFileName::matches))
+           .map(versionFileName -> versionDirectory.getAbsolutePath() + "/" + versionFileName)
+           .filter(versionFilePath -> exclusionPattern
+               .get()
+               .noneMatch(versionFilePath::matches))
+           .collect(Collectors.toList());
 
         return container;
     }
index e87a05c..50b9dc2 100644 (file)
@@ -1,5 +1,4 @@
-/** 
- * ============LICENSE_START=======================================================
+/**  ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
  * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
@@ -16,7 +15,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- */
+*/
 
 package org.onap.aai.setup;
 
@@ -45,12 +44,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 public abstract class ConfigTranslator extends Translator {
     private static final Logger LOGGER = LoggerFactory.getLogger(ConfigTranslator.class);
 
-    protected SchemaLocationsBean bean;
+    protected SchemaLocationsBean schemaLocationsBean;
 
     @Autowired
-    public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaConfigVersions schemaVersions) {
-        super(schemaVersions);
-        this.bean = schemaLocationbean;
+    public ConfigTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaConfigVersions) {
+        super(schemaConfigVersions);
+        this.schemaLocationsBean = schemaLocationsBean;
 
     }
 
index 680bdd1..ec6e41a 100644 (file)
@@ -22,7 +22,6 @@ 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;
@@ -32,19 +31,22 @@ import org.onap.aai.restclient.RestClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.core.io.Resource;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
 
 /**
  * <b>AAIConfigTranslator</b> is responsible for looking at the schema files and
  * edge files based on the available versions Also has the ability to exclude
  * them based on the node.exclusion.pattern
  */
+@Component
+@ConditionalOnProperty(name = "schema.translator.list", havingValue = "schema-service", matchIfMissing = false)
 public class SchemaServiceTranslator extends Translator {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(SchemaServiceTranslator.class);
index 3d415e6..45ca0cd 100644 (file)
@@ -45,9 +45,9 @@ public abstract class Translator {
      *         ingested for that version
      */
 
-    public abstract List<InputStream> getVersionNodeStream(SchemaVersion version) throws IOException;
+    public abstract List<InputStream> getVersionNodeStream(SchemaVersion schemaVersion) throws IOException;
 
-    public abstract List<String> getJsonPayload(SchemaVersion version) throws IOException;
+    public abstract List<String> getJsonPayload(SchemaVersion schemaVersion) throws IOException;
 
     /**
      * Translates the contents of the schema config file
index 1d8e4bc..a711312 100644 (file)
@@ -32,14 +32,14 @@ import org.onap.aai.setup.SchemaVersion;
 
 public class ConfigTranslatorForWiringTest extends ConfigTranslator {
 
-    public ConfigTranslatorForWiringTest(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
-        super(bean, schemaVersions);
+    public ConfigTranslatorForWiringTest(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaVersions) {
+        super(schemaLocationsBean, schemaVersions);
     }
 
     @Override
     public Map<SchemaVersion, List<String>> getNodeFiles() {
 
-        String f = bean.getNodeDirectory() + "test_business_v10.xml";
+        String f = schemaLocationsBean.getNodeDirectory() + "test_business_v10.xml";
         List<String> files = new ArrayList<>();
         files.add(f);
         Map<SchemaVersion, List<String>> mp = new TreeMap<>();
@@ -49,7 +49,7 @@ public class ConfigTranslatorForWiringTest extends ConfigTranslator {
 
     @Override
     public Map<SchemaVersion, List<String>> getEdgeFiles() {
-        String f = bean.getEdgeDirectory() + "test.json";
+        String f = schemaLocationsBean.getEdgeDirectory() + "test.json";
         List<String> files = new ArrayList<>();
         files.add(f);
         Map<SchemaVersion, List<String>> mp = new TreeMap<>();