Fix the sonar issue and clm issue
[multicloud/framework.git] / artifactbroker / plugins / reception-plugins / src / main / java / org / onap / policy / distribution / reception / handling / sdc / SdcReceptionHandler.java
index fc2211b..8bf69da 100644 (file)
@@ -27,8 +27,9 @@ import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
@@ -36,7 +37,7 @@ import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.model.CloudArtifact;
 import org.onap.policy.distribution.model.Csar;
 import org.onap.policy.distribution.model.GsonUtil;
-import org.onap.policy.distribution.model.VfModuelModel;
+import org.onap.policy.distribution.model.VfModuleModel;
 import org.onap.policy.distribution.reception.decoding.PolicyDecodingException;
 import org.onap.policy.distribution.reception.handling.AbstractReceptionHandler;
 import org.onap.policy.distribution.reception.handling.sdc.SdcClientHandler.SdcClientOperationType;
@@ -220,22 +221,20 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
         DistributionStatisticsManager.updateTotalDistributionCount();
         List<String> relevantArtifactTypes = sdcConfig.getRelevantArtifactTypes();
         Path path = Paths.get("/data");
-        List<VfModuelModel> vfModuelModels = null;
-        Map<String, String> artifactTypeMap = null; //key is UUID, value is type for k8s plugin
-        Map<String, IArtifactInfo> artifactMap = null;//key is UUID, value is artifact for shared folder
+        ArrayList<VfModuleModel> vfModuleModels = new ArrayList<>();
+        HashMap<String, IArtifactInfo> artifactMap = new HashMap<>();//key is UUID, value is artifact for shared folder
         String vfArtifactData = null;
 
         for (final IArtifactInfo artifact : resource.getArtifacts()) {
-            artifactTypeMap.put(artifact.getArtifactUUID(),artifact.getArtifactType());
             artifactMap.put(artifact.getArtifactUUID(),artifact);
 
-             //extract the artifactlist and write them into MongoDB
+            //extract the artifactlist and write them into MongoDB
             if (artifact.getArtifactType().equals("VF_MODULES_METADATA")) {
                 try {
                     final IDistributionClientDownloadResult resultArtifact =
                             downloadTheArtifact(artifact,notificationData);
                     vfArtifactData = new String(resultArtifact.getArtifactPayload());
-                    vfModuelModels= GsonUtil.parseJsonArrayWithGson(vfArtifactData,VfModuelModel.class);
+                    vfModuleModels = GsonUtil.parseJsonArrayWithGson(vfArtifactData,VfModuleModel.class);
                 } catch (final ArtifactDownloadException exp) {
                     LOGGER.error("Failed to process csar service artifacts ", exp);
                     artifactsProcessedSuccessfully = false;
@@ -251,16 +250,18 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
         //  2. put the vfmodule-meta.json into it
         //  3. put the service-meta.json into it
         //  3. go through each aritfact uuid under artifact_list of vf_module and download
-        for (final VfModuelModel vfModule : vfModuelModels) {
+        for (final VfModuleModel vfModule : vfModuleModels) {
             try {
                 //create the new dir
                 Path temp = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID());
                 path = Files.createDirectory(temp);//create UUID path
                 //store the value to vfmodule-meta.json
-                String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"vfmodule-meta.json").toString();
+                String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),
+                    "vfmodule-meta.json").toString();
                 writeFileByFileWriter(filePath, vfArtifactData);
                 //store the service level info to serivce-meta.json
-                filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"service-meta.json").toString();
+                filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),
+                    "service-meta.json").toString();
                 writeFileByFileWriter(filePath, notificationData.toString());
             } catch (final IOException exp) {
                 LOGGER.error("Failed to create  directory artifact file", exp);
@@ -283,7 +284,7 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
 
         //for subplug work
         try {
-            final CloudArtifact cloudArtifact = new CloudArtifact(vfModuelModels, artifactTypeMap);
+            final CloudArtifact cloudArtifact = new CloudArtifact(vfModuleModels, artifactMap);
             inputReceived(cloudArtifact);
         } catch ( final PolicyDecodingException exp) {
             LOGGER.error("Failed to process cloud  artifacts ", exp);
@@ -337,9 +338,11 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
     private static void writeFileByFileWriter(String filePath, String content) throws IOException {
         File file = new File(filePath);
         synchronized (file) {
-            FileWriter fw = new FileWriter(filePath);
-            fw.write(content);
-            fw.close();
+            try (FileWriter fw = new FileWriter(filePath)) {
+                fw.write(content);
+            } catch (final IOException exp) {
+                LOGGER.error("Failed to write File by File Writer ", exp);
+            }
         }
     }
     /**