2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.controller;
24 import java.io.BufferedInputStream;
25 import java.io.BufferedOutputStream;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33 import java.io.PrintWriter;
34 import java.nio.file.Files;
35 import java.nio.file.Path;
36 import java.nio.file.Paths;
37 import java.util.ArrayList;
38 import java.util.Enumeration;
39 import java.util.HashMap;
40 import java.util.HashSet;
41 import java.util.Iterator;
42 import java.util.LinkedHashMap;
43 import java.util.LinkedList;
44 import java.util.List;
46 import java.util.Map.Entry;
48 import java.util.TreeMap;
49 import java.util.zip.ZipEntry;
50 import java.util.zip.ZipFile;
52 import javax.servlet.http.HttpServletRequest;
53 import javax.servlet.http.HttpServletResponse;
55 import org.apache.commons.compress.utils.IOUtils;
56 import org.apache.commons.fileupload.FileItem;
57 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
58 import org.apache.commons.fileupload.servlet.ServletFileUpload;
59 import org.apache.commons.io.FileUtils;
60 import org.apache.commons.lang.StringUtils;
61 import org.json.JSONArray;
62 import org.json.JSONObject;
63 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
64 import org.openecomp.policy.common.logging.flexlogger.Logger;
65 import org.openecomp.policy.rest.XACMLRestProperties;
66 import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
67 import org.openecomp.policy.rest.dao.CommonClassDao;
68 import org.openecomp.policy.rest.jpa.GroupPolicyScopeList;
69 import org.openecomp.policy.rest.jpa.MicroServiceModels;
70 import org.openecomp.policy.rest.jpa.PolicyEntity;
71 import org.openecomp.policy.rest.util.MSAttributeObject;
72 import org.openecomp.policy.rest.util.MSModelUtils;
73 import org.openecomp.policy.rest.util.MSModelUtils.MODEL_TYPE;
74 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
75 import org.openecomp.portalsdk.core.web.support.JsonMessage;
76 import org.springframework.beans.factory.annotation.Autowired;
77 import org.springframework.http.MediaType;
78 import org.springframework.stereotype.Controller;
79 import org.springframework.web.bind.annotation.RequestMapping;
80 import org.springframework.web.servlet.ModelAndView;
81 import org.yaml.snakeyaml.Yaml;
83 import com.att.research.xacml.util.XACMLProperties;
84 import com.fasterxml.jackson.core.JsonProcessingException;
85 import com.fasterxml.jackson.databind.DeserializationFeature;
86 import com.fasterxml.jackson.databind.JsonNode;
87 import com.fasterxml.jackson.databind.ObjectMapper;
88 import com.fasterxml.jackson.databind.ObjectWriter;
89 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
90 import com.fasterxml.jackson.databind.node.ObjectNode;
91 import com.google.gson.Gson;
93 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
94 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
95 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
96 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
97 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
98 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
102 public class CreateDcaeMicroServiceController extends RestrictedBaseController {
103 private static final Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
105 private static CommonClassDao commonClassDao;
106 private MicroServiceModels newModel;
107 private String newFile;
108 private String directory;
109 private List<String> modelList = new ArrayList<String>();
110 private List<String> dirDependencyList = new ArrayList<String>();
111 private HashMap<String,MSAttributeObject > classMap = new HashMap<String,MSAttributeObject>();
112 //Tosca Model related Datastructure.
113 String referenceAttributes;
114 String attributeString;
115 String listConstraints;
116 String subAttributeString;
117 HashMap<String, Object> retmap = new HashMap<String, Object>();
118 Set<String> uniqueKeys= new HashSet<String>();
119 Set<String> uniqueDataKeys= new HashSet<String>();
122 private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
123 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
126 public CreateDcaeMicroServiceController(){}
128 protected PolicyRestAdapter policyAdapter = null;
129 private int priorityCount;
130 private Map<String, String> attributesListRefMap = new HashMap<String, String>();
131 private Map<String, LinkedList<String>> arrayTextList = new HashMap<String, LinkedList<String>>();
133 public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
135 String jsonContent = null;
137 jsonContent = decodeContent(root.get("policyJSON")).toString();
138 constructJson(policyData, jsonContent);
140 logger.error("Error while decoding microservice content");
146 private GroupPolicyScopeList getPolicyObject(String policyScope) {
147 GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
151 private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent) {
152 ObjectWriter om = new ObjectMapper().writer();
154 DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
155 MicroServiceModels returnModel = new MicroServiceModels();
156 microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS));
157 if(policyAdapter.getServiceType() !=null){
158 microServiceObject.setService(policyAdapter.getServiceType());
159 microServiceObject.setVersion(policyAdapter.getVersion());
160 returnModel = getAttributeObject(microServiceObject.getService(), microServiceObject.getVersion());
162 if (returnModel.getAnnotation()==null || returnModel.getAnnotation().isEmpty()){
163 if(policyAdapter.getUuid()!=null){
164 microServiceObject.setUuid(policyAdapter.getUuid());
166 if(policyAdapter.getLocation()!=null){
167 microServiceObject.setLocation(policyAdapter.getLocation());
169 if(policyAdapter.getConfigName()!=null){
170 microServiceObject.setConfigName(policyAdapter.getConfigName());
172 GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope());
173 if(policyScopeValue!=null){
174 microServiceObject.setPolicyScope(policyScopeValue.getGroupList());
178 if(policyAdapter.getPolicyName()!=null){
179 microServiceObject.setPolicyName(policyAdapter.getPolicyName());
181 if(policyAdapter.getPolicyDescription()!=null){
182 microServiceObject.setDescription(policyAdapter.getPolicyDescription());
184 if (policyAdapter.getPriority()!=null){
185 microServiceObject.setPriority(policyAdapter.getPriority());
187 microServiceObject.setPriority("9999");
190 if (policyAdapter.getRiskLevel()!=null){
191 microServiceObject.setRiskLevel(policyAdapter.getRiskLevel());
193 if (policyAdapter.getRiskType()!=null){
194 microServiceObject.setRiskType(policyAdapter.getRiskType());
196 if (policyAdapter.getGuard()!=null){
197 microServiceObject.setGuard(policyAdapter.getGuard());
199 microServiceObject.setContent(jsonContent);
202 json = om.writeValueAsString(microServiceObject);
203 } catch (JsonProcessingException e) {
204 logger.error("Error writing out the object");
207 String cleanJson = cleanUPJson(json);
208 cleanJson = removeNullAttributes(cleanJson);
209 policyAdapter.setJsonBody(cleanJson);
210 return policyAdapter;
213 private String removeNullAttributes(String cleanJson) {
214 ObjectMapper mapper = new ObjectMapper();
217 JsonNode rootNode = mapper.readTree(cleanJson);
218 JsonNode returnNode = mapper.readTree(cleanJson);
219 Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
220 boolean remove = false;
221 while (fieldsIterator.hasNext()) {
222 Map.Entry<String, JsonNode> field = fieldsIterator.next();
223 final String key = field.getKey();
224 final JsonNode value = field.getValue();
225 if (value==null || value.isNull()){
226 ((ObjectNode) returnNode).remove(key);
231 cleanJson = returnNode.toString();
233 } catch (IOException e) {
234 logger.error("Error writing out the JsonNode");
239 // Second index of dot should be returned.
240 public void stringBetweenDots(String str,String value){
241 String stringToSearch=str;
242 String[]ss=stringToSearch.split("\\.");
246 uniqueKeys.add(ss[2]);
251 public void stringBetweenDotsForDataFields(String str,String value){
252 String stringToSearch=str;
253 String[]ss=stringToSearch.split("\\.");
258 uniqueDataKeys.add(ss[0]+"%"+ss[2]);
264 public Map<String, String> load(String fileName) throws IOException {
265 File newConfiguration = new File(fileName);
266 InputStream is = null;
268 is = new FileInputStream(newConfiguration);
269 } catch (FileNotFoundException e) {
273 Yaml yaml = new Yaml();
274 @SuppressWarnings("unchecked")
275 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is);
276 StringBuilder sb = new StringBuilder();
277 Map<String, String> settings = new HashMap<String, String>();
278 if (yamlMap == null) {
281 List<String> path = new ArrayList<String>();
282 serializeMap(settings, sb, path, yamlMap);
286 public Map<String, String> load(byte[] source) throws IOException {
287 Yaml yaml = new Yaml();
288 @SuppressWarnings("unchecked")
289 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source.toString());
290 StringBuilder sb = new StringBuilder();
291 Map<String, String> settings = new HashMap<String, String>();
292 if (yamlMap == null) {
295 List<String> path = new ArrayList<String>();
296 serializeMap(settings, sb, path, yamlMap);
300 @SuppressWarnings({ "unchecked", "rawtypes" })
301 private void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) {
302 for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) {
303 if (entry.getValue() instanceof Map) {
304 path.add((String) entry.getKey());
305 serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
306 path.remove(path.size() - 1);
307 } else if (entry.getValue() instanceof List) {
308 path.add((String) entry.getKey());
309 serializeList(settings, sb, path, (List) entry.getValue());
310 path.remove(path.size() - 1);
312 serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
317 @SuppressWarnings("unchecked")
318 private void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List<String> yamlList) {
320 for (Object listEle : yamlList) {
321 if (listEle instanceof Map) {
322 path.add(Integer.toString(counter));
323 serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
324 path.remove(path.size() - 1);
325 } else if (listEle instanceof List) {
326 path.add(Integer.toString(counter));
327 serializeList(settings, sb, path, (List<String>) listEle);
328 path.remove(path.size() - 1);
330 serializeValue(settings, sb, path, Integer.toString(counter), listEle);
336 private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) {
341 for (String pathEle : path) {
342 sb.append(pathEle).append('.');
345 settings.put(sb.toString(), value.toString());
349 public void parseTosca (String fileName){
350 Map<String,String> map= new HashMap<String, String>();
353 for(String key:map.keySet()){
354 if(key.contains("policy.nodes.Root"))
358 else if(key.contains("policy.nodes")){
359 String wordToFind = "policy.nodes.";
360 int indexForPolicyNode=key.indexOf(wordToFind);
361 String subNodeString= key.substring(indexForPolicyNode+13, key.length());
363 stringBetweenDots(subNodeString,map.get(key));
365 else if(key.contains("policy.data")){
366 String wordToFind="policy.data.";
367 int indexForPolicyNode=key.indexOf(wordToFind);
368 String subNodeString= key.substring(indexForPolicyNode+12, key.length());
370 stringBetweenDotsForDataFields(subNodeString,map.get(key));
371 Iterator<String> itr= uniqueDataKeys.iterator();
372 while(itr.hasNext()){
373 logger.info(itr.next());
378 String attributeIndividualString="";
379 String userDefinedIndividualString="";
380 String referenceIndividualAttributes="";
382 String attributeString="";
383 String userDefinedString="";
384 String referenceAttributes="";
385 String listConstraints="";
387 for(String uniqueDataKey: uniqueDataKeys){
388 String[] uniqueDataKeySplit= uniqueDataKey.split("%");
389 userDefinedIndividualString=userDefinedIndividualString+uniqueDataKey+"=";
390 userDefinedIndividualString=userDefinedIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
391 for(String key:map.keySet()){
392 if(key.contains("policy.data")){
393 String containsKey= uniqueDataKeySplit[1]+".type";
394 if(key.contains(uniqueDataKeySplit[0])){
395 if(key.contains("default")){
396 userDefinedIndividualString=userDefinedIndividualString.replace("#B", map.get(key));
398 else if(key.contains("required")){
399 userDefinedIndividualString=userDefinedIndividualString.replace("#C", map.get(key));
401 else if(key.contains(containsKey)){
402 String typeValue= map.get(key);
403 userDefinedIndividualString=userDefinedIndividualString.replace("#A", typeValue);
409 if(userDefinedString!=""){
410 userDefinedString=userDefinedString+","+userDefinedIndividualString;
412 userDefinedString=userDefinedString+userDefinedIndividualString;
414 userDefinedIndividualString="";
416 logger.info("userDefinedString :"+userDefinedString);
418 HashMap<String,ArrayList<String>> mapKey= new HashMap<String,ArrayList<String>>();
419 String secondPartString="";
420 String firstPartString="";
421 for(String value: userDefinedString.split(",")){
422 String[] splitWithEquals= value.split("=");
423 secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1);
424 firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%"));
425 ArrayList<String> list;
426 if(mapKey.containsKey(firstPartString)){
427 list = mapKey.get(firstPartString);
428 list.add(secondPartString+"<"+splitWithEquals[1]);
430 list = new ArrayList<String>();
431 list.add(secondPartString+"<"+splitWithEquals[1]);
432 mapKey.put(firstPartString, list);
436 JSONObject mainObject= new JSONObject();;
438 for(String s: mapKey.keySet()){
439 json= new JSONObject();
440 List<String> value=mapKey.get(s);
441 for(String listValue:value){
442 String[] splitValue=listValue.split("<");
443 json.put(splitValue[0], splitValue[1]);
445 mainObject.put(s,json);
448 logger.info(mainObject);
450 Iterator<String> keysItr = mainObject.keys();
451 while(keysItr.hasNext()) {
452 String key = keysItr.next();
453 String value = mainObject.get(key).toString();
454 retmap.put(key, value);
457 for(String str:retmap.keySet()){
458 logger.info(str+":"+retmap.get(str));
461 String typeValueFromKey="";
462 boolean userDefinedDataType=false;
463 boolean isList=false;
464 for(String uniqueKey: uniqueKeys){
465 List<String> constraints= new ArrayList<String>();
466 logger.info("====================");
467 attributeIndividualString=attributeIndividualString+uniqueKey+"=";
468 attributeIndividualString=attributeIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
470 logger.info("UniqueStrings: "+uniqueKey);
471 for(String key:map.keySet()){
472 if(key.contains("policy.nodes.Root")||
473 key.contains("policy.data"))
477 else if(key.contains("policy.nodes")){
478 if(key.contains(uniqueKey)){
479 int p=key.lastIndexOf(".");
480 String firstLastOccurance=key.substring(0,p);
481 int p1=firstLastOccurance.lastIndexOf(".");
482 String secondLastOccurance= firstLastOccurance.substring(p1+1,firstLastOccurance.length());
483 if(secondLastOccurance.equals(uniqueKey)){
484 String checkTypeString= firstLastOccurance+".type";
485 typeValueFromKey= map.get(checkTypeString);
487 else if (key.contains("entry_schema")){
488 if(key.contains("constraints")){
489 constraints.add(map.get(key));
491 if(key.contains("type")){
493 String value= map.get(key);
494 if(! (value.contains("string")) ||
495 (value.contains("integer")) ||
496 (value.contains("boolean")) )
498 if(!key.contains("valid_values")){
499 String trimValue=value.substring(value.lastIndexOf(".")+1);
500 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-true";
501 attributeIndividualString="";
508 if(!(typeValueFromKey.equals("string")||
509 typeValueFromKey.equals("integer") ||
510 typeValueFromKey.equals("boolean")))
512 if(typeValueFromKey.equals("list")){
514 userDefinedDataType=false;
517 userDefinedDataType=true;
520 if(userDefinedDataType==false && isList==false){
521 if(key.contains("default")){
522 attributeIndividualString=attributeIndividualString.replace("#B", map.get(key));
524 else if(key.contains("required")){
525 attributeIndividualString=attributeIndividualString.replace("#C", map.get(key));
527 else if(key.contains("type")){
528 String typeValue= map.get(key);
529 attributeIndividualString=attributeIndividualString.replace("#A", typeValue);
532 else if(userDefinedDataType==true){
533 String checkTypeAndUpdate=key.substring(p+1);
534 if(checkTypeAndUpdate.equals("type")){
535 String value=map.get(key);
536 String trimValue=value.substring(value.lastIndexOf(".")+1);
537 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-false";
539 attributeIndividualString="";
545 if(constraints!=null &&constraints.isEmpty()==false){
547 listConstraints=uniqueKey.toUpperCase()+"=[";
549 for(String str:constraints){
550 listConstraints=listConstraints+str+",";
552 listConstraints+="],";
553 logger.info(listConstraints);
554 attributeIndividualString="";
555 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+uniqueKey.toUpperCase()+":MANY-false";
559 if(userDefinedDataType==false && isList==false){
560 if(attributeString!=""){
561 attributeString=attributeString+","+attributeIndividualString;
563 attributeString=attributeString+attributeIndividualString;
566 if(isList==true || userDefinedDataType==true){
567 if(referenceAttributes!=""){
568 referenceAttributes=referenceAttributes+","+referenceIndividualAttributes;
570 referenceAttributes=referenceAttributes+referenceIndividualAttributes;
572 logger.info("ReferenceAttributes: "+referenceAttributes);
575 logger.info("AttributeString: "+ attributeString);
576 logger.info("ListConstraints is: "+listConstraints);
578 attributeIndividualString="";
579 referenceIndividualAttributes="";
580 userDefinedDataType=false;
584 this.listConstraints=listConstraints;
585 this.referenceAttributes=referenceAttributes;
586 this.attributeString=attributeString;
587 } catch (IOException e) {
592 private String cleanUPJson(String json) {
593 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
594 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
595 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"});
597 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"});
598 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"});
599 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
600 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"{", "}\""}, new String[]{"{", "}"});
601 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""});
602 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\""}, new String[]{""});
603 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\""}, new String[]{"\""});
604 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\\\\\\"}, new String[]{"\""});
605 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\\""}, new String[]{"\""});
606 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
610 private JSONObject decodeContent(JsonNode jsonNode){
611 Iterator<JsonNode> jsonElements = jsonNode.elements();
612 Iterator<String> jsonKeys = jsonNode.fieldNames();
613 Map<String,String> element = new TreeMap<String,String>();
614 while(jsonElements.hasNext() && jsonKeys.hasNext()){
615 element.put(jsonKeys.next(), jsonElements.next().toString());
617 JSONObject jsonResult = new JSONObject();
618 JSONArray jsonArray = null;
619 String oldValue = null;
620 String nodeKey = null;
621 String arryKey = null;
622 Boolean isArray = false;
623 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
624 ObjectNode node = nodeFactory.objectNode();
625 String prevKey = null;
626 String presKey = null;
627 for(String key: element.keySet()){
628 if(key.contains(".")){
629 presKey = key.substring(0,key.indexOf("."));
630 }else if(key.contains("@")){
631 presKey = key.substring(0,key.indexOf("@"));
635 // first check if we are different from old.
636 logger.info(key+"\n");
637 if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
638 if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
639 jsonResult.put(oldValue, jsonArray);
640 jsonArray = new JSONArray();
642 }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){
643 jsonResult.put(oldValue, jsonArray);
645 jsonArray = new JSONArray();
650 if(key.contains(".")){
652 nodeKey = key.substring(0,key.indexOf("."));
654 if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
655 node.put(key.substring(key.indexOf(".")+1), element.get(key));
658 if(nodeKey.contains("@")){
660 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
662 if(nodeKey.endsWith("@0")){
664 jsonArray = new JSONArray();
666 if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
667 jsonArray.put(decodeContent(node));
669 if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){
670 jsonResult.put(arryKey, jsonArray);
671 jsonArray = new JSONArray();
672 }else if(!key.contains("@")){
673 jsonResult.put(arryKey, jsonArray);
674 jsonArray = new JSONArray();
676 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
679 jsonResult.put(nodeKey, decodeContent(node));
681 node = nodeFactory.objectNode();
683 nodeKey = key.substring(0,key.indexOf("."));
684 if(nodeKey.contains("@")){
685 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
687 node.put(key.substring(key.indexOf(".")+1), element.get(key));
689 }else if(node.size()!=0){
690 if(nodeKey.contains("@")){
692 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
694 if(nodeKey.endsWith("@0")){
696 jsonArray = new JSONArray();
698 if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
699 jsonArray.put(decodeContent(node));
701 jsonResult.put(arryKey, jsonArray);
702 jsonArray = new JSONArray();
703 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
706 jsonResult.put(nodeKey, decodeContent(node));
708 node = nodeFactory.objectNode();
709 if(key.contains("@")){
711 if(key.endsWith("@0")|| jsonArray==null){
712 jsonArray = new JSONArray();
714 }else if(!key.contains("@")){
719 oldValue = key.substring(0,key.indexOf("@"));
721 if(oldValue!=prevKey){
722 oldValue = key.substring(0,key.indexOf("@"));
724 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
725 jsonArray.put(element.get(key));
727 jsonResult.put(oldValue, jsonArray);
728 jsonArray = new JSONArray();
730 oldValue = key.substring(0,key.indexOf("@"));
732 jsonResult.put(key, element.get(key));
735 if(key.contains("@")){
737 if(key.endsWith("@0")|| jsonArray==null){
738 jsonArray = new JSONArray();
740 }else if(!key.contains("@")){
745 oldValue = key.substring(0,key.indexOf("@"));
747 if(oldValue!=prevKey){
748 oldValue = key.substring(0,key.indexOf("@"));
750 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
751 jsonArray.put(element.get(key));
753 jsonResult.put(oldValue, jsonArray);
754 jsonArray = new JSONArray();
756 oldValue = key.substring(0,key.indexOf("@"));
758 jsonResult.put(key, element.get(key));
763 if(nodeKey.contains("@")){
765 jsonArray = new JSONArray();
768 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
770 jsonArray.put(decodeContent(node));
771 jsonResult.put(arryKey, jsonArray);
774 jsonResult.put(nodeKey, decodeContent(node));
777 if(isArray && jsonArray.length() > 0){
778 jsonResult.put(oldValue, jsonArray);
783 @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
784 public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws Exception{
785 ObjectMapper mapper = new ObjectMapper();
786 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
787 JsonNode root = mapper.readTree(request.getReader());
789 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
790 String servicename = value.toString().split("-v")[0];
791 String version = null;
792 if (value.toString().contains("-v")){
793 version = value.toString().split("-v")[1];
795 MicroServiceModels returnModel = getAttributeObject(servicename, version);
797 String jsonModel = createMicroSeriveJson(returnModel);
799 response.setCharacterEncoding("UTF-8");
800 response.setContentType("application / json");
801 request.setCharacterEncoding("UTF-8");
802 List<Object> list = new ArrayList<>();
803 PrintWriter out = response.getWriter();
804 String responseString = mapper.writeValueAsString(returnModel);
805 JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
807 out.write(list.toString());
811 @SuppressWarnings({ "unchecked", "rawtypes" })
812 private String createMicroSeriveJson(MicroServiceModels returnModel) {
813 Map<String, String> attributeMap = new HashMap<String, String>();
814 Map<String, String> refAttributeMap = new HashMap<String, String>();
815 String attribute = returnModel.getAttributes();
816 if(attribute != null){
817 attribute = attribute.trim();
819 String refAttribute = returnModel.getRef_attributes();
820 if(refAttribute != null){
821 refAttribute = refAttribute.trim();
823 String enumAttribute = returnModel.getEnumValues();
824 if(enumAttribute != null){
825 enumAttribute = enumAttribute.trim();
827 if (!StringUtils.isEmpty(attribute)){
828 attributeMap = convert(attribute, ",");
830 if (!StringUtils.isEmpty(refAttribute)){
831 refAttributeMap = convert(refAttribute, ",");
834 Gson gson = new Gson();
836 String subAttributes = returnModel.getSub_attributes();
837 if(subAttributes != null){
838 subAttributes = subAttributes.trim();
842 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
844 JSONObject object = new JSONObject();
845 JSONArray array = new JSONArray();
847 for (Entry<String, String> keySet : attributeMap.entrySet()){
848 array = new JSONArray();
849 String value = keySet.getValue();
850 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
852 object.put(keySet.getKey().trim(), array);
854 object.put(keySet.getKey().trim(), value.trim());
858 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
859 array = new JSONArray();
860 String value = keySet.getValue().split(":")[0];
861 if (gsonObject.containsKey(value)){
862 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
863 array.put(recursiveReference(value, gsonObject, enumAttribute));
864 object.put(keySet.getKey().trim(), array);
866 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
869 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
870 array.put(value.trim());
871 object.put(keySet.getKey().trim(), array);
873 object.put(keySet.getKey().trim(), value.trim());
878 return object.toString();
881 @SuppressWarnings("unchecked")
882 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
883 JSONObject object = new JSONObject();
884 Map<String, String> map = new HashMap<String, String>();
885 Object returnClass = subAttributeMap.get(name);
886 map = (Map<String, String>) returnClass;
887 JSONArray array = new JSONArray();
889 for( Entry<String, String> m:map.entrySet()){
890 String[] splitValue = m.getValue().split(":");
891 array = new JSONArray();
892 if (subAttributeMap.containsKey(splitValue[0])){
893 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
894 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
895 object.put(m.getKey().trim(), array);
897 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
900 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
901 array.put(splitValue[0].trim());
902 object.put(m.getKey().trim(), array);
904 object.put(m.getKey().trim(), splitValue[0].trim());
913 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
914 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws Exception{
915 ObjectMapper mapper = new ObjectMapper();
916 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
917 JsonNode root = mapper.readTree(request.getReader());
919 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
920 String servicename = value.toString().split("-v")[0];
921 Set<String> returnList = getVersionList(servicename);
923 response.setCharacterEncoding("UTF-8");
924 response.setContentType("application / json");
925 request.setCharacterEncoding("UTF-8");
926 List<Object> list = new ArrayList<>();
927 PrintWriter out = response.getWriter();
928 String responseString = mapper.writeValueAsString(returnList);
929 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
931 out.write(list.toString());
935 private Set<String> getVersionList(String name) {
936 MicroServiceModels workingModel = new MicroServiceModels();
937 Set<String> list = new HashSet<String>();
938 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
939 for (int i = 0; i < microServiceModelsData.size(); i++) {
940 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
941 if (workingModel.getVersion()!=null){
942 list.add(workingModel.getVersion());
950 private MicroServiceModels getAttributeObject(String name, String version) {
951 MicroServiceModels workingModel = new MicroServiceModels();
952 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
953 for (int i = 0; i < microServiceModelsData.size(); i++) {
954 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
956 if (workingModel.getVersion()!=null){
957 if (workingModel.getVersion().equals(version)){
971 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
972 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
974 Map<String, Object> model = new HashMap<String, Object>();
975 ObjectMapper mapper = new ObjectMapper();
976 List<String> priorityList = new ArrayList<String>();
978 for (int i = 1; i < priorityCount; i++) {
979 priorityList.add(String.valueOf(i));
981 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
982 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
983 JSONObject j = new JSONObject(msg);
984 response.getWriter().write(j.toString());
991 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
992 if (policyAdapter.getPolicyData() instanceof PolicyType) {
993 Object policyData = policyAdapter.getPolicyData();
994 PolicyType policy = (PolicyType) policyData;
995 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
996 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
997 policyAdapter.setPolicyName(policyNameValue);
998 String description = "";
1000 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
1001 }catch(Exception e){
1002 description = policy.getDescription();
1004 policyAdapter.setPolicyDescription(description);
1005 // Get the target data under policy.
1006 TargetType target = policy.getTarget();
1007 if (target != null) {
1008 // Under target we have AnyOFType
1009 List<AnyOfType> anyOfList = target.getAnyOf();
1010 if (anyOfList != null) {
1011 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
1012 while (iterAnyOf.hasNext()) {
1013 AnyOfType anyOf = iterAnyOf.next();
1014 // Under AnyOFType we have AllOFType
1015 List<AllOfType> allOfList = anyOf.getAllOf();
1016 if (allOfList != null) {
1017 Iterator<AllOfType> iterAllOf = allOfList.iterator();
1018 while (iterAllOf.hasNext()) {
1019 AllOfType allOf = iterAllOf.next();
1020 // Under AllOFType we have Match
1021 List<MatchType> matchList = allOf.getMatch();
1022 if (matchList != null) {
1024 Iterator<MatchType> iterMatch = matchList.iterator();
1025 while (matchList.size()>1 && iterMatch.hasNext()) {
1026 MatchType match = iterMatch.next();
1028 // Under the match we have attributevalue and
1029 // attributeDesignator. So,finally down to the actual attribute.
1031 AttributeValueType attributeValue = match.getAttributeValue();
1032 String value = (String) attributeValue.getContent().get(0);
1034 // First match in the target is EcompName, so set that value.
1036 policyAdapter.setEcompName(value);
1039 policyAdapter.setConfigName(value);
1043 readFile(policyAdapter, entity);
1047 policyAdapter.setUuid(value);
1050 policyAdapter.setLocation(value);
1053 policyAdapter.setRiskType(value);
1057 policyAdapter.setRiskLevel(value);
1061 policyAdapter.setGuard(value);
1063 if (index == 8 && !value.contains("NA")){
1064 String newDate = convertDate(value, true);
1065 policyAdapter.setTtlDate(newDate);
1078 private String convertDate(String dateTTL, boolean portalType) {
1079 String formateDate = null;
1080 String[] date = dateTTL.split("T");
1081 String[] parts = date[0].split("-");
1083 formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
1087 public static Map<String, String> convert(String str, String split) {
1088 Map<String, String> map = new HashMap<String, String>();
1089 for(final String entry : str.split(split)) {
1090 String[] parts = entry.split("=");
1091 map.put(parts[0], parts[1]);
1097 @SuppressWarnings("unchecked")
1098 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1099 String policyScopeName = null;
1100 ObjectMapper mapper = new ObjectMapper();
1102 DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1103 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1104 policyAdapter.setPolicyScope(policyScopeName);
1106 policyAdapter.setPriority(msBody.getPriority());
1108 if (msBody.getVersion()!= null){
1109 policyAdapter.setServiceType(msBody.getService());
1110 policyAdapter.setVersion(msBody.getVersion());
1112 policyAdapter.setServiceType(msBody.getService());
1114 if(msBody.getContent() != null){
1115 LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
1116 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1117 readRecursivlyJSONContent(map, data);
1118 policyAdapter.setRuleData(data);
1121 } catch (Exception e) {
1127 @SuppressWarnings({ "rawtypes", "unchecked" })
1128 private void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1129 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1130 Object key = iterator.next();
1131 Object value = map.get(key);
1132 if(value instanceof LinkedHashMap<?, ?>){
1133 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<String, Object>();
1134 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1135 for(String objKey: secondObjec.keySet()){
1136 data.put(key+"." +objKey, secondObjec.get(objKey));
1138 }else if(value instanceof ArrayList){
1139 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1140 for(int i = 0; i < jsonArrayVal.size(); i++){
1141 Object arrayvalue = jsonArrayVal.get(i);
1142 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1143 LinkedHashMap<String, Object> newData = new LinkedHashMap<String, Object>();
1144 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1145 for(String objKey: newData.keySet()){
1146 data.put(key+"@"+i+"." +objKey, newData.get(objKey));
1148 }else if(arrayvalue instanceof ArrayList){
1149 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1150 for(int j = 0; j < jsonArrayVal1.size(); j++){
1151 Object arrayvalue1 = jsonArrayVal1.get(i);
1152 data.put(key+"@"+j, arrayvalue1.toString());
1155 data.put(key+"@"+i, arrayvalue.toString());
1159 data.put(key.toString(), value.toString());
1164 private String getPolicyScope(String value) {
1165 GroupPolicyScopeList pScope = new GroupPolicyScopeList();
1166 List<Object> groupList= commonClassDao.getData(GroupPolicyScopeList.class);
1167 if(groupList.size() > 0){
1168 for(int i = 0 ; i < groupList.size() ; i ++){
1169 pScope = (GroupPolicyScopeList) groupList.get(i);
1170 if (pScope.getGroupList().equals(value)){
1175 return pScope.getGroupName();
1178 //Convert the map values and set into JSON body
1179 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1180 Map<String, String> attribute = new HashMap<String, String>();
1184 for (Entry<String, String> entry : attributesMap.entrySet()) {
1185 key = entry.getKey();
1186 value = entry.getValue();
1187 attribute.put(key, value);
1189 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1190 key = entryRef.getKey();
1191 value = entryRef.getValue().toString();
1192 attribute.put(key, value);
1194 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1195 key = entryList.getKey();
1196 value = entryList.getValue().toString();
1197 attribute.put(key, value);
1199 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1200 key = arrayList.getKey();
1202 for (Object textList : arrayList.getValue()){
1204 temp = "[" + textList;
1206 temp = temp + "," + textList;
1209 attribute.put(key, temp+ "]");
1215 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1216 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws Exception{
1217 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1218 boolean zip = false;
1220 for (FileItem item : items) {
1221 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1222 this.newModel = new MicroServiceModels();
1224 File file = new File(item.getName());
1225 OutputStream outputStream = new FileOutputStream(file);
1226 IOUtils.copy(item.getInputStream(), outputStream);
1227 outputStream.close();
1228 this.newFile = file.toString();
1229 this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
1231 if (this.newFile.toString().contains("-v")){
1232 if (item.getName().endsWith(".zip")){
1233 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
1235 }else if(item.getName().endsWith(".yml")){
1236 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
1240 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
1244 }catch(Exception e){
1245 logger.error("Upload error : " + e);
1250 List<File> fileList = new ArrayList<File>();;
1251 this.directory = "model";
1253 extractFolder(this.newFile);
1254 fileList = listModelFiles(this.directory);
1255 }else if (yml==true){
1256 parseTosca(this.newFile);
1258 File file = new File(this.newFile);
1261 String modelType= "";
1264 //Process Main Model file first
1265 classMap = new HashMap<String,MSAttributeObject>();
1266 for (File file : fileList) {
1267 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1268 retreiveDependency(file.toString(), true);
1272 modelList = createList();
1274 cleanUp(this.newFile);
1278 modelList.add(this.newModel.getModelName());
1279 String className=this.newModel.getModelName();
1280 MSAttributeObject msAttributes= new MSAttributeObject();
1281 msAttributes.setClassName(className);
1283 HashMap<String, String> returnAttributeList =new HashMap<String, String>();
1284 returnAttributeList.put(className, this.attributeString);
1285 msAttributes.setAttribute(returnAttributeList);
1287 msAttributes.setSubClass(this.retmap);
1289 HashMap<String, String> returnReferenceList =new HashMap<String, String>();
1290 //String[] referenceArray=this.referenceAttributes.split("=");
1291 returnReferenceList.put(className, this.referenceAttributes);
1292 msAttributes.setRefAttribute(returnReferenceList);
1294 if(this.listConstraints!=""){
1295 HashMap<String, String> enumList =new HashMap<String, String>();
1296 String[] listArray=this.listConstraints.split("=");
1297 enumList.put(listArray[0], listArray[1]);
1298 msAttributes.setEnumType(enumList);
1301 classMap=new HashMap<String,MSAttributeObject>();
1302 classMap.put(className, msAttributes);
1306 PrintWriter out = response.getWriter();
1308 response.setCharacterEncoding("UTF-8");
1309 response.setContentType("application / json");
1310 request.setCharacterEncoding("UTF-8");
1312 ObjectMapper mapper = new ObjectMapper();
1313 JSONObject j = new JSONObject();
1314 j.put("classListDatas", modelList);
1315 j.put("modelDatas", mapper.writeValueAsString(classMap));
1316 j.put("modelType", modelType);
1317 out.write(j.toString());
1321 * Unzip file and store in the model directory for processing
1323 @SuppressWarnings("rawtypes")
1324 private void extractFolder(String zipFile ) {
1326 File file = new File(zipFile);
1330 zip = new ZipFile(file);
1331 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1332 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1333 checkZipDirectory(this.directory);
1334 new File(newPath).mkdir();
1335 Enumeration zipFileEntries = zip.entries();
1337 // Process each entry
1338 while (zipFileEntries.hasMoreElements()){
1339 // grab a zip file entry
1340 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1341 String currentEntry = entry.getName();
1342 File destFile = new File("model" + File.separator + currentEntry);
1343 File destinationParent = destFile.getParentFile();
1345 destinationParent.mkdirs();
1347 if (!entry.isDirectory()){
1348 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1350 byte data[] = new byte[BUFFER];
1351 FileOutputStream fos = new FileOutputStream(destFile);
1352 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
1353 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1354 dest.write(data, 0, currentByte);
1361 if (currentEntry.endsWith(".zip")){
1362 extractFolder(destFile.getAbsolutePath());
1365 } catch (IOException e) {
1366 logger.error("Failed to unzip model file " + zipFile);
1370 private void retreiveDependency(String workingFile, Boolean modelClass) {
1372 MSModelUtils utils = new MSModelUtils(PolicyController.msEcompName, PolicyController.msPolicyName);
1373 HashMap<String, MSAttributeObject> tempMap = new HashMap<String, MSAttributeObject>();
1375 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1377 classMap.putAll(tempMap);
1378 logger.info(tempMap);
1384 private List<File> listModelFiles(String directoryName) {
1385 File directory = new File(directoryName);
1386 List<File> resultList = new ArrayList<File>();
1387 File[] fList = directory.listFiles();
1388 for (File file : fList) {
1389 if (file.isFile()) {
1390 resultList.add(file);
1391 } else if (file.isDirectory()) {
1392 dirDependencyList.add(file.getName());
1393 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1399 private void cleanUp(String path) {
1402 FileUtils.forceDelete(new File(path));
1403 } catch (IOException e) {
1404 logger.error("Failed to delete folder " + path);
1409 private void checkZipDirectory(String zipDirectory) {
1410 Path path = Paths.get(zipDirectory);
1412 if (Files.exists(path)) {
1413 cleanUp(zipDirectory);
1417 private List<String> createList() {
1418 List<String> list = new ArrayList<String>();
1419 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1420 if (cMap.getValue().isPolicyTempalate()){
1421 list.add(cMap.getKey());
1426 if (list.isEmpty()){
1427 if (classMap.containsKey(this.newModel.getModelName())){
1428 list.add(this.newModel.getModelName());
1438 class DCAEMicroServiceObject {
1440 public String service;
1441 public String location;
1443 public String policyName;
1444 public String description;
1445 public String configName;
1446 public String templateVersion;
1447 public String version;
1448 public String priority;
1449 public String policyScope;
1450 public String riskType;
1451 public String riskLevel;
1452 public String guard = null;
1454 public String getGuard() {
1457 public void setGuard(String guard) {
1460 public String getRiskType() {
1463 public void setRiskType(String riskType) {
1464 this.riskType = riskType;
1466 public String getRiskLevel() {
1469 public void setRiskLevel(String riskLevel) {
1470 this.riskLevel = riskLevel;
1472 public String getPolicyScope() {
1475 public void setPolicyScope(String policyScope) {
1476 this.policyScope = policyScope;
1479 public String getPriority() {
1482 public void setPriority(String priority) {
1483 this.priority = priority;
1485 public String getVersion() {
1488 public void setVersion(String version) {
1489 this.version = version;
1491 private Object content;
1494 public String getPolicyName() {
1497 public void setPolicyName(String policyName) {
1498 this.policyName = policyName;
1500 public String getDescription() {
1503 public void setDescription(String description) {
1504 this.description = description;
1506 public String getConfigName() {
1509 public void setConfigName(String configName) {
1510 this.configName = configName;
1512 public Object getContent() {
1515 public void setContent(Object content) {
1516 this.content = content;
1519 public String getService() {
1522 public void setService(String service) {
1523 this.service = service;
1525 public String getLocation() {
1528 public void setLocation(String location) {
1529 this.location = location;
1532 public String getUuid() {
1535 public void setUuid(String uuid) {
1538 public String getTemplateVersion() {
1539 return templateVersion;
1541 public void setTemplateVersion(String templateVersion) {
1542 this.templateVersion = templateVersion;