2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.restcore.util;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import freemarker.template.Configuration;
27 import freemarker.template.Template;
28 import freemarker.template.TemplateException;
33 public class GenerateEdgeRules {
35 private static final EELFLogger LOG = EELFManager.getInstance().getLogger(GenerateEdgeRules.class);
37 public static void main(String[] args) throws IOException, TemplateException {
39 String filename = "/AAI8032.csv";
40 InputStream inputStream = GenerateEdgeRules.class.getResourceAsStream(filename);
41 Map<String, Integer> headers = new HashMap<>();
42 Map<String, Object> edgeRulesMap = new TreeMap<String, Object>();
43 List<Map<String, String>> edgeRules = new ArrayList<>();
45 try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
51 // Retrieve the header line to map the indexes to their column names
53 while ((line = reader.readLine()) != null) {
56 headers = retrieveHeaderMap(line);
58 String[] columns = line.split(",");
60 String originalNode = columns[headers.get("Orig NodeA|NodeB")];
61 String finalNode = columns[headers.get("Final NodeA|NodeB")];
62 String originalEdge = columns[headers.get("Orig EdgeLabel")];
63 String finalEdge = columns[headers.get("Final EdgeLabel")];
65 String lineage = columns[headers.get("Final Lineage")];
66 String originalParent = columns[headers.get("Orig ParentOf")];
67 String usesResource = columns[headers.get("Revised UsesResource")];
68 String hasDelTarget = columns[headers.get("Revised hasDelTarget")];
69 String svcInfra = columns[headers.get("Final SVC-INFRA")];
70 String svcInfraRev = "";
72 if(usesResource.equals("T"))
73 usesResource = "true";
74 else if(usesResource.equals("F"))
75 usesResource = "false";
77 if (hasDelTarget.equals("T") || hasDelTarget.equals("AB")) {
78 hasDelTarget = "true";
79 } else if (hasDelTarget.equals("F")) {
80 hasDelTarget = "false";
83 if (svcInfra.equals("T")) {
85 } else if (svcInfra.equals("F")) {
87 } else if (svcInfra.equals("R")) {
91 if (originalParent.equals("T")) {
92 if (lineage.trim().equalsIgnoreCase("CHILD")) {
94 } else if (lineage.trim().equalsIgnoreCase("PARENT")) {
101 Map<String, String> edgeMap = new HashMap<String, String>();
103 edgeMap.put("lineage", lineage);
104 edgeMap.put("usesResource", usesResource);
105 edgeMap.put("hasDelTarget", hasDelTarget);
106 edgeMap.put("SVC-INFRA", svcInfra);
107 edgeMap.put("SVC-INFRA-REV", svcInfraRev);
108 edgeMap.put("nodes", finalNode);
109 edgeMap.put("edge", finalEdge);
110 edgeMap.put("direction", columns[headers.get("Orig Direction")]);
111 edgeMap.put("multiplicity", columns[headers.get("Revised Multiplicity")]);
113 edgeRules.add(edgeMap);
118 } catch(Exception ex){
119 ex.printStackTrace();
122 edgeRulesMap.put("edgeRules", edgeRules);
124 Collections.sort(edgeRules, new Comparator<Map<String, String>>() {
126 public int compare(Map<String, String> o1, Map<String, String> o2) {
127 return o1.get("nodes").compareTo(o2.get("nodes"));
131 Configuration configuration = new Configuration();
132 Template template = configuration.getTemplate("ajsc-aai/src/main/resources/EdgeRules.ftl");
133 Writer file = new FileWriter(new File("ajsc-aai/src/main/resources" + "/" + "EdgeRules.txt"));
134 template.process(edgeRulesMap, file);
137 private static Map<String, Integer> retrieveHeaderMap(String line){
140 throw new NullPointerException();
142 String[] columnNames = line.split(",");
144 Map<String, Integer> map = new HashMap<String, Integer>();
148 for(String columnName : columnNames){
149 map.put(columnName, index++);