2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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=========================================================
21 package org.openecomp.aai.restcore.util;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
25 import freemarker.template.Configuration;
26 import freemarker.template.Template;
27 import freemarker.template.TemplateException;
32 public class GenerateEdgeRules {
34 private static final EELFLogger LOG = EELFManager.getInstance().getLogger(GenerateEdgeRules.class);
36 public static void main(String[] args) throws IOException, TemplateException {
38 String filename = "/AAI8032.csv";
39 InputStream inputStream = GenerateEdgeRules.class.getResourceAsStream(filename);
40 Map<String, Integer> headers = new HashMap<>();
41 Map<String, Object> edgeRulesMap = new TreeMap<String, Object>();
42 List<Map<String, String>> edgeRules = new ArrayList<>();
44 try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
50 // Retrieve the header line to map the indexes to their column names
52 while ((line = reader.readLine()) != null) {
55 headers = retrieveHeaderMap(line);
57 String[] columns = line.split(",");
59 String originalNode = columns[headers.get("Orig NodeA|NodeB")];
60 String finalNode = columns[headers.get("Final NodeA|NodeB")];
61 String originalEdge = columns[headers.get("Orig EdgeLabel")];
62 String finalEdge = columns[headers.get("Final EdgeLabel")];
64 String lineage = columns[headers.get("Final Lineage")];
65 String originalParent = columns[headers.get("Orig ParentOf")];
66 String usesResource = columns[headers.get("Revised UsesResource")];
67 String hasDelTarget = columns[headers.get("Revised hasDelTarget")];
68 String svcInfra = columns[headers.get("Final SVC-INFRA")];
69 String svcInfraRev = "";
71 if(usesResource.equals("T"))
72 usesResource = "true";
73 else if(usesResource.equals("F"))
74 usesResource = "false";
76 if (hasDelTarget.equals("T") || hasDelTarget.equals("AB")) {
77 hasDelTarget = "true";
78 } else if (hasDelTarget.equals("F")) {
79 hasDelTarget = "false";
82 if (svcInfra.equals("T")) {
84 } else if (svcInfra.equals("F")) {
86 } else if (svcInfra.equals("R")) {
90 if (originalParent.equals("T")) {
91 if (lineage.trim().equalsIgnoreCase("CHILD")) {
93 } else if (lineage.trim().equalsIgnoreCase("PARENT")) {
100 Map<String, String> edgeMap = new HashMap<String, String>();
102 edgeMap.put("lineage", lineage);
103 edgeMap.put("usesResource", usesResource);
104 edgeMap.put("hasDelTarget", hasDelTarget);
105 edgeMap.put("SVC-INFRA", svcInfra);
106 edgeMap.put("SVC-INFRA-REV", svcInfraRev);
107 edgeMap.put("nodes", finalNode);
108 edgeMap.put("edge", finalEdge);
109 edgeMap.put("direction", columns[headers.get("Orig Direction")]);
110 edgeMap.put("multiplicity", columns[headers.get("Revised Multiplicity")]);
112 edgeRules.add(edgeMap);
117 } catch(Exception ex){
118 ex.printStackTrace();
121 edgeRulesMap.put("edgeRules", edgeRules);
123 Collections.sort(edgeRules, new Comparator<Map<String, String>>() {
125 public int compare(Map<String, String> o1, Map<String, String> o2) {
126 return o1.get("nodes").compareTo(o2.get("nodes"));
130 Configuration configuration = new Configuration();
131 Template template = configuration.getTemplate("ajsc-aai/src/main/resources/EdgeRules.ftl");
132 Writer file = new FileWriter(new File("ajsc-aai/src/main/resources" + "/" + "EdgeRules.txt"));
133 template.process(edgeRulesMap, file);
136 private static Map<String, Integer> retrieveHeaderMap(String line){
139 throw new NullPointerException();
141 String[] columnNames = line.split(",");
143 Map<String, Integer> map = new HashMap<String, Integer>();
147 for(String columnName : columnNames){
148 map.put(columnName, index++);