2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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.onap.policy.controller;
24 import java.io.BufferedInputStream;
25 import java.io.BufferedOutputStream;
27 import java.io.FileOutputStream;
28 import java.io.IOException;
29 import java.io.OutputStream;
30 import java.io.PrintWriter;
31 import java.io.StringReader;
32 import java.nio.file.Files;
33 import java.nio.file.Path;
34 import java.nio.file.Paths;
35 import java.util.ArrayList;
36 import java.util.Enumeration;
37 import java.util.HashMap;
38 import java.util.HashSet;
39 import java.util.Iterator;
40 import java.util.LinkedHashMap;
41 import java.util.LinkedList;
42 import java.util.List;
44 import java.util.Map.Entry;
46 import java.util.TreeMap;
47 import java.util.UUID;
48 import java.util.zip.ZipEntry;
49 import java.util.zip.ZipFile;
51 import javax.json.Json;
52 import javax.json.JsonArray;
53 import javax.json.JsonArrayBuilder;
54 import javax.json.JsonObject;
55 import javax.json.JsonObjectBuilder;
56 import javax.json.JsonReader;
57 import javax.json.JsonValue;
58 import javax.servlet.http.HttpServletRequest;
59 import javax.servlet.http.HttpServletResponse;
61 import org.apache.commons.compress.utils.IOUtils;
62 import org.apache.commons.fileupload.FileItem;
63 import org.apache.commons.fileupload.FileUploadException;
64 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
65 import org.apache.commons.fileupload.servlet.ServletFileUpload;
66 import org.apache.commons.io.FileUtils;
67 import org.apache.commons.lang.StringUtils;
68 import org.json.JSONArray;
69 import org.json.JSONObject;
70 import org.onap.policy.common.logging.flexlogger.FlexLogger;
71 import org.onap.policy.common.logging.flexlogger.Logger;
72 import org.onap.policy.rest.XACMLRestProperties;
73 import org.onap.policy.rest.adapter.PolicyRestAdapter;
74 import org.onap.policy.rest.dao.CommonClassDao;
75 import org.onap.policy.rest.jpa.GroupPolicyScopeList;
76 import org.onap.policy.rest.jpa.MicroServiceModels;
77 import org.onap.policy.rest.jpa.MicroserviceHeaderdeFaults;
78 import org.onap.policy.rest.jpa.PolicyEntity;
79 import org.onap.policy.rest.util.MSAttributeObject;
80 import org.onap.policy.rest.util.MSModelUtils;
81 import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
82 import org.onap.portalsdk.core.controller.RestrictedBaseController;
83 import org.onap.portalsdk.core.web.support.JsonMessage;
84 import org.springframework.beans.factory.annotation.Autowired;
85 import org.springframework.http.MediaType;
86 import org.springframework.stereotype.Controller;
87 import org.springframework.web.bind.annotation.RequestMapping;
88 import org.springframework.web.servlet.ModelAndView;
89 import com.att.research.xacml.util.XACMLProperties;
90 import com.fasterxml.jackson.core.JsonProcessingException;
91 import com.fasterxml.jackson.databind.DeserializationFeature;
92 import com.fasterxml.jackson.databind.JsonNode;
93 import com.fasterxml.jackson.databind.ObjectMapper;
94 import com.fasterxml.jackson.databind.ObjectWriter;
95 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
96 import com.fasterxml.jackson.databind.node.ObjectNode;
97 import com.google.gson.Gson;
99 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
100 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
101 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
102 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
103 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
104 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
105 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
109 public class CreateDcaeMicroServiceController extends RestrictedBaseController {
110 private static final Logger LOGGER = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
112 private static CommonClassDao commonClassDao;
114 public static CommonClassDao getCommonClassDao() {
115 return commonClassDao;
118 public static void setCommonClassDao(CommonClassDao commonClassDao) {
119 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
122 private MicroServiceModels newModel;
123 private String newFile;
124 private String directory;
125 private List<String> modelList = new ArrayList<>();
126 private List<String> dirDependencyList = new ArrayList<>();
127 private LinkedHashMap<String,MSAttributeObject > classMap = new LinkedHashMap<>();
128 String referenceAttributes;
129 String attributeString;
130 Set<String> allManyTrueKeys= new HashSet <>();
132 public static final String DATATYPE = "data_types.policy.data.";
133 public static final String PROPERTIES=".properties.";
134 public static final String TYPE=".type";
135 public static final String STRING="string";
136 public static final String INTEGER="integer";
137 public static final String LIST="list";
138 public static final String DEFAULT=".default";
139 public static final String REQUIRED=".required";
140 public static final String MATCHABLE=".matchable";
141 public static final String MANYFALSE=":MANY-false";
145 private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
146 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
149 public CreateDcaeMicroServiceController(){
153 protected PolicyRestAdapter policyAdapter = null;
154 private int priorityCount;
155 private Map<String, String> attributesListRefMap = new HashMap<>();
156 private Map<String, LinkedList<String>> arrayTextList = new HashMap<>();
158 public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
160 String jsonContent = null;
162 LOGGER.info("policyJSON :" + (root.get("policyJSON")).toString());
164 String tempJson = root.get("policyJSON").toString();
166 //---replace empty value with the value below before calling decodeContent method.
167 String dummyValue = "*empty-value*" + UUID.randomUUID().toString();
168 LOGGER.info("dummyValue:" + dummyValue);
169 tempJson = StringUtils.replaceEach(tempJson, new String[]{"\"\""}, new String[]{"\""+dummyValue+"\""});
170 ObjectMapper mapper = new ObjectMapper();
171 JsonNode tempJsonNode = mapper.readTree(tempJson);
172 jsonContent = decodeContent(tempJsonNode).toString();
173 constructJson(policyData, jsonContent, dummyValue);
175 LOGGER.error("Error while decoding microservice content", e);
181 private GroupPolicyScopeList getPolicyObject(String policyScope) {
182 return (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
185 private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent, String dummyValue) {
186 ObjectWriter om = new ObjectMapper().writer();
188 DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
189 MicroServiceModels returnModel = new MicroServiceModels();
190 microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS));
191 if(policyAdapter.getServiceType() !=null){
192 microServiceObject.setService(policyAdapter.getServiceType());
193 microServiceObject.setVersion(policyAdapter.getVersion());
194 returnModel = getAttributeObject(microServiceObject.getService(), microServiceObject.getVersion());
196 if (returnModel.getAnnotation()==null || returnModel.getAnnotation().isEmpty()){
197 if(policyAdapter.getUuid()!=null){
198 microServiceObject.setUuid(policyAdapter.getUuid());
200 if(policyAdapter.getLocation()!=null){
201 microServiceObject.setLocation(policyAdapter.getLocation());
203 if(policyAdapter.getConfigName()!=null){
204 microServiceObject.setConfigName(policyAdapter.getConfigName());
206 GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope());
207 if(policyScopeValue!=null){
208 microServiceObject.setPolicyScope(policyScopeValue.getGroupList());
212 if(policyAdapter.getPolicyName()!=null){
213 microServiceObject.setPolicyName(policyAdapter.getPolicyName());
215 if(policyAdapter.getPolicyDescription()!=null){
216 microServiceObject.setDescription(policyAdapter.getPolicyDescription());
218 if (policyAdapter.getPriority()!=null){
219 microServiceObject.setPriority(policyAdapter.getPriority());
221 microServiceObject.setPriority("9999");
224 if (policyAdapter.getRiskLevel()!=null){
225 microServiceObject.setRiskLevel(policyAdapter.getRiskLevel());
227 if (policyAdapter.getRiskType()!=null){
228 microServiceObject.setRiskType(policyAdapter.getRiskType());
230 if (policyAdapter.getGuard()!=null){
231 microServiceObject.setGuard(policyAdapter.getGuard());
233 microServiceObject.setContent(jsonContent);
236 json = om.writeValueAsString(microServiceObject);
237 } catch (JsonProcessingException e) {
238 LOGGER.error("Error writing out the object", e);
240 LOGGER.info("input json: " + json);
241 LOGGER.info("input jsonContent: " + jsonContent);
242 String cleanJson = cleanUPJson(json);
243 //--- reset empty value back after called cleanUPJson method and before calling removeNullAttributes
244 String tempJson = StringUtils.replaceEach(cleanJson, new String[]{"\""+dummyValue+"\""}, new String[]{"\"\""});
245 LOGGER.info("tempJson: " + tempJson);
246 cleanJson = removeNullAttributes(tempJson);
247 policyAdapter.setJsonBody(cleanJson);
248 return policyAdapter;
251 public String removeNullAttributes(String cleanJson) {
252 ObjectMapper mapper = new ObjectMapper();
255 JsonNode rootNode = mapper.readTree(cleanJson);
256 JsonNode returnNode = mapper.readTree(cleanJson);
257 Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
258 boolean remove = false;
259 JsonObject removed = null;
260 boolean contentChanged = false;
261 while (fieldsIterator.hasNext()) {
262 Map.Entry<String, JsonNode> field = fieldsIterator.next();
263 final String key = field.getKey();
264 final JsonNode value = field.getValue();
265 if("content".equalsIgnoreCase(key)){
266 String contentStr = value.toString();
267 try(JsonReader reader = Json.createReader(new StringReader(contentStr))){
268 JsonObject jsonContent = reader.readObject();
269 removed = removeNull(jsonContent);
270 if(!jsonContent.toString().equals(removed.toString())){
271 contentChanged = true;
275 if (value==null || value.isNull()){
276 ((ObjectNode) returnNode).remove(key);
281 cleanJson = returnNode.toString();
283 if (value==null || value.isNull()){
284 ((ObjectNode) returnNode).remove(key);
289 cleanJson = returnNode.toString();
293 //set modified content to cleanJson
294 JSONObject jObject = new JSONObject(cleanJson);
295 jObject.put("content",removed.toString());
296 cleanJson = cleanUPJson(jObject.toString());
299 } catch (IOException e) {
300 LOGGER.error("Error writing out the JsonNode",e);
305 public static JsonArray removeNull(JsonArray array) {
306 JsonArrayBuilder builder = Json.createArrayBuilder();
308 for (Iterator<JsonValue> it = array.iterator(); it.hasNext(); ++i) {
309 JsonValue value = it.next();
310 switch (value.getValueType()) {
312 JsonArray a = removeNull(array.getJsonArray(i));
317 JsonObject object = removeNull(array.getJsonObject(i));
318 if (!object.isEmpty())
322 String s = array.getString(i);
323 if (s != null && !s.isEmpty())
327 builder.add(array.getJsonNumber(i));
331 builder.add(array.getBoolean(i));
337 return builder.build();
340 public static JsonObject removeNull(JsonObject obj) {
341 JsonObjectBuilder builder = Json.createObjectBuilder();
342 for (Iterator<Entry<String, JsonValue>> it = obj.entrySet().iterator(); it.hasNext();) {
343 Entry<String, JsonValue> e = it.next();
344 String key = e.getKey();
345 JsonValue value = e.getValue();
346 switch (value.getValueType()) {
348 JsonArray array = removeNull(obj.getJsonArray(key));
349 if (!array.isEmpty())
350 builder.add(key, array);
353 JsonObject object = removeNull(obj.getJsonObject(key));
354 if (!object.isEmpty())
355 builder.add(key, object);
358 String s = obj.getString(key);
359 if (s != null && !s.isEmpty())
363 builder.add(key, obj.getJsonNumber(key));
367 builder.add(key, obj.getBoolean(key));
373 return builder.build();
376 public String cleanUPJson(String json) {
377 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
378 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
379 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"});
381 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"});
382 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"});
383 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
384 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"{", "}\""}, new String[]{"{", "}"});
385 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""});
386 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\""}, new String[]{""});
387 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\""}, new String[]{"\""});
388 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\\\\\\"}, new String[]{"\""});
389 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\\""}, new String[]{"\""});
390 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
394 public JSONObject decodeContent(JsonNode jsonNode){
395 Iterator<JsonNode> jsonElements = jsonNode.elements();
396 Iterator<String> jsonKeys = jsonNode.fieldNames();
397 Map<String,String> element = new TreeMap<>();
398 while(jsonElements.hasNext() && jsonKeys.hasNext()){
399 element.put(jsonKeys.next(), jsonElements.next().toString());
401 JSONObject jsonResult = new JSONObject();
402 JSONArray jsonArray = null;
403 String oldValue = null;
404 String nodeKey = null;
405 String arryKey = null;
406 Boolean isArray = false;
407 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
408 ObjectNode node = nodeFactory.objectNode();
409 String prevKey = null;
411 for(Entry<String, String> entry: element.entrySet()){
412 String key = entry.getKey();
413 String value = entry.getValue();
414 if(key.contains(".")){
415 presKey = key.substring(0,key.indexOf('.'));
416 }else if(key.contains("@")){
417 presKey = key.substring(0,key.indexOf('@'));
421 // first check if we are different from old.
422 LOGGER.info(key+"\n");
423 if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
424 if(!oldValue.equals(key.substring(0,key.indexOf('@')))){
425 jsonResult.put(oldValue, jsonArray);
426 jsonArray = new JSONArray();
428 }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){
429 jsonResult.put(oldValue, jsonArray);
431 jsonArray = new JSONArray();
436 if(key.contains(".")){
438 nodeKey = key.substring(0,key.indexOf('.'));
440 if(nodeKey.equals(key.substring(0,key.indexOf('.')))){
441 node.put(key.substring(key.indexOf('.')+1), value);
444 if(nodeKey.contains("@")){
446 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
448 if(nodeKey.endsWith("@0")){
450 jsonArray = new JSONArray();
452 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){
453 jsonArray.put(decodeContent(node));
455 if((key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf('@')))) || !key.contains("@")){
456 jsonResult.put(arryKey, jsonArray);
457 jsonArray = new JSONArray();
459 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
462 jsonResult.put(nodeKey, decodeContent(node));
464 node = nodeFactory.objectNode();
466 nodeKey = key.substring(0,key.indexOf('.'));
467 if(nodeKey.contains("@")){
468 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
470 node.put(key.substring(key.indexOf('.')+1), value);
474 if(nodeKey.contains("@")){
476 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
478 if(nodeKey.endsWith("@0")){
480 jsonArray = new JSONArray();
482 if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf('@')))){
483 jsonArray.put(decodeContent(node));
485 jsonResult.put(arryKey, jsonArray);
486 jsonArray = new JSONArray();
487 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
490 jsonResult.put(nodeKey, decodeContent(node));
492 node = nodeFactory.objectNode();
494 if(key.contains("@")){
496 if(key.endsWith("@0")|| jsonArray==null){
497 jsonArray = new JSONArray();
499 }else if(!key.contains("@")){
504 oldValue = key.substring(0,key.indexOf('@'));
506 if(oldValue!=prevKey){
507 oldValue = key.substring(0,key.indexOf('@'));
509 if(oldValue.equals(key.substring(0,key.indexOf('@')))){
510 jsonArray.put(value);
512 jsonResult.put(oldValue, jsonArray);
513 jsonArray = new JSONArray();
515 oldValue = key.substring(0,key.indexOf('@'));
517 jsonResult.put(key, value);
522 if(nodeKey.contains("@")){
524 jsonArray = new JSONArray();
527 arryKey = nodeKey.substring(0,nodeKey.indexOf('@'));
529 jsonArray.put(decodeContent(node));
530 jsonResult.put(arryKey, jsonArray);
533 jsonResult.put(nodeKey, decodeContent(node));
536 if(isArray && jsonArray.length() > 0){
537 jsonResult.put(oldValue, jsonArray);
542 @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
543 public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws IOException{
544 ObjectMapper mapper = new ObjectMapper();
545 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
546 JsonNode root = mapper.readTree(request.getReader());
548 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
549 String servicename = value.split("-v")[0];
550 String version = null;
551 if (value.contains("-v")){
552 version = value.split("-v")[1];
554 MicroServiceModels returnModel = getAttributeObject(servicename, version);
556 MicroserviceHeaderdeFaults returnHeaderDefauls = getHeaderDefaultsObject(value);
557 JSONObject jsonHdDefaultObj = null;
558 if(returnHeaderDefauls != null){
559 jsonHdDefaultObj = new JSONObject();
560 jsonHdDefaultObj.put("onapName", returnHeaderDefauls.getOnapName());
561 jsonHdDefaultObj.put("guard", returnHeaderDefauls.getGuard());
562 jsonHdDefaultObj.put("riskLevel", returnHeaderDefauls.getRiskLevel());
563 jsonHdDefaultObj.put("riskType", returnHeaderDefauls.getRiskType());
564 jsonHdDefaultObj.put("priority", returnHeaderDefauls.getPriority());
566 String headDefautlsData = "";
567 if(jsonHdDefaultObj != null){
568 headDefautlsData = jsonHdDefaultObj.toString();
570 headDefautlsData = "null";
573 //Get all keys with "MANY-true" defined in their value from subAttribute
574 Set<String> allkeys = null;
575 if(returnModel.getSub_attributes() != null && !returnModel.getSub_attributes().isEmpty()){
576 JSONObject json = new JSONObject(returnModel.getSub_attributes());
578 allkeys = allManyTrueKeys;
579 allManyTrueKeys = new HashSet <>();
580 LOGGER.info("allkeys : " + allkeys);
583 //Get element order info
584 String dataOrderInfo = returnModel.getDataOrderInfo();
585 if(dataOrderInfo != null && !dataOrderInfo.startsWith("\"")){
586 dataOrderInfo = "\"" + dataOrderInfo + "\"";
588 LOGGER.info("dataOrderInfo : " + dataOrderInfo);
590 String allManyTrueKeys = "";
592 allManyTrueKeys = allkeys.toString();
595 String jsonModel = createMicroSeriveJson(returnModel, allkeys);
597 JSONObject jsonObject = new JSONObject(jsonModel);
599 JSONObject finalJsonObject = null;
601 Iterator<String> iter = allkeys.iterator();
602 while(iter.hasNext()){
603 //Convert to array values for MANY-true keys
604 finalJsonObject = convertToArrayElement(jsonObject, iter.next());
608 if(finalJsonObject != null){
609 LOGGER.info(finalJsonObject.toString());
610 jsonModel = finalJsonObject.toString();
613 //get all properties with "MANY-true" defined in Ref_attributes
614 Set<String> manyTrueProperties = getManyTrueProperties(returnModel.getRef_attributes());
615 if(manyTrueProperties != null){
616 JSONObject jsonObj = new JSONObject(jsonModel);
617 for (String s : manyTrueProperties) {
619 //convert to array element for MANY-true properties
620 finalJsonObject = convertToArrayElement(jsonObj, s.trim());
623 if(finalJsonObject != null){
624 LOGGER.info(finalJsonObject.toString());
625 jsonModel = finalJsonObject.toString();
629 response.setCharacterEncoding("UTF-8");
630 response.setContentType("application / json");
631 request.setCharacterEncoding("UTF-8");
632 List<Object> list = new ArrayList<>();
633 PrintWriter out = response.getWriter();
634 String responseString = mapper.writeValueAsString(returnModel);
638 if("".equals(allManyTrueKeys)){
639 j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData +"}");
641 j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData+ "}");
644 out.write(list.toString());
648 @SuppressWarnings({ "unchecked", "rawtypes" })
649 private String createMicroSeriveJson(MicroServiceModels returnModel, Set<String> allkeys) {
650 Map<String, String> attributeMap = new HashMap<>();
651 Map<String, String> refAttributeMap = new HashMap<>();
652 String attribute = returnModel.getAttributes();
653 if(attribute != null){
654 attribute = attribute.trim();
656 String refAttribute = returnModel.getRef_attributes();
657 if(refAttribute != null){
658 refAttribute = refAttribute.trim();
660 String enumAttribute = returnModel.getEnumValues();
661 if(enumAttribute != null){
662 enumAttribute = enumAttribute.trim();
664 if (!StringUtils.isEmpty(attribute)){
665 attributeMap = convert(attribute, ",");
667 if (!StringUtils.isEmpty(refAttribute)){
668 refAttributeMap = convert(refAttribute, ",");
671 Gson gson = new Gson();
673 String subAttributes = returnModel.getSub_attributes();
674 if(subAttributes != null){
675 subAttributes = subAttributes.trim();
680 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
682 JSONObject object = new JSONObject();
683 JSONArray array = new JSONArray();
685 for (Entry<String, String> keySet : attributeMap.entrySet()){
686 array = new JSONArray();
687 String value = keySet.getValue();
688 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
690 object.put(keySet.getKey().trim(), array);
692 object.put(keySet.getKey().trim(), value.trim());
696 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
697 array = new JSONArray();
698 String value = keySet.getValue().split(":")[0];
699 if (gsonObject.containsKey(value)){
700 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
701 array.put(recursiveReference(value, gsonObject, enumAttribute));
702 object.put(keySet.getKey().trim(), array);
704 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
707 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
708 array.put(value.trim());
709 object.put(keySet.getKey().trim(), array);
711 object.put(keySet.getKey().trim(), value.trim());
716 return object.toString();
719 @SuppressWarnings("unchecked")
720 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
721 JSONObject object = new JSONObject();
722 Map<String, String> map;
723 Object returnClass = subAttributeMap.get(name);
724 map = (Map<String, String>) returnClass;
727 for( Entry<String, String> m:map.entrySet()){
728 String[] splitValue = m.getValue().split(":");
729 array = new JSONArray();
730 if (subAttributeMap.containsKey(splitValue[0])){
731 if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
732 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
733 object.put(m.getKey().trim(), array);
735 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
738 if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
739 array.put(splitValue[0].trim());
740 object.put(m.getKey().trim(), array);
742 object.put(m.getKey().trim(), splitValue[0].trim());
751 public static JSONObject convertToArrayElement(JSONObject json, String keyValue) {
752 return convertToArrayElement(json, new HashSet<>(), keyValue);
755 private static JSONObject convertToArrayElement(JSONObject json, Set<String> keys, String keyValue) {
756 for (String key : json.keySet()) {
757 Object obj = json.get(key);
758 if(key.equals(keyValue.trim())){
759 if(!(obj instanceof JSONArray)){
760 JSONArray newJsonArray = new JSONArray();
761 newJsonArray.put(obj);
762 json.put(key, newJsonArray);
764 LOGGER.info("key : " + key);
765 LOGGER.info("obj : " + obj);
766 LOGGER.info("json.get(key) : " + json.get(key));
767 LOGGER.info("keyValue : " + keyValue);
768 keys.addAll(json.keySet());
773 if (obj instanceof JSONObject) convertToArrayElement(json.getJSONObject(key), keyValue);
779 // call this method to get all MANY-true properties
780 public static Set<String> getManyTrueProperties(String referAttributes){
781 LOGGER.info("referAttributes : " + referAttributes);
782 Set<String> manyTrueProperties = new HashSet<>();
784 if(referAttributes != null){
785 String[] referAarray = referAttributes.split(",");
786 String []element= null;
787 for(int i=0; i<referAarray.length; i++){
788 element = referAarray[i].split("=");
789 if(element.length > 1 && element[1].contains("MANY-true")){
790 manyTrueProperties.add(element[0]);
795 return manyTrueProperties;
798 //call this method to start the recursive
799 private Set<String> getAllKeys(JSONObject json) {
800 return getAllKeys(json, new HashSet<>());
803 private Set<String> getAllKeys(JSONArray arr) {
804 return getAllKeys(arr, new HashSet<>());
807 private Set<String> getAllKeys(JSONArray arr, Set<String> keys) {
808 for (int i = 0; i < arr.length(); i++) {
809 Object obj = arr.get(i);
810 if (obj instanceof JSONObject) keys.addAll(getAllKeys(arr.getJSONObject(i)));
811 if (obj instanceof JSONArray) keys.addAll(getAllKeys(arr.getJSONArray(i)));
817 // this method returns a set of keys with "MANY-true" defined in their value.
818 private Set<String> getAllKeys(JSONObject json, Set<String> keys) {
819 for (String key : json.keySet()) {
820 Object obj = json.get(key);
821 if(obj instanceof String && ((String) obj).contains("MANY-true")){
822 LOGGER.info("key : " + key);
823 LOGGER.info("obj : " + obj);
824 allManyTrueKeys.add(key);
826 if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key)));
827 if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key)));
834 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
835 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws IOException{
836 ObjectMapper mapper = new ObjectMapper();
837 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
838 JsonNode root = mapper.readTree(request.getReader());
840 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
841 String servicename = value.split("-v")[0];
842 Set<String> returnList = getVersionList(servicename);
844 response.setCharacterEncoding("UTF-8");
845 response.setContentType("application / json");
846 request.setCharacterEncoding("UTF-8");
847 List<Object> list = new ArrayList<>();
848 PrintWriter out = response.getWriter();
849 String responseString = mapper.writeValueAsString(returnList);
850 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
852 out.write(list.toString());
856 private Set<String> getVersionList(String name) {
857 MicroServiceModels workingModel;
858 Set<String> list = new HashSet<>();
859 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
860 for (int i = 0; i < microServiceModelsData.size(); i++) {
861 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
862 if (workingModel.getVersion()!=null){
863 list.add(workingModel.getVersion());
871 private MicroServiceModels getAttributeObject(String name, String version) {
872 MicroServiceModels workingModel = new MicroServiceModels();
873 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
874 for (int i = 0; i < microServiceModelsData.size(); i++) {
875 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
877 if (workingModel.getVersion()!=null){
878 if (workingModel.getVersion().equals(version)){
892 private MicroserviceHeaderdeFaults getHeaderDefaultsObject(String modelName) {
893 return (MicroserviceHeaderdeFaults) commonClassDao.getEntityItem(MicroserviceHeaderdeFaults.class, "modelName", modelName);
896 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
897 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
899 Map<String, Object> model = new HashMap<>();
900 ObjectMapper mapper = new ObjectMapper();
901 List<String> priorityList = new ArrayList<>();
903 for (int i = 1; i < priorityCount; i++) {
904 priorityList.add(String.valueOf(i));
906 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
907 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
908 JSONObject j = new JSONObject(msg);
909 response.getWriter().write(j.toString());
916 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
917 if (policyAdapter.getPolicyData() instanceof PolicyType) {
918 Object policyData = policyAdapter.getPolicyData();
919 PolicyType policy = (PolicyType) policyData;
920 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
921 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
922 policyAdapter.setPolicyName(policyNameValue);
923 String description = "";
925 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
927 LOGGER.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue ,e);
928 description = policy.getDescription();
930 policyAdapter.setPolicyDescription(description);
931 // Get the target data under policy.
932 TargetType target = policy.getTarget();
933 if (target != null) {
934 // Under target we have AnyOFType
935 List<AnyOfType> anyOfList = target.getAnyOf();
936 if (anyOfList != null) {
937 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
938 while (iterAnyOf.hasNext()) {
939 AnyOfType anyOf = iterAnyOf.next();
940 // Under AnyOFType we have AllOFType
941 List<AllOfType> allOfList = anyOf.getAllOf();
942 if (allOfList != null) {
943 Iterator<AllOfType> iterAllOf = allOfList.iterator();
944 while (iterAllOf.hasNext()) {
945 AllOfType allOf = iterAllOf.next();
946 // Under AllOFType we have Match
947 List<MatchType> matchList = allOf.getMatch();
948 if (matchList != null) {
949 Iterator<MatchType> iterMatch = matchList.iterator();
950 while (matchList.size()>1 && iterMatch.hasNext()) {
951 MatchType match = iterMatch.next();
953 // Under the match we have attribute value and
954 // attributeDesignator. So,finally down to the actual attribute.
956 AttributeValueType attributeValue = match.getAttributeValue();
957 String value = (String) attributeValue.getContent().get(0);
958 AttributeDesignatorType designator = match.getAttributeDesignator();
959 String attributeId = designator.getAttributeId();
960 // First match in the target is OnapName, so set that value.
961 if ("ONAPName".equals(attributeId)) {
962 policyAdapter.setOnapName(value);
964 if ("ConfigName".equals(attributeId)){
965 policyAdapter.setConfigName(value);
967 if ("uuid".equals(attributeId)){
968 policyAdapter.setUuid(value);
970 if ("location".equals(attributeId)){
971 policyAdapter.setLocation(value);
973 if ("RiskType".equals(attributeId)){
974 policyAdapter.setRiskType(value);
976 if ("RiskLevel".equals(attributeId)){
977 policyAdapter.setRiskLevel(value);
979 if ("guard".equals(attributeId)){
980 policyAdapter.setGuard(value);
982 if ("TTLDate".equals(attributeId) && !value.contains("NA")){
983 PolicyController controller = new PolicyController();
984 String newDate = controller.convertDate(value);
985 policyAdapter.setTtlDate(newDate);
988 readFile(policyAdapter, entity);
998 public static Map<String, String> convert(String str, String split) {
999 Map<String, String> map = new HashMap<>();
1000 for(final String entry : str.split(split)) {
1001 String[] parts = entry.split("=");
1002 map.put(parts[0], parts[1]);
1008 @SuppressWarnings("unchecked")
1009 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1010 String policyScopeName = null;
1011 ObjectMapper mapper = new ObjectMapper();
1013 DCAEMicroServiceObject msBody = mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1014 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1015 policyAdapter.setPolicyScope(policyScopeName);
1017 policyAdapter.setPriority(msBody.getPriority());
1019 if (msBody.getVersion()!= null){
1020 policyAdapter.setServiceType(msBody.getService());
1021 policyAdapter.setVersion(msBody.getVersion());
1023 policyAdapter.setServiceType(msBody.getService());
1025 if(msBody.getContent() != null){
1026 LinkedHashMap<String, Object> data = new LinkedHashMap<>();
1027 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1028 readRecursivlyJSONContent(map, data);
1029 policyAdapter.setRuleData(data);
1032 } catch (Exception e) {
1038 @SuppressWarnings({ "rawtypes", "unchecked" })
1039 public void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1040 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1041 Object key = iterator.next();
1042 Object value = map.get(key);
1043 if(value instanceof LinkedHashMap<?, ?>){
1044 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
1045 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1046 for( Entry<String, Object> entry : secondObjec.entrySet()){
1047 data.put(key+"." + entry.getKey(), entry.getValue());
1049 }else if(value instanceof ArrayList){
1050 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1051 for(int i = 0; i < jsonArrayVal.size(); i++){
1052 Object arrayvalue = jsonArrayVal.get(i);
1053 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1054 LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
1055 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1056 for(Entry<String, Object> entry: newData.entrySet()){
1057 data.put(key+"@"+i+"." +entry.getKey(), entry.getValue());
1059 }else if(arrayvalue instanceof ArrayList){
1060 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1061 for(int j = 0; j < jsonArrayVal1.size(); j++){
1062 Object arrayvalue1 = jsonArrayVal1.get(i);
1063 data.put(key+"@"+j, arrayvalue1.toString());
1066 data.put(key+"@"+i, arrayvalue.toString());
1070 data.put(key.toString(), value.toString());
1075 public String getPolicyScope(String value) {
1076 List<Object> groupList= commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
1077 if(groupList != null && !groupList.isEmpty()){
1078 GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
1079 return pScope.getGroupName();
1084 //Convert the map values and set into JSON body
1085 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1086 Map<String, String> attribute = new HashMap<>();
1090 for (Entry<String, String> entry : attributesMap.entrySet()) {
1091 key = entry.getKey();
1092 value = entry.getValue();
1093 attribute.put(key, value);
1095 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1096 key = entryRef.getKey();
1097 value = entryRef.getValue();
1098 attribute.put(key, value);
1100 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1101 key = entryList.getKey();
1102 value = entryList.getValue();
1103 attribute.put(key, value);
1105 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1106 key = arrayList.getKey();
1108 for (Object textList : arrayList.getValue()){
1110 temp = new StringBuilder();
1111 temp.append("[" + textList);
1113 temp.append("," + textList);
1116 attribute.put(key, temp+ "]");
1122 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1123 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException{
1124 modelList = new ArrayList<>();
1125 dirDependencyList = new ArrayList<>();
1126 classMap = new LinkedHashMap<>();
1127 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1128 boolean zip = false;
1130 String errorMsg = "";
1131 for (FileItem item : items) {
1132 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1133 this.newModel = new MicroServiceModels();
1135 File file = new File(item.getName());
1136 OutputStream outputStream = new FileOutputStream(file);
1137 IOUtils.copy(item.getInputStream(), outputStream);
1138 outputStream.close();
1139 this.newFile = file.toString();
1140 this.newModel.setModelName(this.newFile.split("-v")[0]);
1142 if (this.newFile.contains("-v")){
1143 if (item.getName().endsWith(".zip")){
1144 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".zip", ""));
1146 }else if(item.getName().endsWith(".yml")){
1147 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".yml", ""));
1151 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".xmi", ""));
1154 }catch(Exception e){
1155 LOGGER.error("Upload error : ", e);
1156 errorMsg = "Upload error:" + e.getMessage();
1162 if(!errorMsg.isEmpty()){
1164 PrintWriter out = response.getWriter();
1166 response.setCharacterEncoding("UTF-8");
1167 response.setContentType("application / json");
1168 request.setCharacterEncoding("UTF-8");
1170 JSONObject j = new JSONObject();
1171 j.put("errorMsg", errorMsg);
1172 out.write(j.toString());
1176 List<File> fileList = new ArrayList<>();
1177 MSModelUtils msMLUtils = new MSModelUtils();
1178 this.directory = "model";
1180 extractFolder(this.newFile);
1181 fileList = listModelFiles(this.directory);
1182 }else if (yml==true){
1184 errorMsg = msMLUtils.parseTosca(this.newFile);
1185 if(errorMsg != null){
1186 PrintWriter out = response.getWriter();
1187 response.setCharacterEncoding("UTF-8");
1188 response.setContentType("application / json");
1189 request.setCharacterEncoding("UTF-8");
1190 JSONObject j = new JSONObject();
1191 j.put("errorMsg", errorMsg);
1192 out.write(j.toString());
1197 File file = new File(this.newFile);
1200 String modelType= "";
1203 //Process Main Model file first
1204 classMap = new LinkedHashMap<>();
1205 for (File file : fileList) {
1206 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1207 retreiveDependency(file.toString(), true);
1211 modelList = createList();
1213 cleanUp(this.newFile);
1217 modelList.add(this.newModel.getModelName());
1218 String className=this.newModel.getModelName();
1219 MSAttributeObject msAttributes= new MSAttributeObject();
1220 msAttributes.setClassName(className);
1222 LinkedHashMap<String, String> returnAttributeList =new LinkedHashMap<>();
1223 returnAttributeList.put(className, msMLUtils.getAttributeString());
1224 msAttributes.setAttribute(returnAttributeList);
1226 msAttributes.setSubClass(msMLUtils.getRetmap());
1228 msAttributes.setMatchingSet(msMLUtils.getMatchableValues());
1230 LinkedHashMap<String, String> returnReferenceList =new LinkedHashMap<>();
1232 returnReferenceList.put(className, msMLUtils.getReferenceAttributes());
1233 msAttributes.setRefAttribute(returnReferenceList);
1235 if(msMLUtils.getListConstraints()!=""){
1236 LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
1237 String[] listArray=msMLUtils.getListConstraints().split("#");
1238 for(String str:listArray){
1239 String[] strArr= str.split("=");
1240 if(strArr.length>1){
1241 enumList.put(strArr[0], strArr[1]);
1244 msAttributes.setEnumType(enumList);
1247 classMap=new LinkedHashMap<>();
1248 classMap.put(className, msAttributes);
1252 PrintWriter out = response.getWriter();
1254 response.setCharacterEncoding("UTF-8");
1255 response.setContentType("application / json");
1256 request.setCharacterEncoding("UTF-8");
1258 ObjectMapper mapper = new ObjectMapper();
1259 JSONObject j = new JSONObject();
1260 j.put("classListDatas", modelList);
1261 j.put("modelDatas", mapper.writeValueAsString(classMap));
1262 j.put("modelType", modelType);
1263 j.put("dataOrderInfo", msMLUtils.getDataOrderInfo());
1265 out.write(j.toString());
1269 * Unzip file and store in the model directory for processing
1271 @SuppressWarnings("rawtypes")
1272 private void extractFolder(String zipFile ) {
1274 File file = new File(zipFile);
1276 try (ZipFile zip = new ZipFile(file)) {
1277 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1278 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1279 checkZipDirectory(this.directory);
1280 new File(newPath).mkdir();
1281 Enumeration zipFileEntries = zip.entries();
1283 // Process each entry
1284 while (zipFileEntries.hasMoreElements()){
1285 // grab a zip file entry
1286 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1287 String currentEntry = entry.getName();
1288 File destFile = new File("model" + File.separator + currentEntry);
1289 File destinationParent = destFile.getParentFile();
1291 destinationParent.mkdirs();
1293 if (!entry.isDirectory()){
1294 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1296 byte[] data = new byte[BUFFER];
1297 try (FileOutputStream fos = new FileOutputStream(destFile);
1298 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
1299 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1300 dest.write(data, 0, currentByte);
1303 } catch (IOException e) {
1304 LOGGER.error("Failed to write zip contents to {}" + destFile + e);
1306 // PLD should I throw e?
1312 if (currentEntry.endsWith(".zip")){
1313 extractFolder(destFile.getAbsolutePath());
1316 } catch (IOException e) {
1317 LOGGER.error("Failed to unzip model file " + zipFile, e);
1321 private void retreiveDependency(String workingFile, Boolean modelClass) {
1323 MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
1324 Map<String, MSAttributeObject> tempMap;
1326 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1328 classMap.putAll(tempMap);
1329 LOGGER.info(tempMap);
1335 private List<File> listModelFiles(String directoryName) {
1336 File fileDirectory = new File(directoryName);
1337 List<File> resultList = new ArrayList<>();
1338 File[] fList = fileDirectory.listFiles();
1339 for (File file : fList) {
1340 if (file.isFile()) {
1341 resultList.add(file);
1342 } else if (file.isDirectory()) {
1343 dirDependencyList.add(file.getName());
1344 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1350 public void cleanUp(String path) {
1353 FileUtils.forceDelete(new File(path));
1354 } catch (IOException e) {
1355 LOGGER.error("Failed to delete folder " + path, e);
1360 public void checkZipDirectory(String zipDirectory) {
1361 Path path = Paths.get(zipDirectory);
1363 if (Files.exists(path)) {
1364 cleanUp(zipDirectory);
1368 private List<String> createList() {
1369 List<String> list = new ArrayList<>();
1370 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1371 if (cMap.getValue().isPolicyTempalate()){
1372 list.add(cMap.getKey());
1377 if (list.isEmpty()){
1378 if (classMap.containsKey(this.newModel.getModelName())){
1379 list.add(this.newModel.getModelName());
1387 public Map<String, String> getAttributesListRefMap() {
1388 return attributesListRefMap;
1391 public Map<String, LinkedList<String>> getArrayTextList() {
1392 return arrayTextList;
1397 class DCAEMicroServiceObject {
1399 private String service;
1400 private String location;
1401 private String uuid;
1402 private String policyName;
1403 private String description;
1404 private String configName;
1405 private String templateVersion;
1406 private String version;
1407 private String priority;
1408 private String policyScope;
1409 private String riskType;
1410 private String riskLevel;
1411 private String guard = null;
1413 public String getGuard() {
1416 public void setGuard(String guard) {
1419 public String getRiskType() {
1422 public void setRiskType(String riskType) {
1423 this.riskType = riskType;
1425 public String getRiskLevel() {
1428 public void setRiskLevel(String riskLevel) {
1429 this.riskLevel = riskLevel;
1431 public String getPolicyScope() {
1434 public void setPolicyScope(String policyScope) {
1435 this.policyScope = policyScope;
1438 public String getPriority() {
1441 public void setPriority(String priority) {
1442 this.priority = priority;
1444 public String getVersion() {
1447 public void setVersion(String version) {
1448 this.version = version;
1450 private Object content;
1453 public String getPolicyName() {
1456 public void setPolicyName(String policyName) {
1457 this.policyName = policyName;
1459 public String getDescription() {
1462 public void setDescription(String description) {
1463 this.description = description;
1465 public String getConfigName() {
1468 public void setConfigName(String configName) {
1469 this.configName = configName;
1471 public Object getContent() {
1474 public void setContent(Object content) {
1475 this.content = content;
1478 public String getService() {
1481 public void setService(String service) {
1482 this.service = service;
1484 public String getLocation() {
1487 public void setLocation(String location) {
1488 this.location = location;
1491 public String getUuid() {
1494 public void setUuid(String uuid) {
1497 public String getTemplateVersion() {
1498 return templateVersion;
1500 public void setTemplateVersion(String templateVersion) {
1501 this.templateVersion = templateVersion;