diff options
Diffstat (limited to 'common/src/main/java/org/onap/so/client/aai/entities/Relationships.java')
-rw-r--r-- | common/src/main/java/org/onap/so/client/aai/entities/Relationships.java | 110 |
1 files changed, 24 insertions, 86 deletions
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/Relationships.java b/common/src/main/java/org/onap/so/client/aai/entities/Relationships.java index e907bc97d7..61a2f4b8fa 100644 --- a/common/src/main/java/org/onap/so/client/aai/entities/Relationships.java +++ b/common/src/main/java/org/onap/so/client/aai/entities/Relationships.java @@ -20,117 +20,55 @@ package org.onap.so.client.aai.entities; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Predicate; import javax.ws.rs.core.UriBuilder; -import org.onap.so.client.aai.AAICommonObjectMapperProvider; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.graphinventory.GraphInventoryObjectName; -import org.onap.so.jsonpath.JsonPathUtil; +import org.onap.so.client.graphinventory.entities.GraphInventoryRelationships; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.CaseFormat; +public class Relationships extends GraphInventoryRelationships<AAIResultWrapper, AAIResourceUri, AAIObjectType>{ -public class Relationships { - - private final ObjectMapper mapper; - private Map<String, Object> map; - private final String jsonBody; public Relationships(String json) { - this.jsonBody = json; - this.mapper = new AAICommonObjectMapperProvider().getMapper(); - try { - this.map = mapper.readValue(json, new TypeReference<Map<String, Object>>() {}); - } catch (IOException e) { - this.map = new HashMap<>(); - } - } - - public List<AAIResultWrapper> getByType(GraphInventoryObjectName type) { - - return this.getAll(Optional.of(type)); - } - - public List<AAIResultWrapper> getAll() { - - return this.getAll(Optional.empty()); - } - - - public List<String> getRelatedLinks() { - return this.getRelatedLinks(Optional.empty()); - } - - public List<String> getRelatedLinks(GraphInventoryObjectName type) { - return this.getRelatedLinks(Optional.of(type)); + super(json); } + @Deprecated + /** + * Use getRelatedUris instead + * @return + */ public List<AAIResourceUri> getRelatedAAIUris() { - return this.getRelatedAAIUris(x -> true); + return this.getRelatedUris(); } + @Deprecated + /** + * Use getRelatedUris instead + * @return + */ public List<AAIResourceUri> getRelatedAAIUris(GraphInventoryObjectName type) { - return this.getRelatedAAIUris(x -> type.typeName().equals(x)); - } - protected List<AAIResourceUri> getRelatedAAIUris(Predicate<String> p) { - List<AAIResourceUri> result = new ArrayList<>(); - if (map.containsKey("relationship")) { - List<Map<String, Object>> relationships = (List<Map<String, Object>>)map.get("relationship"); - for (Map<String, Object> relationship : relationships) { - final String relatedTo = (String)relationship.get("related-to"); - if (p.test(relatedTo)) { - AAIObjectType type; - type = AAIObjectType.fromTypeName(relatedTo); - final String relatedLink = (String)relationship.get("related-link"); - - result.add(AAIUriFactory.createResourceFromExistingURI(type, UriBuilder.fromPath(relatedLink).build())); - } - } - } - return result; + return this.getRelatedUris(type); } - - protected List<AAIResultWrapper> getAll(final Optional<GraphInventoryObjectName> type) { - List<AAIResourceUri> relatedLinks; - if (type.isPresent()) { - relatedLinks = this.getRelatedAAIUris(type.get()); - } else { - relatedLinks = this.getRelatedAAIUris(); - } - ArrayList<AAIResultWrapper> result = new ArrayList<>(); - for (AAIResourceUri link : relatedLinks) { - result.add(this.get(link)); - } - return result; - } - protected AAIResultWrapper get(AAIResourceUri uri) { return new AAIResourcesClient().get(uri); } - - protected List<String> getRelatedLinks(Optional<GraphInventoryObjectName> type) { - String matcher = ""; - if (type.isPresent()) { - matcher = "[?(@.related-to=='" + type.get() + "')]"; - } - return JsonPathUtil.getInstance().locateResultList(this.jsonBody, String.format("$.relationship%s.related-link", matcher)); + + @Override + protected AAIResourceUri createUri(AAIObjectType type, String relatedLink) { + + return AAIUriFactory.createResourceFromExistingURI(type, UriBuilder.fromPath(relatedLink).build()); } - - public String getJson() { - return this.jsonBody; + + @Override + protected AAIObjectType fromTypeName(String name) { + return AAIObjectType.fromTypeName(name); } } |