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();
586 String allManyTrueKeys = "";
588 allManyTrueKeys = allkeys.toString();
591 String jsonModel = createMicroSeriveJson(returnModel, allkeys);
593 JSONObject jsonObject = new JSONObject(jsonModel);
595 JSONObject finalJsonObject = null;
597 Iterator<String> iter = allkeys.iterator();
598 while(iter.hasNext()){
599 //Convert to array values for MANY-true keys
600 finalJsonObject = convertToArrayElement(jsonObject, iter.next());
604 if(finalJsonObject != null){
605 LOGGER.info(finalJsonObject.toString());
606 jsonModel = finalJsonObject.toString();
609 //get all properties with "MANY-true" defined in Ref_attributes
610 Set<String> manyTrueProperties = getManyTrueProperties(returnModel.getRef_attributes());
611 if(manyTrueProperties != null){
612 JSONObject jsonObj = new JSONObject(jsonModel);
613 for (String s : manyTrueProperties) {
615 //convert to array element for MANY-true properties
616 finalJsonObject = convertToArrayElement(jsonObj, s.trim());
619 if(finalJsonObject != null){
620 LOGGER.info(finalJsonObject.toString());
621 jsonModel = finalJsonObject.toString();
625 response.setCharacterEncoding("UTF-8");
626 response.setContentType("application / json");
627 request.setCharacterEncoding("UTF-8");
628 List<Object> list = new ArrayList<>();
629 PrintWriter out = response.getWriter();
630 String responseString = mapper.writeValueAsString(returnModel);
634 if("".equals(allManyTrueKeys)){
635 j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData +"}");
637 j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + ",allManyTrueKeys: " + allManyTrueKeys+",dataOrderInfo:" + dataOrderInfo + ",headDefautlsData:" + headDefautlsData+ "}");
640 out.write(list.toString());
644 @SuppressWarnings({ "unchecked", "rawtypes" })
645 private String createMicroSeriveJson(MicroServiceModels returnModel, Set<String> allkeys) {
646 Map<String, String> attributeMap = new HashMap<>();
647 Map<String, String> refAttributeMap = new HashMap<>();
648 String attribute = returnModel.getAttributes();
649 if(attribute != null){
650 attribute = attribute.trim();
652 String refAttribute = returnModel.getRef_attributes();
653 if(refAttribute != null){
654 refAttribute = refAttribute.trim();
656 String enumAttribute = returnModel.getEnumValues();
657 if(enumAttribute != null){
658 enumAttribute = enumAttribute.trim();
660 if (!StringUtils.isEmpty(attribute)){
661 attributeMap = convert(attribute, ",");
663 if (!StringUtils.isEmpty(refAttribute)){
664 refAttributeMap = convert(refAttribute, ",");
667 Gson gson = new Gson();
669 String subAttributes = returnModel.getSub_attributes();
670 if(subAttributes != null){
671 subAttributes = subAttributes.trim();
676 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
678 JSONObject object = new JSONObject();
679 JSONArray array = new JSONArray();
681 for (Entry<String, String> keySet : attributeMap.entrySet()){
682 array = new JSONArray();
683 String value = keySet.getValue();
684 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
686 object.put(keySet.getKey().trim(), array);
688 object.put(keySet.getKey().trim(), value.trim());
692 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
693 array = new JSONArray();
694 String value = keySet.getValue().split(":")[0];
695 if (gsonObject.containsKey(value)){
696 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
697 array.put(recursiveReference(value, gsonObject, enumAttribute));
698 object.put(keySet.getKey().trim(), array);
700 object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
703 if ("true".equalsIgnoreCase(keySet.getValue().split("MANY-")[1])){
704 array.put(value.trim());
705 object.put(keySet.getKey().trim(), array);
707 object.put(keySet.getKey().trim(), value.trim());
712 return object.toString();
715 @SuppressWarnings("unchecked")
716 private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
717 JSONObject object = new JSONObject();
718 Map<String, String> map;
719 Object returnClass = subAttributeMap.get(name);
720 map = (Map<String, String>) returnClass;
723 for( Entry<String, String> m:map.entrySet()){
724 String[] splitValue = m.getValue().split(":");
725 array = new JSONArray();
726 if (subAttributeMap.containsKey(splitValue[0])){
727 if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
728 array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
729 object.put(m.getKey().trim(), array);
731 object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
734 if ("true".equalsIgnoreCase(m.getValue().split("MANY-")[1])){
735 array.put(splitValue[0].trim());
736 object.put(m.getKey().trim(), array);
738 object.put(m.getKey().trim(), splitValue[0].trim());
747 public static JSONObject convertToArrayElement(JSONObject json, String keyValue) {
748 return convertToArrayElement(json, new HashSet<>(), keyValue);
751 private static JSONObject convertToArrayElement(JSONObject json, Set<String> keys, String keyValue) {
752 for (String key : json.keySet()) {
753 Object obj = json.get(key);
754 if(key.equals(keyValue.trim())){
755 if(!(obj instanceof JSONArray)){
756 JSONArray newJsonArray = new JSONArray();
757 newJsonArray.put(obj);
758 json.put(key, newJsonArray);
760 LOGGER.info("key : " + key);
761 LOGGER.info("obj : " + obj);
762 LOGGER.info("json.get(key) : " + json.get(key));
763 LOGGER.info("keyValue : " + keyValue);
764 keys.addAll(json.keySet());
769 if (obj instanceof JSONObject) convertToArrayElement(json.getJSONObject(key), keyValue);
775 // call this method to get all MANY-true properties
776 public static Set<String> getManyTrueProperties(String referAttributes){
777 LOGGER.info("referAttributes : " + referAttributes);
778 Set<String> manyTrueProperties = new HashSet<>();
780 if(referAttributes != null){
781 String[] referAarray = referAttributes.split(",");
782 String []element= null;
783 for(int i=0; i<referAarray.length; i++){
784 element = referAarray[i].split("=");
785 if(element.length > 1 && element[1].contains("MANY-true")){
786 manyTrueProperties.add(element[0]);
791 return manyTrueProperties;
794 //call this method to start the recursive
795 private Set<String> getAllKeys(JSONObject json) {
796 return getAllKeys(json, new HashSet<>());
799 private Set<String> getAllKeys(JSONArray arr) {
800 return getAllKeys(arr, new HashSet<>());
803 private Set<String> getAllKeys(JSONArray arr, Set<String> keys) {
804 for (int i = 0; i < arr.length(); i++) {
805 Object obj = arr.get(i);
806 if (obj instanceof JSONObject) keys.addAll(getAllKeys(arr.getJSONObject(i)));
807 if (obj instanceof JSONArray) keys.addAll(getAllKeys(arr.getJSONArray(i)));
813 // this method returns a set of keys with "MANY-true" defined in their value.
814 private Set<String> getAllKeys(JSONObject json, Set<String> keys) {
815 for (String key : json.keySet()) {
816 Object obj = json.get(key);
817 if(obj instanceof String && ((String) obj).contains("MANY-true")){
818 LOGGER.info("key : " + key);
819 LOGGER.info("obj : " + obj);
820 allManyTrueKeys.add(key);
822 if (obj instanceof JSONObject) keys.addAll(getAllKeys(json.getJSONObject(key)));
823 if (obj instanceof JSONArray) keys.addAll(getAllKeys(json.getJSONArray(key)));
830 @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
831 public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws IOException{
832 ObjectMapper mapper = new ObjectMapper();
833 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
834 JsonNode root = mapper.readTree(request.getReader());
836 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
837 String servicename = value.split("-v")[0];
838 Set<String> returnList = getVersionList(servicename);
840 response.setCharacterEncoding("UTF-8");
841 response.setContentType("application / json");
842 request.setCharacterEncoding("UTF-8");
843 List<Object> list = new ArrayList<>();
844 PrintWriter out = response.getWriter();
845 String responseString = mapper.writeValueAsString(returnList);
846 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
848 out.write(list.toString());
852 private Set<String> getVersionList(String name) {
853 MicroServiceModels workingModel;
854 Set<String> list = new HashSet<>();
855 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
856 for (int i = 0; i < microServiceModelsData.size(); i++) {
857 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
858 if (workingModel.getVersion()!=null){
859 list.add(workingModel.getVersion());
867 private MicroServiceModels getAttributeObject(String name, String version) {
868 MicroServiceModels workingModel = new MicroServiceModels();
869 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
870 for (int i = 0; i < microServiceModelsData.size(); i++) {
871 workingModel = (MicroServiceModels) microServiceModelsData.get(i);
873 if (workingModel.getVersion()!=null){
874 if (workingModel.getVersion().equals(version)){
888 private MicroserviceHeaderdeFaults getHeaderDefaultsObject(String modelName) {
889 return (MicroserviceHeaderdeFaults) commonClassDao.getEntityItem(MicroserviceHeaderdeFaults.class, "modelName", modelName);
892 @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
893 public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
895 Map<String, Object> model = new HashMap<>();
896 ObjectMapper mapper = new ObjectMapper();
897 List<String> priorityList = new ArrayList<>();
899 for (int i = 1; i < priorityCount; i++) {
900 priorityList.add(String.valueOf(i));
902 model.put("priorityDatas", mapper.writeValueAsString(priorityList));
903 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
904 JSONObject j = new JSONObject(msg);
905 response.getWriter().write(j.toString());
912 public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
913 if (policyAdapter.getPolicyData() instanceof PolicyType) {
914 Object policyData = policyAdapter.getPolicyData();
915 PolicyType policy = (PolicyType) policyData;
916 policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
917 String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
918 policyAdapter.setPolicyName(policyNameValue);
919 String description = "";
921 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
923 LOGGER.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue ,e);
924 description = policy.getDescription();
926 policyAdapter.setPolicyDescription(description);
927 // Get the target data under policy.
928 TargetType target = policy.getTarget();
929 if (target != null) {
930 // Under target we have AnyOFType
931 List<AnyOfType> anyOfList = target.getAnyOf();
932 if (anyOfList != null) {
933 Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
934 while (iterAnyOf.hasNext()) {
935 AnyOfType anyOf = iterAnyOf.next();
936 // Under AnyOFType we have AllOFType
937 List<AllOfType> allOfList = anyOf.getAllOf();
938 if (allOfList != null) {
939 Iterator<AllOfType> iterAllOf = allOfList.iterator();
940 while (iterAllOf.hasNext()) {
941 AllOfType allOf = iterAllOf.next();
942 // Under AllOFType we have Match
943 List<MatchType> matchList = allOf.getMatch();
944 if (matchList != null) {
945 Iterator<MatchType> iterMatch = matchList.iterator();
946 while (matchList.size()>1 && iterMatch.hasNext()) {
947 MatchType match = iterMatch.next();
949 // Under the match we have attribute value and
950 // attributeDesignator. So,finally down to the actual attribute.
952 AttributeValueType attributeValue = match.getAttributeValue();
953 String value = (String) attributeValue.getContent().get(0);
954 AttributeDesignatorType designator = match.getAttributeDesignator();
955 String attributeId = designator.getAttributeId();
956 // First match in the target is OnapName, so set that value.
957 if ("ONAPName".equals(attributeId)) {
958 policyAdapter.setOnapName(value);
960 if ("ConfigName".equals(attributeId)){
961 policyAdapter.setConfigName(value);
963 if ("uuid".equals(attributeId)){
964 policyAdapter.setUuid(value);
966 if ("location".equals(attributeId)){
967 policyAdapter.setLocation(value);
969 if ("RiskType".equals(attributeId)){
970 policyAdapter.setRiskType(value);
972 if ("RiskLevel".equals(attributeId)){
973 policyAdapter.setRiskLevel(value);
975 if ("guard".equals(attributeId)){
976 policyAdapter.setGuard(value);
978 if ("TTLDate".equals(attributeId) && !value.contains("NA")){
979 PolicyController controller = new PolicyController();
980 String newDate = controller.convertDate(value);
981 policyAdapter.setTtlDate(newDate);
984 readFile(policyAdapter, entity);
994 public static Map<String, String> convert(String str, String split) {
995 Map<String, String> map = new HashMap<>();
996 for(final String entry : str.split(split)) {
997 String[] parts = entry.split("=");
998 map.put(parts[0], parts[1]);
1004 @SuppressWarnings("unchecked")
1005 private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1006 String policyScopeName = null;
1007 ObjectMapper mapper = new ObjectMapper();
1009 DCAEMicroServiceObject msBody = mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1010 policyScopeName = getPolicyScope(msBody.getPolicyScope());
1011 policyAdapter.setPolicyScope(policyScopeName);
1013 policyAdapter.setPriority(msBody.getPriority());
1015 if (msBody.getVersion()!= null){
1016 policyAdapter.setServiceType(msBody.getService());
1017 policyAdapter.setVersion(msBody.getVersion());
1019 policyAdapter.setServiceType(msBody.getService());
1021 if(msBody.getContent() != null){
1022 LinkedHashMap<String, Object> data = new LinkedHashMap<>();
1023 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1024 readRecursivlyJSONContent(map, data);
1025 policyAdapter.setRuleData(data);
1028 } catch (Exception e) {
1034 @SuppressWarnings({ "rawtypes", "unchecked" })
1035 public void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1036 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1037 Object key = iterator.next();
1038 Object value = map.get(key);
1039 if(value instanceof LinkedHashMap<?, ?>){
1040 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>();
1041 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1042 for( Entry<String, Object> entry : secondObjec.entrySet()){
1043 data.put(key+"." + entry.getKey(), entry.getValue());
1045 }else if(value instanceof ArrayList){
1046 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1047 for(int i = 0; i < jsonArrayVal.size(); i++){
1048 Object arrayvalue = jsonArrayVal.get(i);
1049 if(arrayvalue instanceof LinkedHashMap<?, ?>){
1050 LinkedHashMap<String, Object> newData = new LinkedHashMap<>();
1051 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1052 for(Entry<String, Object> entry: newData.entrySet()){
1053 data.put(key+"@"+i+"." +entry.getKey(), entry.getValue());
1055 }else if(arrayvalue instanceof ArrayList){
1056 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1057 for(int j = 0; j < jsonArrayVal1.size(); j++){
1058 Object arrayvalue1 = jsonArrayVal1.get(i);
1059 data.put(key+"@"+j, arrayvalue1.toString());
1062 data.put(key+"@"+i, arrayvalue.toString());
1066 data.put(key.toString(), value.toString());
1071 public String getPolicyScope(String value) {
1072 List<Object> groupList= commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
1073 if(groupList != null && !groupList.isEmpty()){
1074 GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
1075 return pScope.getGroupName();
1080 //Convert the map values and set into JSON body
1081 public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1082 Map<String, String> attribute = new HashMap<>();
1086 for (Entry<String, String> entry : attributesMap.entrySet()) {
1087 key = entry.getKey();
1088 value = entry.getValue();
1089 attribute.put(key, value);
1091 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1092 key = entryRef.getKey();
1093 value = entryRef.getValue();
1094 attribute.put(key, value);
1096 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1097 key = entryList.getKey();
1098 value = entryList.getValue();
1099 attribute.put(key, value);
1101 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1102 key = arrayList.getKey();
1104 for (Object textList : arrayList.getValue()){
1106 temp = new StringBuilder();
1107 temp.append("[" + textList);
1109 temp.append("," + textList);
1112 attribute.put(key, temp+ "]");
1118 @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1119 public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException{
1120 modelList = new ArrayList<>();
1121 dirDependencyList = new ArrayList<>();
1122 classMap = new LinkedHashMap<>();
1123 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1124 boolean zip = false;
1126 String errorMsg = "";
1127 for (FileItem item : items) {
1128 if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1129 this.newModel = new MicroServiceModels();
1131 File file = new File(item.getName());
1132 OutputStream outputStream = new FileOutputStream(file);
1133 IOUtils.copy(item.getInputStream(), outputStream);
1134 outputStream.close();
1135 this.newFile = file.toString();
1136 this.newModel.setModelName(this.newFile.split("-v")[0]);
1138 if (this.newFile.contains("-v")){
1139 if (item.getName().endsWith(".zip")){
1140 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".zip", ""));
1142 }else if(item.getName().endsWith(".yml")){
1143 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".yml", ""));
1147 this.newModel.setVersion(this.newFile.split("-v")[1].replace(".xmi", ""));
1150 }catch(Exception e){
1151 LOGGER.error("Upload error : ", e);
1152 errorMsg = "Upload error:" + e.getMessage();
1158 if(!errorMsg.isEmpty()){
1160 PrintWriter out = response.getWriter();
1162 response.setCharacterEncoding("UTF-8");
1163 response.setContentType("application / json");
1164 request.setCharacterEncoding("UTF-8");
1166 JSONObject j = new JSONObject();
1167 j.put("errorMsg", errorMsg);
1168 out.write(j.toString());
1172 List<File> fileList = new ArrayList<>();
1173 MSModelUtils msMLUtils = new MSModelUtils();
1174 this.directory = "model";
1176 extractFolder(this.newFile);
1177 fileList = listModelFiles(this.directory);
1178 }else if (yml==true){
1180 errorMsg = msMLUtils.parseTosca(this.newFile);
1181 if(errorMsg != null){
1182 PrintWriter out = response.getWriter();
1183 response.setCharacterEncoding("UTF-8");
1184 response.setContentType("application / json");
1185 request.setCharacterEncoding("UTF-8");
1186 JSONObject j = new JSONObject();
1187 j.put("errorMsg", errorMsg);
1188 out.write(j.toString());
1193 File file = new File(this.newFile);
1196 String modelType= "";
1199 //Process Main Model file first
1200 classMap = new LinkedHashMap<>();
1201 for (File file : fileList) {
1202 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1203 retreiveDependency(file.toString(), true);
1207 modelList = createList();
1209 cleanUp(this.newFile);
1213 modelList.add(this.newModel.getModelName());
1214 String className=this.newModel.getModelName();
1215 MSAttributeObject msAttributes= new MSAttributeObject();
1216 msAttributes.setClassName(className);
1218 LinkedHashMap<String, String> returnAttributeList =new LinkedHashMap<>();
1219 returnAttributeList.put(className, msMLUtils.getAttributeString());
1220 msAttributes.setAttribute(returnAttributeList);
1222 msAttributes.setSubClass(msMLUtils.getRetmap());
1224 msAttributes.setMatchingSet(msMLUtils.getMatchableValues());
1226 LinkedHashMap<String, String> returnReferenceList =new LinkedHashMap<>();
1228 returnReferenceList.put(className, msMLUtils.getReferenceAttributes());
1229 msAttributes.setRefAttribute(returnReferenceList);
1231 if(msMLUtils.getListConstraints()!=""){
1232 LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
1233 String[] listArray=msMLUtils.getListConstraints().split("#");
1234 for(String str:listArray){
1235 String[] strArr= str.split("=");
1236 if(strArr.length>1){
1237 enumList.put(strArr[0], strArr[1]);
1240 msAttributes.setEnumType(enumList);
1243 classMap=new LinkedHashMap<>();
1244 classMap.put(className, msAttributes);
1248 PrintWriter out = response.getWriter();
1250 response.setCharacterEncoding("UTF-8");
1251 response.setContentType("application / json");
1252 request.setCharacterEncoding("UTF-8");
1254 ObjectMapper mapper = new ObjectMapper();
1255 JSONObject j = new JSONObject();
1256 j.put("classListDatas", modelList);
1257 j.put("modelDatas", mapper.writeValueAsString(classMap));
1258 j.put("modelType", modelType);
1259 j.put("dataOrderInfo", msMLUtils.getDataOrderInfo());
1261 out.write(j.toString());
1265 * Unzip file and store in the model directory for processing
1267 @SuppressWarnings("rawtypes")
1268 private void extractFolder(String zipFile ) {
1270 File file = new File(zipFile);
1272 try (ZipFile zip = new ZipFile(file)) {
1273 String newPath = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1274 this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1275 checkZipDirectory(this.directory);
1276 new File(newPath).mkdir();
1277 Enumeration zipFileEntries = zip.entries();
1279 // Process each entry
1280 while (zipFileEntries.hasMoreElements()){
1281 // grab a zip file entry
1282 ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1283 String currentEntry = entry.getName();
1284 File destFile = new File("model" + File.separator + currentEntry);
1285 File destinationParent = destFile.getParentFile();
1287 destinationParent.mkdirs();
1289 if (!entry.isDirectory()){
1290 BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1292 byte[] data = new byte[BUFFER];
1293 try (FileOutputStream fos = new FileOutputStream(destFile);
1294 BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
1295 while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1296 dest.write(data, 0, currentByte);
1299 } catch (IOException e) {
1300 LOGGER.error("Failed to write zip contents to {}" + destFile + e);
1302 // PLD should I throw e?
1308 if (currentEntry.endsWith(".zip")){
1309 extractFolder(destFile.getAbsolutePath());
1312 } catch (IOException e) {
1313 LOGGER.error("Failed to unzip model file " + zipFile, e);
1317 private void retreiveDependency(String workingFile, Boolean modelClass) {
1319 MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
1320 Map<String, MSAttributeObject> tempMap;
1322 tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1324 classMap.putAll(tempMap);
1325 LOGGER.info(tempMap);
1331 private List<File> listModelFiles(String directoryName) {
1332 File fileDirectory = new File(directoryName);
1333 List<File> resultList = new ArrayList<>();
1334 File[] fList = fileDirectory.listFiles();
1335 for (File file : fList) {
1336 if (file.isFile()) {
1337 resultList.add(file);
1338 } else if (file.isDirectory()) {
1339 dirDependencyList.add(file.getName());
1340 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1346 public void cleanUp(String path) {
1349 FileUtils.forceDelete(new File(path));
1350 } catch (IOException e) {
1351 LOGGER.error("Failed to delete folder " + path, e);
1356 public void checkZipDirectory(String zipDirectory) {
1357 Path path = Paths.get(zipDirectory);
1359 if (Files.exists(path)) {
1360 cleanUp(zipDirectory);
1364 private List<String> createList() {
1365 List<String> list = new ArrayList<>();
1366 for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1367 if (cMap.getValue().isPolicyTempalate()){
1368 list.add(cMap.getKey());
1373 if (list.isEmpty()){
1374 if (classMap.containsKey(this.newModel.getModelName())){
1375 list.add(this.newModel.getModelName());
1383 public Map<String, String> getAttributesListRefMap() {
1384 return attributesListRefMap;
1387 public Map<String, LinkedList<String>> getArrayTextList() {
1388 return arrayTextList;
1393 class DCAEMicroServiceObject {
1395 private String service;
1396 private String location;
1397 private String uuid;
1398 private String policyName;
1399 private String description;
1400 private String configName;
1401 private String templateVersion;
1402 private String version;
1403 private String priority;
1404 private String policyScope;
1405 private String riskType;
1406 private String riskLevel;
1407 private String guard = null;
1409 public String getGuard() {
1412 public void setGuard(String guard) {
1415 public String getRiskType() {
1418 public void setRiskType(String riskType) {
1419 this.riskType = riskType;
1421 public String getRiskLevel() {
1424 public void setRiskLevel(String riskLevel) {
1425 this.riskLevel = riskLevel;
1427 public String getPolicyScope() {
1430 public void setPolicyScope(String policyScope) {
1431 this.policyScope = policyScope;
1434 public String getPriority() {
1437 public void setPriority(String priority) {
1438 this.priority = priority;
1440 public String getVersion() {
1443 public void setVersion(String version) {
1444 this.version = version;
1446 private Object content;
1449 public String getPolicyName() {
1452 public void setPolicyName(String policyName) {
1453 this.policyName = policyName;
1455 public String getDescription() {
1458 public void setDescription(String description) {
1459 this.description = description;
1461 public String getConfigName() {
1464 public void setConfigName(String configName) {
1465 this.configName = configName;
1467 public Object getContent() {
1470 public void setContent(Object content) {
1471 this.content = content;
1474 public String getService() {
1477 public void setService(String service) {
1478 this.service = service;
1480 public String getLocation() {
1483 public void setLocation(String location) {
1484 this.location = location;
1487 public String getUuid() {
1490 public void setUuid(String uuid) {
1493 public String getTemplateVersion() {
1494 return templateVersion;
1496 public void setTemplateVersion(String templateVersion) {
1497 this.templateVersion = templateVersion;