2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.schemaservice.config;
24 import java.util.Arrays;
25 import java.util.List;
27 import java.util.TreeMap;
28 import java.util.function.Supplier;
29 import java.util.stream.Collectors;
30 import java.util.stream.Stream;
32 import org.onap.aai.schemaservice.nodeschema.SchemaVersion;
33 import org.onap.aai.schemaservice.nodeschema.SchemaVersions;
36 * <b>AAIConfigTranslator</b> is responsible for looking at the
37 * schema files and edge files based on the available versions
38 * Also has the ability to exclude them based on the node.exclusion.pattern
40 public class AAIConfigTranslator extends ConfigTranslator {
42 private static final String FILESEP =
43 (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
45 public AAIConfigTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) {
46 super(bean, schemaVersions);
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) {
68 return getVersionFiles(bean.getNodeDirectory(), v,
69 () -> bean.getNodesInclusionPattern().stream(),
70 () -> bean.getNodesExclusionPattern().stream());
76 * @see org.onap.aai.setup.ConfigTranslator#getEdgeFiles()
79 public Map<SchemaVersion, List<String>> getEdgeFiles() {
81 Map<SchemaVersion, List<String>> files = new TreeMap<>();
82 for (SchemaVersion v : schemaVersions.getVersions()) {
83 List<String> container = getVersionEdgeFiles(v);
84 files.put(v, container);
90 private List<String> getVersionEdgeFiles(SchemaVersion v) {
92 return getVersionFiles(bean.getEdgeDirectory(), v,
93 () -> bean.getEdgesInclusionPattern().stream(),
94 () -> bean.getEdgesExclusionPattern().stream());
97 private List<String> getVersionFiles(String startDirectory, SchemaVersion schemaVersion,
98 Supplier<Stream<String>> inclusionPattern, Supplier<Stream<String>> exclusionPattern) {
100 List<String> container;
101 final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP;
103 container = Arrays.stream(new File(directoryName).listFiles()).map(File::getName)
104 .filter(name -> inclusionPattern.get().anyMatch(name::matches))
105 .map(name -> directoryName + name)
106 .filter(name -> exclusionPattern.get().noneMatch(name::matches))
107 .collect(Collectors.toList());