X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FCreateNewMicroServiceModel.java;h=86455aa30bd83de561b9b6f8b6454482331dfd65;hb=f2b8028cc05cce994c855a8574d4d89e5a27be62;hp=d6718ab8111b0de200743b87eb55b05d676a93d7;hpb=3555353c1baedc080f310e9e737a46f7cc7aa89e;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java index d6718ab81..86455aa30 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java @@ -2,7 +2,8 @@ * ============LICENSE_START======================================================= * ONAP-PAP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,7 +58,7 @@ public class CreateNewMicroServiceModel { private HashMap 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 +81,8 @@ public class CreateNewMicroServiceModel { File directory = new File("ExtractDir" + File.separator + randomID); List 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 +100,39 @@ public class CreateNewMicroServiceModel { } } + private void processFiles(String modelName, List fileList) { + Map 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 +156,7 @@ public class CreateNewMicroServiceModel { returnReferenceList.put(modelName, utils.getReferenceAttributes()); msAttributes.setRefAttribute(returnReferenceList); - if(utils.getListConstraints()!=""){ + if(!PolicyDBDao.isNullOrEmpty(utils.getListConstraints())){ LinkedHashMap enumList =new LinkedHashMap<>(); String[] listArray=utils.getListConstraints().split("#"); for(String str:listArray){ @@ -322,7 +333,7 @@ public class CreateNewMicroServiceModel { Map successMap = new HashMap<>(); CommonClassDaoImpl dbConnection = new CommonClassDaoImpl(); List result = dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName+":"+version); - if(result.isEmpty()){ + if(result == null || result.isEmpty()){ MicroServiceModels model = new MicroServiceModels(); model.setModelName(modelName); model.setVersion(version);