summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java65
1 files changed, 38 insertions, 27 deletions
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..abb425131 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
@@ -3,6 +3,7 @@
* ONAP-PAP-REST
* ================================================================================
* Copyright (C) 2017 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<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 +81,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 +100,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 +156,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){