Merge "Add proper error messages on delete rApp response"
[nonrtric/plt/rappmanager.git] / rapp-manager-application / src / main / java / com / oransc / rappmanager / rest / RappController.java
index 8cfbddc..287e297 100755 (executable)
@@ -59,6 +59,7 @@ public class RappController {
     private final RappManagerConfiguration rappManagerConfiguration;
     private final RappCacheService rappCacheService;
     private final RappService rappService;
+    private static final String RAPP_NOT_FOUND = "rApp %s not found.";
 
     @GetMapping
     public ResponseEntity<Collection<Rapp>> getRapps() {
@@ -68,7 +69,7 @@ public class RappController {
     @GetMapping("{rapp_id}")
     public ResponseEntity<Rapp> getRapp(@PathVariable("rapp_id") String rappId) {
         return rappCacheService.getRapp(rappId).map(ResponseEntity::ok).orElseThrow(
-                () -> new RappHandlerException(HttpStatus.NOT_FOUND, "rApp '" + rappId + "' not found."));
+                () -> new RappHandlerException(HttpStatus.NOT_FOUND, String.format(RAPP_NOT_FOUND, rappId)));
     }
 
     @PostMapping("{rapp_id}")
@@ -102,21 +103,17 @@ public class RappController {
                             .map(primeOrder -> rappService.primeRapp(rapp))
                             .orElseGet(() -> rappService.deprimeRapp(rapp)))
                        .orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
-                               "rApp '" + rappId + "' not found."));
+                               String.format(RAPP_NOT_FOUND, rappId)));
         // @formatter:on
     }
 
     @DeleteMapping("{rapp_id}")
-    public ResponseEntity<Object> deleteRapp(@PathVariable("rapp_id") String rappId) {
+    public ResponseEntity<String> deleteRapp(@PathVariable("rapp_id") String rappId) {
         // @formatter:off
         return rappCacheService.getRapp(rappId)
-               .filter(rapp -> rapp.getRappInstances().isEmpty() && rapp.getState().equals(RappState.COMMISSIONED))
-               .map(rapp -> {
-                   rappCacheService.deleteRapp(rapp);
-                   return ResponseEntity.ok().build();
-               })
+               .map(rappService::deleteRapp)
                .orElseThrow(() -> new RappHandlerException(HttpStatus.NOT_FOUND,
-                               "rApp '" + rappId + "' not found."));
+                       String.format(RAPP_NOT_FOUND, rappId)));
         // @formatter:on
     }
 }