Ensure transaction id utilised for endpoint 53/58453/3
authormichaere <michael.reece@amdocs.com>
Wed, 1 Aug 2018 16:20:16 +0000 (17:20 +0100)
committermichaere <michaere@amdocs.com>
Mon, 6 Aug 2018 15:29:54 +0000 (16:29 +0100)
Transaction id is now handled for the end point objects/relationships/
in champ to ensure that edges are retrieved within the context of the
transaction

Issue-ID: AAI-1439

Change-Id: I5c9e4c3cf99b4e8316701cba41670a17faea381f
Signed-off-by: michaere <michaere@amdocs.com>
champ-service/src/main/java/org/onap/champ/ChampRESTAPI.java

index b312af3..093675e 100644 (file)
@@ -282,10 +282,19 @@ public class ChampRESTAPI {
     long startTimeInMs = System.currentTimeMillis();
     List<ChampRelationship> retrieved;
     Response response = null;
-    ChampTransaction transaction = null;
+    logger.info(ChampMsgs.INCOMING_REQUEST, tId, oId);
     try {
       httpHeadersValidator.validateRequestHeaders(headers);
+      ChampTransaction transaction = tId == null ? null : champDataService.getTransaction(tId);
+
+      if (transaction == null) {
+        throw new ChampServiceException("No transaction found for transaction ID: " + tId, Status.BAD_REQUEST);
+      }
       retrieved = champDataService.getRelationshipsByObject(oId, Optional.ofNullable(transaction));
+      if (retrieved == null) {
+        response = Response.status(Status.NOT_FOUND).entity(oId + " not found").build();
+        return response;
+      }
       EntityTag eTag = new EntityTag(etagGenerator.computeHashForChampRelationships(retrieved));
       response = Response.status(Status.OK).entity(mapper.writeValueAsString(retrieved)).tag(eTag).build();
     } catch (JsonProcessingException e) {