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<>();
111 private List<String> dirDependencyList = new ArrayList<>();
112 private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
113 //Tosca Model related Datastructure.
114 String referenceAttributes;
115 String attributeString;
116 String listConstraints;
117 String subAttributeString;
118 HashMap<String, Object> retmap = new HashMap<>();
119 Set<String> uniqueKeys= new HashSet<>();
120 Set<String> uniqueDataKeys= new HashSet<>();
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<>();
132 private Map<String, LinkedList<String>> arrayTextList = new HashMap<>();
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<>();
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<>();
354 for(String key:map.keySet()){
355 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));
374 String userDefinedIndividualString="";
375 String userDefinedString="";
377 for(String uniqueDataKey: uniqueDataKeys){
378 String[] uniqueDataKeySplit= uniqueDataKey.split("%");
379 userDefinedIndividualString=userDefinedIndividualString+uniqueDataKey+"=";
380 userDefinedIndividualString=userDefinedIndividualString+"#A:defaultValue-#B:required-#C:MANY-false";
381 for(String key:map.keySet()){
382 if(key.contains("policy.data")){
383 String containsKey= uniqueDataKeySplit[1]+".type";
384 if(key.contains(uniqueDataKeySplit[0])){
385 if(key.contains("default")){
386 userDefinedIndividualString=userDefinedIndividualString.replace("#B", map.get(key));
388 else if(key.contains("required")){
389 userDefinedIndividualString=userDefinedIndividualString.replace("#C", map.get(key));
391 else if(key.contains(containsKey)){
392 String typeValue= map.get(key);
393 userDefinedIndividualString=userDefinedIndividualString.replace("#A", typeValue);
398 if(userDefinedString!=""){
399 userDefinedString=userDefinedString+","+userDefinedIndividualString;
401 userDefinedString=userDefinedString+userDefinedIndividualString;
403 userDefinedIndividualString="";
405 LOGGER.info("userDefinedString :"+userDefinedString);
407 HashMap<String,ArrayList<String>> mapKeyUserdefined= new HashMap<>();
408 String secondPartString="";
409 String firstPartString="";
410 for(String value: userDefinedString.split(",")){
411 String[] splitWithEquals= value.split("=");
412 secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1);
413 firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%"));
414 ArrayList<String> list;
415 if(mapKeyUserdefined.containsKey(firstPartString)){
416 list = mapKeyUserdefined.get(firstPartString);
417 list.add(secondPartString+"<"+splitWithEquals[1]);
419 list = new ArrayList<String>();
420 list.add(secondPartString+"<"+splitWithEquals[1]);
421 mapKeyUserdefined.put(firstPartString, list);
425 JSONObject mainObject= new JSONObject();;
427 for(String s: mapKeyUserdefined.keySet()){
428 json= new JSONObject();
429 List<String> value=mapKeyUserdefined.get(s);
430 for(String listValue:value){
431 String[] splitValue=listValue.split("<");
432 json.put(splitValue[0], splitValue[1]);
434 mainObject.put(s,json);
436 Iterator<String> keysItr = mainObject.keys();
437 while(keysItr.hasNext()) {
438 String key = keysItr.next();
439 String value = mainObject.get(key).toString();
440 retmap.put(key, value);
443 LOGGER.info("#############################################################################");
444 LOGGER.info(mainObject);
445 LOGGER.info("###############################################################################");
447 HashMap<String,HashMap<String,String>> mapKey= new HashMap<>();
448 for(String uniqueKey: uniqueKeys){
449 HashMap<String,String> hm;
451 for(String key:map.keySet()){
452 if(key.contains(uniqueKey)){
453 if(mapKey.containsKey(uniqueKey)){
454 hm = mapKey.get(uniqueKey);
455 String keyStr= key.substring(key.lastIndexOf(".")+1);
456 String valueStr= map.get(key);
457 if(keyStr.equals("type")){
458 if(!key.contains("entry_schema")){
459 hm.put(keyStr,valueStr);
462 hm.put(keyStr,valueStr);
465 hm = new HashMap<>();
466 String keyStr= key.substring(key.lastIndexOf(".")+1);
467 String valueStr= map.get(key);
468 if(keyStr.equals("type")){
469 if(!key.contains("entry_schema")){
470 hm.put(keyStr,valueStr);
473 hm.put(keyStr,valueStr);
475 mapKey.put(uniqueKey, hm);
481 StringBuilder attributeStringBuilder= new StringBuilder();
482 StringBuilder referenceStringBuilder= new StringBuilder();
483 StringBuilder listBuffer= new StringBuilder();
485 List<String> constraints= new ArrayList<>();
486 for(String keySetString: mapKey.keySet()){
487 HashMap<String,String> keyValues=mapKey.get(keySetString);
488 if(keyValues.get("type").equalsIgnoreCase("string")|| keyValues.get("type").equalsIgnoreCase("integer")){
489 StringBuilder attributeIndividualStringBuilder= new StringBuilder();
490 attributeIndividualStringBuilder.append(keySetString+"=");
491 attributeIndividualStringBuilder.append(keyValues.get("type")+":defaultValue-");
492 attributeIndividualStringBuilder.append(keyValues.get("default")+":required-");
493 attributeIndividualStringBuilder.append(keyValues.get("required")+":MANY-false");
494 attributeStringBuilder.append(attributeIndividualStringBuilder+",");
496 else if(keyValues.get("type").equalsIgnoreCase("list")){
498 Set<String> keys= keyValues.keySet();
499 Iterator<String> itr=keys.iterator();
500 while(itr.hasNext()){
501 String key= itr.next().toString();
502 if((!key.equals("type"))){
503 String value= keyValues.get(key);
504 //The "." in the value determines if its a string or a user defined type.
505 if (!value.contains(".")){
507 constraints.add(keyValues.get(key));
509 //This is user defined string
510 String trimValue=value.substring(value.lastIndexOf(".")+1);
511 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
512 referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true");
513 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
518 //User defined Datatype.
519 String value=keyValues.get("type");
520 String trimValue=value.substring(value.lastIndexOf(".")+1);
521 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
522 referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
523 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
525 if(constraints!=null &&constraints.isEmpty()==false){
527 listBuffer.append(keySetString.toUpperCase()+"=[");
528 for(String str:constraints){
529 listBuffer.append(str+",");
531 listBuffer.append("]#");
532 LOGGER.info(listBuffer);
535 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
536 referenceIndividualStringBuilder.append(keySetString+"="+keySetString.toUpperCase()+":MANY-false");
537 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
542 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
543 LOGGER.info("Whole attribute String is:"+attributeStringBuilder);
544 LOGGER.info("Whole reference String is:"+referenceStringBuilder);
545 LOGGER.info("List String is:"+listBuffer);
546 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
547 this.listConstraints=listBuffer.toString();
548 this.referenceAttributes=referenceStringBuilder.toString();
549 this.attributeString=attributeStringBuilder.toString();
551 } catch (IOException e) {
556 private String cleanUPJson(String json) {
557 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
558 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
559 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"});
561 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"});
562 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"});
563 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
564 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"{", "}\""}, new String[]{"{", "}"});
565 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""});
566 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\""}, new String[]{""});
567 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\""}, new String[]{"\""});
568 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\\\\\\"}, new String[]{"\""});
569 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\\""}, new String[]{"\""});
570 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
574 private JSONObject decodeContent(JsonNode jsonNode){
575 Iterator<JsonNode> jsonElements = jsonNode.elements();
576 Iterator<String> jsonKeys = jsonNode.fieldNames();
577 Map<String,String> element = new TreeMap<>();
578 while(jsonElements.hasNext() && jsonKeys.hasNext()){
579 element.put(jsonKeys.next(), jsonElements.next().toString());
581 JSONObject jsonResult = new JSONObject();
582 JSONArray jsonArray = null;
583 String oldValue = null;
584 String nodeKey = null;
585 String arryKey = null;
586 Boolean isArray = false;
587 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
588 ObjectNode node = nodeFactory.objectNode();
589 String prevKey = null;
590 String presKey = null;
591 for(String key: element.keySet()){
592 if(key.contains(".")){
593 presKey = key.substring(0,key.indexOf("."));
594 }else if(key.contains("@")){
595 presKey = key.substring(0,key.indexOf("@"));
599 // first check if we are different from old.
600 LOGGER.info(key+"\n");
601 if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
602 if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
603 jsonResult.put(oldValue, jsonArray);
604 jsonArray = new JSONArray();
606 }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){
607 jsonResult.put(oldValue, jsonArray);
609 jsonArray = new JSONArray();
614 if(key.contains(".")){
616 nodeKey = key.substring(0,key.indexOf("."));
618 if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
619 node.put(key.substring(key.indexOf(".")+1), element.get(key));
622 if(nodeKey.contains("@")){
624 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
626 if(nodeKey.endsWith("@0")){
628 jsonArray = new JSONArray();
630 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
631 jsonArray.put(decodeContent(node));
633 if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){
634 jsonResult.put(arryKey, jsonArray);
635 jsonArray = new JSONArray();
636 }else if(!key.contains("@")){
637 jsonResult.put(arryKey, jsonArray);
638 jsonArray = new JSONArray();
640 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
643 jsonResult.put(nodeKey, decodeContent(node));
645 node = nodeFactory.objectNode();
647 nodeKey = key.substring(0,key.indexOf("."));
648 if(nodeKey.contains("@")){
649 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
651 node.put(key.substring(key.indexOf(".")+1), element.get(key));
653 }else if(node.size()!=0){
654 if(nodeKey.contains("@")){
656 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
658 if(nodeKey.endsWith("@0")){
660 jsonArray = new JSONArray();
662 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
663 jsonArray.put(decodeContent(node));
665 jsonResult.put(arryKey, jsonArray);
666 jsonArray = new JSONArray();
667 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
670 jsonResult.put(nodeKey, decodeContent(node));
672 node = nodeFactory.objectNode();
673 if(key.contains("@")){
675 if(key.endsWith("@0")|| jsonArray==null){
676 jsonArray = new JSONArray();
678 }else if(!key.contains("@")){
683 oldValue = key.substring(0,key.indexOf("@"));
685 if(oldValue!=prevKey){
686 oldValue = key.substring(0,key.indexOf("@"));
688 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
689 jsonArray.put(element.get(key));
691 jsonResult.put(oldValue, jsonArray);
692 jsonArray = new JSONArray();
694 oldValue = key.substring(0,key.indexOf("@"));
696 jsonResult.put(key, element.get(key));
699 if(key.contains("@")){
701 if(key.endsWith("@0")|| jsonArray==null){
702 jsonArray = new JSONArray();
704 }else if(!key.contains("@")){
709 oldValue = key.substring(0,key.indexOf("@"));
711 if(oldValue!=prevKey){
712 oldValue = key.substring(0,key.indexOf("@"));
714 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
715 jsonArray.put(element.get(key));
717 jsonResult.put(oldValue, jsonArray);
718 jsonArray = new JSONArray();
720 oldValue = key.substring(0,key.indexOf("@"));
722 jsonResult.put(key, element.get(key));
727 if(nodeKey.contains("@")){
729 jsonArray = new JSONArray();
732 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
734 jsonArray.put(decodeContent(node));
735 jsonResult.put(arryKey, jsonArray);
738 jsonResult.put(nodeKey, decodeContent(node));
741 if(isArray && jsonArray.length() > 0){
742 jsonResult.put(oldValue, jsonArray);
747 @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
748 public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws Exception{
749 ObjectMapper mapper = new ObjectMapper();
750 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
751 JsonNode root = mapper.readTree(request.getReader());
753 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
754 String servicename = value.toString().split("-v")[0];
755 String version = null;
756 if (value.toString().contains("-v")){
757 version = value.toString().split("-v")[1];
759 MicroServiceModels returnModel = getAttributeObject(servicename, version);
761 String jsonModel = createMicroSeriveJson(returnModel);
763 response.setCharacterEncoding("UTF-8");
764 response.setContentType("application / json");
765 request.setCharacterEncoding("UTF-8");
766 List<Object> list = new ArrayList<>();
767 PrintWriter out = response.getWriter();
768 String responseString = mapper.writeValueAsString(returnModel);
769 JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
771 out.write(list.toString());
775 @SuppressWarnings({ "unchecked", "rawtypes" })
776 private String createMicroSeriveJson(MicroServiceModels returnModel) {
777 Map<String, String> attributeMap = new HashMap<>();
778 Map<String, String> refAttributeMap = new HashMap<>();
779 String attribute = returnModel.getAttributes();
780 if(attribute != null){
781 attribute = attribute.trim();
783 String refAttribute = returnModel.getRef_attributes();
784 if(refAttribute != null){
785 refAttribute = refAttribute.trim();
787 String enumAttribute = returnModel.getEnumValues();
788 if(enumAttribute != null){
789 enumAttribute = enumAttribute.trim();
791 if (!StringUtils.isEmpty(attribute)){
792 attributeMap = convert(attribute, ",");
794 if (!StringUtils.isEmpty(refAttribute)){
795 refAttributeMap = convert(refAttribute, ",");
798 Gson gson = new Gson();
800 String subAttributes = returnModel.getSub_attributes();
801 if(subAttributes != null){
802 subAttributes = subAttributes.trim();
806 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
808 JSONObject object = new JSONObject();
809 JSONArray array = new JSONArray();
811 for (Entry<String, String> keySet : attributeMap.entrySet()){
812 array = new JSONArray();
813 String value = keySet.getValue();
814 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
816 object.put(keySet.getKey().trim(), array);
818 object.put(keySet.getKey().trim(), value.trim());
822 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
823 array = new JSONArray();
824 String value = keySet.getValue().split(":")[0];
825 if (gsonObject.containsKey(value)){
826 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
827 array.put(recursiveReference(value, gsonObject, enumAttribute));
828 object.put(keySet.getKey().trim(), array);
830 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
833 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
834 array.put(value.trim());
835 object.put(keySet.getKey().trim(), array);
837 object.put(keySet.getKey().trim(), value.trim());
842 return object.toString();
845 @SuppressWarnings("unchecked")
846 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
847 JSONObject object = new JSONObject();
848 Map<String, String> map = new HashMap<>();
849 Object returnClass = subAttributeMap.get(name);
850 map = (Map<String, String>) returnClass;
851 JSONArray array = new JSONArray();
853 for( Entry<String, String> m:map.entrySet()){
854 String[] splitValue = m.getValue().split(":");
855 array = new JSONArray();
856 if (subAttributeMap.containsKey(splitValue[0])){
857 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
858 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
859 object.put(m.getKey().trim(), array);
861 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
864 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
865 array.put(splitValue[0].trim());
866 object.put(m.getKey().trim(), array);
868 object.put(m.getKey().trim(), splitValue[0].trim());
877 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
878 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws Exception{
879 ObjectMapper mapper = new ObjectMapper();
880 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
881 JsonNode root = mapper.readTree(request.getReader());
883 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
884 String servicename = value.toString().split("-v")[0];
885 Set<String> returnList = getVersionList(servicename);
887 response.setCharacterEncoding("UTF-8");
888 response.setContentType("application / json");
889 request.setCharacterEncoding("UTF-8");
890 List<Object> list = new ArrayList<>();
891 PrintWriter out = response.getWriter();
892 String responseString = mapper.writeValueAsString(returnList);
893 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
895 out.write(list.toString());
899 private Set<String> getVersionList(String name) {
900 MicroServiceModels workingModel = new MicroServiceModels();
901 Set<String> list = new HashSet<>();
902 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
903 for (int i = 0; i < microServiceModelsData.size(); i++) {
904 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
905 if (workingModel.getVersion()!=null){
906 list.add(workingModel.getVersion());
914 private MicroServiceModels getAttributeObject(String name, String version) {
915 MicroServiceModels workingModel = new MicroServiceModels();
916 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
917 for (int i = 0; i < microServiceModelsData.size(); i++) {
918 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
920 if (workingModel.getVersion()!=null){
921 if (workingModel.getVersion().equals(version)){
935 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
936 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
938 Map<String, Object> model = new HashMap<>();
939 ObjectMapper mapper = new ObjectMapper();
940 List<String> priorityList = new ArrayList<>();
942 for (int i = 1; i < priorityCount; i++) {
943 priorityList.add(String.valueOf(i));
945 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
946 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
947 JSONObject j = new JSONObject(msg);
948 response.getWriter().write(j.toString());
955 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
956 if (policyAdapter.getPolicyData() instanceof PolicyType) {
957 Object policyData = policyAdapter.getPolicyData();
958 PolicyType policy = (PolicyType) policyData;
959 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
960 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
961 policyAdapter.setPolicyName(policyNameValue);
962 String description = "";
964 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
966 description = policy.getDescription();
968 policyAdapter.setPolicyDescription(description);
969 // Get the target data under policy.
970 TargetType target = policy.getTarget();
971 if (target != null) {
972 // Under target we have AnyOFType
973 List<AnyOfType> anyOfList = target.getAnyOf();
974 if (anyOfList != null) {
975 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
976 while (iterAnyOf.hasNext()) {
977 AnyOfType anyOf = iterAnyOf.next();
978 // Under AnyOFType we have AllOFType
979 List<AllOfType> allOfList = anyOf.getAllOf();
980 if (allOfList != null) {
981 Iterator<AllOfType> iterAllOf = allOfList.iterator();
982 while (iterAllOf.hasNext()) {
983 AllOfType allOf = iterAllOf.next();
984 // Under AllOFType we have Match
985 List<MatchType> matchList = allOf.getMatch();
986 if (matchList != null) {
987 Iterator<MatchType> iterMatch = matchList.iterator();
988 while (matchList.size()>1 && iterMatch.hasNext()) {
989 MatchType match = iterMatch.next();
991 // Under the match we have attribute value and
992 // attributeDesignator. So,finally down to the actual attribute.
994 AttributeValueType attributeValue = match.getAttributeValue();
995 String value = (String) attributeValue.getContent().get(0);
996 AttributeDesignatorType designator = match.getAttributeDesignator();
997 String attributeId = designator.getAttributeId();
998 // First match in the target is EcompName, so set that value.
999 if (attributeId.equals("ECOMPName")) {
1000 policyAdapter.setEcompName(value);
1002 if (attributeId.equals("ConfigName")){
1003 policyAdapter.setConfigName(value);
1005 if (attributeId.equals("uuid")){
1006 policyAdapter.setUuid(value);
1008 if (attributeId.equals("location")){
1009 policyAdapter.setLocation(value);
1011 if (attributeId.equals("RiskType")){
1012 policyAdapter.setRiskType(value);
1014 if (attributeId.equals("RiskLevel")){
1015 policyAdapter.setRiskLevel(value);
1017 if (attributeId.equals("guard")){
1018 policyAdapter.setGuard(value);
1020 if (attributeId.equals("TTLDate") && !value.contains("NA")){
1021 String newDate = convertDate(value, true);
1022 policyAdapter.setTtlDate(newDate);
1025 readFile(policyAdapter, entity);
1035 private String convertDate(String dateTTL, boolean portalType) {
1036 String formateDate = null;
1037 String[] date = dateTTL.split("T");
1038 String[] parts = date[0].split("-");
1040 formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
1044 public static Map<String, String> convert(String str, String split) {
1045 Map<String, String> map = new HashMap<>();
1046 for(final String entry : str.split(split)) {
1047 String[] parts = entry.split("=");
1048 map.put(parts[0], parts[1]);
1054 @SuppressWarnings("unchecked")
1055 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1056 String policyScopeName = null;
1057 ObjectMapper mapper = new ObjectMapper();
1059 DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1060 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1061 policyAdapter.setPolicyScope(policyScopeName);
1063 policyAdapter.setPriority(msBody.getPriority());
1065 if (msBody.getVersion()!= null){
1066 policyAdapter.setServiceType(msBody.getService());
1067 policyAdapter.setVersion(msBody.getVersion());
1069 policyAdapter.setServiceType(msBody.getService());
1071 if(msBody.getContent() != null){
1072 LinkedHashMap<String, Object> data = new LinkedHashMap<>();
1073 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1074 readRecursivlyJSONContent(map, data);
1075 policyAdapter.setRuleData(data);
1078 } catch (Exception e) {
1084 @SuppressWarnings({ "rawtypes", "unchecked" })
1085 private void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1086 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1087 Object key = iterator.next();
1088 Object value = map.get(key);
1089 if(value instanceof LinkedHashMap<?, ?>){
1090 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
1091 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1092 for(String objKey: secondObjec.keySet()){
1093 data.put(key+"." +objKey, secondObjec.get(objKey));
1095 }else if(value instanceof ArrayList){
1096 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1097 for(int i = 0; i < jsonArrayVal.size(); i++){
1098 Object arrayvalue = jsonArrayVal.get(i);
1099 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1100 LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
1101 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1102 for(String objKey: newData.keySet()){
1103 data.put(key+"@"+i+"." +objKey, newData.get(objKey));
1105 }else if(arrayvalue instanceof ArrayList){
1106 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1107 for(int j = 0; j < jsonArrayVal1.size(); j++){
1108 Object arrayvalue1 = jsonArrayVal1.get(i);
1109 data.put(key+"@"+j, arrayvalue1.toString());
1112 data.put(key+"@"+i, arrayvalue.toString());
1116 data.put(key.toString(), value.toString());
1121 private String getPolicyScope(String value) {
1122 GroupPolicyScopeList pScope = new GroupPolicyScopeList();
1123 List<Object> groupList= commonClassDao.getData(GroupPolicyScopeList.class);
1124 if(groupList.size() > 0){
1125 for(int i = 0 ; i < groupList.size() ; i ++){
1126 pScope = (GroupPolicyScopeList) groupList.get(i);
1127 if (pScope.getGroupList().equals(value)){
1132 return pScope.getGroupName();
1135 //Convert the map values and set into JSON body
1136 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1137 Map<String, String> attribute = new HashMap<>();
1141 for (Entry<String, String> entry : attributesMap.entrySet()) {
1142 key = entry.getKey();
1143 value = entry.getValue();
1144 attribute.put(key, value);
1146 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1147 key = entryRef.getKey();
1148 value = entryRef.getValue().toString();
1149 attribute.put(key, value);
1151 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1152 key = entryList.getKey();
1153 value = entryList.getValue().toString();
1154 attribute.put(key, value);
1156 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1157 key = arrayList.getKey();
1159 for (Object textList : arrayList.getValue()){
1161 temp = "[" + textList;
1163 temp = temp + "," + textList;
1166 attribute.put(key, temp+ "]");
1172 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1173 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws Exception{
1174 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1175 boolean zip = false;
1177 for (FileItem item : items) {
1178 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1179 this.newModel = new MicroServiceModels();
1181 File file = new File(item.getName());
1182 OutputStream outputStream = new FileOutputStream(file);
1183 IOUtils.copy(item.getInputStream(), outputStream);
1184 outputStream.close();
1185 this.newFile = file.toString();
1186 this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
1188 if (this.newFile.toString().contains("-v")){
1189 if (item.getName().endsWith(".zip")){
1190 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
1192 }else if(item.getName().endsWith(".yml")){
1193 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
1197 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
1201 }catch(Exception e){
1202 LOGGER.error("Upload error : " + e);
1207 List<File> fileList = new ArrayList<>();;
1208 this.directory = "model";
1210 extractFolder(this.newFile);
1211 fileList = listModelFiles(this.directory);
1212 }else if (yml==true){
1213 parseTosca(this.newFile);
1215 File file = new File(this.newFile);
1218 String modelType= "";
1221 //Process Main Model file first
1222 classMap = new HashMap<>();
1223 for (File file : fileList) {
1224 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1225 retreiveDependency(file.toString(), true);
1229 modelList = createList();
1231 cleanUp(this.newFile);
1235 modelList.add(this.newModel.getModelName());
1236 String className=this.newModel.getModelName();
1237 MSAttributeObject msAttributes= new MSAttributeObject();
1238 msAttributes.setClassName(className);
1240 HashMap<String, String> returnAttributeList =new HashMap<>();
1241 returnAttributeList.put(className, this.attributeString);
1242 msAttributes.setAttribute(returnAttributeList);
1244 msAttributes.setSubClass(this.retmap);
1246 HashMap<String, String> returnReferenceList =new HashMap<>();
1247 //String[] referenceArray=this.referenceAttributes.split("=");
1248 returnReferenceList.put(className, this.referenceAttributes);
1249 msAttributes.setRefAttribute(returnReferenceList);
1251 if(this.listConstraints!=""){
1252 HashMap<String, String> enumList =new HashMap<>();
1253 String[] listArray=this.listConstraints.split("#");
1254 for(String str:listArray){
1255 String[] strArr= str.split("=");
1256 if(strArr.length>1){
1257 enumList.put(strArr[0], strArr[1]);
1260 msAttributes.setEnumType(enumList);
1263 classMap=new HashMap<>();
1264 classMap.put(className, msAttributes);
1268 PrintWriter out = response.getWriter();
1270 response.setCharacterEncoding("UTF-8");
1271 response.setContentType("application / json");
1272 request.setCharacterEncoding("UTF-8");
1274 ObjectMapper mapper = new ObjectMapper();
1275 JSONObject j = new JSONObject();
1276 j.put("classListDatas", modelList);
1277 j.put("modelDatas", mapper.writeValueAsString(classMap));
1278 j.put("modelType", modelType);
1279 out.write(j.toString());
1283 * Unzip file and store in the model directory for processing
1285 @SuppressWarnings("rawtypes")
1286 private void extractFolder(String zipFile ) {
1288 File file = new File(zipFile);
1292 zip = new ZipFile(file);
1293 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1294 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1295 checkZipDirectory(this.directory);
1296 new File(newPath).mkdir();
1297 Enumeration zipFileEntries = zip.entries();
1299 // Process each entry
1300 while (zipFileEntries.hasMoreElements()){
1301 // grab a zip file entry
1302 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1303 String currentEntry = entry.getName();
1304 File destFile = new File("model" + File.separator + currentEntry);
1305 File destinationParent = destFile.getParentFile();
1307 destinationParent.mkdirs();
1309 if (!entry.isDirectory()){
1310 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1312 byte data[] = new byte[BUFFER];
1313 FileOutputStream fos = new FileOutputStream(destFile);
1314 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
1315 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1316 dest.write(data, 0, currentByte);
1323 if (currentEntry.endsWith(".zip")){
1324 extractFolder(destFile.getAbsolutePath());
1327 } catch (IOException e) {
1328 LOGGER.error("Failed to unzip model file " + zipFile);
1333 } catch (IOException e) {
1334 LOGGER.error("Exception Occured While closing zipfile " + e);
1339 private void retreiveDependency(String workingFile, Boolean modelClass) {
1341 MSModelUtils utils = new MSModelUtils(PolicyController.msEcompName, PolicyController.msPolicyName);
1342 HashMap<String, MSAttributeObject> tempMap = new HashMap<>();
1344 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1346 classMap.putAll(tempMap);
1347 LOGGER.info(tempMap);
1353 private List<File> listModelFiles(String directoryName) {
1354 File directory = new File(directoryName);
1355 List<File> resultList = new ArrayList<>();
1356 File[] fList = directory.listFiles();
1357 for (File file : fList) {
1358 if (file.isFile()) {
1359 resultList.add(file);
1360 } else if (file.isDirectory()) {
1361 dirDependencyList.add(file.getName());
1362 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1368 private void cleanUp(String path) {
1371 FileUtils.forceDelete(new File(path));
1372 } catch (IOException e) {
1373 LOGGER.error("Failed to delete folder " + path);
1378 private void checkZipDirectory(String zipDirectory) {
1379 Path path = Paths.get(zipDirectory);
1381 if (Files.exists(path)) {
1382 cleanUp(zipDirectory);
1386 private List<String> createList() {
1387 List<String> list = new ArrayList<>();
1388 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1389 if (cMap.getValue().isPolicyTempalate()){
1390 list.add(cMap.getKey());
1395 if (list.isEmpty()){
1396 if (classMap.containsKey(this.newModel.getModelName())){
1397 list.add(this.newModel.getModelName());
1407 class DCAEMicroServiceObject {
1409 public String service;
1410 public String location;
1412 public String policyName;
1413 public String description;
1414 public String configName;
1415 public String templateVersion;
1416 public String version;
1417 public String priority;
1418 public String policyScope;
1419 public String riskType;
1420 public String riskLevel;
1421 public String guard = null;
1423 public String getGuard() {
1426 public void setGuard(String guard) {
1429 public String getRiskType() {
1432 public void setRiskType(String riskType) {
1433 this.riskType = riskType;
1435 public String getRiskLevel() {
1438 public void setRiskLevel(String riskLevel) {
1439 this.riskLevel = riskLevel;
1441 public String getPolicyScope() {
1444 public void setPolicyScope(String policyScope) {
1445 this.policyScope = policyScope;
1448 public String getPriority() {
1451 public void setPriority(String priority) {
1452 this.priority = priority;
1454 public String getVersion() {
1457 public void setVersion(String version) {
1458 this.version = version;
1460 private Object content;
1463 public String getPolicyName() {
1466 public void setPolicyName(String policyName) {
1467 this.policyName = policyName;
1469 public String getDescription() {
1472 public void setDescription(String description) {
1473 this.description = description;
1475 public String getConfigName() {
1478 public void setConfigName(String configName) {
1479 this.configName = configName;
1481 public Object getContent() {
1484 public void setContent(Object content) {
1485 this.content = content;
1488 public String getService() {
1491 public void setService(String service) {
1492 this.service = service;
1494 public String getLocation() {
1497 public void setLocation(String location) {
1498 this.location = location;
1501 public String getUuid() {
1504 public void setUuid(String uuid) {
1507 public String getTemplateVersion() {
1508 return templateVersion;
1510 public void setTemplateVersion(String templateVersion) {
1511 this.templateVersion = templateVersion;