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;
108 public static CommonClassDao getCommonClassDao() {
109 return commonClassDao;
112 public static void setCommonClassDao(CommonClassDao commonClassDao) {
113 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
116 private MicroServiceModels newModel;
117 private String newFile;
118 private String directory;
119 private List<String> modelList = new ArrayList<>();
120 private List<String> dirDependencyList = new ArrayList<>();
121 private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
122 //Tosca Model related Datastructure.
123 String referenceAttributes;
124 String attributeString;
125 String listConstraints;
126 String subAttributeString;
127 HashMap<String, Object> retmap = new HashMap<>();
128 Set<String> uniqueKeys= new HashSet<>();
129 Set<String> uniqueDataKeys= new HashSet<>();
132 private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
133 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
136 public CreateDcaeMicroServiceController(){}
138 protected PolicyRestAdapter policyAdapter = null;
139 private int priorityCount;
140 private Map<String, String> attributesListRefMap = new HashMap<>();
141 private Map<String, LinkedList<String>> arrayTextList = new HashMap<>();
143 public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
145 String jsonContent = null;
147 jsonContent = decodeContent(root.get("policyJSON")).toString();
148 constructJson(policyData, jsonContent);
150 LOGGER.error("Error while decoding microservice content");
156 private GroupPolicyScopeList getPolicyObject(String policyScope) {
157 GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
161 private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent) {
162 ObjectWriter om = new ObjectMapper().writer();
164 DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
165 MicroServiceModels returnModel = new MicroServiceModels();
166 microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS));
167 if(policyAdapter.getServiceType() !=null){
168 microServiceObject.setService(policyAdapter.getServiceType());
169 microServiceObject.setVersion(policyAdapter.getVersion());
170 returnModel = getAttributeObject(microServiceObject.getService(), microServiceObject.getVersion());
172 if (returnModel.getAnnotation()==null || returnModel.getAnnotation().isEmpty()){
173 if(policyAdapter.getUuid()!=null){
174 microServiceObject.setUuid(policyAdapter.getUuid());
176 if(policyAdapter.getLocation()!=null){
177 microServiceObject.setLocation(policyAdapter.getLocation());
179 if(policyAdapter.getConfigName()!=null){
180 microServiceObject.setConfigName(policyAdapter.getConfigName());
182 GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope());
183 if(policyScopeValue!=null){
184 microServiceObject.setPolicyScope(policyScopeValue.getGroupList());
188 if(policyAdapter.getPolicyName()!=null){
189 microServiceObject.setPolicyName(policyAdapter.getPolicyName());
191 if(policyAdapter.getPolicyDescription()!=null){
192 microServiceObject.setDescription(policyAdapter.getPolicyDescription());
194 if (policyAdapter.getPriority()!=null){
195 microServiceObject.setPriority(policyAdapter.getPriority());
197 microServiceObject.setPriority("9999");
200 if (policyAdapter.getRiskLevel()!=null){
201 microServiceObject.setRiskLevel(policyAdapter.getRiskLevel());
203 if (policyAdapter.getRiskType()!=null){
204 microServiceObject.setRiskType(policyAdapter.getRiskType());
206 if (policyAdapter.getGuard()!=null){
207 microServiceObject.setGuard(policyAdapter.getGuard());
209 microServiceObject.setContent(jsonContent);
212 json = om.writeValueAsString(microServiceObject);
213 } catch (JsonProcessingException e) {
214 LOGGER.error("Error writing out the object");
217 String cleanJson = cleanUPJson(json);
218 cleanJson = removeNullAttributes(cleanJson);
219 policyAdapter.setJsonBody(cleanJson);
220 return policyAdapter;
223 private String removeNullAttributes(String cleanJson) {
224 ObjectMapper mapper = new ObjectMapper();
227 JsonNode rootNode = mapper.readTree(cleanJson);
228 JsonNode returnNode = mapper.readTree(cleanJson);
229 Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
230 boolean remove = false;
231 while (fieldsIterator.hasNext()) {
232 Map.Entry<String, JsonNode> field = fieldsIterator.next();
233 final String key = field.getKey();
234 final JsonNode value = field.getValue();
235 if (value==null || value.isNull()){
236 ((ObjectNode) returnNode).remove(key);
241 cleanJson = returnNode.toString();
243 } catch (IOException e) {
244 LOGGER.error("Error writing out the JsonNode");
249 // Second index of dot should be returned.
250 public int stringBetweenDots(String str,String value){
251 String stringToSearch=str;
252 String[]ss=stringToSearch.split("\\.");
256 uniqueKeys.add(ss[2]);
260 return uniqueKeys.size();
263 public void stringBetweenDotsForDataFields(String str,String value){
264 String stringToSearch=str;
265 String[]ss=stringToSearch.split("\\.");
270 uniqueDataKeys.add(ss[0]+"%"+ss[2]);
276 public Map<String, String> load(String fileName) throws IOException {
277 File newConfiguration = new File(fileName);
278 InputStream is = null;
280 is = new FileInputStream(newConfiguration);
281 } catch (FileNotFoundException e) {
285 Yaml yaml = new Yaml();
286 @SuppressWarnings("unchecked")
287 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is);
288 StringBuilder sb = new StringBuilder();
289 Map<String, String> settings = new HashMap<>();
290 if (yamlMap == null) {
293 List<String> path = new ArrayList<String>();
294 serializeMap(settings, sb, path, yamlMap);
298 public Map<String, String> load(byte[] source) throws IOException {
299 Yaml yaml = new Yaml();
300 @SuppressWarnings("unchecked")
301 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(source.toString());
302 StringBuilder sb = new StringBuilder();
303 Map<String, String> settings = new HashMap<String, String>();
304 if (yamlMap == null) {
307 List<String> path = new ArrayList<String>();
308 serializeMap(settings, sb, path, yamlMap);
312 @SuppressWarnings({ "unchecked", "rawtypes" })
313 private void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) {
314 for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) {
315 if (entry.getValue() instanceof Map) {
316 path.add((String) entry.getKey());
317 serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue());
318 path.remove(path.size() - 1);
319 } else if (entry.getValue() instanceof List) {
320 path.add((String) entry.getKey());
321 serializeList(settings, sb, path, (List) entry.getValue());
322 path.remove(path.size() - 1);
324 serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue());
329 @SuppressWarnings("unchecked")
330 private void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List<String> yamlList) {
332 for (Object listEle : yamlList) {
333 if (listEle instanceof Map) {
334 path.add(Integer.toString(counter));
335 serializeMap(settings, sb, path, (Map<Object, Object>) listEle);
336 path.remove(path.size() - 1);
337 } else if (listEle instanceof List) {
338 path.add(Integer.toString(counter));
339 serializeList(settings, sb, path, (List<String>) listEle);
340 path.remove(path.size() - 1);
342 serializeValue(settings, sb, path, Integer.toString(counter), listEle);
348 private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) {
353 for (String pathEle : path) {
354 sb.append(pathEle).append('.');
357 settings.put(sb.toString(), value.toString());
361 public void parseTosca (String fileName){
362 Map<String,String> map= new HashMap<>();
365 for(String key:map.keySet()){
366 if(key.contains("policy.nodes.Root")){
369 else if(key.contains("policy.nodes")){
370 String wordToFind = "policy.nodes.";
371 int indexForPolicyNode=key.indexOf(wordToFind);
372 String subNodeString= key.substring(indexForPolicyNode+13, key.length());
374 stringBetweenDots(subNodeString,map.get(key));
376 else if(key.contains("policy.data")){
377 String wordToFind="policy.data.";
378 int indexForPolicyNode=key.indexOf(wordToFind);
379 String subNodeString= key.substring(indexForPolicyNode+12, key.length());
381 stringBetweenDotsForDataFields(subNodeString,map.get(key));
385 String userDefinedIndividualString="";
386 String userDefinedString="";
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);
409 if(userDefinedString!=""){
410 userDefinedString=userDefinedString+","+userDefinedIndividualString;
412 userDefinedString=userDefinedString+userDefinedIndividualString;
414 userDefinedIndividualString="";
416 LOGGER.info("userDefinedString :"+userDefinedString);
418 HashMap<String,ArrayList<String>> mapKeyUserdefined= new HashMap<>();
419 String secondPartString="";
420 String firstPartString="";
421 for(String value: userDefinedString.split(",")){
422 String[] splitWithEquals= value.split("=");
423 secondPartString=splitWithEquals[0].substring(splitWithEquals[0].indexOf("%")+1);
424 firstPartString=splitWithEquals[0].substring(0, splitWithEquals[0].indexOf("%"));
425 ArrayList<String> list;
426 if(mapKeyUserdefined.containsKey(firstPartString)){
427 list = mapKeyUserdefined.get(firstPartString);
428 list.add(secondPartString+"<"+splitWithEquals[1]);
430 list = new ArrayList<String>();
431 list.add(secondPartString+"<"+splitWithEquals[1]);
432 mapKeyUserdefined.put(firstPartString, list);
436 JSONObject mainObject= new JSONObject();;
438 for(String s: mapKeyUserdefined.keySet()){
439 json= new JSONObject();
440 List<String> value=mapKeyUserdefined.get(s);
441 for(String listValue:value){
442 String[] splitValue=listValue.split("<");
443 json.put(splitValue[0], splitValue[1]);
445 mainObject.put(s,json);
447 Iterator<String> keysItr = mainObject.keys();
448 while(keysItr.hasNext()) {
449 String key = keysItr.next();
450 String value = mainObject.get(key).toString();
451 retmap.put(key, value);
454 LOGGER.info("#############################################################################");
455 LOGGER.info(mainObject);
456 LOGGER.info("###############################################################################");
458 HashMap<String,HashMap<String,String>> mapKey= new HashMap<>();
459 for(String uniqueKey: uniqueKeys){
460 HashMap<String,String> hm;
462 for(String key:map.keySet()){
463 if(key.contains(uniqueKey)){
464 if(mapKey.containsKey(uniqueKey)){
465 hm = mapKey.get(uniqueKey);
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);
476 hm = new HashMap<>();
477 String keyStr= key.substring(key.lastIndexOf(".")+1);
478 String valueStr= map.get(key);
479 if(keyStr.equals("type")){
480 if(!key.contains("entry_schema")){
481 hm.put(keyStr,valueStr);
484 hm.put(keyStr,valueStr);
486 mapKey.put(uniqueKey, hm);
492 StringBuilder attributeStringBuilder= new StringBuilder();
493 StringBuilder referenceStringBuilder= new StringBuilder();
494 StringBuilder listBuffer= new StringBuilder();
496 List<String> constraints= new ArrayList<>();
497 for(String keySetString: mapKey.keySet()){
498 HashMap<String,String> keyValues=mapKey.get(keySetString);
499 if(keyValues.get("type").equalsIgnoreCase("string")|| keyValues.get("type").equalsIgnoreCase("integer")){
500 StringBuilder attributeIndividualStringBuilder= new StringBuilder();
501 attributeIndividualStringBuilder.append(keySetString+"=");
502 attributeIndividualStringBuilder.append(keyValues.get("type")+":defaultValue-");
503 attributeIndividualStringBuilder.append(keyValues.get("default")+":required-");
504 attributeIndividualStringBuilder.append(keyValues.get("required")+":MANY-false");
505 attributeStringBuilder.append(attributeIndividualStringBuilder+",");
507 else if(keyValues.get("type").equalsIgnoreCase("list")){
509 Set<String> keys= keyValues.keySet();
510 Iterator<String> itr=keys.iterator();
511 while(itr.hasNext()){
512 String key= itr.next().toString();
513 if((!key.equals("type"))){
514 String value= keyValues.get(key);
515 //The "." in the value determines if its a string or a user defined type.
516 if (!value.contains(".")){
518 constraints.add(keyValues.get(key));
520 //This is user defined string
521 String trimValue=value.substring(value.lastIndexOf(".")+1);
522 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
523 referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true");
524 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
529 //User defined Datatype.
530 String value=keyValues.get("type");
531 String trimValue=value.substring(value.lastIndexOf(".")+1);
532 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
533 referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
534 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
536 if(constraints!=null &&constraints.isEmpty()==false){
538 listBuffer.append(keySetString.toUpperCase()+"=[");
539 for(String str:constraints){
540 listBuffer.append(str+",");
542 listBuffer.append("]#");
543 LOGGER.info(listBuffer);
546 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
547 referenceIndividualStringBuilder.append(keySetString+"="+keySetString.toUpperCase()+":MANY-false");
548 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
553 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
554 LOGGER.info("Whole attribute String is:"+attributeStringBuilder);
555 LOGGER.info("Whole reference String is:"+referenceStringBuilder);
556 LOGGER.info("List String is:"+listBuffer);
557 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
558 this.listConstraints=listBuffer.toString();
559 this.referenceAttributes=referenceStringBuilder.toString();
560 this.attributeString=attributeStringBuilder.toString();
562 } catch (IOException e) {
567 private String cleanUPJson(String json) {
568 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
569 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
570 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"});
572 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"});
573 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"});
574 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
575 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"{", "}\""}, new String[]{"{", "}"});
576 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""});
577 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\""}, new String[]{""});
578 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\""}, new String[]{"\""});
579 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\\\\\\"}, new String[]{"\""});
580 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\\""}, new String[]{"\""});
581 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
585 private JSONObject decodeContent(JsonNode jsonNode){
586 Iterator<JsonNode> jsonElements = jsonNode.elements();
587 Iterator<String> jsonKeys = jsonNode.fieldNames();
588 Map<String,String> element = new TreeMap<>();
589 while(jsonElements.hasNext() && jsonKeys.hasNext()){
590 element.put(jsonKeys.next(), jsonElements.next().toString());
592 JSONObject jsonResult = new JSONObject();
593 JSONArray jsonArray = null;
594 String oldValue = null;
595 String nodeKey = null;
596 String arryKey = null;
597 Boolean isArray = false;
598 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
599 ObjectNode node = nodeFactory.objectNode();
600 String prevKey = null;
601 String presKey = null;
602 for(String key: element.keySet()){
603 if(key.contains(".")){
604 presKey = key.substring(0,key.indexOf("."));
605 }else if(key.contains("@")){
606 presKey = key.substring(0,key.indexOf("@"));
610 // first check if we are different from old.
611 LOGGER.info(key+"\n");
612 if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
613 if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
614 jsonResult.put(oldValue, jsonArray);
615 jsonArray = new JSONArray();
617 }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){
618 jsonResult.put(oldValue, jsonArray);
620 jsonArray = new JSONArray();
625 if(key.contains(".")){
627 nodeKey = key.substring(0,key.indexOf("."));
629 if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
630 node.put(key.substring(key.indexOf(".")+1), element.get(key));
633 if(nodeKey.contains("@")){
635 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
637 if(nodeKey.endsWith("@0")){
639 jsonArray = new JSONArray();
641 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
642 jsonArray.put(decodeContent(node));
644 if(key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))){
645 jsonResult.put(arryKey, jsonArray);
646 jsonArray = new JSONArray();
647 }else if(!key.contains("@")){
648 jsonResult.put(arryKey, jsonArray);
649 jsonArray = new JSONArray();
651 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
654 jsonResult.put(nodeKey, decodeContent(node));
656 node = nodeFactory.objectNode();
658 nodeKey = key.substring(0,key.indexOf("."));
659 if(nodeKey.contains("@")){
660 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
662 node.put(key.substring(key.indexOf(".")+1), element.get(key));
664 }else if(node.size()!=0){
665 if(nodeKey.contains("@")){
667 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
669 if(nodeKey.endsWith("@0")){
671 jsonArray = new JSONArray();
673 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
674 jsonArray.put(decodeContent(node));
676 jsonResult.put(arryKey, jsonArray);
677 jsonArray = new JSONArray();
678 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
681 jsonResult.put(nodeKey, decodeContent(node));
683 node = nodeFactory.objectNode();
684 if(key.contains("@")){
686 if(key.endsWith("@0")|| jsonArray==null){
687 jsonArray = new JSONArray();
689 }else if(!key.contains("@")){
694 oldValue = key.substring(0,key.indexOf("@"));
696 if(oldValue!=prevKey){
697 oldValue = key.substring(0,key.indexOf("@"));
699 if(oldValue.equals(key.substring(0,key.indexOf("@")))){
700 jsonArray.put(element.get(key));
702 jsonResult.put(oldValue, jsonArray);
703 jsonArray = new JSONArray();
705 oldValue = key.substring(0,key.indexOf("@"));
707 jsonResult.put(key, element.get(key));
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));
738 if(nodeKey.contains("@")){
740 jsonArray = new JSONArray();
743 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
745 jsonArray.put(decodeContent(node));
746 jsonResult.put(arryKey, jsonArray);
749 jsonResult.put(nodeKey, decodeContent(node));
752 if(isArray && jsonArray.length() > 0){
753 jsonResult.put(oldValue, jsonArray);
758 @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
759 public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws Exception{
760 ObjectMapper mapper = new ObjectMapper();
761 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
762 JsonNode root = mapper.readTree(request.getReader());
764 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
765 String servicename = value.toString().split("-v")[0];
766 String version = null;
767 if (value.toString().contains("-v")){
768 version = value.toString().split("-v")[1];
770 MicroServiceModels returnModel = getAttributeObject(servicename, version);
772 String jsonModel = createMicroSeriveJson(returnModel);
774 response.setCharacterEncoding("UTF-8");
775 response.setContentType("application / json");
776 request.setCharacterEncoding("UTF-8");
777 List<Object> list = new ArrayList<>();
778 PrintWriter out = response.getWriter();
779 String responseString = mapper.writeValueAsString(returnModel);
780 JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
782 out.write(list.toString());
786 @SuppressWarnings({ "unchecked", "rawtypes" })
787 private String createMicroSeriveJson(MicroServiceModels returnModel) {
788 Map<String, String> attributeMap = new HashMap<>();
789 Map<String, String> refAttributeMap = new HashMap<>();
790 String attribute = returnModel.getAttributes();
791 if(attribute != null){
792 attribute = attribute.trim();
794 String refAttribute = returnModel.getRef_attributes();
795 if(refAttribute != null){
796 refAttribute = refAttribute.trim();
798 String enumAttribute = returnModel.getEnumValues();
799 if(enumAttribute != null){
800 enumAttribute = enumAttribute.trim();
802 if (!StringUtils.isEmpty(attribute)){
803 attributeMap = convert(attribute, ",");
805 if (!StringUtils.isEmpty(refAttribute)){
806 refAttributeMap = convert(refAttribute, ",");
809 Gson gson = new Gson();
811 String subAttributes = returnModel.getSub_attributes();
812 if(subAttributes != null){
813 subAttributes = subAttributes.trim();
817 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
819 JSONObject object = new JSONObject();
820 JSONArray array = new JSONArray();
822 for (Entry<String, String> keySet : attributeMap.entrySet()){
823 array = new JSONArray();
824 String value = keySet.getValue();
825 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
827 object.put(keySet.getKey().trim(), array);
829 object.put(keySet.getKey().trim(), value.trim());
833 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
834 array = new JSONArray();
835 String value = keySet.getValue().split(":")[0];
836 if (gsonObject.containsKey(value)){
837 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
838 array.put(recursiveReference(value, gsonObject, enumAttribute));
839 object.put(keySet.getKey().trim(), array);
841 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
844 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
845 array.put(value.trim());
846 object.put(keySet.getKey().trim(), array);
848 object.put(keySet.getKey().trim(), value.trim());
853 return object.toString();
856 @SuppressWarnings("unchecked")
857 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
858 JSONObject object = new JSONObject();
859 Map<String, String> map = new HashMap<>();
860 Object returnClass = subAttributeMap.get(name);
861 map = (Map<String, String>) returnClass;
862 JSONArray array = new JSONArray();
864 for( Entry<String, String> m:map.entrySet()){
865 String[] splitValue = m.getValue().split(":");
866 array = new JSONArray();
867 if (subAttributeMap.containsKey(splitValue[0])){
868 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
869 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
870 object.put(m.getKey().trim(), array);
872 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
875 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
876 array.put(splitValue[0].trim());
877 object.put(m.getKey().trim(), array);
879 object.put(m.getKey().trim(), splitValue[0].trim());
888 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
889 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws Exception{
890 ObjectMapper mapper = new ObjectMapper();
891 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
892 JsonNode root = mapper.readTree(request.getReader());
894 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
895 String servicename = value.toString().split("-v")[0];
896 Set<String> returnList = getVersionList(servicename);
898 response.setCharacterEncoding("UTF-8");
899 response.setContentType("application / json");
900 request.setCharacterEncoding("UTF-8");
901 List<Object> list = new ArrayList<>();
902 PrintWriter out = response.getWriter();
903 String responseString = mapper.writeValueAsString(returnList);
904 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
906 out.write(list.toString());
910 private Set<String> getVersionList(String name) {
911 MicroServiceModels workingModel = new MicroServiceModels();
912 Set<String> list = new HashSet<>();
913 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
914 for (int i = 0; i < microServiceModelsData.size(); i++) {
915 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
916 if (workingModel.getVersion()!=null){
917 list.add(workingModel.getVersion());
925 private MicroServiceModels getAttributeObject(String name, String version) {
926 MicroServiceModels workingModel = new MicroServiceModels();
927 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
928 for (int i = 0; i < microServiceModelsData.size(); i++) {
929 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
931 if (workingModel.getVersion()!=null){
932 if (workingModel.getVersion().equals(version)){
946 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
947 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
949 Map<String, Object> model = new HashMap<>();
950 ObjectMapper mapper = new ObjectMapper();
951 List<String> priorityList = new ArrayList<>();
953 for (int i = 1; i < priorityCount; i++) {
954 priorityList.add(String.valueOf(i));
956 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
957 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
958 JSONObject j = new JSONObject(msg);
959 response.getWriter().write(j.toString());
966 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
967 if (policyAdapter.getPolicyData() instanceof PolicyType) {
968 Object policyData = policyAdapter.getPolicyData();
969 PolicyType policy = (PolicyType) policyData;
970 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
971 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
972 policyAdapter.setPolicyName(policyNameValue);
973 String description = "";
975 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
977 description = policy.getDescription();
979 policyAdapter.setPolicyDescription(description);
980 // Get the target data under policy.
981 TargetType target = policy.getTarget();
982 if (target != null) {
983 // Under target we have AnyOFType
984 List<AnyOfType> anyOfList = target.getAnyOf();
985 if (anyOfList != null) {
986 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
987 while (iterAnyOf.hasNext()) {
988 AnyOfType anyOf = iterAnyOf.next();
989 // Under AnyOFType we have AllOFType
990 List<AllOfType> allOfList = anyOf.getAllOf();
991 if (allOfList != null) {
992 Iterator<AllOfType> iterAllOf = allOfList.iterator();
993 while (iterAllOf.hasNext()) {
994 AllOfType allOf = iterAllOf.next();
995 // Under AllOFType we have Match
996 List<MatchType> matchList = allOf.getMatch();
997 if (matchList != null) {
998 Iterator<MatchType> iterMatch = matchList.iterator();
999 while (matchList.size()>1 && iterMatch.hasNext()) {
1000 MatchType match = iterMatch.next();
1002 // Under the match we have attribute value and
1003 // attributeDesignator. So,finally down to the actual attribute.
1005 AttributeValueType attributeValue = match.getAttributeValue();
1006 String value = (String) attributeValue.getContent().get(0);
1007 AttributeDesignatorType designator = match.getAttributeDesignator();
1008 String attributeId = designator.getAttributeId();
1009 // First match in the target is EcompName, so set that value.
1010 if (attributeId.equals("ECOMPName")) {
1011 policyAdapter.setEcompName(value);
1013 if (attributeId.equals("ConfigName")){
1014 policyAdapter.setConfigName(value);
1016 if (attributeId.equals("uuid")){
1017 policyAdapter.setUuid(value);
1019 if (attributeId.equals("location")){
1020 policyAdapter.setLocation(value);
1022 if (attributeId.equals("RiskType")){
1023 policyAdapter.setRiskType(value);
1025 if (attributeId.equals("RiskLevel")){
1026 policyAdapter.setRiskLevel(value);
1028 if (attributeId.equals("guard")){
1029 policyAdapter.setGuard(value);
1031 if (attributeId.equals("TTLDate") && !value.contains("NA")){
1032 String newDate = convertDate(value, true);
1033 policyAdapter.setTtlDate(newDate);
1036 readFile(policyAdapter, entity);
1046 private String convertDate(String dateTTL, boolean portalType) {
1047 String formateDate = null;
1048 String[] date = dateTTL.split("T");
1049 String[] parts = date[0].split("-");
1051 formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
1055 public static Map<String, String> convert(String str, String split) {
1056 Map<String, String> map = new HashMap<>();
1057 for(final String entry : str.split(split)) {
1058 String[] parts = entry.split("=");
1059 map.put(parts[0], parts[1]);
1065 @SuppressWarnings("unchecked")
1066 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1067 String policyScopeName = null;
1068 ObjectMapper mapper = new ObjectMapper();
1070 DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1071 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1072 policyAdapter.setPolicyScope(policyScopeName);
1074 policyAdapter.setPriority(msBody.getPriority());
1076 if (msBody.getVersion()!= null){
1077 policyAdapter.setServiceType(msBody.getService());
1078 policyAdapter.setVersion(msBody.getVersion());
1080 policyAdapter.setServiceType(msBody.getService());
1082 if(msBody.getContent() != null){
1083 LinkedHashMap<String, Object> data = new LinkedHashMap<>();
1084 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1085 readRecursivlyJSONContent(map, data);
1086 policyAdapter.setRuleData(data);
1089 } catch (Exception e) {
1095 @SuppressWarnings({ "rawtypes", "unchecked" })
1096 private void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1097 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1098 Object key = iterator.next();
1099 Object value = map.get(key);
1100 if(value instanceof LinkedHashMap<?, ?>){
1101 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
1102 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1103 for(String objKey: secondObjec.keySet()){
1104 data.put(key+"." +objKey, secondObjec.get(objKey));
1106 }else if(value instanceof ArrayList){
1107 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1108 for(int i = 0; i < jsonArrayVal.size(); i++){
1109 Object arrayvalue = jsonArrayVal.get(i);
1110 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1111 LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
1112 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1113 for(String objKey: newData.keySet()){
1114 data.put(key+"@"+i+"." +objKey, newData.get(objKey));
1116 }else if(arrayvalue instanceof ArrayList){
1117 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1118 for(int j = 0; j < jsonArrayVal1.size(); j++){
1119 Object arrayvalue1 = jsonArrayVal1.get(i);
1120 data.put(key+"@"+j, arrayvalue1.toString());
1123 data.put(key+"@"+i, arrayvalue.toString());
1127 data.put(key.toString(), value.toString());
1132 private String getPolicyScope(String value) {
1133 GroupPolicyScopeList pScope = new GroupPolicyScopeList();
1134 List<Object> groupList= commonClassDao.getData(GroupPolicyScopeList.class);
1135 if(groupList.size() > 0){
1136 for(int i = 0 ; i < groupList.size() ; i ++){
1137 pScope = (GroupPolicyScopeList) groupList.get(i);
1138 if (pScope.getGroupList().equals(value)){
1143 return pScope.getGroupName();
1146 //Convert the map values and set into JSON body
1147 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1148 Map<String, String> attribute = new HashMap<>();
1152 for (Entry<String, String> entry : attributesMap.entrySet()) {
1153 key = entry.getKey();
1154 value = entry.getValue();
1155 attribute.put(key, value);
1157 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1158 key = entryRef.getKey();
1159 value = entryRef.getValue().toString();
1160 attribute.put(key, value);
1162 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1163 key = entryList.getKey();
1164 value = entryList.getValue().toString();
1165 attribute.put(key, value);
1167 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1168 key = arrayList.getKey();
1170 for (Object textList : arrayList.getValue()){
1172 temp = "[" + textList;
1174 temp = temp + "," + textList;
1177 attribute.put(key, temp+ "]");
1183 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1184 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws Exception{
1185 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1186 boolean zip = false;
1188 for (FileItem item : items) {
1189 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1190 this.newModel = new MicroServiceModels();
1192 File file = new File(item.getName());
1193 OutputStream outputStream = new FileOutputStream(file);
1194 IOUtils.copy(item.getInputStream(), outputStream);
1195 outputStream.close();
1196 this.newFile = file.toString();
1197 this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
1199 if (this.newFile.toString().contains("-v")){
1200 if (item.getName().endsWith(".zip")){
1201 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
1203 }else if(item.getName().endsWith(".yml")){
1204 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
1208 this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
1212 }catch(Exception e){
1213 LOGGER.error("Upload error : " + e);
1218 List<File> fileList = new ArrayList<>();;
1219 this.directory = "model";
1221 extractFolder(this.newFile);
1222 fileList = listModelFiles(this.directory);
1223 }else if (yml==true){
1224 parseTosca(this.newFile);
1226 File file = new File(this.newFile);
1229 String modelType= "";
1232 //Process Main Model file first
1233 classMap = new HashMap<>();
1234 for (File file : fileList) {
1235 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1236 retreiveDependency(file.toString(), true);
1240 modelList = createList();
1242 cleanUp(this.newFile);
1246 modelList.add(this.newModel.getModelName());
1247 String className=this.newModel.getModelName();
1248 MSAttributeObject msAttributes= new MSAttributeObject();
1249 msAttributes.setClassName(className);
1251 HashMap<String, String> returnAttributeList =new HashMap<>();
1252 returnAttributeList.put(className, this.attributeString);
1253 msAttributes.setAttribute(returnAttributeList);
1255 msAttributes.setSubClass(this.retmap);
1257 HashMap<String, String> returnReferenceList =new HashMap<>();
1258 //String[] referenceArray=this.referenceAttributes.split("=");
1259 returnReferenceList.put(className, this.referenceAttributes);
1260 msAttributes.setRefAttribute(returnReferenceList);
1262 if(this.listConstraints!=""){
1263 HashMap<String, String> enumList =new HashMap<>();
1264 String[] listArray=this.listConstraints.split("#");
1265 for(String str:listArray){
1266 String[] strArr= str.split("=");
1267 if(strArr.length>1){
1268 enumList.put(strArr[0], strArr[1]);
1271 msAttributes.setEnumType(enumList);
1274 classMap=new HashMap<>();
1275 classMap.put(className, msAttributes);
1279 PrintWriter out = response.getWriter();
1281 response.setCharacterEncoding("UTF-8");
1282 response.setContentType("application / json");
1283 request.setCharacterEncoding("UTF-8");
1285 ObjectMapper mapper = new ObjectMapper();
1286 JSONObject j = new JSONObject();
1287 j.put("classListDatas", modelList);
1288 j.put("modelDatas", mapper.writeValueAsString(classMap));
1289 j.put("modelType", modelType);
1290 out.write(j.toString());
1294 * Unzip file and store in the model directory for processing
1296 @SuppressWarnings("rawtypes")
1297 private void extractFolder(String zipFile ) {
1299 File file = new File(zipFile);
1303 zip = new ZipFile(file);
1304 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1305 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1306 checkZipDirectory(this.directory);
1307 new File(newPath).mkdir();
1308 Enumeration zipFileEntries = zip.entries();
1310 // Process each entry
1311 while (zipFileEntries.hasMoreElements()){
1312 // grab a zip file entry
1313 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1314 String currentEntry = entry.getName();
1315 File destFile = new File("model" + File.separator + currentEntry);
1316 File destinationParent = destFile.getParentFile();
1318 destinationParent.mkdirs();
1320 if (!entry.isDirectory()){
1321 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1323 byte data[] = new byte[BUFFER];
1324 FileOutputStream fos = new FileOutputStream(destFile);
1325 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
1326 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1327 dest.write(data, 0, currentByte);
1334 if (currentEntry.endsWith(".zip")){
1335 extractFolder(destFile.getAbsolutePath());
1338 } catch (IOException e) {
1339 LOGGER.error("Failed to unzip model file " + zipFile);
1344 } catch (IOException e) {
1345 LOGGER.error("Exception Occured While closing zipfile " + e);
1350 private void retreiveDependency(String workingFile, Boolean modelClass) {
1352 MSModelUtils utils = new MSModelUtils(PolicyController.getMsEcompName(), PolicyController.getMsPolicyName());
1353 HashMap<String, MSAttributeObject> tempMap = new HashMap<>();
1355 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1357 classMap.putAll(tempMap);
1358 LOGGER.info(tempMap);
1364 private List<File> listModelFiles(String directoryName) {
1365 File directory = new File(directoryName);
1366 List<File> resultList = new ArrayList<>();
1367 File[] fList = directory.listFiles();
1368 for (File file : fList) {
1369 if (file.isFile()) {
1370 resultList.add(file);
1371 } else if (file.isDirectory()) {
1372 dirDependencyList.add(file.getName());
1373 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1379 private void cleanUp(String path) {
1382 FileUtils.forceDelete(new File(path));
1383 } catch (IOException e) {
1384 LOGGER.error("Failed to delete folder " + path);
1389 private void checkZipDirectory(String zipDirectory) {
1390 Path path = Paths.get(zipDirectory);
1392 if (Files.exists(path)) {
1393 cleanUp(zipDirectory);
1397 private List<String> createList() {
1398 List<String> list = new ArrayList<>();
1399 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1400 if (cMap.getValue().isPolicyTempalate()){
1401 list.add(cMap.getKey());
1406 if (list.isEmpty()){
1407 if (classMap.containsKey(this.newModel.getModelName())){
1408 list.add(this.newModel.getModelName());
1416 public Map<String, String> getAttributesListRefMap() {
1417 return attributesListRefMap;
1420 public Map<String, LinkedList<String>> getArrayTextList() {
1421 return arrayTextList;
1426 class DCAEMicroServiceObject {
1428 private String service;
1429 private String location;
1430 private String uuid;
1431 private String policyName;
1432 private String description;
1433 private String configName;
1434 private String templateVersion;
1435 private String version;
1436 private String priority;
1437 private String policyScope;
1438 private String riskType;
1439 private String riskLevel;
1440 private String guard = null;
1442 public String getGuard() {
1445 public void setGuard(String guard) {
1448 public String getRiskType() {
1451 public void setRiskType(String riskType) {
1452 this.riskType = riskType;
1454 public String getRiskLevel() {
1457 public void setRiskLevel(String riskLevel) {
1458 this.riskLevel = riskLevel;
1460 public String getPolicyScope() {
1463 public void setPolicyScope(String policyScope) {
1464 this.policyScope = policyScope;
1467 public String getPriority() {
1470 public void setPriority(String priority) {
1471 this.priority = priority;
1473 public String getVersion() {
1476 public void setVersion(String version) {
1477 this.version = version;
1479 private Object content;
1482 public String getPolicyName() {
1485 public void setPolicyName(String policyName) {
1486 this.policyName = policyName;
1488 public String getDescription() {
1491 public void setDescription(String description) {
1492 this.description = description;
1494 public String getConfigName() {
1497 public void setConfigName(String configName) {
1498 this.configName = configName;
1500 public Object getContent() {
1503 public void setContent(Object content) {
1504 this.content = content;
1507 public String getService() {
1510 public void setService(String service) {
1511 this.service = service;
1513 public String getLocation() {
1516 public void setLocation(String location) {
1517 this.location = location;
1520 public String getUuid() {
1523 public void setUuid(String uuid) {
1526 public String getTemplateVersion() {
1527 return templateVersion;
1529 public void setTemplateVersion(String templateVersion) {
1530 this.templateVersion = templateVersion;