07183436006a98f0a826cd944c73de21df6bcb97
[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.net.URL;
25 import java.util.*;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28
29 import org.onap.aai.setup.*;
30 import org.onap.aai.util.AAIConstants;
31
32 /**
33  * Quick and dirty access to test schema files
34  *
35  */
36 public abstract class AbstractConfigTranslator extends ConfigTranslator {
37
38     public AbstractConfigTranslator(SchemaLocationsBean bean, SchemaConfigVersions schemaVersions) {
39         super(bean, schemaVersions);
40     }
41
42     /*
43      * (non-Javadoc)
44      * 
45      * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
46      */
47     @Override
48     public Map<SchemaVersion, List<String>> getNodeFiles() {
49         String prefix = bean.getNodeDirectory() + AAIConstants.AAI_FILESEP;
50
51         String suffix = ".xml";
52
53         Map<SchemaVersion, List<String>> files = new TreeMap<>();
54         for (SchemaVersion v : schemaVersions.getVersions()) {
55
56             List<String> container = getVersionNodeFiles(v);
57
58             files.put(v, container);
59         }
60
61         return files;
62     }
63
64     public List<String> getVersionNodeFiles(SchemaVersion v) {
65         Pattern p = Pattern.compile("aai(.*)" + "_oxm_(.*).xml");
66
67         List<String> container = new ArrayList<>();
68         String directoryName =
69                 bean.getNodeDirectory() + AAIConstants.AAI_FILESEP + v.toString() + AAIConstants.AAI_FILESEP;
70
71         File[] files = new File(directoryName).listFiles();
72         for (File f : files) {
73             String fileName = f.getName();
74             Matcher m = p.matcher(fileName);
75             if (m.find()) {
76                 String file = directoryName + m.group();
77                 container.add(file.toString());
78             }
79
80         }
81         return container;
82
83     }
84
85 }