[AAI-178 Amsterdam] Make Edge Properties to be
[aai/aai-common.git] / aai-core / src / main / java / org / openecomp / aai / dbmodel / ConvertDeleteScope.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.openecomp.aai
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
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.openecomp.aai.dbmodel;
22 //import static com.jayway.jsonpath.Criteria.where;
23 //import static com.jayway.jsonpath.Filter.filter;
24 //
25 //import java.io.IOException;
26 //import java.nio.file.Files;
27 //import java.nio.file.Paths;
28 //import java.util.Collection;
29 //import java.util.List;
30 //import java.util.Map;
31 //import java.util.Map.Entry;
32 //
33 //import org.openecomp.aai.introspection.Version;
34 //import org.openecomp.aai.serialization.db.AAIDirection;
35 //
36 //import com.google.common.collect.Multimap;
37 //import com.jayway.jsonpath.Configuration;
38 //import com.jayway.jsonpath.DocumentContext;
39 //import com.jayway.jsonpath.JsonPath;
40 //import com.jayway.jsonpath.Option;
41 //
42 //public class ConvertDeleteScope {
43 //      
44 //      
45 //      
46 //      private static final String edgeClasspath = "org.openecomp.aai.dbmodel";
47 //      private static final String edgeClassSuffix = ".%s.gen";
48 //      private static final String jsonEdgeFile = "src/main/resources/dbedgerules/DbEdgeRules_%s.json";
49 //
50 //      public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, IllegalArgumentException, NoSuchFieldException, SecurityException {
51 //              for (Version v : Version.values()) {
52 //                      convert(v);
53 //              }
54 //      }
55 //      private static void convert(Version v) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, NoSuchFieldException, SecurityException {
56 //              DocumentContext rulesDoc;
57 //              Multimap<String, String> deleteScope;
58 //              Configuration conf = Configuration.defaultConfiguration().addOptions(Option.ALWAYS_RETURN_LIST, Option.SUPPRESS_EXCEPTIONS);
59 //
60 //              rulesDoc = JsonPath.using(conf).parse(readFile(String.format(jsonEdgeFile, v)));
61 //              if (v.equals(Version.getLatest())) {
62 //                      Object rules = Class.forName(edgeClasspath + ".DbEdgeRules").newInstance();
63 //                      deleteScope = (Multimap<String, String>) rules.getClass().getField("DefaultDeleteScope").get(rules);
64 //              } else {
65 //                      Object rules = Class.forName(edgeClasspath + String.format(edgeClassSuffix, v) + ".DbEdgeRules").newInstance();
66 //                      deleteScope = (Multimap<String, String>) rules.getClass().getField("DefaultDeleteScope").get(rules);
67 //              }
68 //              Collection<Entry<String, String>> entries = deleteScope.entries();
69 //              for (Entry<String, String> entry : entries) {
70 //                      String key = entry.getKey();
71 //                      String value = entry.getValue();
72 //                      
73 //                      addRule(rulesDoc, key, value);
74 //                      
75 //              }
76 //              List<Map<String, String>> results = rulesDoc.read("$.rules.[?]", filter(where("preventDelete").exists(false)));
77 //              for (Map<String, String> result : results) {
78 //                      result.put("preventDelete", AAIDirection.NONE.toString());
79 //              }
80 //              System.out.println("Version: " + v + " " + rulesDoc.jsonString());
81 //              
82 //              
83 //      }
84 //      
85 //      private static String readFile (String path) throws IOException {
86 //              return new String(Files.readAllBytes(Paths.get(path)));
87 //      }
88 //      
89 //      private static void addRule(DocumentContext rulesDoc, String nodeType, String deleteScope) {
90 //              
91 //              if (deleteScope.equals("THIS_NODE_ONLY")) {
92 //                      List<Map<String, String>> results = rulesDoc.read("$.rules.[?]", filter(
93 //                                      where("from").is(nodeType)
94 //                              ).and(
95 //                                      filter(where("isParent").is("${direction}")).or(
96 //                                                      where("hasDelTarget").is("${direction}")
97 //                                      )
98 //                              )
99 //                      );
100 //                      for (Map<String, String> result : results) {
101 //                              result.put("preventDelete", "${direction}");
102 //                      }
103 //              } else if (deleteScope.contains("_IN_")) {
104 //                      List<Map<String, String>> results = rulesDoc.read("$.rules.[?]", filter(where("to").is(nodeType).and("isParent").is("false")));
105 //                      for (Map<String, String> result : results) {
106 //                              result.put("preventDelete", "!${direction}");
107 //                      }
108 //              } else {
109 //                      
110 //              }
111 //      }
112 //      
113 //
114 //}