Enhance error messages Marketplace UI 57/40957/2
authorMurali-P <murali.p@huawei.com>
Wed, 4 Apr 2018 12:55:46 +0000 (18:25 +0530)
committerMurali-P <murali.p@huawei.com>
Wed, 11 Apr 2018 05:25:08 +0000 (10:55 +0530)
Show proper error message in UI

Change-Id: I5000e23560cfe0b8bf25b167ea80b7390953a9db
Issue-ID: VNFSDK-233
Signed-off-by: Murali-P <murali.p@huawei.com>
vnfmarket-be/vnf-sdk-marketplace/pom.xml
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/db/exception/ErrorCodeException.java
vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapper.java

index 77cc60e..f928a8e 100644 (file)
                <dependency>
                        <groupId>org.onap.vnfsdk.validation</groupId>
                        <artifactId>validation-csar</artifactId>
-                       <version>1.1.0</version>
+                       <version>1.1.1</version>
                </dependency>
        </dependencies>
        <profiles>
index 50cdb2a..b41a759 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onap.vnfsdk.marketplace.db.exception;
 
 public class ErrorCodeException extends Exception {
 
-       private static final long serialVersionUID = 3220072444842529499L;
-       private final int errorCode;    
+    private static final long serialVersionUID = 3220072444842529499L;
+
+    private final int errorCode;
+
+    public ErrorCodeException(Throwable source, int category, int code, String debugMessage, String[] arguments) {
+        super(debugMessage, source);
+        this.errorCode = code;
+    }
 
-       public ErrorCodeException(Throwable source, int category, int code, String debugMessage, String[] arguments) {
-               super(debugMessage, source);
-               this.errorCode = code;
-       }
+    public ErrorCodeException(int errorCode, String debugMessage) {
+        super(debugMessage);
+        this.errorCode = errorCode;
+    }
 
-       public int getErrorCode() {
-               return errorCode;
-       }
+    public int getErrorCode() {
+        return errorCode;
+    }
 
 }
index cc3ec20..3fbdd94 100644 (file)
@@ -34,6 +34,7 @@ import javax.ws.rs.core.Response.Status;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.eclipse.jetty.http.HttpStatus;
 import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
 import org.onap.validation.csar.CsarValidator;
 import org.onap.vnfsdk.marketplace.common.CommonConstant;
@@ -41,6 +42,7 @@ import org.onap.vnfsdk.marketplace.common.FileUtil;
 import org.onap.vnfsdk.marketplace.common.RestUtil;
 import org.onap.vnfsdk.marketplace.common.ToolUtil;
 import org.onap.vnfsdk.marketplace.db.entity.PackageData;
+import org.onap.vnfsdk.marketplace.db.exception.ErrorCodeException;
 import org.onap.vnfsdk.marketplace.db.exception.MarketplaceResourceException;
 import org.onap.vnfsdk.marketplace.db.resource.PackageManager;
 import org.onap.vnfsdk.marketplace.db.util.MarketplaceDbUtil;
@@ -85,8 +87,9 @@ public class PackageWrapper {
             return Response.status(Status.EXPECTATION_FAILED).build();
         }
 
-        ValidateLifecycleTestResponse lyfValidateResp = null; //TBD - Use Gson - jackson has security issue/
-                //JsonUtil.fromJson(reqParam, ValidateLifecycleTestResponse.class);
+        ValidateLifecycleTestResponse lyfValidateResp = null; // TBD - Use Gson - jackson has
+                                                              // security issue/
+        // JsonUtil.fromJson(reqParam, ValidateLifecycleTestResponse.class);
         if(!checkOperationSucess(lyfValidateResp)) {
             return Response.status(Status.EXPECTATION_FAILED).build();
         }
