summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main/java
diff options
context:
space:
mode:
authorVenkata Harish K Kajur <vk250x@att.com>2017-08-15 09:58:15 -0400
committerVenkata Harish K Kajur <vk250x@att.com>2017-08-15 09:59:55 -0400
commitfbb825ab807725146a9f01aed5c85367f6df609e (patch)
tree3e226386427a008709d08899504d3dff84dc48a3 /aai-core/src/main/java
parenta84e52f06e453e9fb405c3dcb0e3e4d5e6ffbd1a (diff)
[AAI-169 Amsterdam] Add ability for older versions
Change-Id: Ica6c4962e9cc7d98634606c010c3555e5a0a2f67 Signed-off-by: Venkata Harish K Kajur <vk250x@att.com>
Diffstat (limited to 'aai-core/src/main/java')
-rw-r--r--aai-core/src/main/java/org/openecomp/aai/serialization/db/EdgeRules.java72
1 files changed, 59 insertions, 13 deletions
diff --git a/aai-core/src/main/java/org/openecomp/aai/serialization/db/EdgeRules.java b/aai-core/src/main/java/org/openecomp/aai/serialization/db/EdgeRules.java
index 7f925a16..454aa1ee 100644
--- a/aai-core/src/main/java/org/openecomp/aai/serialization/db/EdgeRules.java
+++ b/aai-core/src/main/java/org/openecomp/aai/serialization/db/EdgeRules.java
@@ -20,22 +20,25 @@
package org.openecomp.aai.serialization.db;
-import java.io.File;
-import java.io.IOException;
+import static com.jayway.jsonpath.Criteria.where;
+import static com.jayway.jsonpath.Filter.filter;
+
import java.io.InputStream;
import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Scanner;
+import java.util.concurrent.ConcurrentHashMap;
-import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-
import org.openecomp.aai.db.props.AAIProperties;
import org.openecomp.aai.dbmodel.DbEdgeRules;
import org.openecomp.aai.exceptions.AAIException;
@@ -47,15 +50,9 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
-import com.jayway.jsonpath.JsonPath;
-
-import static com.jayway.jsonpath.Filter.filter;
-import static com.jayway.jsonpath.Criteria.where;
-
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.Filter;
-
-import java.util.Scanner;
+import com.jayway.jsonpath.JsonPath;
public class EdgeRules {
@@ -72,16 +69,51 @@ public class EdgeRules {
*/
private EdgeRules() {
- InputStream is = getClass().getResourceAsStream("/dbedgerules/DbEdgeRules_" + Version.getLatest().toString() + ".json");
+ String json = this.getEdgeRuleJson(Version.getLatest());
+ rulesDoc = JsonPath.parse(json);
+
+ }
+
+ /**
+ * Loads the versioned DbEdgeRules json file for later parsing.
+ */
+ @SuppressWarnings("unchecked")
+ private EdgeRules(Version version) {
+
+ String json = this.getEdgeRuleJson(version);
+ rulesDoc = JsonPath.parse(json);
+
+ if (!Version.isLatest(version)) {
+ try {
+ Class<?> dbEdgeRules = Class.forName("org.openecomp.aai.dbmodel." + version.toString() + ".gen.DbEdgeRules");
+ this.deleteScope = (Multimap<String, String>)dbEdgeRules.getDeclaredField("DefaultDeleteScope").get(null);
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ private String getEdgeRuleJson(Version version) {
+ InputStream is = getClass().getResourceAsStream("/dbedgerules/DbEdgeRules_" + version.toString() + ".json");
Scanner scanner = new Scanner(is);
String json = scanner.useDelimiter("\\Z").next();
scanner.close();
- rulesDoc = JsonPath.parse(json);
+
+ return json;
}
private static class Helper {
private static final EdgeRules INSTANCE = new EdgeRules();
+ private static final Map<Version, EdgeRules> INSTANCEMAP = new ConcurrentHashMap<>();
+ private static EdgeRules getVersionedEdgeRules(Version v) {
+ if (Version.isLatest(v)) {
+ return INSTANCE;
+ }
+ if (!INSTANCEMAP.containsKey(v)) {
+ INSTANCEMAP.put(v, new EdgeRules(v));
+ }
+ return INSTANCEMAP.get(v);
+ }
}
/**
@@ -95,6 +127,16 @@ public class EdgeRules {
}
/**
+ * Gets the versioned instance of EdgeRules.
+ *
+ * @return versioned instance of EdgeRules
+ */
+ public static EdgeRules getInstance(Version v) {
+ return Helper.getVersionedEdgeRules(v);
+
+ }
+
+ /**
* Adds the tree edge.
*
* @param aVertex the out vertex
@@ -464,4 +506,8 @@ public class EdgeRules {
return result;
}
+ public Multimap<String, String> getDeleteSemantics() {
+ return this.deleteScope;
+ }
+
}