X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fschema%2FRelationshipSchema.java;fp=src%2Fmain%2Fjava%2Forg%2Fonap%2Fschema%2FRelationshipSchema.java;h=fc91662ea23abce493fa45f512ed279945f51735;hb=00832f054dd0c21492af531548e321ea25cdb8b4;hp=557c374862ca2def1aa24af5fd246edd237054fc;hpb=18703cdc19842806969d30f19f8171469c79a0fe;p=aai%2Fgizmo.git diff --git a/src/main/java/org/onap/schema/RelationshipSchema.java b/src/main/java/org/onap/schema/RelationshipSchema.java index 557c374..fc91662 100644 --- a/src/main/java/org/onap/schema/RelationshipSchema.java +++ b/src/main/java/org/onap/schema/RelationshipSchema.java @@ -20,10 +20,9 @@ */ package org.onap.schema; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - +import com.google.common.collect.Multimap; import org.codehaus.jackson.map.ObjectMapper; +import org.onap.aai.edges.EdgeRule; import org.onap.crud.exception.CrudException; import java.io.IOException; @@ -33,12 +32,8 @@ import javax.ws.rs.core.Response.Status; public class RelationshipSchema { - private static final Gson gson = new GsonBuilder().create(); - public static final String SCHEMA_SOURCE_NODE_TYPE = "from"; - public static final String SCHEMA_TARGET_NODE_TYPE = "to"; public static final String SCHEMA_RELATIONSHIP_TYPE = "label"; - public static final String SCHEMA_RULES_ARRAY = "rules"; private Map>> relations = new HashMap<>(); @@ -47,12 +42,7 @@ public class RelationshipSchema { */ private Map>> relationTypes = new HashMap<>(); - - public RelationshipSchema(List jsonStrings) throws CrudException, IOException { - String edgeRules = jsonStrings.get(0); - String props = jsonStrings.get(1); - - HashMap>> rules = new ObjectMapper().readValue(edgeRules, HashMap.class); + public RelationshipSchema( Multimap rules, String props) throws CrudException, IOException { HashMap properties = new ObjectMapper().readValue(props, HashMap.class); Map> edgeProps = properties.entrySet().stream().collect(Collectors.toMap(p -> p.getKey(), p -> { try { @@ -63,14 +53,12 @@ public class RelationshipSchema { return null; })); - rules.get(SCHEMA_RULES_ARRAY).forEach(l -> { - relationTypes.put(l.get(SCHEMA_RELATIONSHIP_TYPE), edgeProps); - relations.put(buildRelation(l.get(SCHEMA_SOURCE_NODE_TYPE), l.get(SCHEMA_TARGET_NODE_TYPE), l.get(SCHEMA_RELATIONSHIP_TYPE)), edgeProps); + rules.entries ().forEach ( (kv) -> { + relationTypes.put(kv.getValue ().getLabel (), edgeProps); + relations.put (buildRelation ( kv.getValue ().getFrom (), kv.getValue ().getTo (), kv.getValue ().getLabel ()), edgeProps); }); } - - public Map> lookupRelation(String key) { return this.relations.get(key); }