diff options
author | sblimkie <steven.blimkie@amdocs.com> | 2017-12-20 10:15:36 -0500 |
---|---|---|
committer | sblimkie <steven.blimkie@amdocs.com> | 2017-12-20 10:21:46 -0500 |
commit | 0e7b5a7e16a4f807580b152f3de766d1512543f1 (patch) | |
tree | c5b50902b1115e3be89111a53852609e32735227 /src/main | |
parent | 382e07e97ccd5f7bd47bdd735143ab3658661a68 (diff) |
Consolidate syncrounous and asyncronous APIs
Gizmo to present a single API, and the mode in which it interacts with
the backend is configurable at deploy time.
Change-Id: Iab96f71c9f99dd1d8d70f01a90478a975c50bff1
Issue-ID: AAI-482
Signed-off-by: sblimkie <steven.blimkie@amdocs.com>
Diffstat (limited to 'src/main')
7 files changed, 136 insertions, 820 deletions
diff --git a/src/main/ajsc/crud-api_v1/crud-api/v1/routes/crud2.route b/src/main/ajsc/crud-api_v1/crud-api/v1/routes/crud2.route deleted file mode 100644 index 40a98bf..0000000 --- a/src/main/ajsc/crud-api_v1/crud-api/v1/routes/crud2.route +++ /dev/null @@ -1,4 +0,0 @@ -<route xmlns="http://camel.apache.org/schema/spring" trace="true"> - <from uri="att-dme2-servlet:///inventory-async?matchOnUriPrefix=true" /> - <to uri="cxfbean:crudServicesAsync" /> -</route>
\ No newline at end of file diff --git a/src/main/java/org/onap/crud/service/AaiResourceService.java b/src/main/java/org/onap/crud/service/AaiResourceService.java index 98f83af..f7bda6a 100644 --- a/src/main/java/org/onap/crud/service/AaiResourceService.java +++ b/src/main/java/org/onap/crud/service/AaiResourceService.java @@ -79,7 +79,7 @@ public class AaiResourceService { public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override";
private Auth auth;
- CrudGraphDataService crudGraphDataService;
+ AbstractGraphDataService graphDataService;
Gson gson = new Gson();
private Logger logger = LoggerFactory.getInstance().getLogger(AaiResourceService.class.getName());
@@ -94,9 +94,9 @@ public class AaiResourceService { *
* @throws Exception
*/
- public AaiResourceService(CrudGraphDataService crudGraphDataService) throws Exception {
- this.crudGraphDataService = crudGraphDataService;
- this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE);
+ public AaiResourceService(AbstractGraphDataService graphDataService) throws Exception {
+ this.graphDataService = graphDataService;
+ this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE);
}
/**
@@ -168,7 +168,7 @@ public class AaiResourceService { }
// Now, create our edge in the graph store.
- String result = crudGraphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), type, payload);
+ String result = graphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), type, payload);
response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
} catch (CrudException e) {
@@ -232,7 +232,7 @@ public class AaiResourceService { payload = applyEdgeRulesToPayload(payload);
// Now, create our edge in the graph store.
- String result = crudGraphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), payload.getType(), payload);
+ String result = graphDataService.addEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), payload.getType(), payload);
response = Response.status(Status.CREATED).entity(result).type(mediaType).build();
} catch (CrudException ce) {
@@ -307,10 +307,10 @@ public class AaiResourceService { String result;
if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null &&
headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE).equalsIgnoreCase("PATCH")) {
- result = crudGraphDataService.patchEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);
+ result = graphDataService.patchEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);
} else {
- result = crudGraphDataService.updateEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);
+ result = graphDataService.updateEdge(RelationshipSchemaLoader.getLatestSchemaVersion(), id, type, payload);
}
response = Response.status(Status.OK).entity(result).type(mediaType).build();
diff --git a/src/main/java/org/onap/crud/service/AbstractGraphDataService.java b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java new file mode 100644 index 0000000..e627def --- /dev/null +++ b/src/main/java/org/onap/crud/service/AbstractGraphDataService.java @@ -0,0 +1,83 @@ +/** + * ============LICENSE_START======================================================= + * Gizmo + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. + * Copyright © 2017 Amdocs + * All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.crud.service; + +import java.util.List; +import java.util.Map; + +import org.onap.crud.dao.GraphDao; +import org.onap.crud.entity.Edge; +import org.onap.crud.entity.Vertex; +import org.onap.crud.exception.CrudException; +import org.onap.crud.parser.CrudResponseBuilder; +import org.onap.crud.util.CrudServiceUtil; +import org.onap.schema.OxmModelValidator; +import org.onap.schema.RelationshipSchemaValidator; + +public abstract class AbstractGraphDataService { + protected GraphDao dao; + + public AbstractGraphDataService(GraphDao dao) throws CrudException { + this.dao = dao; + + CrudServiceUtil.loadModels(); + } + + public String getEdge(String version, String id, String type) throws CrudException { + RelationshipSchemaValidator.validateType(version, type); + Edge edge = dao.getEdge(id, type); + + return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), version); + } + + public String getEdges(String version, String type, Map<String, String> filter) throws CrudException { + RelationshipSchemaValidator.validateType(version, type); + List<Edge> items = dao.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter)); + return CrudResponseBuilder.buildGetEdgesResponse(items, version); + } + + public String getVertex(String version, String id, String type) throws CrudException { + type = OxmModelValidator.resolveCollectionType(version, type); + Vertex vertex = dao.getVertex(id, type); + List<Edge> edges = dao.getVertexEdges(id); + return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges, + version); + } + + public String getVertices(String version, String type, Map<String, String> filter) throws CrudException { + type = OxmModelValidator.resolveCollectionType(version, type); + List<Vertex> items = dao.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter)); + return CrudResponseBuilder.buildGetVerticesResponse(items, version); + } + + public abstract String addVertex(String version, String type, VertexPayload payload) throws CrudException; + public abstract String updateVertex(String version, String id, String type, VertexPayload payload) throws CrudException; + public abstract String patchVertex(String version, String id, String type, VertexPayload payload) throws CrudException; + public abstract String deleteVertex(String version, String id, String type) throws CrudException; + public abstract String addEdge(String version, String type, EdgePayload payload) throws CrudException; + public abstract String deleteEdge(String version, String id, String type) throws CrudException; + public abstract String updateEdge(String version, String id, String type, EdgePayload payload) throws CrudException; + public abstract String patchEdge(String version, String id, String type, EdgePayload payload) throws CrudException; + public abstract String addBulk(String version, BulkPayload payload) throws CrudException; +} diff --git a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java index 9efc7df..16f054e 100644 --- a/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java +++ b/src/main/java/org/onap/crud/service/CrudAsyncGraphDataService.java @@ -44,13 +44,10 @@ import org.onap.crud.logging.CrudServiceMsgs; import org.onap.crud.parser.CrudResponseBuilder; import org.onap.crud.util.CrudProperties; import org.onap.crud.util.CrudServiceConstants; -import org.onap.crud.util.CrudServiceUtil; import org.onap.schema.OxmModelValidator; import org.onap.schema.RelationshipSchemaValidator; import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Map; import java.util.Timer; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -63,12 +60,10 @@ import java.util.concurrent.TimeoutException; import javax.annotation.PreDestroy; import javax.ws.rs.core.Response.Status; -public class CrudAsyncGraphDataService { +public class CrudAsyncGraphDataService extends AbstractGraphDataService { private static Integer requestTimeOut; - private GraphDao dao; - private EventPublisher asyncRequestPublisher; private Timer timer; @@ -94,6 +89,8 @@ public class CrudAsyncGraphDataService { EventPublisher asyncRequestPublisher, EventConsumer asyncResponseConsumer) throws CrudException { + super(dao); + requestTimeOut = DEFAULT_REQUEST_TIMEOUT; try { requestTimeOut @@ -113,8 +110,6 @@ public class CrudAsyncGraphDataService { + " error: " + ex.getMessage()); } - this.dao = dao; - // Start the Response Consumer timer CrudAsyncResponseConsumer crudAsyncResponseConsumer = new CrudAsyncResponseConsumer(asyncResponseConsumer); @@ -122,9 +117,7 @@ public class CrudAsyncGraphDataService { timer.schedule(crudAsyncResponseConsumer, responsePollInterval, responsePollInterval); this.asyncRequestPublisher = asyncRequestPublisher; - - // load the schemas - CrudServiceUtil.loadModels(); + logger.info(CrudServiceMsgs.ASYNC_DATA_SERVICE_INFO, "CrudAsyncGraphDataService initialized SUCCESSFULLY!"); } @@ -155,7 +148,7 @@ public class CrudAsyncGraphDataService { } } - private GraphEvent sendAndWait(GraphEvent event) throws Exception { + private GraphEvent sendAndWait(GraphEvent event) throws CrudException { long startTimeInMs = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); @@ -163,7 +156,11 @@ public class CrudAsyncGraphDataService { override.addAttribute(MdcContext.MDC_START_TIME, formatter.format(startTimeInMs)); // publish to request queue - asyncRequestPublisher.sendSync(event.toJson()); + try { + asyncRequestPublisher.sendSync(event.toJson()); + } catch (Exception e) { + throw new CrudException("Error publishing request " + event.getTransactionId() + " Cause: " + e.getMessage(), Status.INTERNAL_SERVER_ERROR); + } logger.info(CrudServiceMsgs.ASYNC_DATA_SERVICE_INFO, "Event submitted of type: " + event.getObjectType() + " with key: " + event.getObjectKey() @@ -197,7 +194,7 @@ public class CrudAsyncGraphDataService { return response; } - public String addVertex(String version, String type, VertexPayload payload) throws Exception { + public String addVertex(String version, String type, VertexPayload payload) throws CrudException { // Validate the incoming payload Vertex vertex = OxmModelValidator.validateIncomingUpsertPayload(null, version, type, payload.getProperties()); @@ -227,7 +224,7 @@ public class CrudAsyncGraphDataService { } - public String addEdge(String version, String type, EdgePayload payload) throws Exception { + public String addEdge(String version, String type, EdgePayload payload) throws CrudException { Edge edge = RelationshipSchemaValidator.validateIncomingAddPayload(version, type, payload); // Create graph request event GraphEvent event = GraphEvent.builder(GraphEventOperation.CREATE) @@ -255,7 +252,7 @@ public class CrudAsyncGraphDataService { } public String updateVertex(String version, String id, String type, VertexPayload payload) - throws Exception { + throws CrudException { Vertex vertex = OxmModelValidator.validateIncomingUpsertPayload(id, version, type, payload.getProperties()); GraphEvent event = GraphEvent.builder(GraphEventOperation.UPDATE) @@ -284,7 +281,7 @@ public class CrudAsyncGraphDataService { } public String patchVertex(String version, String id, String type, VertexPayload payload) - throws Exception { + throws CrudException { Vertex existingVertex = dao.getVertex(id, OxmModelValidator.resolveCollectionType(version, type)); Vertex patchedVertex = OxmModelValidator.validateIncomingPatchPayload(id, version, @@ -315,7 +312,7 @@ public class CrudAsyncGraphDataService { } - public String deleteVertex(String version, String id, String type) throws Exception { + public String deleteVertex(String version, String id, String type) throws CrudException { type = OxmModelValidator.resolveCollectionType(version, type); GraphEvent event = GraphEvent.builder(GraphEventOperation.DELETE) .vertex(new GraphEventVertex(id, version, type, null)).build(); @@ -340,7 +337,7 @@ public class CrudAsyncGraphDataService { } - public String deleteEdge(String version, String id, String type) throws Exception { + public String deleteEdge(String version, String id, String type) throws CrudException { RelationshipSchemaValidator.validateType(version, type); GraphEvent event = GraphEvent.builder(GraphEventOperation.DELETE) .edge(new GraphEventEdge(id, version, type, null, null, null)).build(); @@ -366,7 +363,7 @@ public class CrudAsyncGraphDataService { } public String updateEdge(String version, String id, String type, EdgePayload payload) - throws Exception { + throws CrudException { Edge edge = dao.getEdge(id, type); Edge validatedEdge = RelationshipSchemaValidator.validateIncomingUpdatePayload(edge, version, payload); @@ -396,7 +393,7 @@ public class CrudAsyncGraphDataService { } public String patchEdge(String version, String id, String type, EdgePayload payload) - throws Exception { + throws CrudException { Edge edge = dao.getEdge(id, type); Edge patchedEdge = RelationshipSchemaValidator.validateIncomingPatchPayload(edge, version, payload); @@ -425,45 +422,16 @@ public class CrudAsyncGraphDataService { } - public String getEdge(String version, String id, String type) throws CrudException { - RelationshipSchemaValidator.validateType(version, type); - Edge edge = dao.getEdge(id, type); - - return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator - .validateOutgoingPayload(version, edge), - version); - } - - public String getEdges(String version, String type, Map<String, String> filter) - throws CrudException { - RelationshipSchemaValidator.validateType(version, type); - List<Edge> items = dao.getEdges(type, - RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter)); - return CrudResponseBuilder.buildGetEdgesResponse(items, version); - } - - public String getVertex(String version, String id, String type) throws CrudException { - type = OxmModelValidator.resolveCollectionType(version, type); - Vertex vertex = dao.getVertex(id, type); - List<Edge> edges = dao.getVertexEdges(id); - return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator - .validateOutgoingPayload(version, vertex), edges, - version); - } - - public String getVertices(String version, String type, Map<String, String> filter) - throws CrudException { - type = OxmModelValidator.resolveCollectionType(version, type); - List<Vertex> items = dao.getVertices(type, - OxmModelValidator.resolveCollectionfilter(version, type, filter)); - return CrudResponseBuilder.buildGetVerticesResponse(items, version); - } - @PreDestroy protected void preShutdown() { timer.cancel(); } + @Override + public String addBulk(String version, BulkPayload payload) throws CrudException { + throw new CrudException("Bulk operation not supported in async mode", Status.BAD_REQUEST); + } + }
\ No newline at end of file diff --git a/src/main/java/org/onap/crud/service/CrudAsyncRestService.java b/src/main/java/org/onap/crud/service/CrudAsyncRestService.java deleted file mode 100644 index 4769c93..0000000 --- a/src/main/java/org/onap/crud/service/CrudAsyncRestService.java +++ /dev/null @@ -1,693 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * Gizmo - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. - * Copyright © 2017 Amdocs - * All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -package org.onap.crud.service; - -import org.apache.cxf.jaxrs.ext.PATCH; -import org.onap.aai.cl.api.Logger; -import org.onap.aai.cl.eelf.LoggerFactory; -import org.onap.aaiauth.auth.Auth; -import org.onap.crud.exception.CrudException; -import org.onap.crud.logging.CrudServiceMsgs; -import org.onap.crud.logging.LoggingUtil; -import org.onap.crud.util.CrudServiceConstants; -import org.slf4j.MDC; - -import java.security.cert.X509Certificate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import javax.security.auth.x500.X500Principal; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.Encoded; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.core.UriInfo; - - -public class CrudAsyncRestService { - - private CrudAsyncGraphDataService crudAsyncGraphDataService; - Logger logger = LoggerFactory.getInstance().getLogger(CrudAsyncRestService.class.getName()); - Logger auditLogger = LoggerFactory.getInstance() - .getAuditLogger(CrudAsyncRestService.class.getName()); - private Auth auth; - - private String mediaType = MediaType.APPLICATION_JSON; - public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override"; - - public CrudAsyncRestService(CrudAsyncGraphDataService crudAsyncGraphDataService) - throws Exception { - this.crudAsyncGraphDataService = crudAsyncGraphDataService; - this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE); - } - - public enum Action { - POST, GET, PUT, DELETE, PATCH - } - - public void startup() { - - } - - @GET - @Path("/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response getVertex(String content, @PathParam("version") String version, - @PathParam("type") String type, - @PathParam("id") String id, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.GET, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - String result = crudAsyncGraphDataService.getVertex(version, id, type); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @GET - @Path("/{version}/{type}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response getVertices(String content, @PathParam("version") String version, - @PathParam("type") String type, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - Map<String, String> filter = new HashMap<String, String>(); - for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) { - filter.put(e.getKey(), e.getValue().get(0)); - } - - try { - String result = crudAsyncGraphDataService.getVertices(version, type, filter); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @GET - @Path("/relationships/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response getEdge(String content, @PathParam("version") String version, - @PathParam("type") String type, - @PathParam("id") String id, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - - String result = crudAsyncGraphDataService.getEdge(version, id, type); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @GET - @Path("/relationships/{version}/{type}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response getEdges(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, @Context UriInfo uriInfo, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - Map<String, String> filter = new HashMap<String, String>(); - for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) { - filter.put(e.getKey(), e.getValue().get(0)); - } - - try { - String result = crudAsyncGraphDataService.getEdges(version, type, filter); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @PUT - @Path("/relationships/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response updateEdge(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - EdgePayload payload = EdgePayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null && !payload.getId().equals(id)) { - throw new CrudException("ID Mismatch", Status.BAD_REQUEST); - } - String result; - - if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null - && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) - .equalsIgnoreCase("PATCH")) { - result = crudAsyncGraphDataService.patchEdge(version, id, type, payload); - } else { - - result = crudAsyncGraphDataService.updateEdge(version, id, type, payload); - } - - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @PATCH - @Path("/relationships/{version}/{type}/{id}") - @Consumes({"application/merge-patch+json"}) - @Produces({MediaType.APPLICATION_JSON}) - public Response patchEdge(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - if (validateRequest(req, uri, content, Action.PATCH, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - EdgePayload payload = EdgePayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null && !payload.getId().equals(id)) { - throw new CrudException("ID Mismatch", Status.BAD_REQUEST); - } - - String result = crudAsyncGraphDataService.patchEdge(version, id, type, payload); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @PUT - @Path("/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response updateVertex(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.PUT, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - VertexPayload payload = VertexPayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null && !payload.getId().equals(id)) { - throw new CrudException("ID Mismatch", Status.BAD_REQUEST); - } - String result; - if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null - && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) - .equalsIgnoreCase("PATCH")) { - result = crudAsyncGraphDataService.patchVertex(version, id, type, payload); - } else { - - result = crudAsyncGraphDataService.updateVertex(version, id, type, payload); - } - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @PATCH - @Path("/{version}/{type}/{id}") - @Consumes({"application/merge-patch+json"}) - @Produces({MediaType.APPLICATION_JSON}) - public Response patchVertex(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.PATCH, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - try { - VertexPayload payload = VertexPayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null && !payload.getId().equals(id)) { - throw new CrudException("ID Mismatch", Status.BAD_REQUEST); - } - - String result = crudAsyncGraphDataService.patchVertex(version, id, type, payload); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @POST - @Path("/{version}/{type}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response addVertex(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, @Context UriInfo uriInfo, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.POST, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - try { - VertexPayload payload = VertexPayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null) { - throw new CrudException("ID specified , use Http PUT to update Vertex", - Status.BAD_REQUEST); - } - - if (payload.getType() != null && !payload.getType().equals(type)) { - throw new CrudException("Vertex Type mismatch", Status.BAD_REQUEST); - } - - String result = crudAsyncGraphDataService.addVertex(version, type, payload); - response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @POST - @Path("/{version}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response addVertex(String content, @PathParam("version") String version, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.POST, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - try { - - VertexPayload payload = VertexPayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null) { - throw new CrudException("ID specified , use Http PUT to update Vertex", - Status.BAD_REQUEST); - } - - if (payload.getType() == null || payload.getType().isEmpty()) { - throw new CrudException("Missing Vertex Type ", Status.BAD_REQUEST); - } - String result = crudAsyncGraphDataService.addVertex(version, payload.getType(), payload); - response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content).type(MediaType.APPLICATION_JSON) - .build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @POST - @Path("/relationships/{version}/{type}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response addEdge(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("uri") @Encoded String uri, - @Context HttpHeaders headers, @Context UriInfo uriInfo, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.POST, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - - try { - EdgePayload payload = EdgePayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null) { - throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST); - } - - if (payload.getType() != null && !payload.getType().equals(type)) { - throw new CrudException("Edge Type mismatch", Status.BAD_REQUEST); - } - String result = crudAsyncGraphDataService.addEdge(version, type, payload); - response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content) - .type(MediaType.APPLICATION_JSON).build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @POST - @Path("/relationships/{version}/") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response addEdge(String content, @PathParam("version") String version, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.POST, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - - try { - EdgePayload payload = EdgePayload.fromJson(content); - if (payload.getProperties() == null || payload.getProperties().isJsonNull()) { - throw new CrudException("Invalid request Payload", Status.BAD_REQUEST); - } - if (payload.getId() != null) { - throw new CrudException("ID specified , use Http PUT to update Edge", Status.BAD_REQUEST); - } - - if (payload.getType() == null || payload.getType().isEmpty()) { - throw new CrudException("Missing Edge Type ", Status.BAD_REQUEST); - } - String result = crudAsyncGraphDataService.addEdge(version, payload.getType(), payload); - - response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content) - .type(MediaType.APPLICATION_JSON).build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @DELETE - @Path("/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response deleteVertex(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - - if (validateRequest(req, uri, content, Action.DELETE, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - - try { - String result = crudAsyncGraphDataService.deleteVertex(version, id, type); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content) - .type(MediaType.APPLICATION_JSON).build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - @DELETE - @Path("/relationships/{version}/{type}/{id}") - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public Response deleteEdge(String content, @PathParam("version") String version, - @PathParam("type") String type, @PathParam("id") String id, - @PathParam("uri") @Encoded String uri, @Context HttpHeaders headers, - @Context UriInfo uriInfo, @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - - logger.debug("Incoming request..." + content); - Response response = null; - if (validateRequest(req, uri, content, Action.DELETE, - CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { - - - try { - String result = crudAsyncGraphDataService.deleteEdge(version, id, type); - response = Response.status(Status.OK).entity(result).type(mediaType).build(); - } catch (CrudException ce) { - response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); - } catch (Exception e) { - response = Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); - } - } else { - response = Response.status(Status.FORBIDDEN).entity(content) - .type(MediaType.APPLICATION_JSON).build(); - } - - LoggingUtil.logRestRequest(logger, auditLogger, req, response); - return response; - } - - protected boolean validateRequest(HttpServletRequest req, String uri, String content, - Action action, String authPolicyFunctionName) { - try { - String cipherSuite = (String) req.getAttribute("javax.servlet.request.cipher_suite"); - String authUser = null; - if (cipherSuite != null) { - X509Certificate[] certChain = (X509Certificate[]) req - .getAttribute("javax.servlet.request.X509Certificate"); - X509Certificate clientCert = certChain[0]; - X500Principal subjectDn = clientCert.getSubjectX500Principal(); - authUser = subjectDn.toString(); - } - return this.auth.validateRequest(authUser.toLowerCase(), action.toString() - + ":" + authPolicyFunctionName); - } catch (Exception e) { - logResult(action, uri, e); - return false; - } - } - - void logResult(Action op, String uri, Exception e) { - - logger.error(CrudServiceMsgs.EXCEPTION_DURING_METHOD_CALL, op.toString(), - uri, e.getStackTrace().toString()); - - // Clear the MDC context so that no other transaction inadvertently - // uses our transaction id. - MDC.clear(); - } -}
\ No newline at end of file diff --git a/src/main/java/org/onap/crud/service/CrudGraphDataService.java b/src/main/java/org/onap/crud/service/CrudGraphDataService.java index 4e42d44..49bf370 100644 --- a/src/main/java/org/onap/crud/service/CrudGraphDataService.java +++ b/src/main/java/org/onap/crud/service/CrudGraphDataService.java @@ -36,24 +36,17 @@ import org.onap.crud.entity.Edge; import org.onap.crud.entity.Vertex; import org.onap.crud.exception.CrudException; import org.onap.crud.parser.CrudResponseBuilder; -import org.onap.crud.util.CrudServiceUtil; import org.onap.schema.OxmModelValidator; import org.onap.schema.RelationshipSchemaValidator; import com.google.gson.JsonElement; -public class CrudGraphDataService { - - private GraphDao dao; +public class CrudGraphDataService extends AbstractGraphDataService { public CrudGraphDataService(GraphDao dao) throws CrudException { - this.dao = dao; - - CrudServiceUtil.loadModels(); + super(dao); } - - public String addVertex(String version, String type, VertexPayload payload) throws CrudException { Vertex vertex = OxmModelValidator.validateIncomingUpsertPayload(null, version, type, payload.getProperties()); return addVertex(version, vertex); @@ -195,20 +188,6 @@ public class CrudGraphDataService { .buildUpsertEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, addedEdge), version); } - public String getEdge(String version, String id, String type) throws CrudException { - RelationshipSchemaValidator.validateType(version, type); - Edge edge = dao.getEdge(id, type); - - return CrudResponseBuilder.buildGetEdgeResponse(RelationshipSchemaValidator.validateOutgoingPayload(version, edge), - version); - } - - public String getEdges(String version, String type, Map<String, String> filter) throws CrudException { - RelationshipSchemaValidator.validateType(version, type); - List<Edge> items = dao.getEdges(type, RelationshipSchemaValidator.resolveCollectionfilter(version, type, filter)); - return CrudResponseBuilder.buildGetEdgesResponse(items, version); - } - public String updateVertex(String version, String id, String type, VertexPayload payload) throws CrudException { Vertex vertex = OxmModelValidator.validateIncomingUpsertPayload(id, version, type, payload.getProperties()); return updateVertex(version, vertex); @@ -267,18 +246,4 @@ public class CrudGraphDataService { return dao.getVertex(id); } - public String getVertex(String version, String id, String type) throws CrudException { - type = OxmModelValidator.resolveCollectionType(version, type); - Vertex vertex = dao.getVertex(id, type); - List<Edge> edges = dao.getVertexEdges(id); - return CrudResponseBuilder.buildGetVertexResponse(OxmModelValidator.validateOutgoingPayload(version, vertex), edges, - version); - } - - public String getVertices(String version, String type, Map<String, String> filter) throws CrudException { - type = OxmModelValidator.resolveCollectionType(version, type); - List<Vertex> items = dao.getVertices(type, OxmModelValidator.resolveCollectionfilter(version, type, filter)); - return CrudResponseBuilder.buildGetVerticesResponse(items, version); - } - } diff --git a/src/main/java/org/onap/crud/service/CrudRestService.java b/src/main/java/org/onap/crud/service/CrudRestService.java index 974dbb2..054866a 100644 --- a/src/main/java/org/onap/crud/service/CrudRestService.java +++ b/src/main/java/org/onap/crud/service/CrudRestService.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import javax.security.auth.x500.X500Principal; import javax.servlet.http.HttpServletRequest; @@ -62,7 +61,7 @@ import com.google.gson.JsonElement; public class CrudRestService { - private CrudGraphDataService crudGraphDataService; + private AbstractGraphDataService graphDataService; Logger logger = LoggerFactory.getInstance().getLogger(CrudRestService.class.getName()); Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(CrudRestService.class.getName()); private Auth auth; @@ -70,8 +69,8 @@ public class CrudRestService { private String mediaType = MediaType.APPLICATION_JSON; public static final String HTTP_PATCH_METHOD_OVERRIDE = "X-HTTP-Method-Override"; - public CrudRestService(CrudGraphDataService crudGraphDataService) throws Exception { - this.crudGraphDataService = crudGraphDataService; + public CrudRestService(AbstractGraphDataService graphDataService) throws Exception { + this.graphDataService = graphDataService; this.auth = new Auth(CrudServiceConstants.CRD_AUTH_FILE); } @@ -79,8 +78,6 @@ public class CrudRestService { POST, GET, PUT, DELETE, PATCH } - ; - public void startup() { } @@ -100,7 +97,7 @@ public class CrudRestService { if (validateRequest(req, uri, content, Action.GET, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { try { - String result = crudGraphDataService.getVertex(version, id, type); + String result = graphDataService.getVertex(version, id, type); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -135,7 +132,7 @@ public class CrudRestService { } try { - String result = crudGraphDataService.getVertices(version, type, filter); + String result = graphDataService.getVertices(version, type, filter); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -166,7 +163,7 @@ public class CrudRestService { try { - String result = crudGraphDataService.getEdge(version, id, type); + String result = graphDataService.getEdge(version, id, type); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -202,7 +199,7 @@ public class CrudRestService { } try { - String result = crudGraphDataService.getEdges(version, type, filter); + String result = graphDataService.getEdges(version, type, filter); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -245,10 +242,10 @@ public class CrudRestService { if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE).equalsIgnoreCase("PATCH")) { - result = crudGraphDataService.patchEdge(version, id, type, payload); + result = graphDataService.patchEdge(version, id, type, payload); } else { - result = crudGraphDataService.updateEdge(version, id, type, payload); + result = graphDataService.updateEdge(version, id, type, payload); } response = Response.status(Status.OK).entity(result).type(mediaType).build(); @@ -289,7 +286,7 @@ public class CrudRestService { throw new CrudException("ID Mismatch", Status.BAD_REQUEST); } - String result = crudGraphDataService.patchEdge(version, id, type, payload); + String result = graphDataService.patchEdge(version, id, type, payload); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -330,10 +327,10 @@ public class CrudRestService { String result; if (headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE) != null && headers.getRequestHeaders().getFirst(HTTP_PATCH_METHOD_OVERRIDE).equalsIgnoreCase("PATCH")) { - result = crudGraphDataService.patchVertex(version, id, type, payload); + result = graphDataService.patchVertex(version, id, type, payload); } else { - result = crudGraphDataService.updateVertex(version, id, type, payload); + result = graphDataService.updateVertex(version, id, type, payload); } response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { @@ -372,7 +369,7 @@ public class CrudRestService { throw new CrudException("ID Mismatch", Status.BAD_REQUEST); } - String result = crudGraphDataService.patchVertex(version, id, type, payload); + String result = graphDataService.patchVertex(version, id, type, payload); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -415,7 +412,7 @@ public class CrudRestService { throw new CrudException("Vertex Type mismatch", Status.BAD_REQUEST); } - String result = crudGraphDataService.addVertex(version, type, payload); + String result = graphDataService.addVertex(version, type, payload); response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -554,7 +551,7 @@ public class CrudRestService { } validateBulkPayload(payload); - String result = crudGraphDataService.addBulk(version, payload); + String result = graphDataService.addBulk(version, payload); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -595,7 +592,7 @@ public class CrudRestService { if (payload.getType() == null || payload.getType().isEmpty()) { throw new CrudException("Missing Vertex Type ", Status.BAD_REQUEST); } - String result = crudGraphDataService.addVertex(version, payload.getType(), payload); + String result = graphDataService.addVertex(version, payload.getType(), payload); response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -637,7 +634,7 @@ public class CrudRestService { if (payload.getType() != null && !payload.getType().equals(type)) { throw new CrudException("Edge Type mismatch", Status.BAD_REQUEST); } - String result = crudGraphDataService.addEdge(version, type, payload); + String result = graphDataService.addEdge(version, type, payload); response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -678,7 +675,7 @@ public class CrudRestService { if (payload.getType() == null || payload.getType().isEmpty()) { throw new CrudException("Missing Edge Type ", Status.BAD_REQUEST); } - String result = crudGraphDataService.addEdge(version, payload.getType(), payload); + String result = graphDataService.addEdge(version, payload.getType(), payload); response = Response.status(Status.CREATED).entity(result).type(mediaType).build(); } catch (CrudException ce) { @@ -710,7 +707,7 @@ public class CrudRestService { if (validateRequest(req, uri, content, Action.DELETE, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { try { - String result = crudGraphDataService.deleteVertex(version, id, type); + String result = graphDataService.deleteVertex(version, id, type); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); @@ -740,7 +737,7 @@ public class CrudRestService { if (validateRequest(req, uri, content, Action.DELETE, CrudServiceConstants.CRD_AUTH_POLICY_NAME)) { try { - String result = crudGraphDataService.deleteEdge(version, id, type); + String result = graphDataService.deleteEdge(version, id, type); response = Response.status(Status.OK).entity(result).type(mediaType).build(); } catch (CrudException ce) { response = Response.status(ce.getHttpStatus()).entity(ce.getMessage()).build(); |