diff options
Diffstat (limited to 'src/main/java/org/onap/crud/dao')
-rw-r--r-- | src/main/java/org/onap/crud/dao/GraphDao.java | 16 | ||||
-rw-r--r-- | src/main/java/org/onap/crud/dao/champ/ChampDao.java | 19 |
2 files changed, 34 insertions, 1 deletions
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; @@ -62,6 +63,21 @@ public interface GraphDao { public List<Vertex> getVertices(String type, Map<String, Object> 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<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> 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<Vertex> getVertices(String type, Map<String, Object> filter) throws CrudException { + return getVertices(type, filter, new HashSet<String>()); + } + + @Override + public List<Vertex> getVertices(String type, Map<String, Object> filter, HashSet<String> properties) throws CrudException { filter.put(org.onap.schema.OxmModelValidator.Metadata.NODE_TYPE.propertyName(), type); + List<NameValuePair> 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<NameValuePair> convertToNameValuePair(String key, HashSet<String> values) { + List<NameValuePair> nvpList = new ArrayList<>(values.size()); + + values.forEach((value) -> nvpList.add(new BasicNameValuePair(key, value))); + + return nvpList; + } private Map<String, List<String>> createHeader() { Map<String, List<String>> headers = new HashMap<>(); |