From 58c89ea1f45ffd4a9f812ae1c18e93b636737f55 Mon Sep 17 00:00:00 2001 From: Gurjeet Bedi Date: Wed, 14 Feb 2018 13:56:58 -0500 Subject: For supporting t_k query Passing queryparameters from GET Issue-ID: AAI-482 Change-Id: I7db51c6549fe5f7e4d61ad96121e7da3a57ff325 Signed-off-by: Gurjeet Bedi --- .../org/onap/crud/service/AbstractGraphDataService.java | 14 +++++++------- .../org/onap/crud/service/CrudAsyncGraphDataService.java | 7 ++++--- .../java/org/onap/crud/service/CrudGraphDataService.java | 8 +++++--- src/main/java/org/onap/crud/service/CrudRestService.java | 12 ++++++++++-- 4 files changed, 26 insertions(+), 15 deletions(-) (limited to 'src/main/java/org/onap/crud/service') 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 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 queryParams) throws CrudException { type = OxmModelValidator.resolveCollectionType(version, type); - Vertex vertex = daoForGet.getVertex(id, type, version); - List edges = daoForGet.getVertexEdges(id); + Vertex vertex = daoForGet.getVertex(id, type, version, queryParams); + List 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()); 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()); 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()); 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()); 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()); 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()); 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()); 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 params = new HashMap(); + for (Map.Entry> 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 params = new HashMap(); + for (Map.Entry> 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(); -- cgit 1.2.3-korg