@@ -166,7 +169,7 @@ public class PackageWrapper {
      * @throws Exception e
      */
     public Response uploadPackage(InputStream uploadedInputStream, FormDataContentDisposition fileDetail,
-            String details, HttpHeaders head) throws MarketplaceResourceException {
+            String details, HttpHeaders head) {
         LOG.info("Upload/Reupload request Received !!!!");
         try {
             String packageId = MarketplaceDbUtil.generateId();
@@ -178,7 +181,7 @@ public class PackageWrapper {
     }
 
     private UploadPackageResponse manageUpload(String packageId, String fileName, String fileLocation, String details,
-            String contentRange) throws IOException, MarketplaceResourceException {
+            String contentRange) throws IOException, ErrorCodeException {
         String localDirName = ToolUtil.getTempDir(CommonConstant.CATALOG_CSAR_DIR_NAME, fileName);
         PackageBasicInfo basicInfo = PackageWrapperUtil.getPacageBasicInfo(fileLocation);
         UploadPackageResponse result = new UploadPackageResponse();
@@ -198,12 +201,12 @@ public class PackageWrapper {
                 LOG.info("packageMeta = " + ToolUtil.objectToString(packageMeta));
 
                 PackageData packageData = PackageWrapperUtil.getPackageData(packageMeta);
-                
-                List<PackageData> lstPkgData = PackageManager.getInstance().queryPackage(packageMeta.getName(), "", "", "", "");
-                if (!lstPkgData.isEmpty())
-                {
-                    LOG.error ("Package name is not unique");
-                    return null;
+
+                List<PackageData> lstPkgData =
+                        PackageManager.getInstance().queryPackage(packageMeta.getName(), "", "", "", "");
+                if(!lstPkgData.isEmpty()) {
+                    LOG.error("Package name is not unique");
+                    throw new ErrorCodeException(HttpStatus.INTERNAL_SERVER_ERROR_500, "Package name already exists");
                 }
 
                 String destPath = File.separator + path + File.separator + File.separator;
@@ -249,12 +252,12 @@ public class PackageWrapper {
      * @throws MarketplaceResourceException
      */
     private Response handlePackageUpload(String packageId, InputStream uploadedInputStream,
-            FormDataContentDisposition fileDetail, String details, HttpHeaders head)
-            throws IOException, MarketplaceResourceException {
+            FormDataContentDisposition fileDetail, String details, HttpHeaders head) throws IOException {
         boolean bResult = handleDataValidate(packageId, uploadedInputStream, fileDetail);
         if(!bResult) {
             LOG.error("Validation of Input received for Package Upload failed !!!");
-            return Response.status(Status.EXPECTATION_FAILED).build();
+            return Response.status(Status.EXPECTATION_FAILED)
+                    .entity("Input package is empty or exception happened during validation").build();
         }
 
         String fileName = "temp_" + packageId + ".csar";
@@ -284,16 +287,23 @@ public class PackageWrapper {
         try {
             CsarValidator cv = new CsarValidator(packageId, fileLocation);
 
-            if(!cv.validateCsar()) {
+            String validationResp = cv.validateCsar();
+            if("SUCCESS" != validationResp) {
                 LOG.error("Could not validate failed");
-                return Response.status(Status.EXPECTATION_FAILED).build();
+                return Response.status(Status.EXPECTATION_FAILED).entity(validationResp).build();
             }
         } catch(Exception e) {
             LOG.error("CSAR validation panicked", e);
-            return Response.status(Status.EXPECTATION_FAILED).build();
+            return Response.status(Status.EXPECTATION_FAILED)
+                    .entity("Exception occurred while validating csar package:" + e.getMessage()).build();
         }
 
-        UploadPackageResponse result = manageUpload(packageId, fileName, fileLocation, details, contentRange);
+        UploadPackageResponse result = null;
+        try {
+            result = manageUpload(packageId, fileName, fileLocation, details, contentRange);
+        } catch(ErrorCodeException e) {
+            return Response.status(Status.EXPECTATION_FAILED).entity("Package Name already exists").build();
+        }
         if(null != result) {
             return Response.ok(ToolUtil.objectToString(result), MediaType.APPLICATION_JSON).build();
         } else {