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.AttributeDesignatorType;
96 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
97 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
98 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
99 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
103 public class CreateDcaeMicroServiceController extends RestrictedBaseController {
104 private static final Logger logger = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
106 private static CommonClassDao commonClassDao;
107 private MicroServiceModels newModel;
108 private String newFile;
109 private String directory;
110 private List<String> modelList = new ArrayList<String>();
111 private List<String> dirDependencyList = new ArrayList<String>();
112 private HashMap<String,MSAttributeObject > classMap = new HashMap<String,MSAttributeObject>();
113 //Tosca Model related Datastructure.
114 String referenceAttributes;
115 String attributeString;
116 String listConstraints;
117 String subAttributeString;
118 HashMap<String, Object> retmap = new HashMap<String, Object>();
119 Set<String> uniqueKeys= new HashSet<String>();
120 Set<String> uniqueDataKeys= new HashSet<String>();
123 private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
124 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
127 public CreateDcaeMicroServiceController(){}
129 protected PolicyRestAdapter policyAdapter = null;
130 private int priorityCount;
131 private Map<String, String> attributesListRefMap = new HashMap<String, String>();
132 private Map<String, LinkedList<String>> arrayTextList = new HashMap<String, LinkedList<String>>();
134 public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
136 String jsonContent = null;
138 jsonContent = decodeContent(root.get("policyJSON")).toString();
139 constructJson(policyData, jsonContent);
141 logger.error("Error while decoding microservice content");
147 private GroupPolicyScopeList getPolicyObject(String policyScope) {
148 GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
152 private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent) {
153 ObjectWriter om = new ObjectMapper().writer();
155 DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
156 MicroServiceModels returnModel = new MicroServiceModels();
157 microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS));
158 if(policyAdapter.getServiceType() !=null){
159 microServiceObject.setService(policyAdapter.getServiceType());
160 microServiceObject.setVersion(policyAdapter.getVersion());
161 returnModel = getAttributeObject(microServiceObject.getService(), microServiceObject.getVersion());
163 if (returnModel.getAnnotation()==null || returnModel.getAnnotation().isEmpty()){
164 if(policyAdapter.getUuid()!=null){
165 microServiceObject.setUuid(policyAdapter.getUuid());
167 if(policyAdapter.getLocation()!=null){
168 microServiceObject.setLocation(policyAdapter.getLocation());
170 if(policyAdapter.getConfigName()!=null){
171 microServiceObject.setConfigName(policyAdapter.getConfigName());
173 GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope());
174 if(policyScopeValue!=null){
175 microServiceObject.setPolicyScope(policyScopeValue.getGroupList());
179 if(policyAdapter.getPolicyName()!=null){
180 microServiceObject.setPolicyName(policyAdapter.getPolicyName());
182 if(policyAdapter.getPolicyDescription()!=null){
183 microServiceObject.setDescription(policyAdapter.getPolicyDescription());
185 if (policyAdapter.getPriority()!=null){
186 microServiceObject.setPriority(policyAdapter.getPriority());
188 microServiceObject.setPriority("9999");
191 if (policyAdapter.getRiskLevel()!=null){
192 microServiceObject.setRiskLevel(policyAdapter.getRiskLevel());
194 if (policyAdapter.getRiskType()!=null){
195 microServiceObject.setRiskType(policyAdapter.getRiskType());
197 if (policyAdapter.getGuard()!=null){
198 microServiceObject.setGuard(policyAdapter.getGuard());
200 microServiceObject.setContent(jsonContent);
203 json = om.writeValueAsString(microServiceObject);
204 } catch (JsonProcessingException e) {
205 logger.error("Error writing out the object");
208 String cleanJson = cleanUPJson(json);
209 cleanJson = removeNullAttributes(cleanJson);
210 policyAdapter.setJsonBody(cleanJson);
211 return policyAdapter;
214 private String removeNullAttributes(String cleanJson) {
215 ObjectMapper mapper = new ObjectMapper();
218 JsonNode rootNode = mapper.readTree(cleanJson);
219 JsonNode returnNode = mapper.readTree(cleanJson);
220 Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
221 boolean remove = false;
222 while (fieldsIterator.hasNext()) {
223 Map.Entry<String, JsonNode> field = fieldsIterator.next();
224 final String key = field.getKey();
225 final JsonNode value = field.getValue();
226 if (value==null || value.isNull()){
227 ((ObjectNode) returnNode).remove(key);
232 cleanJson = returnNode.toString();
234 } catch (IOException e) {
235 logger.error("Error writing out the JsonNode");
240 // Second index of dot should be returned.
241 public void stringBetweenDots(String str,String value){
242 String stringToSearch=str;
243 String[]ss=stringToSearch.split("\\.");
247 uniqueKeys.add(ss[2]);
252 public void stringBetweenDotsForDataFields(String str,String value){
253 String stringToSearch=str;
254 String[]ss=stringToSearch.split("\\.");
259 uniqueDataKeys.add(ss[0]+"%"+ss[2]);
265 public Map<String, String> load(String fileName) throws IOException {
266 File newConfiguration = new File(fileName);
267 InputStream is = null;
269 is = new FileInputStream(newConfiguration);
270 } catch (FileNotFoundException e) {
274 Yaml yaml = new Yaml();
275 @SuppressWarnings("unchecked")
276 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is);
277 StringBuilder sb = new StringBuilder();
278 Map<String, String> settings = new HashMap<String, String>();
279 if (yamlMap == null) {
282 List<String> path = new ArrayList<String>();
283 serializeMap(settings, sb, path, yamlMap);
287 public Map<String, String> load(byte[] source) throws IOException {
288 Yaml yaml = new Yaml();
289 @SuppressWarnings("unchecked")
290 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source.toString());
291 StringBuilder sb = new StringBuilder();
292 Map<String, String> settings = new HashMap<String, String>();
293 if (yamlMap == null) {
296 List<String> path = new ArrayList<String>();
297 serializeMap(settings, sb, path, yamlMap);
301 @SuppressWarnings({ "unchecked", "rawtypes" })
302 private void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) {
303 for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) {
304 if (entry.getValue() instanceof Map) {
305 path.add((String) entry.getKey());
306 serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
307 path.remove(path.size() - 1);
308 } else if (entry.getValue() instanceof List) {
309 path.add((String) entry.getKey());
310 serializeList(settings, sb, path, (List) entry.getValue());
311 path.remove(path.size() - 1);
313 serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
318 @SuppressWarnings("unchecked")
319 private void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List<String> yamlList) {
321 for (Object listEle : yamlList) {
322 if (listEle instanceof Map) {
323 path.add(Integer.toString(counter));
324 serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
325 path.remove(path.size() - 1);
326 } else if (listEle instanceof List) {
327 path.add(Integer.toString(counter));
328 serializeList(settings, sb, path, (List<String>) listEle);
329 path.remove(path.size() - 1);
331 serializeValue(settings, sb, path, Integer.toString(counter), listEle);
337 private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) {
342 for (String pathEle : path) {
343 sb.append(pathEle).append('.');
346 settings.put(sb.toString(), value.toString());
350 public void parseTosca (String fileName){
351 Map<String,String> map= new HashMap<String, String>();
354 for(String key:map.keySet()){
355 if(key.contains("policy.nodes.Root"))
359 else if(key.contains("policy.nodes")){
360 String wordToFind = "policy.nodes.";
361 int indexForPolicyNode=key.indexOf(wordToFind);
362 String subNodeString= key.substring(indexForPolicyNode+13, key.length());
364 stringBetweenDots(subNodeString,map.get(key));
366 else if(key.contains("policy.data")){
367 String wordToFind="policy.data.";
368 int indexForPolicyNode=key.indexOf(wordToFind);
369 String subNodeString= key.substring(indexForPolicyNode+12, key.length());
371 stringBetweenDotsForDataFields(subNodeString,map.get(key));
372 Iterator<String> itr= uniqueDataKeys.iterator();
373 while(itr.hasNext()){
374 logger.info(itr.next());
379 String attributeIndividualString="";
380 String userDefinedIndividualString="";
381 String referenceIndividualAttributes="";
383 String attributeString="";
384 String userDefinedString="";
385 String referenceAttributes="";
386 String listConstraints="";
388 for(String uniqueDataKey: uniqueDataKeys){
389 String[] uniqueDataKeySplit= uniqueDataKey.split("%");
390 userDefinedIndividualString=userDefinedIndividualString+uniqueDataKey+"=";
391 userDefinedIndividualString=userDefinedIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
392 for(String key:map.keySet()){
393 if(key.contains("policy.data")){
394 String containsKey= uniqueDataKeySplit[1]+".type";
395 if(key.contains(uniqueDataKeySplit[0])){
396 if(key.contains("default")){
397 userDefinedIndividualString=userDefinedIndividualString.replace("#B", map.get(key));
399 else if(key.contains("required")){
400 userDefinedIndividualString=userDefinedIndividualString.replace("#C", map.get(key));
402 else if(key.contains(containsKey)){
403 String typeValue= map.get(key);
404 userDefinedIndividualString=userDefinedIndividualString.replace("#A", typeValue);
410 if(userDefinedString!=""){
411 userDefinedString=userDefinedString+","+userDefinedIndividualString;
413 userDefinedString=userDefinedString+userDefinedIndividualString;
415 userDefinedIndividualString="";
417 logger.info("userDefinedString :"+userDefinedString);
419 HashMap<String,ArrayList<String>> mapKey= new HashMap<String,ArrayList<String>>();
420 String secondPartString="";
421 String firstPartString="";
422 for(String value: userDefinedString.split(",")){
423 String[] splitWithEquals= value.split("=");
424 secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1);
425 firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%"));
426 ArrayList<String> list;
427 if(mapKey.containsKey(firstPartString)){
428 list = mapKey.get(firstPartString);
429 list.add(secondPartString+"<"+splitWithEquals[1]);
431 list = new ArrayList<String>();
432 list.add(secondPartString+"<"+splitWithEquals[1]);
433 mapKey.put(firstPartString, list);
437 JSONObject mainObject= new JSONObject();;
439 for(String s: mapKey.keySet()){
440 json= new JSONObject();
441 List<String> value=mapKey.get(s);
442 for(String listValue:value){
443 String[] splitValue=listValue.split("<");
444 json.put(splitValue[0], splitValue[1]);
446 mainObject.put(s,json);
449 logger.info(mainObject);
451 Iterator<String> keysItr = mainObject.keys();
452 while(keysItr.hasNext()) {
453 String key = keysItr.next();
454 String value = mainObject.get(key).toString();
455 retmap.put(key, value);
458 for(String str:retmap.keySet()){
459 logger.info(str+":"+retmap.get(str));
462 String typeValueFromKey="";
463 boolean userDefinedDataType=false;
464 boolean isList=false;
465 for(String uniqueKey: uniqueKeys){
466 List<String> constraints= new ArrayList<String>();
467 logger.info("====================");
468 attributeIndividualString=attributeIndividualString+uniqueKey+"=";
469 attributeIndividualString=attributeIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
471 logger.info("UniqueStrings: "+uniqueKey);
472 for(String key:map.keySet()){
473 if(key.contains("policy.nodes.Root")||
474 key.contains("policy.data"))
478 else if(key.contains("policy.nodes")){
479 if(key.contains(uniqueKey)){
480 int p=key.lastIndexOf(".");
481 String firstLastOccurance=key.substring(0,p);
482 int p1=firstLastOccurance.lastIndexOf(".");
483 String secondLastOccurance= firstLastOccurance.substring(p1+1,firstLastOccurance.length());
484 if(secondLastOccurance.equals(uniqueKey)){
485 String checkTypeString= firstLastOccurance+".type";
486 typeValueFromKey= map.get(checkTypeString);
488 else if (key.contains("entry_schema")){
489 if(key.contains("constraints")){
490 constraints.add(map.get(key));
492 if(key.contains("type")){
494 String value= map.get(key);
495 if(! (value.contains("string")) ||
496 (value.contains("integer")) ||
497 (value.contains("boolean")) )
499 if(!key.contains("valid_values")){
500 String trimValue=value.substring(value.lastIndexOf(".")+1);
501 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-true";
502 attributeIndividualString="";
509 if(!(typeValueFromKey.equals("string")||
510 typeValueFromKey.equals("integer") ||
511 typeValueFromKey.equals("boolean")))
513 if(typeValueFromKey.equals("list")){
515 userDefinedDataType=false;
518 userDefinedDataType=true;
521 if(userDefinedDataType==false && isList==false){
522 if(key.contains("default")){
523 attributeIndividualString=attributeIndividualString.replace("#B", map.get(key));
525 else if(key.contains("required")){
526 attributeIndividualString=attributeIndividualString.replace("#C", map.get(key));
528 else if(key.contains("type")){
529 String typeValue= map.get(key);
530 attributeIndividualString=attributeIndividualString.replace("#A", typeValue);
533 else if(userDefinedDataType==true){
534 String checkTypeAndUpdate=key.substring(p+1);
535 if(checkTypeAndUpdate.equals("type")){
536 String value=map.get(key);
537 String trimValue=value.substring(value.lastIndexOf(".")+1);
538 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+trimValue+":MANY-false";
540 attributeIndividualString="";
546 if(constraints!=null &&constraints.isEmpty()==false){
548 listConstraints=uniqueKey.toUpperCase()+"=[";
550 for(String str:constraints){
551 listConstraints=listConstraints+str+",";
553 listConstraints+="],";
554 logger.info(listConstraints);
555 attributeIndividualString="";
556 referenceIndividualAttributes=referenceIndividualAttributes+uniqueKey+"="+uniqueKey.toUpperCase()+":MANY-false";
560 if(userDefinedDataType==false && isList==false){
561 if(attributeString!=""){
562 attributeString=attributeString+","+attributeIndividualString;
564 attributeString=attributeString+attributeIndividualString;
567 if(isList==true || userDefinedDataType==true){
568 if(referenceAttributes!=""){
569 referenceAttributes=referenceAttributes+","+referenceIndividualAttributes;
571 referenceAttributes=referenceAttributes+referenceIndividualAttributes;
573 logger.info("ReferenceAttributes: "+referenceAttributes);
576 logger.info("AttributeString: "+ attributeString);
577 logger.info("ListConstraints is: "+listConstraints);
579 attributeIndividualString="";
580 referenceIndividualAttributes="";
581 userDefinedDataType=false;
585 this.listConstraints=listConstraints;
586 this.referenceAttributes=referenceAttributes;
587 this.attributeString=attributeString;
588 } catch (IOException e) {
593 private String cleanUPJson(String json) {
594 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
595 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
596 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[]{"\""});
607 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
611 private JSONObject decodeContent(JsonNode jsonNode){
612 Iterator<JsonNode> jsonElements = jsonNode.elements();
613 Iterator<String> jsonKeys = jsonNode.fieldNames();
614 Map<String,String> element = new TreeMap<String,String>();
615 while(jsonElements.hasNext() && jsonKeys.hasNext()){
616 element.put(jsonKeys.next(), jsonElements.next().toString());
618 JSONObject jsonResult = new JSONObject();
619 JSONArray jsonArray = null;
620 String oldValue = null;
621 String nodeKey = null;
622 String arryKey = null;
623 Boolean isArray = false;
624 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
625 ObjectNode node = nodeFactory.objectNode();
626 String prevKey = null;
627 String presKey = null;
628 for(String key: element.keySet()){
629 if(key.contains(".")){
630 presKey = key.substring(0,key.indexOf("."));
631 }else if(key.contains("@")){
632 presKey = key.substring(0,key.indexOf("@"));
636 // first check if we are different from old.
637 logger.info(key+"\n");
638 if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
639 if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
640 jsonResult.put(oldValue, jsonArray);
641 jsonArray = new JSONArray();
643 }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){
644 jsonResult.put(oldValue, jsonArray);
646 jsonArray = new JSONArray();
651 if(key.contains(".")){
653 nodeKey = key.substring(0,key.indexOf("."));
655 if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
656 node.put(key.substring(key.indexOf(".")+1), element.get(key));
659 if(nodeKey.contains("@")){
661 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
663 if(nodeKey.endsWith("@0")){
665 jsonArray = new JSONArray();
667 if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
668 jsonArray.put(decodeContent(node));
670 if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){
671 jsonResult.put(arryKey, jsonArray);
672 jsonArray = new JSONArray();
673 }else if(!key.contains("@")){
674 jsonResult.put(arryKey, jsonArray);
675 jsonArray = new JSONArray();
677 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
680 jsonResult.put(nodeKey, decodeContent(node));
682 node = nodeFactory.objectNode();
684 nodeKey = key.substring(0,key.indexOf("."));
685 if(nodeKey.contains("@")){
686 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
688 node.put(key.substring(key.indexOf(".")+1), element.get(key));
690 }else if(node.size()!=0){
691 if(nodeKey.contains("@")){
693 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
695 if(nodeKey.endsWith("@0")){
697 jsonArray = new JSONArray();
699 if(arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
700 jsonArray.put(decodeContent(node));
702 jsonResult.put(arryKey, jsonArray);
703 jsonArray = new JSONArray();
704 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
707 jsonResult.put(nodeKey, decodeContent(node));
709 node = nodeFactory.objectNode();
710 if(key.contains("@")){
712 if(key.endsWith("@0")|| jsonArray==null){
713 jsonArray = new JSONArray();
715 }else if(!key.contains("@")){
720 oldValue = key.substring(0,key.indexOf("@"));
722 if(oldValue!=prevKey){
723 oldValue = key.substring(0,key.indexOf("@"));
725 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
726 jsonArray.put(element.get(key));
728 jsonResult.put(oldValue, jsonArray);
729 jsonArray = new JSONArray();
731 oldValue = key.substring(0,key.indexOf("@"));
733 jsonResult.put(key, element.get(key));
736 if(key.contains("@")){
738 if(key.endsWith("@0")|| jsonArray==null){
739 jsonArray = new JSONArray();
741 }else if(!key.contains("@")){
746 oldValue = key.substring(0,key.indexOf("@"));
748 if(oldValue!=prevKey){
749 oldValue = key.substring(0,key.indexOf("@"));
751 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
752 jsonArray.put(element.get(key));
754 jsonResult.put(oldValue, jsonArray);
755 jsonArray = new JSONArray();
757 oldValue = key.substring(0,key.indexOf("@"));
759 jsonResult.put(key, element.get(key));
764 if(nodeKey.contains("@")){
766 jsonArray = new JSONArray();
769 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
771 jsonArray.put(decodeContent(node));
772 jsonResult.put(arryKey, jsonArray);
775 jsonResult.put(nodeKey, decodeContent(node));
778 if(isArray && jsonArray.length() > 0){
779 jsonResult.put(oldValue, jsonArray);
784 @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
785 public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws Exception{
786 ObjectMapper mapper = new ObjectMapper();
787 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
788 JsonNode root = mapper.readTree(request.getReader());
790 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
791 String servicename = value.toString().split("-v")[0];
792 String version = null;
793 if (value.toString().contains("-v")){
794 version = value.toString().split("-v")[1];
796 MicroServiceModels returnModel = getAttributeObject(servicename, version);
798 String jsonModel = createMicroSeriveJson(returnModel);
800 response.setCharacterEncoding("UTF-8");
801 response.setContentType("application / json");
802 request.setCharacterEncoding("UTF-8");
803 List<Object> list = new ArrayList<>();
804 PrintWriter out = response.getWriter();
805 String responseString = mapper.writeValueAsString(returnModel);
806 JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
808 out.write(list.toString());
812 @SuppressWarnings({ "unchecked", "rawtypes" })
813 private String createMicroSeriveJson(MicroServiceModels returnModel) {
814 Map<String, String> attributeMap = new HashMap<String, String>();
815 Map<String, String> refAttributeMap = new HashMap<String, String>();
816 String attribute = returnModel.getAttributes();
817 if(attribute != null){
818 attribute = attribute.trim();
820 String refAttribute = returnModel.getRef_attributes();
821 if(refAttribute != null){
822 refAttribute = refAttribute.trim();
824 String enumAttribute = returnModel.getEnumValues();
825 if(enumAttribute != null){
826 enumAttribute = enumAttribute.trim();
828 if (!StringUtils.isEmpty(attribute)){
829 attributeMap = convert(attribute, ",");
831 if (!StringUtils.isEmpty(refAttribute)){
832 refAttributeMap = convert(refAttribute, ",");
835 Gson gson = new Gson();
837 String subAttributes = returnModel.getSub_attributes();
838 if(subAttributes != null){
839 subAttributes = subAttributes.trim();
843 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
845 JSONObject object = new JSONObject();
846 JSONArray array = new JSONArray();
848 for (Entry<String, String> keySet : attributeMap.entrySet()){
849 array = new JSONArray();
850 String value = keySet.getValue();
851 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
853 object.put(keySet.getKey().trim(), array);
855 object.put(keySet.getKey().trim(), value.trim());
859 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
860 array = new JSONArray();
861 String value = keySet.getValue().split(":")[0];
862 if (gsonObject.containsKey(value)){
863 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
864 array.put(recursiveReference(value, gsonObject, enumAttribute));
865 object.put(keySet.getKey().trim(), array);
867 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
870 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
871 array.put(value.trim());
872 object.put(keySet.getKey().trim(), array);
874 object.put(keySet.getKey().trim(), value.trim());
879 return object.toString();
882 @SuppressWarnings("unchecked")
883 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
884 JSONObject object = new JSONObject();
885 Map<String, String> map = new HashMap<String, String>();
886 Object returnClass = subAttributeMap.get(name);
887 map = (Map<String, String>) returnClass;
888 JSONArray array = new JSONArray();
890 for( Entry<String, String> m:map.entrySet()){
891 String[] splitValue = m.getValue().split(":");
892 array = new JSONArray();
893 if (subAttributeMap.containsKey(splitValue[0])){
894 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
895 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
896 object.put(m.getKey().trim(), array);
898 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
901 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
902 array.put(splitValue[0].trim());
903 object.put(m.getKey().trim(), array);
905 object.put(m.getKey().trim(), splitValue[0].trim());
914 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
915 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws Exception{
916 ObjectMapper mapper = new ObjectMapper();
917 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
918 JsonNode root = mapper.readTree(request.getReader());
920 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
921 String servicename = value.toString().split("-v")[0];
922 Set<String> returnList = getVersionList(servicename);
924 response.setCharacterEncoding("UTF-8");
925 response.setContentType("application / json");
926 request.setCharacterEncoding("UTF-8");
927 List<Object> list = new ArrayList<>();
928 PrintWriter out = response.getWriter();
929 String responseString = mapper.writeValueAsString(returnList);
930 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
932 out.write(list.toString());
936 private Set<String> getVersionList(String name) {
937 MicroServiceModels workingModel = new MicroServiceModels();
938 Set<String> list = new HashSet<String>();
939 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
940 for (int i = 0; i < microServiceModelsData.size(); i++) {
941 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
942 if (workingModel.getVersion()!=null){
943 list.add(workingModel.getVersion());
951 private MicroServiceModels getAttributeObject(String name, String version) {
952 MicroServiceModels workingModel = new MicroServiceModels();
953 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
954 for (int i = 0; i < microServiceModelsData.size(); i++) {
955 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
957 if (workingModel.getVersion()!=null){
958 if (workingModel.getVersion().equals(version)){
972 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
973 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
975 Map<String, Object> model = new HashMap<String, Object>();
976 ObjectMapper mapper = new ObjectMapper();
977 List<String> priorityList = new ArrayList<String>();
979 for (int i = 1; i < priorityCount; i++) {
980 priorityList.add(String.valueOf(i));
982 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
983 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
984 JSONObject j = new JSONObject(msg);
985 response.getWriter().write(j.toString());
992 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
993 if (policyAdapter.getPolicyData() instanceof PolicyType) {
994 Object policyData = policyAdapter.getPolicyData();
995 PolicyType policy = (PolicyType) policyData;
996 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
997 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
998 policyAdapter.setPolicyName(policyNameValue);
999 String description = "";
1001 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
1002 }catch(Exception e){
1003 description = policy.getDescription();
1005 policyAdapter.setPolicyDescription(description);
1006 // Get the target data under policy.
1007 TargetType target = policy.getTarget();
1008 if (target != null) {
1009 // Under target we have AnyOFType
1010 List<AnyOfType> anyOfList = target.getAnyOf();
1011 if (anyOfList != null) {
1012 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
1013 while (iterAnyOf.hasNext()) {
1014 AnyOfType anyOf = iterAnyOf.next();
1015 // Under AnyOFType we have AllOFType
1016 List<AllOfType> allOfList = anyOf.getAllOf();
1017 if (allOfList != null) {
1018 Iterator<AllOfType> iterAllOf = allOfList.iterator();
1019 while (iterAllOf.hasNext()) {
1020 AllOfType allOf = iterAllOf.next();
1021 // Under AllOFType we have Match
1022 List<MatchType> matchList = allOf.getMatch();
1023 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 attribute value and
1029 // attributeDesignator. So,finally down to the actual attribute.
1031 AttributeValueType attributeValue = match.getAttributeValue();
1032 String value = (String) attributeValue.getContent().get(0);
1033 AttributeDesignatorType designator = match.getAttributeDesignator();
1034 String attributeId = designator.getAttributeId();
1035 // First match in the target is EcompName, so set that value.
1036 if (attributeId.equals("ECOMPName")) {
1037 policyAdapter.setEcompName(value);
1039 if (attributeId.equals("ConfigName")){
1040 policyAdapter.setConfigName(value);
1042 if (attributeId.equals("uuid")){
1043 policyAdapter.setUuid(value);
1045 if (attributeId.equals("location")){
1046 policyAdapter.setLocation(value);
1048 if (attributeId.equals("RiskType")){
1049 policyAdapter.setRiskType(value);
1051 if (attributeId.equals("RiskLevel")){
1052 policyAdapter.setRiskLevel(value);
1054 if (attributeId.equals("guard")){
1055 policyAdapter.setGuard(value);
1057 if (attributeId.equals("TTLDate") && !value.contains("NA")){
1058 String newDate = convertDate(value, true);
1059 policyAdapter.setTtlDate(newDate);
1062 readFile(policyAdapter, entity);
1072 private String convertDate(String dateTTL, boolean portalType) {
1073 String formateDate = null;
1074 String[] date = dateTTL.split("T");
1075 String[] parts = date[0].split("-");
1077 formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
1081 public static Map<String, String> convert(String str, String split) {
1082 Map<String, String> map = new HashMap<String, String>();
1083 for(final String entry : str.split(split)) {
1084 String[] parts = entry.split("=");
1085 map.put(parts[0], parts[1]);
1091 @SuppressWarnings("unchecked")
1092 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1093 String policyScopeName = null;
1094 ObjectMapper mapper = new ObjectMapper();
1096 DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1097 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1098 policyAdapter.setPolicyScope(policyScopeName);
1100 policyAdapter.setPriority(msBody.getPriority());
1102 if (msBody.getVersion()!= null){
1103 policyAdapter.setServiceType(msBody.getService());
1104 policyAdapter.setVersion(msBody.getVersion());
1106 policyAdapter.setServiceType(msBody.getService());
1108 if(msBody.getContent() != null){
1109 LinkedHashMap<String, Object> data = new LinkedHashMap<String, Object>();
1110 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1111 readRecursivlyJSONContent(map, data);
1112 policyAdapter.setRuleData(data);
1115 } catch (Exception e) {
1121 @SuppressWarnings({ "rawtypes", "unchecked" })
1122 private void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1123 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1124 Object key = iterator.next();
1125 Object value = map.get(key);
1126 if(value instanceof LinkedHashMap<?, ?>){
1127 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<String, Object>();
1128 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1129 for(String objKey: secondObjec.keySet()){
1130 data.put(key+"." +objKey, secondObjec.get(objKey));
1132 }else if(value instanceof ArrayList){
1133 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1134 for(int i = 0; i < jsonArrayVal.size(); i++){
1135 Object arrayvalue = jsonArrayVal.get(i);
1136 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1137 LinkedHashMap<String, Object> newData = new LinkedHashMap<String, Object>();
1138 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1139 for(String objKey: newData.keySet()){
1140 data.put(key+"@"+i+"." +objKey, newData.get(objKey));
1142 }else if(arrayvalue instanceof ArrayList){
1143 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1144 for(int j = 0; j < jsonArrayVal1.size(); j++){
1145 Object arrayvalue1 = jsonArrayVal1.get(i);
1146 data.put(key+"@"+j, arrayvalue1.toString());
1149 data.put(key+"@"+i, arrayvalue.toString());
1153 data.put(key.toString(), value.toString());
1158 private String getPolicyScope(String value) {
1159 GroupPolicyScopeList pScope = new GroupPolicyScopeList();
1160 List<Object> groupList= commonClassDao.getData(GroupPolicyScopeList.class);
1161 if(groupList.size() > 0){
1162 for(int i = 0 ; i < groupList.size() ; i ++){
1163 pScope = (GroupPolicyScopeList) groupList.get(i);
1164 if (pScope.getGroupList().equals(value)){
1169 return pScope.getGroupName();
1172 //Convert the map values and set into JSON body
1173 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1174 Map<String, String> attribute = new HashMap<String, String>();
1178 for (Entry<String, String> entry : attributesMap.entrySet()) {
1179 key = entry.getKey();
1180 value = entry.getValue();
1181 attribute.put(key, value);
1183 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1184 key = entryRef.getKey();
1185 value = entryRef.getValue().toString();
1186 attribute.put(key, value);
1188 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1189 key = entryList.getKey();
1190 value = entryList.getValue().toString();
1191 attribute.put(key, value);
1193 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1194 key = arrayList.getKey();
1196 for (Object textList : arrayList.getValue()){
1198 temp = "[" + textList;
1200 temp = temp + "," + textList;
1203 attribute.put(key, temp+ "]");
1209 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1210 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws Exception{
1211 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1212 boolean zip = false;
1214 for (FileItem item : items) {
1215 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1216 this.newModel = new MicroServiceModels();
1218 File file = new File(item.getName());
1219 OutputStream outputStream = new FileOutputStream(file);
1220 IOUtils.copy(item.getInputStream(), outputStream);
1221 outputStream.close();
1222 this.newFile = file.toString();
1223 this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
1225 if (this.newFile.toString().contains("-v")){
1226 if (item.getName().endsWith(".zip")){
1227 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
1229 }else if(item.getName().endsWith(".yml")){
1230 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
1234 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
1238 }catch(Exception e){
1239 logger.error("Upload error : " + e);
1244 List<File> fileList = new ArrayList<File>();;
1245 this.directory = "model";
1247 extractFolder(this.newFile);
1248 fileList = listModelFiles(this.directory);
1249 }else if (yml==true){
1250 parseTosca(this.newFile);
1252 File file = new File(this.newFile);
1255 String modelType= "";
1258 //Process Main Model file first
1259 classMap = new HashMap<String,MSAttributeObject>();
1260 for (File file : fileList) {
1261 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1262 retreiveDependency(file.toString(), true);
1266 modelList = createList();
1268 cleanUp(this.newFile);
1272 modelList.add(this.newModel.getModelName());
1273 String className=this.newModel.getModelName();
1274 MSAttributeObject msAttributes= new MSAttributeObject();
1275 msAttributes.setClassName(className);
1277 HashMap<String, String> returnAttributeList =new HashMap<String, String>();
1278 returnAttributeList.put(className, this.attributeString);
1279 msAttributes.setAttribute(returnAttributeList);
1281 msAttributes.setSubClass(this.retmap);
1283 HashMap<String, String> returnReferenceList =new HashMap<String, String>();
1284 //String[] referenceArray=this.referenceAttributes.split("=");
1285 returnReferenceList.put(className, this.referenceAttributes);
1286 msAttributes.setRefAttribute(returnReferenceList);
1288 if(this.listConstraints!=""){
1289 HashMap<String, String> enumList =new HashMap<String, String>();
1290 String[] listArray=this.listConstraints.split("=");
1291 enumList.put(listArray[0], listArray[1]);
1292 msAttributes.setEnumType(enumList);
1295 classMap=new HashMap<String,MSAttributeObject>();
1296 classMap.put(className, msAttributes);
1300 PrintWriter out = response.getWriter();
1302 response.setCharacterEncoding("UTF-8");
1303 response.setContentType("application / json");
1304 request.setCharacterEncoding("UTF-8");
1306 ObjectMapper mapper = new ObjectMapper();
1307 JSONObject j = new JSONObject();
1308 j.put("classListDatas", modelList);
1309 j.put("modelDatas", mapper.writeValueAsString(classMap));
1310 j.put("modelType", modelType);
1311 out.write(j.toString());
1315 * Unzip file and store in the model directory for processing
1317 @SuppressWarnings("rawtypes")
1318 private void extractFolder(String zipFile ) {
1320 File file = new File(zipFile);
1324 zip = new ZipFile(file);
1325 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1326 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1327 checkZipDirectory(this.directory);
1328 new File(newPath).mkdir();
1329 Enumeration zipFileEntries = zip.entries();
1331 // Process each entry
1332 while (zipFileEntries.hasMoreElements()){
1333 // grab a zip file entry
1334 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1335 String currentEntry = entry.getName();
1336 File destFile = new File("model" + File.separator + currentEntry);
1337 File destinationParent = destFile.getParentFile();
1339 destinationParent.mkdirs();
1341 if (!entry.isDirectory()){
1342 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1344 byte data[] = new byte[BUFFER];
1345 FileOutputStream fos = new FileOutputStream(destFile);
1346 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
1347 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1348 dest.write(data, 0, currentByte);
1355 if (currentEntry.endsWith(".zip")){
1356 extractFolder(destFile.getAbsolutePath());
1359 } catch (IOException e) {
1360 logger.error("Failed to unzip model file " + zipFile);
1364 private void retreiveDependency(String workingFile, Boolean modelClass) {
1366 MSModelUtils utils = new MSModelUtils(PolicyController.msEcompName, PolicyController.msPolicyName);
1367 HashMap<String, MSAttributeObject> tempMap = new HashMap<String, MSAttributeObject>();
1369 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1371 classMap.putAll(tempMap);
1372 logger.info(tempMap);
1378 private List<File> listModelFiles(String directoryName) {
1379 File directory = new File(directoryName);
1380 List<File> resultList = new ArrayList<File>();
1381 File[] fList = directory.listFiles();
1382 for (File file : fList) {
1383 if (file.isFile()) {
1384 resultList.add(file);
1385 } else if (file.isDirectory()) {
1386 dirDependencyList.add(file.getName());
1387 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1393 private void cleanUp(String path) {
1396 FileUtils.forceDelete(new File(path));
1397 } catch (IOException e) {
1398 logger.error("Failed to delete folder " + path);
1403 private void checkZipDirectory(String zipDirectory) {
1404 Path path = Paths.get(zipDirectory);
1406 if (Files.exists(path)) {
1407 cleanUp(zipDirectory);
1411 private List<String> createList() {
1412 List<String> list = new ArrayList<String>();
1413 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1414 if (cMap.getValue().isPolicyTempalate()){
1415 list.add(cMap.getKey());
1420 if (list.isEmpty()){
1421 if (classMap.containsKey(this.newModel.getModelName())){
1422 list.add(this.newModel.getModelName());
1432 class DCAEMicroServiceObject {
1434 public String service;
1435 public String location;
1437 public String policyName;
1438 public String description;
1439 public String configName;
1440 public String templateVersion;
1441 public String version;
1442 public String priority;
1443 public String policyScope;
1444 public String riskType;
1445 public String riskLevel;
1446 public String guard = null;
1448 public String getGuard() {
1451 public void setGuard(String guard) {
1454 public String getRiskType() {
1457 public void setRiskType(String riskType) {
1458 this.riskType = riskType;
1460 public String getRiskLevel() {
1463 public void setRiskLevel(String riskLevel) {
1464 this.riskLevel = riskLevel;
1466 public String getPolicyScope() {
1469 public void setPolicyScope(String policyScope) {
1470 this.policyScope = policyScope;
1473 public String getPriority() {
1476 public void setPriority(String priority) {
1477 this.priority = priority;
1479 public String getVersion() {
1482 public void setVersion(String version) {
1483 this.version = version;
1485 private Object content;
1488 public String getPolicyName() {
1491 public void setPolicyName(String policyName) {
1492 this.policyName = policyName;
1494 public String getDescription() {
1497 public void setDescription(String description) {
1498 this.description = description;
1500 public String getConfigName() {
1503 public void setConfigName(String configName) {
1504 this.configName = configName;
1506 public Object getContent() {
1509 public void setContent(Object content) {
1510 this.content = content;
1513 public String getService() {
1516 public void setService(String service) {
1517 this.service = service;
1519 public String getLocation() {
1522 public void setLocation(String location) {
1523 this.location = location;
1526 public String getUuid() {
1529 public void setUuid(String uuid) {
1532 public String getTemplateVersion() {
1533 return templateVersion;
1535 public void setTemplateVersion(String templateVersion) {
1536 this.templateVersion = templateVersion;