2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright © 2024 DEUTSCHE TELEKOM AG.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.aai.setup;
26 import java.util.Arrays;
27 import java.util.List;
29 import java.util.Objects;
30 import java.util.TreeMap;
31 import java.util.function.Supplier;
32 import java.util.stream.Collectors;
33 import java.util.stream.Stream;
35 import org.springframework.stereotype.Component;
38 * <b>AAIConfigTranslator</b> is responsible for looking at the
39 * schema files and edge files based on the available versions
40 * Also has the ability to exclude them based on the node.exclusion.pattern
43 public class AAIConfigTranslator extends ConfigTranslator {
45 public AAIConfigTranslator(SchemaLocationsBean schemaLocationsBean, SchemaConfigVersions schemaConfigVersions) {
46 super(schemaLocationsBean, schemaConfigVersions);
52 * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
55 public Map<SchemaVersion, List<String>> getNodeFiles() {
57 Map<SchemaVersion, List<String>> files = new TreeMap<>();
58 for (SchemaVersion v : schemaVersions.getVersions()) {
59 List<String> container = getVersionNodeFiles(v);
60 files.put(v, container);
66 private List<String> getVersionNodeFiles(SchemaVersion v) {
67 return getVersionFiles(schemaLocationsBean.getNodeDirectory(), v, () -> schemaLocationsBean.getNodesInclusionPattern().stream(),
68 () -> schemaLocationsBean.getNodesExclusionPattern().stream());
74 * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
77 public Map<SchemaVersion, List<String>> getEdgeFiles() {
79 Map<SchemaVersion, List<String>> files = new TreeMap<>();
80 for (SchemaVersion v : schemaVersions.getVersions()) {
81 List<String> container = getVersionEdgeFiles(v);
82 files.put(v, container);
88 private List<String> getVersionEdgeFiles(SchemaVersion v) {
90 return getVersionFiles(schemaLocationsBean.getEdgeDirectory(), v, () -> schemaLocationsBean.getEdgesInclusionPattern().stream(),
91 () -> schemaLocationsBean.getEdgesExclusionPattern().stream());
94 private List<String> getVersionFiles(String startDirectory, SchemaVersion schemaVersion,
95 Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) {
97 final File versionDirectory = new File(startDirectory + "/" + schemaVersion.toString());
98 final List<String> container = Arrays.stream(versionDirectory.listFiles())
99 .filter(Objects::nonNull)
101 .filter(versionFileName -> inclusionPattern
103 .anyMatch(versionFileName::matches))
104 .map(versionFileName -> versionDirectory.getAbsolutePath() + "/" + versionFileName)
105 .filter(versionFilePath -> exclusionPattern
107 .noneMatch(versionFilePath::matches))
108 .collect(Collectors.toList());