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.dbmodel;
22 //import static com.jayway.jsonpath.Criteria.where;
23 //import static com.jayway.jsonpath.Filter.filter;
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;
33 //import org.openecomp.aai.introspection.Version;
34 //import org.openecomp.aai.serialization.db.AAIDirection;
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;
42 //public class ConvertDeleteScope {
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";
50 // public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, IllegalArgumentException, NoSuchFieldException, SecurityException {
51 // for (Version v : Version.values()) {
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);
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);
65 // Object rules = Class.forName(edgeClasspath + String.format(edgeClassSuffix, v) + ".DbEdgeRules").newInstance();
66 // deleteScope = (Multimap<String, String>) rules.getClass().getField("DefaultDeleteScope").get(rules);
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();
73 // addRule(rulesDoc, key, value);
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());
80 // System.out.println("Version: " + v + " " + rulesDoc.jsonString());
85 // private static String readFile (String path) throws IOException {
86 // return new String(Files.readAllBytes(Paths.get(path)));
89 // private static void addRule(DocumentContext rulesDoc, String nodeType, String deleteScope) {
91 // if (deleteScope.equals("THIS_NODE_ONLY")) {
92 // List<Map<String, String>> results = rulesDoc.read("$.rules.[?]", filter(
93 // where("from").is(nodeType)
95 // filter(where("isParent").is("${direction}")).or(
96 // where("hasDelTarget").is("${direction}")
100 // for (Map<String, String> result : results) {
101 // result.put("preventDelete", "${direction}");
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}");