X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=rapp-manager-application%2Fsrc%2Fmain%2Fjava%2Fcom%2Foransc%2Frappmanager%2Frest%2FRappController.java;h=85e1a44d482916673f78e9065c4ff76df58718bf;hb=refs%2Fchanges%2F52%2F12552%2F2;hp=8cfbddc53467af9d2cddd14f058e991342b6928d;hpb=d01a7931b29554786a41c7212ba00fdc810a80a7;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java index 8cfbddc..85e1a44 100755 --- a/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java +++ b/rapp-manager-application/src/main/java/com/oransc/rappmanager/rest/RappController.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START====================================================================== - * Copyright (C) 2023 Nordix Foundation. All rights reserved. + * Copyright (C) 2023-2024 Nordix Foundation. 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. @@ -21,6 +21,7 @@ package com.oransc.rappmanager.rest; import com.oransc.rappmanager.configuration.RappManagerConfiguration; import com.oransc.rappmanager.models.cache.RappCacheService; import com.oransc.rappmanager.models.csar.RappCsarConfigurationHandler; +import com.oransc.rappmanager.models.csar.validator.RappValidationHandler; import com.oransc.rappmanager.models.exception.RappHandlerException; import com.oransc.rappmanager.models.rapp.PrimeOrder; import com.oransc.rappmanager.models.rapp.Rapp; @@ -56,9 +57,11 @@ public class RappController { Logger logger = LoggerFactory.getLogger(RappController.class); private final RappCsarConfigurationHandler rappCsarConfigurationHandler; + private final RappValidationHandler rappValidationHandler; 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> getRapps() { @@ -68,13 +71,13 @@ public class RappController { @GetMapping("{rapp_id}") public ResponseEntity 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}") public ResponseEntity createRapp(@PathVariable("rapp_id") String rappId, @RequestPart("file") MultipartFile csarFilePart) throws IOException { - if (rappCsarConfigurationHandler.isValidRappPackage(csarFilePart)) { + if (rappValidationHandler.isValidRappPackage(csarFilePart)) { File csarFile = new File( rappCsarConfigurationHandler.getRappPackageLocation(rappManagerConfiguration.getCsarLocation(), rappId, csarFilePart.getOriginalFilename()).toUri()); @@ -102,21 +105,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 deleteRapp(@PathVariable("rapp_id") String rappId) { + public ResponseEntity 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 } }