fix patch 3 75/12875/6
authorHarry Huang <huangxiangyu5@huawei.com>
Sat, 16 Sep 2017 10:26:55 +0000 (18:26 +0800)
committerHarry Huang <huangxiangyu5@huawei.com>
Sun, 17 Sep 2017 07:07:07 +0000 (15:07 +0800)
major:  L199 L210 L240 L349
critical: L290 L326 L327

Change-Id: Iab7f2dc694aa0eedbf443bc291dfcd2d81898390
Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Issue-Id: VNFSDK-85

vnfmarket-be/vnf-sdk-marketplace/src/main/java/org/onap/vnfsdk/marketplace/wrapper/PackageWrapperUtil.java

index a763a36..4fba9f0 100644 (file)
@@ -198,11 +198,10 @@ public class PackageWrapperUtil {
   public static List<PackageMeta> packageDataList2PackageMetaList(
       List<PackageData> dbResult) {
     ArrayList<PackageMeta> metas = new ArrayList<>();
-    PackageMeta meta = null;
     if (! dbResult.isEmpty()) {
       for (int i = 0; i < dbResult.size(); i++) {
         PackageData data = dbResult.get(i);
-        meta = packageData2PackageMeta(data);
+        PackageMeta meta = packageData2PackageMeta(data);
         metas.add(meta);
       }
     }
@@ -245,8 +244,7 @@ public class PackageWrapperUtil {
     } else {
       url += uri;
     }
-    String urlresult = url.replace("\\", "/");
-    return urlresult;
+    return url.replace("\\", "/");
   }
 
   public static String getDownloadUriHead() {
@@ -280,15 +278,15 @@ public class PackageWrapperUtil {
         isXmlCsar = true;
       }
       for (String unzipFile : unzipFiles) {
-                               if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
-                                       basicInfo = readManifest(unzipFile);
+        if (unzipFile.endsWith(CommonConstant.MANIFEST)) {
+          basicInfo = readManifest(unzipFile);
         }
         if (ToolUtil.isYamlFile(new File(unzipFile))) {
           isXmlCsar = false;
         }
       }
     } catch (IOException e1) {
-      LOG.error("judge package type error ! " + e1.getMessage());
+      LOG.error("judge package type error ! " + e1.getMessage(), e1);
     }
     if (isXmlCsar) {
       basicInfo.setFormat(CommonConstant.PACKAGE_XML_FORMAT);
@@ -298,81 +296,51 @@ public class PackageWrapperUtil {
     return basicInfo;
   }
 
-  private static PackageBasicInfo readCsarMeta(String unzipFile) {
+  /**
+   * Reads the manifest file in the package and fills the basic infor about package
+   * @param unzipFile
+   * @return basic infor about package
+   */
+  private static PackageBasicInfo readManifest(String unzipFile) {
+
+    // Fix the package type to CSAR, temporary
     PackageBasicInfo basicInfo = new PackageBasicInfo();
+    basicInfo.setType(EnumType.CSAR);
+
     File file = new File(unzipFile);
     try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+
       String tempString = null;
       while ((tempString = reader.readLine()) != null) {
-        if (tempString.equals("")) {
+
+        // If line is empty, ignore
+        if ("".equals(tempString)) {
           continue;
         }
+
         int count1 = tempString.indexOf(":");
         String meta = tempString.substring(0, count1).trim();
-        if (CommonConstant.CSAR_TYPE_META.equalsIgnoreCase(meta)) {
-          int count = tempString.indexOf(":") + 1;
-          basicInfo.setType(EnumType.valueOf(tempString.substring(count).trim()));
-        }
-        if (CommonConstant.CSAR_PROVIDER_META.equalsIgnoreCase(meta)) {
+
+        // Check for the package provider name
+        if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) {
           int count = tempString.indexOf(":") + 1;
           basicInfo.setProvider(tempString.substring(count).trim());
         }
-        if (CommonConstant.CSAR_VERSION_META.equalsIgnoreCase(meta)) {
+
+        // Check for package version
+        if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) {
           int count = tempString.indexOf(":") + 1;
           basicInfo.setVersion(tempString.substring(count).trim());
         }
       }
+
       reader.close();
-    } catch (IOException e2) {
-      e2.printStackTrace();
+    } catch (IOException e) {
+      LOG.error("Exception while parsing manifest file" + e, e);
     }
+
     return basicInfo;
   }
-       /**
-        * Reads the manifest file in the package and fills the basic infor about package
-        * @param unzipFile
-        * @return basic infor about package
-        */     
-       private static PackageBasicInfo readManifest(String unzipFile) {
-
-               // Fix the package type to CSAR, temporary
-               PackageBasicInfo basicInfo = new PackageBasicInfo();
-               basicInfo.setType(EnumType.CSAR);
-
-               File file = new File(unzipFile);
-               try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
-
-                       String tempString = null;
-                       while ((tempString = reader.readLine()) != null) {
-                               
-                               // If line is empty, ignore
-                               if (tempString.equals("")) {
-                                       continue;
-                               }
-
-                               int count1 = tempString.indexOf(":");
-                               String meta = tempString.substring(0, count1).trim();
-                               
-                               // Check for the package provider name
-                               if (meta.equalsIgnoreCase(CommonConstant.MF_PROVIDER_META)) {
-                                       int count = tempString.indexOf(":") + 1;
-                                       basicInfo.setProvider(tempString.substring(count).trim());
-                               }
-                               
-                               // Check for package version
-                               if (meta.equalsIgnoreCase(CommonConstant.MF_VERSION_META)) {
-                                       int count = tempString.indexOf(":") + 1;
-                                       basicInfo.setVersion(tempString.substring(count).trim());
-                               }
-                       }
-
-                       reader.close();
-               } catch (IOException e) {
-                       LOG.error("Exception while parsing manifest file" + e);                 
-               }
-
-               return basicInfo;
-       }
   /**
    * get package format enum.
    * @param format package format