From a0e716dc093cd8a4a4ec8aaca7bc1635e518527a Mon Sep 17 00:00:00 2001 From: Daniel Silverthorn Date: Mon, 22 Jan 2018 11:28:42 -0500 Subject: Add query parameters to get properties Issue-ID: AAI-685 Change-Id: Id06a08ef668591560d276ef8a79c095f31d8c85b Signed-off-by: Daniel Silverthorn --- src/main/java/org/onap/crud/dao/GraphDao.java | 16 ++++++++++++++++ src/main/java/org/onap/crud/dao/champ/ChampDao.java | 19 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/onap/crud/dao') diff --git a/src/main/java/org/onap/crud/dao/GraphDao.java b/src/main/java/org/onap/crud/dao/GraphDao.java index bc42b15..c62a788 100644 --- a/src/main/java/org/onap/crud/dao/GraphDao.java +++ b/src/main/java/org/onap/crud/dao/GraphDao.java @@ -23,6 +23,7 @@ */ package org.onap.crud.dao; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -61,6 +62,21 @@ public interface GraphDao { */ public List getVertices(String type, Map filter) throws CrudException; + /** + * Retrieve a collection of {@link Vertex} objects which match the supplied + * type label and filter properties. + * + * @param type + * - The vertex type that we want to retrieve. + * @param filter + * - The parameters to filter our results by. + * @param properties + * - The properties to retrieve with the vertex + * @return - A collection of vertices. + * @throws CrudException + */ + public List getVertices(String type, Map filter, HashSet properties) throws CrudException; + /** * Retrieve an {@link Edge} from the graph database by specifying its unique * identifier. diff --git a/src/main/java/org/onap/crud/dao/champ/ChampDao.java b/src/main/java/org/onap/crud/dao/champ/ChampDao.java index adf2a3a..ecbac36 100644 --- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java +++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java @@ -50,6 +50,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import javax.ws.rs.core.MediaType; @@ -150,10 +151,17 @@ public class ChampDao implements GraphDao { @Override public List getVertices(String type, Map filter) throws CrudException { + return getVertices(type, filter, new HashSet()); + } + + @Override + public List getVertices(String type, Map filter, HashSet properties) throws CrudException { filter.put(org.onap.schema.OxmModelValidator.Metadata.NODE_TYPE.propertyName(), type); + List queryParams = convertToNameValuePair(filter); + queryParams.addAll(convertToNameValuePair("properties", properties)); String url = baseObjectUrl + "/filter" + "?" - + URLEncodedUtils.format(convertToNameValuePair(filter), Charset.defaultCharset()); + + URLEncodedUtils.format(queryParams, Charset.defaultCharset()); OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE); @@ -547,6 +555,15 @@ public class ChampDao implements GraphDao { return nvpList; } + + // https://stackoverflow.com/questions/26942330/convert-mapstring-string-to-listnamevaluepair-is-this-the-most-efficient + private List convertToNameValuePair(String key, HashSet values) { + List nvpList = new ArrayList<>(values.size()); + + values.forEach((value) -> nvpList.add(new BasicNameValuePair(key, value))); + + return nvpList; + } private Map> createHeader() { Map> headers = new HashMap<>(); -- cgit 1.2.3-korg