Only load SchemaService related beans in aai-common when schema.translator.list=schem...
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / AbstractConfigTranslator.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai;
22
23 import java.io.File;
24 import java.util.*;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
27
28 import org.onap.aai.setup.*;
29 import org.onap.aai.util.AAIConstants;
30
31 /**
32  * Quick and dirty access to test schema files
33  *
34  */
35 public abstract class AbstractConfigTranslator extends ConfigTranslator {
36
37     public AbstractConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
38         super(bean, schemaVersions);
39     }
40
41     /*
42      * (non-Javadoc)
43      * 
44      * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
45      */
46     @Override
47     public Map<SchemaVersion, List<String>> getNodeFiles() {
48         String prefix = schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
49
50         String suffix = ".xml";
51
52         Map<SchemaVersion, List<String>> files = new TreeMap<>();
53         for (SchemaVersion v : schemaVersions.getVersions()) {
54
55             List<String> container = getVersionNodeFiles(v);
56
57             files.put(v, container);
58         }
59
60         return files;
61     }
62
63     public List<String> getVersionNodeFiles(SchemaVersion v) {
64         Pattern p = Pattern.compile("aai(.*)" + "_oxm_(.*).xml");
65
66         List<String> container = new ArrayList<>();
67         String directoryName =
68                 schemaLocationsBean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP;
69
70         File[] files = new File(directoryName).listFiles();
71         for (File f : files) {
72             String fileName = f.getName();
73             Matcher m = p.matcher(fileName);
74             if (m.find()) {
75                 String file = directoryName + m.group();
76                 container.add(file.toString());
77             }
78
79         }
80         return container;
81
82     }
83
84 }