Integrate aai-schema-ingest library into aai-core
[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 package org.onap.aai;
21
22 import java.io.File;
23 import java.net.URL;
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, SchemaVersions schemaVersions) {
38                 super(bean, schemaVersions);
39         }
40
41         
42
43         /* (non-Javadoc)
44          * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles()
45          */
46         @Override
47         public Map<SchemaVersion, List<String>> getNodeFiles() {
48                 String prefix = bean.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                         
58                         files.put(v, container);
59                 }
60                 
61                 return files;
62         }
63         
64
65         public List<String> getVersionNodeFiles(SchemaVersion v) {
66                 Pattern p = Pattern.compile("aai(.*)"+"_oxm_(.*).xml" );
67                 
68                 List<String> container = new ArrayList<>();
69                 String directoryName = 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 }