Fix the handling of null solution filter 16/2116/3
authorSerban Jora <sj2381@att.com>
Wed, 20 Jun 2018 22:04:58 +0000 (18:04 -0400)
committerSerban Jora <sj2381@att.com>
Thu, 21 Jun 2018 15:32:01 +0000 (11:32 -0400)
Also fixes the handling of no such item errors in the catalog controller.

Change-Id: I9237c28e405e01b5fdd84c58af3b567e0dc0a6e3
Issue-ID: ACUMOS-1194
Signed-off-by: Serban Jora <sj2381@att.com>
docs/release-notes.rst
gateway/src/main/java/org/acumos/federation/gateway/cds/Solution.java
gateway/src/main/java/org/acumos/federation/gateway/controller/CatalogController.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/CatalogServiceImpl.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerServiceImpl.java

index 7f03148..89c35f0 100644 (file)
@@ -26,6 +26,7 @@ Version 1.1.4, 2018-06-20
 -------------------------
 
 * Fix result size test when retrieving 'self' peer
+* Fix handling of null solutions filter in the service. Fix the handling of no such item errors in catalog controller.
 
 Version 1.1.3, 2018-05-10
 -------------------------
index 26b8716..3ae7545 100644 (file)
@@ -30,6 +30,23 @@ import org.acumos.cds.domain.MLPSolutionRevision;
  */
 public class Solution extends MLPSolution {
 
+       /**
+        * For the purpose of defining constants for search criteria.
+        * This exposes CDS maintained information so it has to be kept in sync.
+        * We only define those of interest for searching.
+        */
+       public static interface Fields {
+               public static final String solutionId = "solutionId";
+               public static final String name = "name";
+               public static final String active = "active";
+               public static final String modelTypeCode = "modelTypeCode";
+               public static final String toolkitTypeCode = "toolkitTypeCode";
+               public static final String accessTypeCode = "accessTypeCode";
+               public static final String validationStatusCode = "validationStatusCode";
+               public static final String modified = "modified";
+               public static final String sourceId = "sourceId";
+       };
+
        private List<MLPSolutionRevision>               revisions;
 
        public Solution() {
index a994c84..5e013b5 100644 (file)
@@ -98,7 +98,7 @@ public class CatalogController extends AbstractController {
                List<MLPSolution> solutions = null;
                log.debug(EELFLoggerDelegate.debugLogger, API.Paths.SOLUTIONS);
                try {
-                       log.debug(EELFLoggerDelegate.debugLogger, "getSolutionsListFromPeer: selector " + theSelector);
+                       log.debug(EELFLoggerDelegate.debugLogger, "getSolutions: selector " + theSelector);
                        Map<String, ?> selector = null;
                        if (theSelector != null)
                                selector = Utils.jsonStringToMap(new String(Base64Utils.decodeFromString(theSelector), "UTF-8"));
@@ -141,12 +141,20 @@ public class CatalogController extends AbstractController {
                log.debug(EELFLoggerDelegate.debugLogger, API.Paths.SOLUTION_DETAILS + ": " + theSolutionId);
                try {
                        solution = catalogService.getSolution(theSolutionId, new ControllerContext());
-                       encodeSolution(solution, theHttpRequest);
-                       response = JsonResponse.<MLPSolution> buildResponse()
-                                                                                                               .withMessage("solution details")
-                                                                                                               .withContent(solution)
-                                                                                                               .build();
-                       theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                       if (null == solution) {
+                               response = JsonResponse.<MLPSolution> buildResponse()
+                                                                                                                       .withMessage("No solution with id " + theSolutionId + " is available.")
+                                                                                                                       .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                       }
+                       else {
+                               encodeSolution(solution, theHttpRequest);
+                               response = JsonResponse.<MLPSolution> buildResponse()
+                                                                                                                       .withMessage("solution details")
+                                                                                                                       .withContent(solution)
+                                                                                                                       .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                       }
                }
                catch (Exception x) {
                        response = JsonResponse.<MLPSolution> buildErrorResponse()
@@ -177,13 +185,21 @@ public class CatalogController extends AbstractController {
                log.debug(EELFLoggerDelegate.debugLogger, API.Paths.SOLUTION_REVISIONS);
                try {
                        solutionRevisions = catalogService.getSolutionRevisions(theSolutionId, new ControllerContext());
-                       response = JsonResponse.<List<MLPSolutionRevision>> buildResponse()
-                                                                                                               .withMessage("solution revisions")
-                                                                                                               .withContent(solutionRevisions)
-                                                                                                               .build();
-                       theHttpResponse.setStatus(HttpServletResponse.SC_OK);
-                       log.debug(EELFLoggerDelegate.debugLogger, "getSolutionsRevisions for solution {} provided {} revisions",
+                       if (null == solutionRevisions) {
+                               response = JsonResponse.<List<MLPSolutionRevision>> buildResponse()
+                                                                                                                       .withMessage("No solution with id " + theSolutionId + " is available.")
+                                                                                                                       .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                       }
+                       else {
+                               response = JsonResponse.<List<MLPSolutionRevision>> buildResponse()
+                                                                                                                       .withMessage("solution revisions")
+                                                                                                                       .withContent(solutionRevisions)
+                                                                                                                       .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                               log.debug(EELFLoggerDelegate.debugLogger, "getSolutionsRevisions for solution {} provided {} revisions",
                                                theSolutionId, solutionRevisions == null ? 0 : solutionRevisions.size());
+                       }
                }
                catch (Exception x) {
                        response = JsonResponse.<List<MLPSolutionRevision>> buildErrorResponse()
@@ -220,11 +236,19 @@ public class CatalogController extends AbstractController {
                try {
                        solutionRevision = catalogService.getSolutionRevision(theSolutionId, theRevisionId,
                                        new ControllerContext());
-                       response = JsonResponse.<MLPSolutionRevision> buildResponse()
-                                                                                                               .withMessage("solution revision details")
-                                                                                                               .withContent(solutionRevision)
-                                                                                                               .build();
-                       theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                       if (null == solutionRevision) {
+                               response = JsonResponse.<MLPSolutionRevision> buildResponse()
+                                                                                                                               .withMessage("No solution revision " + theSolutionId + "/" + theRevisionId + " is available.")
+                                                                                                                               .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                       }
+                       else {
+                               response = JsonResponse.<MLPSolutionRevision> buildResponse()
+                                                                                                                               .withMessage("solution revision details")
+                                                                                                                               .withContent(solutionRevision)
+                                                                                                                               .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                       }
                }
                catch (Exception x) {
                        response = JsonResponse.<MLPSolutionRevision> buildErrorResponse()
@@ -263,18 +287,26 @@ public class CatalogController extends AbstractController {
                                API.Paths.SOLUTION_REVISION_ARTIFACTS + "(" + theSolutionId + "," + theRevisionId + ")");
                try {
                        solutionRevisionArtifacts = catalogService.getSolutionRevisionArtifacts(theSolutionId, theRevisionId, context);
-                       for (MLPArtifact artifact : solutionRevisionArtifacts) {
-                               if (!context.getPeer().getPeerInfo().isLocal()) {
-                                       encodeArtifact(artifact, theHttpRequest);
+                       if (null == solutionRevisionArtifacts) {
+                               response = JsonResponse.<List<MLPArtifact>> buildResponse()
+                                                                                                                               .withMessage("No solution revision " + theSolutionId + "/" + theRevisionId + " is available.")
+                                                                                                                               .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                       }
+                       else {
+                               for (MLPArtifact artifact : solutionRevisionArtifacts) {
+                                       if (!context.getPeer().getPeerInfo().isLocal()) {
+                                               encodeArtifact(artifact, theHttpRequest);
+                                       }
                                }
+                               response = JsonResponse.<List<MLPArtifact>> buildResponse()
+                                                                                                               .withMessage("solution revision artifacts")
+                                                                                                               .withContent(solutionRevisionArtifacts)
+                                                                                                               .build();
+                               theHttpResponse.setStatus(HttpServletResponse.SC_OK);
+                               log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifacts provided {} artifacts",
+                                                       solutionRevisionArtifacts == null ? 0 : solutionRevisionArtifacts.size());
                        }
-                       response = JsonResponse.<List<MLPArtifact>> buildResponse()
-                                                                                                       .withMessage("solution revision artifacts")
-                                                                                                       .withContent(solutionRevisionArtifacts)
-                                                                                                       .build();
-                       theHttpResponse.setStatus(HttpServletResponse.SC_OK);
-                       log.debug(EELFLoggerDelegate.debugLogger, "getSolutionRevisionArtifacts provided {} artifacts",
-                                               solutionRevisionArtifacts == null ? 0 : solutionRevisionArtifacts.size());
                } 
                catch (Exception x) {
                        response = JsonResponse.<List<MLPArtifact>> buildErrorResponse()
index 5a963d7..9256c0b 100644 (file)
@@ -87,11 +87,11 @@ public class CatalogServiceImpl extends AbstractServiceImpl
                baseSelector = new HashMap<String, Object>();
 
                // Fetch all active solutions
-               baseSelector.put("active", true);
+               baseSelector.put(Solution.Fields.active, true);
                // Fetch allowed only for Public models
-               baseSelector.put("accessTypeCode", AccessTypeCode.PB.toString());
+               baseSelector.put(Solution.Fields.accessTypeCode, AccessTypeCode.PB.toString());
                // Validation status should be passed locally
-               baseSelector.put("validationStatusCode", ValidationStatusCode.PS.toString());
+               baseSelector.put(Solution.Fields.validationStatusCode, ValidationStatusCode.PS.toString());
        }
 
        @Override
@@ -116,15 +116,15 @@ public class CatalogServiceImpl extends AbstractServiceImpl
 
                do {
                        log.debug(EELFLoggerDelegate.debugLogger, "getSolutions page {}", pageResponse);
-                       if (theSelector.containsKey("modified")) {
+                       if (selector.containsKey(Solution.Fields.modified)) {
                                //Use the dedicated api: this is a 'deep' application of the 'modified' criteria as it will look into revisions
                                //and artifacts for related information modified since.
                                pageResponse =
                                        cdsClient.findSolutionsByDate(
-                                               (Boolean)baseSelector.get("active"),
-                                               new String[] {baseSelector.get("accessTypeCode").toString()},
-                                               new String[] {baseSelector.get("validationStatusCode").toString()},
-                                               new Date((Long)theSelector.get("modified")),
+                                               (Boolean)baseSelector.get(Solution.Fields.active),
+                                               new String[] {selector.get(Solution.Fields.accessTypeCode).toString()},
+                                               new String[] {selector.get(Solution.Fields.validationStatusCode).toString()},
+                                               new Date((Long)selector.get(Solution.Fields.modified)),
                                                pageRequest);
                        
                                //we need to post-process all other selection criteria
index 0d1a63e..fd47ef4 100644 (file)
@@ -102,8 +102,8 @@ public class PeerServiceImpl extends AbstractServiceImpl implements PeerService
                log.debug(EELFLoggerDelegate.debugLogger, "getPeerBySubjectName");
                RestPageResponse<MLPPeer> response = 
                        getClient().searchPeers(new MapBuilder().put("subjectName", theSubjectName).build(), false, null);
-               if (response.getSize() != 1) {
-                       log.warn(EELFLoggerDelegate.errorLogger, "getPeerBySubjectName returned more then one peer: {}", response.getSize());
+               if (response.getNumberOfElements() != 1) {
+                       log.warn(EELFLoggerDelegate.errorLogger, "getPeerBySubjectName returned more then one peer: {}", response.getNumberOfElements());
                }
                return response.getContent();
        }