FIX SONAR ISSUE NESTED TRY BLOCKS
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / components / CreateNewMicroServiceModel.java
index d6718ab..f7f8a33 100644 (file)
@@ -57,7 +57,7 @@ public class CreateNewMicroServiceModel {
     private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
 
 
-    MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
+    private MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
 
     public CreateNewMicroServiceModel(String fileName, String serviceName, String string, String version) {
         super();
@@ -80,31 +80,8 @@ public class CreateNewMicroServiceModel {
             File directory = new File("ExtractDir" + File.separator + randomID);
             List<File> fileList = listModelFiles(directory.toString());
             //get all the files from a director
-            for (File file : fileList){
-                if (file.isFile()){
-                    int i = file.getName().lastIndexOf('.');
-                    String type = file.getName().substring(i+1);
-
-                    if(type != null && "yml".equalsIgnoreCase(type)){
-
-                        processYmlModel(file.toString(), modelName);
-
-                    }else{
-
-                        tempMap = utils.processEpackage(file.getAbsolutePath(), MODEL_TYPE.XMI);
-                        classMap.putAll(tempMap);
-                    }
-                }
-            }
-            cleanUpFile = "ExtractDir" + File.separator + randomID + ".zip";
-            try {
-                FileUtils.deleteDirectory(new File("ExtractDir" + File.separator + randomID));
-                FileUtils.deleteDirectory(new File(randomID));
-                File deleteFile = new File(cleanUpFile);
-                FileUtils.forceDelete(deleteFile);
-            } catch (IOException e) {
-                logger.error("Failed to unzip model file " + randomID, e);
-            }
+            processFiles(modelName, fileList);
+            doCleanUpFiles(randomID);
         }else {
             if(importFile.contains(".yml")){
 
@@ -122,6 +99,39 @@ public class CreateNewMicroServiceModel {
         }
     }
 
+    private void processFiles(String modelName, List<File> fileList) {
+        Map<String, MSAttributeObject> tempMap;
+        for (File file : fileList){
+            if (file.isFile()){
+                int i = file.getName().lastIndexOf('.');
+                String type = file.getName().substring(i+1);
+
+                if("yml".equalsIgnoreCase(type)){
+
+                    processYmlModel(file.toString(), modelName);
+
+                }else{
+
+                    tempMap = utils.processEpackage(file.getAbsolutePath(), MODEL_TYPE.XMI);
+                    classMap.putAll(tempMap);
+                }
+            }
+        }
+    }
+
+    private void doCleanUpFiles(String randomID) {
+        String cleanUpFile;
+        cleanUpFile = "ExtractDir" + File.separator + randomID + ".zip";
+        try {
+            FileUtils.deleteDirectory(new File("ExtractDir" + File.separator + randomID));
+            FileUtils.deleteDirectory(new File(randomID));
+            File deleteFile = new File(cleanUpFile);
+            FileUtils.forceDelete(deleteFile);
+        } catch (IOException e) {
+            logger.error("Failed to unzip model file " + randomID, e);
+        }
+    }
+
     private void processYmlModel(String fileName, String  modelName){
 
         try {
@@ -145,7 +155,7 @@ public class CreateNewMicroServiceModel {
             returnReferenceList.put(modelName, utils.getReferenceAttributes());
             msAttributes.setRefAttribute(returnReferenceList);
 
-            if(utils.getListConstraints()!=""){
+            if(!PolicyDBDao.isNullOrEmpty(utils.getListConstraints())){
                 LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
                 String[] listArray=utils.getListConstraints().split("#");
                 for(String str:listArray){