summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authorGurjeet Bedi <gurjeetb@amdocs.com>2018-02-14 13:56:58 -0500
committerGurjeet Bedi <gurjeetb@amdocs.com>2018-02-14 13:58:38 -0500
commit58c89ea1f45ffd4a9f812ae1c18e93b636737f55 (patch)
tree41d6a47b1c3ae00eea8b37b56acd62f8422433c2 /src/main/java/org
parent5db1e77ef9e2c43fd723dc629346baf3660fdf1b (diff)
For supporting t_k query
Passing queryparameters from GET Issue-ID: AAI-482 Change-Id: I7db51c6549fe5f7e4d61ad96121e7da3a57ff325 Signed-off-by: Gurjeet Bedi <gurjeetb@amdocs.com>
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/crud/dao/GraphDao.java12
-rw-r--r--src/main/java/org/onap/crud/dao/champ/ChampDao.java50
-rw-r--r--src/main/java/org/onap/crud/service/AbstractGraphDataService.java14
-rw-r--r--src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java7
-rw-r--r--src/main/java/org/onap/crud/service/CrudGraphDataService.java8
-rw-r--r--src/main/java/org/onap/crud/service/CrudRestService.java12
6 files changed, 71 insertions, 32 deletions
diff --git a/src/main/java/org/onap/crud/dao/GraphDao.java b/src/main/java/org/onap/crud/dao/GraphDao.java
index 283e1a1..3ae8266 100644
--- a/src/main/java/org/onap/crud/dao/GraphDao.java
+++ b/src/main/java/org/onap/crud/dao/GraphDao.java
@@ -36,7 +36,7 @@ public interface GraphDao {
public Vertex getVertex(String id, String version) throws CrudException;
- public Vertex getVertex(String id, String type, String version) throws CrudException;
+ public Vertex getVertex(String id, String type, String version, Map<String, String> queryParams) throws CrudException;
/**
* Retrieve all of the edges which are incident to the vertex with the
@@ -44,10 +44,12 @@ public interface GraphDao {
*
* @param id
* - The unique identifier of the vertex to retrieve the edges for.
+ * @param queryParams
+ * - query parameters to be passed
* @return - A collection of edges.
* @throws CrudException
*/
- public List<Edge> getVertexEdges(String id) throws CrudException;
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException;
/**
* Retrieve a collection of {@link Vertex} objects which match the supplied
@@ -83,10 +85,14 @@ public interface GraphDao {
*
* @param id
* - The unique identifier for the Edge to be retrieved.
+ * @param type
+ * - The type that we want to retrieve.
+ * @param queryParams
+ * - query parameters to be passed
* @return - The Edge corresponding to the specified identifier.
* @throws CrudException
*/
- public Edge getEdge(String id, String type) throws CrudException;
+ public Edge getEdge(String id, String type, Map<String, String> queryParams) throws CrudException;
/**
* Retrieve a collection of {@link Edge} objects with a given type and which
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 7174bfc..5c6dbbe 100644
--- a/src/main/java/org/onap/crud/dao/champ/ChampDao.java
+++ b/src/main/java/org/onap/crud/dao/champ/ChampDao.java
@@ -120,9 +120,17 @@ public class ChampDao implements GraphDao {
}
@Override
- public Vertex getVertex(String id, String type, String version) throws CrudException {
- String url = baseObjectUrl + "/" + id;
- OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
+ public Vertex getVertex(String id, String type, String version, Map<String, String> queryParams) throws CrudException {
+ StringBuilder strBuild = new StringBuilder(baseObjectUrl);
+ strBuild.append("/");
+ strBuild.append(id);
+ if(queryParams != null && !queryParams.isEmpty())
+ {
+ strBuild.append("?");
+ strBuild.append(URLEncodedUtils.format(convertToNameValuePair(queryParams), Charset.defaultCharset()));
+ }
+
+ OperationResult getResult = client.get(strBuild.toString(), createHeader(), MediaType.APPLICATION_JSON_TYPE);
if (getResult.getResultCode() == 200) {
Vertex vert = Vertex.fromJson(getResult.getResult(), version);
@@ -143,11 +151,18 @@ public class ChampDao implements GraphDao {
}
@Override
- public List<Edge> getVertexEdges(String id) throws CrudException {
- String url = baseObjectUrl + "/relationships/" + id;
-
- OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
+ public List<Edge> getVertexEdges(String id, Map<String, String> queryParams) throws CrudException {
+ StringBuilder strBuild = new StringBuilder(baseObjectUrl);
+ strBuild.append("/relationships/");
+ strBuild.append(id);
+ if(queryParams != null && !queryParams.isEmpty())
+ {
+ strBuild.append("?");
+ strBuild.append(URLEncodedUtils.format(convertToNameValuePair(queryParams), Charset.defaultCharset()));
+ }
+ OperationResult getResult = client.get(strBuild.toString(), createHeader(), MediaType.APPLICATION_JSON_TYPE);
+
if (getResult.getResultCode() == 200) {
return champGson.fromJson(getResult.getResult(), new TypeToken<List<Edge>>() {
}.getType());
@@ -186,10 +201,17 @@ public class ChampDao implements GraphDao {
}
@Override
- public Edge getEdge(String id, String type) throws CrudException {
- String url = baseRelationshipUrl + "/" + id;
- OperationResult getResult = client.get(url, createHeader(), MediaType.APPLICATION_JSON_TYPE);
-
+ public Edge getEdge(String id, String type, Map<String, String> queryParams) throws CrudException {
+ StringBuilder strBuild = new StringBuilder(baseRelationshipUrl);
+ strBuild.append("/");
+ strBuild.append(id);
+ if(queryParams != null && !queryParams.isEmpty())
+ {
+ strBuild.append("?");
+ strBuild.append(URLEncodedUtils.format(convertToNameValuePair(queryParams), Charset.defaultCharset()));
+ }
+ OperationResult getResult = client.get(strBuild.toString(), createHeader(), MediaType.APPLICATION_JSON_TYPE);
+
if (getResult.getResultCode() == 200) {
Edge edge = Edge.fromJson(getResult.getResult());
@@ -291,8 +313,8 @@ public class ChampDao implements GraphDao {
String url = baseRelationshipUrl;
// Try requests to ensure source and target exist in Champ
- Vertex dbSource = getVertex(source.getId().get(), source.getType(), version);
- Vertex dbTarget = getVertex(target.getId().get(), target.getType(), version);
+ Vertex dbSource = getVertex(source.getId().get(), source.getType(), version, new HashMap<String, String>());
+ Vertex dbTarget = getVertex(target.getId().get(), target.getType(), version, new HashMap<String, String>());
Edge.Builder insertEdgeBuilder = new Edge.Builder(type).source(dbSource).target(dbTarget);
properties.forEach(insertEdgeBuilder::property);
@@ -557,7 +579,7 @@ public class ChampDao implements GraphDao {
}
// https://stackoverflow.com/questions/26942330/convert-mapstring-string-to-listnamevaluepair-is-this-the-most-efficient
- private List<NameValuePair> convertToNameValuePair(Map<String, Object> pairs) {
+ private List<NameValuePair> convertToNameValuePair(Map<String, ? super String> pairs) {
List<NameValuePair> nvpList = new ArrayList<>(pairs.size());
pairs.forEach((key, value) -> nvpList.add(new BasicNameValuePair(key, value.toString())));
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
index 5154308..5a89220 100644
--- a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java
@@ -50,10 +50,10 @@ public abstract class AbstractGraphDataService {
public AbstractGraphDataService() throws CrudException {
CrudServiceUtil.loadModels();
}
-
- public String getEdge(String version, String id, String type) throws CrudException {
+
+ public String getEdge(String version, String id, String type, Map<String, String> queryParams) throws CrudException {
RelationshipSchemaValidator.validateType(version, type);
- Edge edge = daoForGet.getEdge(id, type);
+ Edge edge = daoForGet.getEdge(id, type, queryParams);
return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version);
}
@@ -64,10 +64,10 @@ public abstract class AbstractGraphDataService {
return CrudResponseBuilder.buildGetEdgesResponse(items, version);
}
- public String getVertex(String version, String id, String type) throws CrudException {
+ public String getVertex(String version, String id, String type, Map<String, String> queryParams) throws CrudException {
type = OxmModelValidator.resolveCollectionType(version, type);
- Vertex vertex = daoForGet.getVertex(id, type, version);
- List<Edge> edges = daoForGet.getVertexEdges(id);
+ Vertex vertex = daoForGet.getVertex(id, type, version, queryParams);
+ List<Edge> edges = daoForGet.getVertexEdges(id, queryParams);
return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges,
version);
}
@@ -165,7 +165,7 @@ public abstract class AbstractGraphDataService {
vertexPayload.setProperties(CrudServiceUtil.mergeHeaderInFoToPayload(vertexPayload.getProperties(),
headers, false));
- Vertex existingVertex = dao.getVertex(vertexPayload.getId(), OxmModelValidator.resolveCollectionType(version, vertexPayload.getType()), version);
+ Vertex existingVertex = dao.getVertex(vertexPayload.getId(), OxmModelValidator.resolveCollectionType(version, vertexPayload.getType()), version, new HashMap<String, String>());
Vertex validatedVertex = OxmModelValidator.validateIncomingPatchPayload(vertexPayload.getId(),
version, vertexPayload.getType(), vertexPayload.getProperties(), existingVertex);
Vertex persistedVertex = updateBulkVertex(validatedVertex, vertexPayload.getId(), version, txId);
diff --git a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
index 5e264b5..eb8bb75 100644
--- a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java
@@ -48,6 +48,7 @@ import org.onap.schema.OxmModelValidator;
import org.onap.schema.RelationshipSchemaValidator;
import java.text.SimpleDateFormat;
+import java.util.HashMap;
import java.util.Timer;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
@@ -270,7 +271,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
public String patchVertex(String version, String id, String type, VertexPayload payload)
throws CrudException {
Vertex existingVertex
- = dao.getVertex(id, OxmModelValidator.resolveCollectionType(version, type), version);
+ = dao.getVertex(id, OxmModelValidator.resolveCollectionType(version, type), version, new HashMap<String, String>());
Vertex patchedVertex = OxmModelValidator.validateIncomingPatchPayload(id, version,
type, payload.getProperties(),
existingVertex);
@@ -327,7 +328,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
public String updateEdge(String version, String id, String type, EdgePayload payload)
throws CrudException {
- Edge edge = dao.getEdge(id, type);
+ Edge edge = dao.getEdge(id, type, new HashMap<String, String>());
Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version,
payload);
GraphEvent event = GraphEvent.builder(GraphEventOperation.UPDATE)
@@ -349,7 +350,7 @@ public class CrudAsyncGraphDataService extends AbstractGraphDataService {
public String patchEdge(String version, String id, String type, EdgePayload payload)
throws CrudException {
- Edge edge = dao.getEdge(id, type);
+ Edge edge = dao.getEdge(id, type, new HashMap<String, String>());
Edge patchedEdge = RelationshipSchemaValidator.validateIncomingPatchPayload(edge, version,
payload);
GraphEvent event = GraphEvent.builder(GraphEventOperation.UPDATE)
diff --git a/src/main/java/org/onap/crud/service/CrudGraphDataService.java b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
index 3eeac3f..4c8c6a8 100644
--- a/src/main/java/org/onap/crud/service/CrudGraphDataService.java
+++ b/src/main/java/org/onap/crud/service/CrudGraphDataService.java
@@ -24,6 +24,8 @@
package org.onap.crud.service;
+import java.util.HashMap;
+
import org.onap.crud.dao.GraphDao;
import org.onap.crud.entity.Edge;
@@ -84,7 +86,7 @@ public class CrudGraphDataService extends AbstractGraphDataService {
}
public String patchVertex(String version, String id, String type, VertexPayload payload) throws CrudException {
- Vertex existingVertex = dao.getVertex(id, OxmModelValidator.resolveCollectionType(version, type), version);
+ Vertex existingVertex = dao.getVertex(id, OxmModelValidator.resolveCollectionType(version, type), version, new HashMap<String, String>());
Vertex vertex = OxmModelValidator.validateIncomingPatchPayload(id, version, type, payload.getProperties(),
existingVertex);
return updateVertex(version, vertex);
@@ -103,7 +105,7 @@ public class CrudGraphDataService extends AbstractGraphDataService {
}
public String updateEdge(String version, String id, String type, EdgePayload payload) throws CrudException {
- Edge edge = dao.getEdge(id, type);
+ Edge edge = dao.getEdge(id, type, new HashMap<String, String>());
Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, payload);
return updateEdge(version, validatedEdge);
}
@@ -115,7 +117,7 @@ public class CrudGraphDataService extends AbstractGraphDataService {
}
public String patchEdge(String version, String id, String type, EdgePayload payload) throws CrudException {
- Edge edge = dao.getEdge(id, type);
+ Edge edge = dao.getEdge(id, type, new HashMap<String, String>());
Edge patchedEdge = RelationshipSchemaValidator.validateIncomingPatchPayload(edge, version, payload);
return updateEdge(version, patchedEdge);
diff --git a/src/main/java/org/onap/crud/service/CrudRestService.java b/src/main/java/org/onap/crud/service/CrudRestService.java
index b3c5e7a..69f2186 100644
--- a/src/main/java/org/onap/crud/service/CrudRestService.java
+++ b/src/main/java/org/onap/crud/service/CrudRestService.java
@@ -96,10 +96,14 @@ public class CrudRestService {
logger.debug("Incoming request..." + content);
Response response = null;
+ Map<String, String> params = new HashMap<String, String>();
+ for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
+ params.put(e.getKey(), e.getValue().get(0));
+ }
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
- String result = graphDataService.getVertex(version, id, type);
+ String result = graphDataService.getVertex(version, id, type, params);
response = Response.status(Status.OK).entity(result).type(mediaType).build();
} else {
response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON).build();
@@ -174,11 +178,15 @@ public class CrudRestService {
logger.debug("Incoming request..." + content);
Response response = null;
+ Map<String, String> params = new HashMap<String, String>();
+ for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
+ params.put(e.getKey(), e.getValue().get(0));
+ }
try {
if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME, headers)) {
- String result = graphDataService.getEdge(version, id, type);
+ String result = graphDataService.getEdge(version, id, type, params);
response = Response.status(Status.OK).entity(result).type(mediaType).build();
} else {
response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON).build();