- 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>
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() {
*/
@Override
public Map<SchemaVersion, List<String>> getNodeFiles() {
- String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
+ String prefix = schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
String suffix = ".xml";
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) {
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);
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 {
* ================================================================================
* 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
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);
}
/*
}
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());
}
/*
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;
}
-/**
- * ============LICENSE_START=======================================================
+/** ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 2017-18 AT&T Intellectual Property. All rights reserved.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- */
+*/
package org.onap.aai.setup;
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;
}
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 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);
* 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
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<>();
@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<>();