Enhanced MS JSON Generation
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / CreateDcaeMicroServiceController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.policy.controller;
22
23
24 import java.io.BufferedInputStream;
25 import java.io.BufferedOutputStream;
26 import java.io.File;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.FileOutputStream;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import java.io.OutputStream;
33 import java.io.PrintWriter;
34 import java.io.StringReader;
35 import java.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.util.ArrayList;
39 import java.util.Arrays;
40 import java.util.Enumeration;
41 import java.util.HashMap;
42 import java.util.HashSet;
43 import java.util.Iterator;
44 import java.util.LinkedHashMap;
45 import java.util.LinkedList;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.Map.Entry;
49 import java.util.Set;
50 import java.util.TreeMap;
51 import java.util.UUID;
52 import java.util.zip.ZipEntry;
53 import java.util.zip.ZipFile;
54
55 import javax.json.Json;
56 import javax.json.JsonArray;
57 import javax.json.JsonArrayBuilder;
58 import javax.json.JsonObject;
59 import javax.json.JsonObjectBuilder;
60 import javax.json.JsonValue;
61 import javax.servlet.http.HttpServletRequest;
62 import javax.servlet.http.HttpServletResponse;
63
64 import org.apache.commons.compress.utils.IOUtils;
65 import org.apache.commons.fileupload.FileItem;
66 import org.apache.commons.fileupload.FileUploadException;
67 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
68 import org.apache.commons.fileupload.servlet.ServletFileUpload;
69 import org.apache.commons.io.FileUtils;
70 import org.apache.commons.lang.StringUtils;
71 import org.json.JSONArray;
72 import org.json.JSONObject;
73 import org.onap.policy.common.logging.flexlogger.FlexLogger;
74 import org.onap.policy.common.logging.flexlogger.Logger;
75 import org.onap.policy.rest.XACMLRestProperties;
76 import org.onap.policy.rest.adapter.PolicyRestAdapter;
77 import org.onap.policy.rest.dao.CommonClassDao;
78 import org.onap.policy.rest.jpa.GroupPolicyScopeList;
79 import org.onap.policy.rest.jpa.MicroServiceModels;
80 import org.onap.policy.rest.jpa.PolicyEntity;
81 import org.onap.policy.rest.util.MSAttributeObject;
82 import org.onap.policy.rest.util.MSModelUtils;
83 import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
84 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
85 import org.openecomp.portalsdk.core.web.support.JsonMessage;
86 import org.springframework.beans.factory.annotation.Autowired;
87 import org.springframework.http.MediaType;
88 import org.springframework.stereotype.Controller;
89 import org.springframework.web.bind.annotation.RequestMapping;
90 import org.springframework.web.servlet.ModelAndView;
91 import org.yaml.snakeyaml.Yaml;
92
93 import com.att.research.xacml.util.XACMLProperties;
94 import com.fasterxml.jackson.core.JsonProcessingException;
95 import com.fasterxml.jackson.databind.DeserializationFeature;
96 import com.fasterxml.jackson.databind.JsonNode;
97 import com.fasterxml.jackson.databind.ObjectMapper;
98 import com.fasterxml.jackson.databind.ObjectWriter;
99 import com.fasterxml.jackson.databind.node.ArrayNode;
100 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
101 import com.fasterxml.jackson.databind.node.ObjectNode;
102 import com.google.gson.Gson;
103
104 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
105 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
106 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
107 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
108 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
109 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
110 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
111
112 @Controller
113 @RequestMapping("/")
114 public class CreateDcaeMicroServiceController extends RestrictedBaseController {
115         private static final Logger LOGGER = FlexLogger.getLogger(CreateDcaeMicroServiceController.class);
116
117         private static CommonClassDao commonClassDao;
118         
119         public static CommonClassDao getCommonClassDao() {
120                 return commonClassDao;
121         }
122
123         public static void setCommonClassDao(CommonClassDao commonClassDao) {
124                 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
125         }
126
127         private MicroServiceModels newModel;
128         private String newFile;
129         private String directory;
130         private List<String> modelList = new ArrayList<>();
131         private List<String> dirDependencyList = new ArrayList<>();
132         private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
133         //Tosca Model related Datastructure. 
134         String referenceAttributes;
135         String attributeString;
136         String listConstraints;
137         String subAttributeString;
138         HashMap<String, Object> retmap = new HashMap<>();
139         Set<String> uniqueKeys= new HashSet<>();
140         Set<String> uniqueDataKeys= new HashSet<>();
141         StringBuilder dataListBuffer=new StringBuilder();
142         List<String> dataConstraints= new ArrayList <>();
143         
144         public static final String DATATYPE  = "data_types.policy.data.";
145         public static final String PROPERTIES=".properties.";
146         public static final String TYPE=".type";
147         public static final String STRING="string";
148         public static final String INTEGER="integer";
149         public static final String LIST="list";
150         public static final String DEFAULT=".default";
151         public static final String REQUIRED=".required";
152         public static final String MANYFALSE=":MANY-false";
153         
154         
155         @Autowired
156         private CreateDcaeMicroServiceController(CommonClassDao commonClassDao){
157                 CreateDcaeMicroServiceController.commonClassDao = commonClassDao;
158         }
159
160         public CreateDcaeMicroServiceController(){}
161
162         protected PolicyRestAdapter policyAdapter = null;
163         private int priorityCount; 
164         private Map<String, String> attributesListRefMap =  new HashMap<>();
165         private Map<String, LinkedList<String>> arrayTextList =  new HashMap<>();
166
167         public PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter policyData, JsonNode root) {
168                 
169                 String jsonContent = null;
170                 try{
171                         LOGGER.info("policyJSON :" + (root.get("policyJSON")).toString());
172                         
173                         String tempJson = root.get("policyJSON").toString();
174                         
175                         //---replace empty value with the value below before calling decodeContent method.
176                         String dummyValue = "*empty-value*" + UUID.randomUUID().toString();
177                         tempJson = StringUtils.replaceEach(tempJson, new String[]{"\"\""}, new String[]{"\""+dummyValue+"\""});
178                         ObjectMapper mapper = new ObjectMapper();
179                         JsonNode tempJsonNode = mapper.readTree(tempJson);
180                         jsonContent = decodeContent(tempJsonNode).toString();
181                         constructJson(policyData, jsonContent, dummyValue);
182                 }catch(Exception e){
183                         LOGGER.error("Error while decoding microservice content", e);
184                 }
185                 
186                 return policyData;
187         }
188         
189         private GroupPolicyScopeList getPolicyObject(String policyScope) {
190                 GroupPolicyScopeList groupList= (GroupPolicyScopeList) commonClassDao.getEntityItem(GroupPolicyScopeList.class, "name", policyScope);
191                 return groupList;
192         }
193         
194         private PolicyRestAdapter constructJson(PolicyRestAdapter policyAdapter, String jsonContent, String dummyValue) {
195                 ObjectWriter om = new ObjectMapper().writer();
196                 String json="";
197                 DCAEMicroServiceObject microServiceObject = new DCAEMicroServiceObject();
198                 MicroServiceModels returnModel = new MicroServiceModels();
199                 microServiceObject.setTemplateVersion(XACMLProperties.getProperty(XACMLRestProperties.TemplateVersion_MS));
200                 if(policyAdapter.getServiceType() !=null){
201                         microServiceObject.setService(policyAdapter.getServiceType());
202                         microServiceObject.setVersion(policyAdapter.getVersion());
203                         returnModel = getAttributeObject(microServiceObject.getService(), microServiceObject.getVersion());
204                 }
205                 if (returnModel.getAnnotation()==null || returnModel.getAnnotation().isEmpty()){
206                         if(policyAdapter.getUuid()!=null){
207                                 microServiceObject.setUuid(policyAdapter.getUuid());
208                         }
209                         if(policyAdapter.getLocation()!=null){
210                                 microServiceObject.setLocation(policyAdapter.getLocation());
211                         } 
212                         if(policyAdapter.getConfigName()!=null){
213                                 microServiceObject.setConfigName(policyAdapter.getConfigName());
214                         }
215                         GroupPolicyScopeList policyScopeValue = getPolicyObject(policyAdapter.getPolicyScope());
216                         if(policyScopeValue!=null){
217                                 microServiceObject.setPolicyScope(policyScopeValue.getGroupList());     
218                         }
219                 }
220                 
221                 if(policyAdapter.getPolicyName()!=null){
222                         microServiceObject.setPolicyName(policyAdapter.getPolicyName());
223                 }
224                 if(policyAdapter.getPolicyDescription()!=null){
225                         microServiceObject.setDescription(policyAdapter.getPolicyDescription());
226                 }
227                 if (policyAdapter.getPriority()!=null){
228                         microServiceObject.setPriority(policyAdapter.getPriority());
229                 }else {
230                         microServiceObject.setPriority("9999");
231                 }
232                 
233                 if (policyAdapter.getRiskLevel()!=null){
234                         microServiceObject.setRiskLevel(policyAdapter.getRiskLevel());
235                 }
236                 if (policyAdapter.getRiskType()!=null){
237                         microServiceObject.setRiskType(policyAdapter.getRiskType());
238                 }
239                 if (policyAdapter.getGuard()!=null){
240                         microServiceObject.setGuard(policyAdapter.getGuard());
241                 }
242                 microServiceObject.setContent(jsonContent);
243                 
244                 try {
245                         json = om.writeValueAsString(microServiceObject);
246                 } catch (JsonProcessingException e) {
247                         LOGGER.error("Error writing out the object", e);
248                 }
249                 LOGGER.info("input json: " + json);
250                 LOGGER.info("input jsonContent: " + jsonContent);
251                 String cleanJson = cleanUPJson(json);
252         //--- reset empty value back after called cleanUPJson method and before calling removeNullAttributes
253                 String tempJson = StringUtils.replaceEach(cleanJson, new String[]{"\""+dummyValue+"\""},  new String[]{"\"\""});
254                 LOGGER.info("tempJson: " + tempJson);
255                 cleanJson = removeNullAttributes(tempJson);
256                 policyAdapter.setJsonBody(cleanJson);
257                 return policyAdapter;
258         }
259         
260         private String removeNullAttributes(String cleanJson) {
261                 ObjectMapper mapper = new ObjectMapper();
262
263                 try {
264                         JsonNode rootNode = mapper.readTree(cleanJson);
265                         JsonNode returnNode = mapper.readTree(cleanJson);
266                         Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
267                         boolean remove = false;
268                         JsonObject removed = null;
269                         boolean contentChanged = false;
270                         while (fieldsIterator.hasNext()) {
271                                 Map.Entry<String, JsonNode> field = fieldsIterator.next();
272                                 final String key = field.getKey();
273                                 final JsonNode value = field.getValue();
274                                 if("content".equalsIgnoreCase(key)){
275                                         String contentStr = value.toString();
276                                     JsonObject jsonContent = Json.createReader(new StringReader(contentStr)).readObject();                                  
277                                     removed = removeNull(jsonContent);
278                                     if(!jsonContent.toString().equals(removed.toString())){
279                                         contentChanged = true;  
280                                     }
281                                 }
282                                 if  (value==null || value.isNull()){
283                                         ((ObjectNode) returnNode).remove(key);
284                                         remove = true;
285                                 }
286                         }
287                         if (remove){
288                                 cleanJson = returnNode.toString();
289                         }
290                         
291                         if(contentChanged){
292                                 //set modified content to cleanJson
293                                 JSONObject  jObject  =  new JSONObject(cleanJson);      
294                                 jObject.put("content",removed.toString());
295                                 cleanJson = cleanUPJson(jObject.toString());
296                         }
297                         
298                 } catch (IOException e) {
299                         LOGGER.error("Error writing out the JsonNode",e);
300                 }
301                 return cleanJson;
302         }
303         
304         public static JsonArray removeNull(JsonArray array) {
305             JsonArrayBuilder builder = Json.createArrayBuilder();
306             int i = 0;
307             for (Iterator<JsonValue> it = array.iterator(); it.hasNext(); ++i) {
308                 JsonValue value = it.next();
309                 switch (value.getValueType()) {
310                 case ARRAY:
311                     JsonArray a = removeNull(array.getJsonArray(i));
312                     if (!a.isEmpty())
313                         builder.add(a);
314                     break;
315                 case OBJECT:
316                     JsonObject object = removeNull(array.getJsonObject(i));
317                     if (!object.isEmpty())
318                         builder.add(object);
319                     break;
320                 case STRING:
321                     String s = array.getString(i);
322                     if (s != null && !s.isEmpty())
323                         builder.add(s);
324                     break;
325                 case NUMBER:
326                     builder.add(array.getJsonNumber(i));
327                     break;
328                 case TRUE:
329                 case FALSE:
330                     builder.add(array.getBoolean(i));
331                     break;
332                 case NULL:
333                     break;
334                 }
335             }
336             return builder.build();
337         }
338
339         public static JsonObject removeNull(JsonObject obj) {
340             JsonObjectBuilder builder = Json.createObjectBuilder();
341             for (Iterator<Entry<String, JsonValue>> it = obj.entrySet().iterator(); it.hasNext();) {
342                 Entry<String, JsonValue> e = it.next();
343                 String key = e.getKey();
344                 JsonValue value = e.getValue();
345                 switch (value.getValueType()) {
346                 case ARRAY:
347                     JsonArray array = removeNull(obj.getJsonArray(key));
348                     if (!array.isEmpty())
349                         builder.add(key, array);
350                     break;
351                 case OBJECT:
352                     JsonObject object = removeNull(obj.getJsonObject(key));
353                     if (!object.isEmpty())
354                         builder.add(key, object);
355                     break;
356                 case STRING:
357                     String s = obj.getString(key);
358                     if (s != null && !s.isEmpty())
359                         builder.add(key, s);
360                     break;
361                 case NUMBER:
362                     builder.add(key, obj.getJsonNumber(key));
363                     break;
364                 case TRUE:
365                 case FALSE:
366                     builder.add(key, obj.getBoolean(key));
367                     break;
368                 case NULL:
369                     break;
370                 }
371             }
372             return builder.build();
373         }
374         
375         // Second index of dot should be returned. 
376         public int stringBetweenDots(String str){
377                 String stringToSearch=str;
378                 String[]ss=stringToSearch.split("\\.");
379                 if(ss!=null){
380                         int len= ss.length;
381                         if(len>2){
382                                 uniqueKeys.add(ss[2]);
383                         }
384                 }
385                 
386                 return uniqueKeys.size();
387         }
388         
389         public void stringBetweenDotsForDataFields(String str){
390                 String stringToSearch=str;
391                 String[]ss=stringToSearch.split("\\.");
392                 if(ss!=null){
393                         int len= ss.length;
394
395                         if(len>2){
396                                 uniqueDataKeys.add(ss[0]+"%"+ss[2]);
397                         }
398                 }
399         }
400         
401  
402         public Map<String, String> load(String fileName) throws IOException { 
403                 File newConfiguration = new File(fileName);
404                 InputStream is = null;
405                 try {
406                         is = new FileInputStream(newConfiguration);
407                 } catch (FileNotFoundException e) {
408                         LOGGER.error(e);
409                 }
410
411                 Yaml yaml = new Yaml();
412                 @SuppressWarnings("unchecked")
413                 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(is); 
414                 StringBuilder sb = new StringBuilder(); 
415                 Map<String, String> settings = new HashMap<>(); 
416                 if (yamlMap == null) { 
417                         return settings; 
418                 } 
419                 List<String> path = new ArrayList <>(); 
420                 serializeMap(settings, sb, path, yamlMap); 
421                 return settings; 
422         } 
423
424         public Map<String, String> load(byte[] source) throws IOException { 
425                 Yaml yaml = new Yaml(); 
426                 @SuppressWarnings("unchecked")
427                 Map<Object, Object> yamlMap = (Map<Object, Object>) yaml.load(Arrays.toString(source)); 
428                 StringBuilder sb = new StringBuilder(); 
429                 Map<String, String> settings = new HashMap <>(); 
430                 if (yamlMap == null) { 
431                         return settings; 
432                 } 
433                 List<String> path = new ArrayList <>(); 
434                 serializeMap(settings, sb, path, yamlMap); 
435                 return settings; 
436         } 
437
438         @SuppressWarnings({ "unchecked", "rawtypes" })
439         private void serializeMap(Map<String, String> settings, StringBuilder sb, List<String> path, Map<Object, Object> yamlMap) { 
440                 for (Map.Entry<Object, Object> entry : yamlMap.entrySet()) { 
441                         if (entry.getValue() instanceof Map) { 
442                                 path.add((String) entry.getKey()); 
443                                 serializeMap(settings, sb, path, (Map<Object, Object>) entry.getValue()); 
444                                 path.remove(path.size() - 1); 
445                         } else if (entry.getValue() instanceof List) { 
446                                 path.add((String) entry.getKey()); 
447                                 serializeList(settings, sb, path, (List) entry.getValue()); 
448                                 path.remove(path.size() - 1); 
449                         } else { 
450                                 serializeValue(settings, sb, path, (String) entry.getKey(), entry.getValue()); 
451                         } 
452                 } 
453         } 
454
455         @SuppressWarnings("unchecked")
456         private void serializeList(Map<String, String> settings, StringBuilder sb, List<String> path, List<String> yamlList) { 
457                 int counter = 0; 
458                 for (Object listEle : yamlList) { 
459                         if (listEle instanceof Map) { 
460                                 path.add(Integer.toString(counter)); 
461                                 serializeMap(settings, sb, path, (Map<Object, Object>) listEle); 
462                                 path.remove(path.size() - 1); 
463                         } else if (listEle instanceof List) { 
464                                 path.add(Integer.toString(counter)); 
465                                 serializeList(settings, sb, path, (List<String>) listEle); 
466                                 path.remove(path.size() - 1); 
467                         } else { 
468                                 serializeValue(settings, sb, path, Integer.toString(counter), listEle); 
469                         } 
470                         counter++; 
471                 } 
472         } 
473
474         private void serializeValue(Map<String, String> settings, StringBuilder sb, List<String> path, String name, Object value) { 
475                 if (value == null) { 
476                         return; 
477                 } 
478                 sb.setLength(0); 
479                 for (String pathEle : path) { 
480                         sb.append(pathEle).append('.'); 
481                 } 
482                 sb.append(name); 
483                 settings.put(sb.toString(), value.toString()); 
484         } 
485     
486         void parseDataAndPolicyNodes(Map<String,String> map){
487                 for(String key:map.keySet()){
488                         if(key.contains("policy.nodes.Root"))
489                         {
490                                 continue;
491                         }
492                         else if(key.contains("policy.nodes")){
493                                 String wordToFind = "policy.nodes.";
494                                 int indexForPolicyNode=key.indexOf(wordToFind);
495                                 String subNodeString= key.substring(indexForPolicyNode+13, key.length());
496
497                                 stringBetweenDots(subNodeString);
498                         }
499                         else if(key.contains("policy.data")){
500                                 String wordToFind="policy.data.";
501                                 int indexForPolicyNode=key.indexOf(wordToFind);
502                                 String subNodeString= key.substring(indexForPolicyNode+12, key.length());
503
504                                 stringBetweenDotsForDataFields(subNodeString);
505                         }
506                 }
507         }
508         
509         HashMap<String,String> parseDataNodes(Map<String,String> map){
510                 HashMap<String,String> dataMapForJson=new HashMap <>(); 
511                 for(String uniqueDataKey: uniqueDataKeys){
512                         if(uniqueDataKey.contains("%")){
513                                 String[] uniqueDataKeySplit= uniqueDataKey.split("%");
514                                 String findType=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+TYPE;
515                                 String typeValue=map.get(findType);
516                                 LOGGER.info(typeValue);
517                                 if(typeValue.equalsIgnoreCase(STRING)||
518                                                 typeValue.equalsIgnoreCase(INTEGER)
519                                   )
520                                 {
521                                         String findDefault=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+DEFAULT;
522                                         String defaultValue= map.get(findDefault);
523                                         LOGGER.info("defaultValue is:"+ defaultValue);
524                                         
525                                         String findRequired=DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+REQUIRED;
526                                         String requiredValue= map.get(findRequired);
527                                         LOGGER.info("requiredValue is:"+ requiredValue);
528                                         
529                                         StringBuilder attributeIndividualStringBuilder= new StringBuilder();
530                                         attributeIndividualStringBuilder.append(typeValue+":defaultValue-");
531                                         attributeIndividualStringBuilder.append(defaultValue+":required-");
532                                         attributeIndividualStringBuilder.append(requiredValue+MANYFALSE);
533                                         dataMapForJson.put(uniqueDataKey, attributeIndividualStringBuilder.toString());         
534                                 }
535                                 else if(typeValue.equalsIgnoreCase(LIST)){
536                                         String findList= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.type";
537                                         String listValue=map.get(findList);
538                                         if(listValue!=null){
539                                                 LOGGER.info("Type of list is:"+ listValue);
540                                                 //Its userdefined
541                                                 if(listValue.contains(".")){
542                                                         String trimValue=listValue.substring(listValue.lastIndexOf('.')+1);
543                                                         StringBuilder referenceIndividualStringBuilder= new StringBuilder();
544                                                         referenceIndividualStringBuilder.append(trimValue+":MANY-true");
545                                                         dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
546                                                 }//Its string
547                                                 else{
548                                                         StringBuilder stringListItems= new StringBuilder();
549                                                         stringListItems.append(uniqueDataKeySplit[1].toUpperCase()+":MANY-false");
550                                                         dataMapForJson.put(uniqueDataKey, stringListItems.toString());
551                                                         dataListBuffer.append(uniqueDataKeySplit[1].toUpperCase()+"=[");
552                                                         for(int i=0;i<10;i++){
553                                                                 String findConstraints= DATATYPE+uniqueDataKeySplit[0]+PROPERTIES+uniqueDataKeySplit[1]+".entry_schema.constraints.0.valid_values."+i;
554                                                                 String constraintsValue=map.get(findConstraints);
555                                                                 LOGGER.info(constraintsValue);
556                                                                 if(constraintsValue==null){
557                                                                         break;
558                                                                 }
559                                                                 else{
560                                                                         dataConstraints.add(constraintsValue);
561                                                                         dataListBuffer.append(constraintsValue+",");
562                                                                 }
563                                                         }
564                                                         dataListBuffer.append("]#");
565                                                         
566                                                         LOGGER.info(dataListBuffer);
567                                                 }
568                                         }
569                                 }
570                                 else{
571                                         String findUserDefined="data_types.policy.data."+uniqueDataKeySplit[0]+"."+"properties"+"."+uniqueDataKeySplit[1]+".type";
572                                         String userDefinedValue=map.get(findUserDefined);
573                                         String trimValue=userDefinedValue.substring(userDefinedValue.lastIndexOf('.')+1);
574                                         StringBuilder referenceIndividualStringBuilder= new StringBuilder();
575                                         referenceIndividualStringBuilder.append(trimValue+":MANY-false");
576                                         dataMapForJson.put(uniqueDataKey, referenceIndividualStringBuilder.toString());
577                                         
578                                 }
579                         }
580                 }
581                 return dataMapForJson;
582         }
583         
584         void constructJsonForDataFields(HashMap<String,String> dataMapForJson){
585                 HashMap<String,HashMap<String,String>> dataMapKey= new HashMap <>();
586                 HashMap<String,String> hmSub;
587                 for(Map.Entry<String, String> entry: dataMapForJson.entrySet()){
588                         String uniqueDataKey= entry.getKey();
589                         String[] uniqueDataKeySplit=uniqueDataKey.split("%");
590                         String value= dataMapForJson.get(uniqueDataKey);
591                         if(dataMapKey.containsKey(uniqueDataKeySplit[0])){
592                                 hmSub = dataMapKey.get(uniqueDataKeySplit[0]);
593                                 hmSub.put(uniqueDataKeySplit[1], value);
594                         }
595                         else{
596                                 hmSub=new HashMap <>();
597                                 hmSub.put(uniqueDataKeySplit[1], value);
598                         }
599                                 
600                         dataMapKey.put(uniqueDataKeySplit[0], hmSub);
601                 }
602                                 
603                 JSONObject mainObject= new JSONObject();
604                 JSONObject json;
605                 for(Map.Entry<String,HashMap<String,String>> entry: dataMapKey.entrySet()){
606                         String s=entry.getKey();
607                         json= new JSONObject();
608                         HashMap<String,String> jsonHm=dataMapKey.get(s);
609                         for(Map.Entry<String,String> entryMap:jsonHm.entrySet()){
610                                 String key=entryMap.getKey();
611                                 json.put(key, jsonHm.get(key));
612                         }
613                         mainObject.put(s,json);
614                 }       
615                 Iterator<String> keysItr = mainObject.keys();
616                 while(keysItr.hasNext()) {
617                         String key = keysItr.next();
618                         String value = mainObject.get(key).toString();
619                         retmap.put(key, value);
620                 }
621                 
622                 LOGGER.info("#############################################################################");
623                 LOGGER.info(mainObject);
624                 LOGGER.info("###############################################################################"); 
625         }
626         
627         
628         HashMap<String,HashMap<String,String>> parsePolicyNodes(Map<String,String> map){
629                 HashMap<String,HashMap<String,String>> mapKey= new HashMap <>();
630                 for(String uniqueKey: uniqueKeys){
631                         HashMap<String,String> hm;
632
633                         for(Map.Entry<String,String> entry:map.entrySet()){
634                                 String key=entry.getKey();
635                                 if(key.contains(uniqueKey) && key.contains("policy.nodes")){
636                                         if(mapKey.containsKey(uniqueKey)){
637                                                 hm = mapKey.get(uniqueKey);
638                                                 String keyStr= key.substring(key.lastIndexOf('.')+1);
639                                                 String valueStr= map.get(key);
640                                                 if(("type").equals(keyStr)){
641                                                         if(!key.contains("entry_schema"))
642                                                         {
643                                                                 hm.put(keyStr,valueStr);
644                                                         }
645                                                 }else{
646                                                         hm.put(keyStr,valueStr);
647                                                 }
648
649                                         } else {
650                                                 hm = new HashMap <>();
651                                                 String keyStr= key.substring(key.lastIndexOf('.')+1);
652                                                 String valueStr= map.get(key);
653                                                 if(("type").equals(keyStr)){
654                                                         if(!key.contains("entry_schema"))
655                                                         {
656                                                                 hm.put(keyStr,valueStr);
657                                                         }
658                                                 }else{
659                                                         hm.put(keyStr,valueStr);
660                                                 }
661                                                 mapKey.put(uniqueKey, hm);
662                                         }
663                                 }
664                         }
665                 }
666                 return mapKey;
667         }
668
669         void createAttributes(HashMap<String,HashMap<String,String>> mapKey){
670                 StringBuilder attributeStringBuilder= new StringBuilder();
671                 StringBuilder referenceStringBuilder= new StringBuilder();
672                 StringBuilder listBuffer= new StringBuilder();
673                 List<String> constraints= new ArrayList<>();
674                 for(Map.Entry<String,HashMap<String,String>> entry: mapKey.entrySet()){
675                         String keySetString= entry.getKey();
676                         HashMap<String,String> keyValues=mapKey.get(keySetString);
677                         if(keyValues.get("type").equalsIgnoreCase(STRING)||
678                                         keyValues.get("type").equalsIgnoreCase(INTEGER)
679                                         ){
680                                 StringBuilder attributeIndividualStringBuilder= new StringBuilder();
681                                 attributeIndividualStringBuilder.append(keySetString+"=");
682                                 attributeIndividualStringBuilder.append(keyValues.get("type")+":defaultValue-");
683                                 attributeIndividualStringBuilder.append(keyValues.get("default")+":required-");
684                                 attributeIndividualStringBuilder.append(keyValues.get("required")+":MANY-false");
685                                 attributeStringBuilder.append(attributeIndividualStringBuilder+",");    
686
687                         }
688                         else if(keyValues.get("type").equalsIgnoreCase(LIST)){
689                                 //List Datatype
690                                 Set<String> keys= keyValues.keySet();
691                                 Iterator<String> itr=keys.iterator();
692                                 while(itr.hasNext()){
693                                         String key= itr.next();
694                                         if((!("type").equals(key) ||("required").equals(key)))
695                                         {
696                                                 String value= keyValues.get(key);
697                                                 //The "." in the value determines if its a string or a user defined type.  
698                                                 if (!value.contains(".")){
699                                                         //This is string
700                                                         constraints.add(keyValues.get(key));
701                                                 }else{
702                                                         //This is userdefined string
703                                                         String trimValue=value.substring(value.lastIndexOf('.')+1);
704                                                         StringBuilder referenceIndividualStringBuilder= new StringBuilder();
705                                                         referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-true");
706                                                         referenceStringBuilder.append(referenceIndividualStringBuilder+",");
707                                                 }
708                                         }
709                                 }
710
711                         }else{
712                                 //User defined Datatype. 
713                                 String value=keyValues.get("type");
714                                 String trimValue=value.substring(value.lastIndexOf('.')+1);
715                                 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
716                                 referenceIndividualStringBuilder.append(keySetString+"="+trimValue+":MANY-false");
717                                 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
718
719                         }
720                         if(constraints!=null &&constraints.isEmpty()==false){
721                                 //List handling. 
722                                 listBuffer.append(keySetString.toUpperCase()+"=[");
723                                 for(String str:constraints){
724                                         listBuffer.append(str+",");
725                                 }
726                                 listBuffer.append("]#");
727                                 LOGGER.info(listBuffer);
728
729
730                                 StringBuilder referenceIndividualStringBuilder= new StringBuilder();
731                                 referenceIndividualStringBuilder.append(keySetString+"="+keySetString.toUpperCase()+":MANY-false");
732                                 referenceStringBuilder.append(referenceIndividualStringBuilder+",");
733                                 constraints.clear();
734                         }
735                 }
736                 
737                 dataListBuffer.append(listBuffer);
738                 
739
740                 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
741                 LOGGER.info("Whole attribute String is:"+attributeStringBuilder);       
742                 LOGGER.info("Whole reference String is:"+referenceStringBuilder);
743                 LOGGER.info("List String is:"+listBuffer);
744                 LOGGER.info("Data list buffer is:"+dataListBuffer);
745                 LOGGER.info("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
746                 
747                 this.listConstraints=dataListBuffer.toString();
748                 this.referenceAttributes=referenceStringBuilder.toString();
749                 this.attributeString=attributeStringBuilder.toString();
750         }
751         
752         
753     
754         public void parseTosca (String fileName){
755                 Map<String,String> map= new HashMap<>();
756     
757         try {
758                         map=load(fileName);
759                         
760                         parseDataAndPolicyNodes(map);
761                         
762                         HashMap<String,String> dataMapForJson=parseDataNodes(map);
763                         
764                         constructJsonForDataFields(dataMapForJson);     
765                         
766                         HashMap<String,HashMap<String,String>> mapKey= parsePolicyNodes(map);
767                         
768                         createAttributes(mapKey);
769                 
770         } catch (IOException e) {
771                 LOGGER.error(e);
772         }
773         
774         } 
775
776         private String cleanUPJson(String json) {
777                 String cleanJson = StringUtils.replaceEach(json, new String[]{"\\\\", "\\\\\\", "\\\\\\\\"}, new String[]{"\\", "\\", "\\"});
778                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\"}, new String[]{"\\"});
779                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\", "[[", "]]"}, new String[]{"\\", "[", "]"});
780                 
781                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\"", "\\\"", "\"[{", "}]\""}, new String[]{"\"", "\"", "[{", "}]"});
782                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[{", "}]\""}, new String[]{"[{", "}]"});
783                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
784                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"{", "}\""}, new String[]{"{", "}"});
785                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\"\"", "\"\""}, new String[]{"\"", "\""});
786                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\""}, new String[]{""});
787                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\""}, new String[]{"\""});
788                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"\\\\\\"}, new String[]{"\""});
789                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\\\\\\\""}, new String[]{"\""});
790                 cleanJson = StringUtils.replaceEach(cleanJson, new String[]{"\"[", "]\""}, new String[]{"[", "]"});
791                 return cleanJson;
792         }
793         
794         private JSONObject decodeContent(JsonNode jsonNode){
795                 Iterator<JsonNode> jsonElements = jsonNode.elements();
796                 Iterator<String> jsonKeys = jsonNode.fieldNames();
797                 Map<String,String> element = new TreeMap<>();
798                 while(jsonElements.hasNext() && jsonKeys.hasNext()){
799                         element.put(jsonKeys.next(), jsonElements.next().toString());
800                 }
801                 JSONObject jsonResult = new JSONObject();
802                 JSONArray jsonArray = null;
803                 String oldValue = null;
804                 String nodeKey = null;
805                 String arryKey = null;
806                 Boolean isArray = false;
807                 JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
808                 ObjectNode node = nodeFactory.objectNode();
809                 String prevKey = null;
810                 String presKey = null;
811                 for(String key: element.keySet()){
812                         if(key.contains(".")){
813                                 presKey = key.substring(0,key.indexOf("."));
814                         }else if(key.contains("@")){
815                                 presKey = key.substring(0,key.indexOf("@"));
816                         }else{
817                                 presKey = key;
818                         }
819                         // first check if we are different from old.
820                         LOGGER.info(key+"\n");
821                         if(jsonArray!=null && jsonArray.length()>0 && key.contains("@") && !key.contains(".") && oldValue!=null){
822                                 if(!oldValue.equals(key.substring(0,key.indexOf("@")))){
823                                         jsonResult.put(oldValue, jsonArray);
824                                         jsonArray = new JSONArray();
825                                 }
826                         }else if(jsonArray!=null && jsonArray.length()>0 && !presKey.equals(prevKey) && oldValue!=null){ 
827                                 jsonResult.put(oldValue, jsonArray);
828                                 isArray = false;
829                                 jsonArray = new JSONArray();
830                         }
831         
832                         prevKey = presKey;
833                         // 
834                         if(key.contains(".")){
835                                 if(nodeKey==null){
836                                         nodeKey = key.substring(0,key.indexOf("."));
837                                 }
838                                 if(nodeKey.equals(key.substring(0,key.indexOf(".")))){
839                                         node.put(key.substring(key.indexOf(".")+1), element.get(key));
840                                 }else{
841                                         if(node.size()!=0){
842                                                 if(nodeKey.contains("@")){
843                                                         if(arryKey==null){
844                                                                 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
845                                                         }
846                                                         if(nodeKey.endsWith("@0")){
847                                                                 isArray = true;
848                                                                 jsonArray = new JSONArray();
849                                                         }
850                                                         if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
851                                                                 jsonArray.put(decodeContent(node));
852                                                         } 
853                                                         if((key.contains("@") && !arryKey.equals(key.substring(0,nodeKey.indexOf("@")))) || !key.contains("@")){
854                                                                 jsonResult.put(arryKey, jsonArray);
855                                                                 jsonArray = new JSONArray();
856                                                         }
857                                                         arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
858                                                 }else{
859                                                         isArray = false;
860                                                         jsonResult.put(nodeKey, decodeContent(node));
861                                                 }
862                                                 node = nodeFactory.objectNode();
863                                         }
864                                         nodeKey = key.substring(0,key.indexOf("."));
865                                         if(nodeKey.contains("@")){
866                                                 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
867                                         }
868                                         node.put(key.substring(key.indexOf(".")+1), element.get(key));
869                                 }
870                         }else if(node.size()!=0){
871                                 if(nodeKey.contains("@")){
872                                         if(arryKey==null){
873                                                 arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
874                                         }
875                                         if(nodeKey.endsWith("@0")){
876                                                 isArray = true;
877                                                 jsonArray = new JSONArray();
878                                         }
879                                         if(jsonArray != null && arryKey.equals(nodeKey.substring(0,nodeKey.indexOf("@")))){
880                                                 jsonArray.put(decodeContent(node));
881                                         }
882                                         jsonResult.put(arryKey, jsonArray);
883                                         jsonArray = new JSONArray();
884                                         arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
885                                 }else{
886                                         isArray = false;
887                                         jsonResult.put(nodeKey, decodeContent(node));
888                                 }
889                                 node = nodeFactory.objectNode();
890                                 if(key.contains("@")){
891                                         isArray = true;
892                                         if(key.endsWith("@0")|| jsonArray==null){
893                                                 jsonArray = new JSONArray();
894                                         }
895                                 }else if(!key.contains("@")){
896                                         isArray = false;
897                                 }
898                                 if(isArray){
899                                         if(oldValue==null){
900                                                 oldValue = key.substring(0,key.indexOf("@"));
901                                         }
902                                         if(oldValue!=prevKey){
903                                                 oldValue = key.substring(0,key.indexOf("@"));
904                                         }
905                                         if(oldValue.equals(key.substring(0,key.indexOf("@")))){
906                                                 jsonArray.put(element.get(key));
907                                         }else{
908                                                 jsonResult.put(oldValue, jsonArray);
909                                                 jsonArray = new JSONArray();
910                                         }
911                                         oldValue = key.substring(0,key.indexOf("@"));
912                                 }else{
913                                         jsonResult.put(key, element.get(key));
914                                 }
915                         }else{
916                                 if(key.contains("@")){
917                                         isArray = true;
918                                         if(key.endsWith("@0")|| jsonArray==null){
919                                                 jsonArray = new JSONArray();
920                                         }
921                                 }else if(!key.contains("@")){
922                                         isArray = false;
923                                 }
924                                 if(isArray){
925                                         if(oldValue==null){
926                                                 oldValue = key.substring(0,key.indexOf("@"));
927                                         }
928                                         if(oldValue!=prevKey){
929                                                 oldValue = key.substring(0,key.indexOf("@"));
930                                         }
931                                         if(oldValue.equals(key.substring(0,key.indexOf("@")))){
932                                                 jsonArray.put(element.get(key));
933                                         }else{
934                                                 jsonResult.put(oldValue, jsonArray);
935                                                 jsonArray = new JSONArray();
936                                         }
937                                         oldValue = key.substring(0,key.indexOf("@"));
938                                 }else{
939                                         jsonResult.put(key, element.get(key));
940                                 }
941                         }
942                 }
943                 if(node.size()>0){
944                         if(nodeKey.contains("@")){
945                                 if(jsonArray==null){
946                                         jsonArray = new JSONArray();
947                                 }
948                                 if(arryKey==null){
949                                         arryKey = nodeKey.substring(0,nodeKey.indexOf("@"));
950                                 }
951                                 jsonArray.put(decodeContent(node));
952                                 jsonResult.put(arryKey, jsonArray);
953                                 isArray = false;;
954                         }else{
955                                 jsonResult.put(nodeKey, decodeContent(node));
956                         }
957                 }
958                 if(isArray && jsonArray.length() > 0){
959                         jsonResult.put(oldValue, jsonArray);
960                 }
961                 return jsonResult;
962         }
963         
964         @RequestMapping(value={"/policyController/getDCAEMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
965         public ModelAndView getDCAEMSTemplateData(HttpServletRequest request, HttpServletResponse response) throws IOException{
966                 ObjectMapper mapper = new ObjectMapper();
967                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
968                 JsonNode root = mapper.readTree(request.getReader());
969
970                 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
971                 String  servicename = value.toString().split("-v")[0];
972                 String version = null;
973                 if (value.toString().contains("-v")){
974                         version = value.toString().split("-v")[1];
975                 }
976                 MicroServiceModels returnModel = getAttributeObject(servicename, version);
977                 
978                 String jsonModel = createMicroSeriveJson(returnModel);
979                 
980                 response.setCharacterEncoding("UTF-8");
981                 response.setContentType("application / json");
982                 request.setCharacterEncoding("UTF-8");
983                 List<Object>  list = new ArrayList<>();
984                 PrintWriter out = response.getWriter();
985                 String responseString = mapper.writeValueAsString(returnModel);
986                 JSONObject j = new JSONObject("{dcaeModelData: " + responseString + ",jsonValue: " + jsonModel + "}");
987                 list.add(j);
988                 out.write(list.toString());
989                 return null;
990         }
991         
992         @SuppressWarnings({ "unchecked", "rawtypes" })
993         private String createMicroSeriveJson(MicroServiceModels returnModel) {
994                 Map<String, String> attributeMap = new HashMap<>();
995                 Map<String, String> refAttributeMap = new HashMap<>();
996                 String attribute = returnModel.getAttributes();
997                 if(attribute != null){
998                         attribute = attribute.trim();
999                 }
1000                 String refAttribute = returnModel.getRef_attributes();
1001                 if(refAttribute != null){
1002                         refAttribute = refAttribute.trim();
1003                 }
1004                 String enumAttribute = returnModel.getEnumValues();
1005                 if(enumAttribute != null){
1006                         enumAttribute = enumAttribute.trim();
1007                 }
1008                 if (!StringUtils.isEmpty(attribute)){
1009                         attributeMap = convert(attribute, ",");
1010                 }
1011                 if (!StringUtils.isEmpty(refAttribute)){
1012                         refAttributeMap = convert(refAttribute, ",");
1013                 }
1014
1015                 Gson gson = new Gson();
1016                 
1017                 String subAttributes = returnModel.getSub_attributes();
1018                 if(subAttributes != null){
1019                         subAttributes = subAttributes.trim();
1020                 }else{
1021                         subAttributes = "";
1022                 }
1023                 Map gsonObject = (Map) gson.fromJson(subAttributes, Object.class);
1024                 
1025                 JSONObject object = new JSONObject();
1026                 JSONArray array = new JSONArray();
1027                 
1028                 for (Entry<String, String> keySet : attributeMap.entrySet()){
1029                         array = new JSONArray();
1030                         String value = keySet.getValue();
1031                         if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
1032                                 array.put(value);
1033                                 object.put(keySet.getKey().trim(), array);
1034                         }else {
1035                                 object.put(keySet.getKey().trim(), value.trim());
1036                         }
1037                 }
1038                 
1039                 for (Entry<String, String> keySet : refAttributeMap.entrySet()){
1040                         array = new JSONArray();
1041                         String value = keySet.getValue().split(":")[0];
1042                         if (gsonObject.containsKey(value)){
1043                                 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
1044                                         array.put(recursiveReference(value, gsonObject, enumAttribute));
1045                                         object.put(keySet.getKey().trim(), array);
1046                                 }else {
1047                                         object.put(keySet.getKey().trim(), recursiveReference(value, gsonObject, enumAttribute));
1048                                 }
1049                         }else {
1050                                 if (keySet.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
1051                                         array.put(value.trim());
1052                                         object.put(keySet.getKey().trim(), array);
1053                                 }else {
1054                                         object.put(keySet.getKey().trim(), value.trim()); 
1055                                 }
1056                         }
1057                 }
1058
1059                 return object.toString();
1060         }
1061
1062         @SuppressWarnings("unchecked")
1063         private JSONObject recursiveReference(String name, Map<String,String> subAttributeMap, String enumAttribute) {
1064                 JSONObject object = new JSONObject();
1065                 Map<String, String> map = new HashMap<>();
1066                 Object returnClass = subAttributeMap.get(name);
1067                 map = (Map<String, String>) returnClass; 
1068                 JSONArray array = new JSONArray();
1069                 
1070                 for( Entry<String, String> m:map.entrySet()){  
1071                         String[] splitValue = m.getValue().split(":");
1072                         array = new JSONArray();
1073                         if (subAttributeMap.containsKey(splitValue[0])){
1074                                 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
1075                                         array.put(recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
1076                                         object.put(m.getKey().trim(), array);
1077                                 }else {
1078                                         object.put(m.getKey().trim(), recursiveReference(splitValue[0], subAttributeMap, enumAttribute));
1079                                 }
1080                         } else{
1081                                 if (m.getValue().split("MANY-")[1].equalsIgnoreCase("true")){
1082                                         array.put(splitValue[0].trim());
1083                                         object.put(m.getKey().trim(), array);
1084                                 }else {
1085                                         object.put(m.getKey().trim(), splitValue[0].trim());
1086                                 }
1087                         }
1088                   }  
1089                 
1090                 return object;
1091         }
1092
1093         
1094         @RequestMapping(value={"/policyController/getModelServiceVersioneData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1095         public ModelAndView getModelServiceVersionData(HttpServletRequest request, HttpServletResponse response) throws IOException{
1096                 ObjectMapper mapper = new ObjectMapper();
1097                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
1098                 JsonNode root = mapper.readTree(request.getReader());
1099
1100                 String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
1101                 String  servicename = value.toString().split("-v")[0];
1102                 Set<String> returnList = getVersionList(servicename);
1103                 
1104                 response.setCharacterEncoding("UTF-8");
1105                 response.setContentType("application / json");
1106                 request.setCharacterEncoding("UTF-8");
1107         List<Object>  list = new ArrayList<>();
1108                 PrintWriter out = response.getWriter();
1109                 String responseString = mapper.writeValueAsString(returnList);
1110                 JSONObject j = new JSONObject("{dcaeModelVersionData: " + responseString +"}");
1111                 list.add(j);
1112                 out.write(list.toString());
1113                 return null;
1114         }
1115
1116         private Set<String> getVersionList(String name) {       
1117                 MicroServiceModels workingModel = new MicroServiceModels();
1118                 Set<String> list = new HashSet<>();
1119                 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
1120                 for (int i = 0; i < microServiceModelsData.size(); i++) {
1121                         workingModel = (MicroServiceModels) microServiceModelsData.get(i);
1122                         if (workingModel.getVersion()!=null){
1123                                 list.add(workingModel.getVersion());
1124                         }else{
1125                                 list.add("Default");
1126                         }
1127                 }
1128                 return list;
1129         }
1130         
1131         private MicroServiceModels getAttributeObject(String name, String version) {    
1132                 MicroServiceModels workingModel = new MicroServiceModels();
1133                 List<Object> microServiceModelsData = commonClassDao.getDataById(MicroServiceModels.class, "modelName", name);
1134                 for (int i = 0; i < microServiceModelsData.size(); i++) {
1135                         workingModel = (MicroServiceModels) microServiceModelsData.get(i);
1136                         if(version != null){
1137                                 if (workingModel.getVersion()!=null){
1138                                         if (workingModel.getVersion().equals(version)){
1139                                                 return workingModel;
1140                                         }
1141                                 }else{
1142                                         return workingModel;
1143                                 }
1144                         }else{
1145                                 return workingModel;
1146                         }
1147                         
1148                 }
1149                 return workingModel;
1150         }
1151
1152         @RequestMapping(value={"/get_DCAEPriorityValues"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
1153         public void getDCAEPriorityValuesData(HttpServletRequest request, HttpServletResponse response){
1154                 try{
1155                         Map<String, Object> model = new HashMap<>();
1156                         ObjectMapper mapper = new ObjectMapper();
1157                         List<String> priorityList = new ArrayList<>();
1158                         priorityCount = 10;
1159                         for (int i = 1; i < priorityCount; i++) {
1160                                 priorityList.add(String.valueOf(i));
1161                         }
1162                         model.put("priorityDatas", mapper.writeValueAsString(priorityList));
1163                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
1164                         JSONObject j = new JSONObject(msg);
1165                         response.getWriter().write(j.toString());
1166                 }
1167                 catch (Exception e){
1168                         LOGGER.error(e);
1169                 }
1170         }
1171
1172         public void prePopulateDCAEMSPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1173                 if (policyAdapter.getPolicyData() instanceof PolicyType) {
1174                         Object policyData = policyAdapter.getPolicyData();
1175                         PolicyType policy = (PolicyType) policyData;
1176                         policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
1177                         String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf("MS_") +3);
1178                         policyAdapter.setPolicyName(policyNameValue);
1179                         String description = "";
1180                         try{
1181                                 description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
1182                         }catch(Exception e){
1183                             LOGGER.error("Error while collecting the desciption tag in ActionPolicy " + policyNameValue ,e);
1184                                 description = policy.getDescription();
1185                         }
1186                         policyAdapter.setPolicyDescription(description);
1187                         // Get the target data under policy.
1188                         TargetType target = policy.getTarget();
1189                         if (target != null) {
1190                                 // Under target we have AnyOFType
1191                                 List<AnyOfType> anyOfList = target.getAnyOf();
1192                                 if (anyOfList != null) {
1193                                         Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
1194                                         while (iterAnyOf.hasNext()) {
1195                                                 AnyOfType anyOf = iterAnyOf.next();
1196                                                 // Under AnyOFType we have AllOFType
1197                                                 List<AllOfType> allOfList = anyOf.getAllOf();
1198                                                 if (allOfList != null) {
1199                                                         Iterator<AllOfType> iterAllOf = allOfList.iterator();
1200                                                         while (iterAllOf.hasNext()) {
1201                                                                 AllOfType allOf = iterAllOf.next();
1202                                                                 // Under AllOFType we have Match
1203                                                                 List<MatchType> matchList = allOf.getMatch();
1204                                                                 if (matchList != null) {
1205                                                                         Iterator<MatchType> iterMatch = matchList.iterator();
1206                                                                         while (matchList.size()>1 && iterMatch.hasNext()) {
1207                                                                                 MatchType match = iterMatch.next();
1208                                                                                 //
1209                                                                                 // Under the match we have attribute value and
1210                                                                                 // attributeDesignator. So,finally down to the actual attribute.
1211                                                                                 //
1212                                                                                 AttributeValueType attributeValue = match.getAttributeValue();
1213                                                                                 String value = (String) attributeValue.getContent().get(0);
1214                                                                                 AttributeDesignatorType designator = match.getAttributeDesignator();
1215                                                                                 String attributeId = designator.getAttributeId();
1216                                                                                 // First match in the target is OnapName, so set that value.
1217                                                                                 if (attributeId.equals("ONAPName")) {
1218                                                                                         policyAdapter.setOnapName(value);
1219                                                                                 }
1220                                                                                 if (attributeId.equals("ConfigName")){
1221                                                                                         policyAdapter.setConfigName(value);
1222                                                                                 }
1223                                                                                 if (attributeId.equals("uuid")){
1224                                                                                         policyAdapter.setUuid(value);
1225                                                                                 }
1226                                                                                 if (attributeId.equals("location")){
1227                                                                                         policyAdapter.setLocation(value);
1228                                                                                 }
1229                                                                                 if (attributeId.equals("RiskType")){
1230                                                                                         policyAdapter.setRiskType(value);
1231                                                                                 }
1232                                                                                 if (attributeId.equals("RiskLevel")){
1233                                                                                         policyAdapter.setRiskLevel(value);
1234                                                                                 }
1235                                                                                 if (attributeId.equals("guard")){
1236                                                                                         policyAdapter.setGuard(value);
1237                                                                                 }
1238                                                                                 if (attributeId.equals("TTLDate") && !value.contains("NA")){
1239                                                                                         String newDate = convertDate(value, true);
1240                                                                                         policyAdapter.setTtlDate(newDate);
1241                                                                                 }
1242                                                                         }
1243                                                                         readFile(policyAdapter, entity);
1244                                                                 }
1245                                                         }
1246                                                 }
1247                                         }
1248                                 }
1249                         }
1250                 }
1251         }
1252
1253         private String convertDate(String dateTTL, boolean portalType) {
1254                 String formateDate = null;
1255                 String[] date  = dateTTL.split("T");
1256                 String[] parts = date[0].split("-");
1257                         
1258                 formateDate = parts[2] + "-" + parts[1] + "-" + parts[0];
1259                 return formateDate;
1260         }
1261         
1262         public static Map<String, String> convert(String str, String split) {
1263                 Map<String, String> map = new HashMap<>();
1264                 for(final String entry : str.split(split)) {
1265                     String[] parts = entry.split("=");
1266                     map.put(parts[0], parts[1]);
1267                 }
1268                 return map;
1269         }
1270
1271
1272         @SuppressWarnings("unchecked")
1273         private void readFile(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
1274                 String policyScopeName = null;
1275                 ObjectMapper mapper = new ObjectMapper();
1276                 try {
1277                         DCAEMicroServiceObject msBody = (DCAEMicroServiceObject) mapper.readValue(entity.getConfigurationData().getConfigBody(), DCAEMicroServiceObject.class);
1278                         policyScopeName = getPolicyScope(msBody.getPolicyScope());
1279                         policyAdapter.setPolicyScope(policyScopeName);
1280
1281                         policyAdapter.setPriority(msBody.getPriority());
1282
1283                         if (msBody.getVersion()!= null){
1284                                 policyAdapter.setServiceType(msBody.getService());
1285                                 policyAdapter.setVersion(msBody.getVersion());
1286                         }else{
1287                                 policyAdapter.setServiceType(msBody.getService());
1288                         }
1289                         if(msBody.getContent() != null){
1290                                 LinkedHashMap<String, Object>  data = new LinkedHashMap<>();
1291                                 LinkedHashMap<String, ?> map = (LinkedHashMap<String, ?>) msBody.getContent();
1292                                 readRecursivlyJSONContent(map, data);
1293                                 policyAdapter.setRuleData(data);
1294                         }
1295
1296                 } catch (Exception e) {
1297                         LOGGER.error(e);
1298                 }
1299
1300         }
1301
1302         @SuppressWarnings({ "rawtypes", "unchecked" })
1303         private void readRecursivlyJSONContent(LinkedHashMap<String, ?> map, LinkedHashMap<String, Object> data){
1304                 for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
1305                         Object key =  iterator.next();
1306                         Object value = map.get(key);
1307                         if(value instanceof LinkedHashMap<?, ?>){
1308                                 LinkedHashMap<String, Object> secondObjec = new LinkedHashMap<>(); 
1309                                 readRecursivlyJSONContent((LinkedHashMap<String, ?>) value, secondObjec);
1310                                 for(String objKey: secondObjec.keySet()){
1311                                         data.put(key+"." +objKey, secondObjec.get(objKey));
1312                                 }
1313                         }else if(value instanceof ArrayList){
1314                                 ArrayList<?> jsonArrayVal = (ArrayList<?>)value;
1315                                 for(int i = 0; i < jsonArrayVal.size(); i++){
1316                                         Object arrayvalue = jsonArrayVal.get(i);
1317                                         if(arrayvalue instanceof LinkedHashMap<?, ?>){
1318                                                 LinkedHashMap<String, Object> newData = new LinkedHashMap<>();   
1319                                                 readRecursivlyJSONContent((LinkedHashMap<String, ?>) arrayvalue, newData);
1320                                                 for(String objKey: newData.keySet()){
1321                                                         data.put(key+"@"+i+"." +objKey, newData.get(objKey));
1322                                                 }
1323                                         }else if(arrayvalue instanceof ArrayList){
1324                                                 ArrayList<?> jsonArrayVal1 = (ArrayList<?>)value;
1325                                                 for(int j = 0; j < jsonArrayVal1.size(); j++){
1326                                                         Object arrayvalue1 = jsonArrayVal1.get(i);
1327                                                         data.put(key+"@"+j, arrayvalue1.toString());
1328                                                 }       
1329                                         }else{
1330                                                 data.put(key+"@"+i, arrayvalue.toString());
1331                                         }       
1332                                 }
1333                         }else{
1334                                 data.put(key.toString(), value.toString());
1335                         }       
1336                 }
1337         }
1338
1339         private String getPolicyScope(String value) {
1340                 List<Object> groupList= commonClassDao.getDataById(GroupPolicyScopeList.class, "groupList", value);
1341                 if(groupList != null && !groupList.isEmpty()){
1342                         GroupPolicyScopeList pScope = (GroupPolicyScopeList) groupList.get(0);
1343                         return pScope.getGroupName();           
1344                 }
1345                 return null;
1346         }
1347
1348         //Convert the map values and set into JSON body
1349         public Map<String, String> convertMap(Map<String, String> attributesMap, Map<String, String> attributesRefMap) {
1350                 Map<String, String> attribute = new HashMap<>();
1351                 String temp = null;
1352                 String key;
1353                 String value;
1354                 for (Entry<String, String> entry : attributesMap.entrySet()) {
1355                         key = entry.getKey();
1356                         value = entry.getValue();
1357                         attribute.put(key, value);
1358                 }
1359                 for (Entry<String, String> entryRef : attributesRefMap.entrySet()) {
1360                         key = entryRef.getKey();
1361                         value = entryRef.getValue().toString();
1362                         attribute.put(key, value);
1363                 }
1364                 for (Entry<String, String> entryList : attributesListRefMap.entrySet()) {
1365                         key = entryList.getKey();
1366                         value = entryList.getValue().toString();
1367                         attribute.put(key, value);
1368                 }
1369                 for (Entry<String, LinkedList<String>> arrayList : arrayTextList.entrySet()){
1370                         key = arrayList.getKey();
1371                         temp = null;
1372                         for (Object textList : arrayList.getValue()){
1373                                 if (temp == null){
1374                                         temp = "[" + textList;
1375                                 }else{
1376                                         temp = temp + "," + textList;
1377                                 }
1378                         }
1379                         attribute.put(key, temp+ "]");                  
1380                 }
1381
1382                 return  attribute;
1383         }
1384         
1385         @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
1386         public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException{
1387                 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
1388                 boolean zip = false;
1389                 boolean yml= false;
1390                 for (FileItem item : items) {
1391                         if(item.getName().endsWith(".zip") || item.getName().endsWith(".xmi")||item.getName().endsWith(".yml")){
1392                                 this.newModel = new MicroServiceModels();
1393                                 try{
1394                                         File file = new File(item.getName());
1395                                         OutputStream outputStream = new FileOutputStream(file);
1396                                         IOUtils.copy(item.getInputStream(), outputStream);
1397                                         outputStream.close();
1398                                         this.newFile = file.toString();
1399                                         this.newModel.setModelName(this.newFile.toString().split("-v")[0]);
1400                                 
1401                                         if (this.newFile.toString().contains("-v")){
1402                                                 if (item.getName().endsWith(".zip")){
1403                                                         this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".zip", ""));
1404                                                         zip = true;
1405                                                 }else if(item.getName().endsWith(".yml")){
1406                                                         this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".yml", ""));
1407                                                         yml = true;
1408                                                 }
1409                                                 else {
1410                                                         this.newModel.setVersion(this.newFile.toString().split("-v")[1].replace(".xmi", ""));
1411                                                 }
1412                                         }
1413                                 
1414                                 }catch(Exception e){
1415                                         LOGGER.error("Upload error : " + e);
1416                                 }
1417                         }
1418                         
1419                 }
1420                 List<File> fileList = new ArrayList<>();;
1421                 this.directory = "model";
1422                 if (zip){
1423                         extractFolder(this.newFile);
1424                         fileList = listModelFiles(this.directory);
1425                 }else if (yml==true){
1426                         parseTosca(this.newFile);
1427                 }else {
1428                         File file = new File(this.newFile);
1429                         fileList.add(file);
1430                 }
1431                 String modelType= "";
1432                 if(yml==false){
1433                         modelType="xmi";
1434                         //Process Main Model file first
1435                         classMap = new HashMap<>();
1436                         for (File file : fileList) {
1437                                 if(!file.isDirectory() && file.getName().endsWith(".xmi")){
1438                         retreiveDependency(file.toString(), true);
1439                     }   
1440                         }
1441                         
1442                         modelList = createList();
1443                         
1444                         cleanUp(this.newFile);
1445                         cleanUp(directory);
1446                 }else{
1447                         modelType="yml";
1448                         modelList.add(this.newModel.getModelName());
1449                         String className=this.newModel.getModelName();
1450                         MSAttributeObject msAttributes= new MSAttributeObject();
1451                         msAttributes.setClassName(className);
1452                         
1453                         HashMap<String, String> returnAttributeList =new HashMap<>();
1454                         returnAttributeList.put(className, this.attributeString);
1455                         msAttributes.setAttribute(returnAttributeList);
1456                         
1457                         msAttributes.setSubClass(this.retmap);
1458                         
1459                         HashMap<String, String> returnReferenceList =new HashMap<>();
1460                         //String[] referenceArray=this.referenceAttributes.split("=");
1461                         returnReferenceList.put(className, this.referenceAttributes);
1462                         msAttributes.setRefAttribute(returnReferenceList);
1463                         
1464                         if(this.listConstraints!=""){
1465                                 HashMap<String, String> enumList =new HashMap<>();
1466                                 String[] listArray=this.listConstraints.split("#");
1467                 for(String str:listArray){
1468                     String[] strArr= str.split("=");
1469                     if(strArr.length>1){
1470                         enumList.put(strArr[0], strArr[1]);
1471                     }
1472                 }
1473                                 msAttributes.setEnumType(enumList);
1474                         }
1475                         
1476                         classMap=new HashMap<>();
1477                         classMap.put(className, msAttributes);
1478                         
1479                 }
1480                 
1481                 PrintWriter out = response.getWriter();
1482                 
1483                 response.setCharacterEncoding("UTF-8");
1484                 response.setContentType("application / json");
1485                 request.setCharacterEncoding("UTF-8");
1486                 
1487                 ObjectMapper mapper = new ObjectMapper();
1488                 JSONObject j = new JSONObject();
1489                 j.put("classListDatas", modelList);
1490                 j.put("modelDatas", mapper.writeValueAsString(classMap));
1491                 j.put("modelType", modelType);
1492                 out.write(j.toString());
1493         }
1494         
1495         /*
1496          * Unzip file and store in the model directory for processing
1497          */
1498         @SuppressWarnings("rawtypes")
1499         private void extractFolder(String zipFile )  {
1500             int BUFFER = 2048;
1501             File file = new File(zipFile);
1502
1503             ZipFile zip = null;
1504                 try {
1505                         zip = new ZipFile(file);
1506                     String newPath =  "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1507                     this.directory = "model" + File.separator + zipFile.substring(0, zipFile.length() - 4);
1508                     checkZipDirectory(this.directory);
1509                     new File(newPath).mkdir();
1510                     Enumeration zipFileEntries = zip.entries();
1511         
1512                     // Process each entry
1513                     while (zipFileEntries.hasMoreElements()){
1514                         // grab a zip file entry
1515                         ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
1516                         String currentEntry = entry.getName();
1517                         File destFile = new File("model" + File.separator + currentEntry);
1518                         File destinationParent = destFile.getParentFile();
1519                         
1520                         destinationParent.mkdirs();
1521         
1522                         if (!entry.isDirectory()){
1523                             BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
1524                             int currentByte;
1525                             byte data[] = new byte[BUFFER];
1526                             FileOutputStream fos = new FileOutputStream(destFile);
1527                             BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
1528                             while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
1529                                 dest.write(data, 0, currentByte);
1530                             }
1531                             dest.flush();
1532                             dest.close();
1533                             is.close();
1534                         }
1535         
1536                         if (currentEntry.endsWith(".zip")){
1537                             extractFolder(destFile.getAbsolutePath());
1538                         }
1539                     }
1540             } catch (IOException e) {
1541                 LOGGER.error("Failed to unzip model file " + zipFile, e);
1542                 }finally{
1543                         try {
1544                                 if(zip != null)
1545                                 zip.close();
1546                         } catch (IOException e) {
1547                                 LOGGER.error("Exception Occured While closing zipfile " + e);
1548                         }
1549                 }
1550         }
1551         
1552         private void retreiveDependency(String workingFile, Boolean modelClass) {
1553                 
1554                 MSModelUtils utils = new MSModelUtils(PolicyController.getMsOnapName(), PolicyController.getMsPolicyName());
1555             HashMap<String, MSAttributeObject> tempMap = new HashMap<>();
1556             
1557             tempMap = utils.processEpackage(workingFile, MODEL_TYPE.XMI);
1558             
1559             classMap.putAll(tempMap);
1560             LOGGER.info(tempMap);
1561             
1562             return;     
1563             
1564         }
1565                 
1566         private List<File> listModelFiles(String directoryName) {
1567                 File directory = new File(directoryName);
1568                 List<File> resultList = new ArrayList<>();
1569                 File[] fList = directory.listFiles();
1570                 for (File file : fList) {
1571                         if (file.isFile()) {
1572                                 resultList.add(file);
1573                         } else if (file.isDirectory()) {
1574                                 dirDependencyList.add(file.getName());
1575                                 resultList.addAll(listModelFiles(file.getAbsolutePath()));
1576                         }
1577                 }
1578                 return resultList;
1579         }
1580         
1581     private void cleanUp(String path) {
1582         if (path!=null){
1583             try {
1584                 FileUtils.forceDelete(new File(path));
1585             } catch (IOException e) {
1586                 LOGGER.error("Failed to delete folder " + path, e);
1587             }  
1588         }
1589     }
1590  
1591     private void checkZipDirectory(String zipDirectory) {
1592         Path path = Paths.get(zipDirectory);
1593  
1594         if (Files.exists(path)) {
1595             cleanUp(zipDirectory);
1596         }
1597     }
1598         
1599     private List<String> createList() {
1600         List<String> list = new  ArrayList<>();
1601         for (Entry<String, MSAttributeObject> cMap : classMap.entrySet()){
1602             if (cMap.getValue().isPolicyTempalate()){
1603                 list.add(cMap.getKey());
1604             }
1605             
1606         }
1607         
1608         if (list.isEmpty()){
1609             if (classMap.containsKey(this.newModel.getModelName())){
1610                 list.add(this.newModel.getModelName());
1611             }else {
1612                 list.add("EMPTY");
1613             }
1614         }
1615         return list;
1616     }
1617
1618         public Map<String, String> getAttributesListRefMap() {
1619                 return attributesListRefMap;
1620         }
1621
1622         public Map<String, LinkedList<String>> getArrayTextList() {
1623                 return arrayTextList;
1624         }
1625
1626 }
1627
1628 class DCAEMicroServiceObject {
1629
1630         private String service;
1631         private String location;
1632         private String uuid;
1633         private String policyName;
1634         private String description;
1635         private String configName;
1636         private String templateVersion;
1637         private String version;
1638         private String priority;
1639         private String policyScope;
1640         private String riskType;
1641         private String riskLevel; 
1642         private String guard = null;
1643
1644         public String getGuard() {
1645                 return guard;
1646         }
1647         public void setGuard(String guard) {
1648                 this.guard = guard;
1649         }
1650         public String getRiskType() {
1651                 return riskType;
1652         }
1653         public void setRiskType(String riskType) {
1654                 this.riskType = riskType;
1655         }
1656         public String getRiskLevel() {
1657                 return riskLevel;
1658         }
1659         public void setRiskLevel(String riskLevel) {
1660                 this.riskLevel = riskLevel;
1661         }
1662         public String getPolicyScope() {
1663                 return policyScope;
1664         }
1665         public void setPolicyScope(String policyScope) {
1666                 this.policyScope = policyScope;
1667         }
1668
1669         public String getPriority() {
1670                 return priority;
1671         }
1672         public void setPriority(String priority) {
1673                 this.priority = priority;
1674         }
1675         public String getVersion() {
1676                 return version;
1677         }
1678         public void setVersion(String version) {
1679                 this.version = version;
1680         }
1681         private Object content;
1682
1683
1684         public String getPolicyName() {
1685                 return policyName;
1686         }
1687         public void setPolicyName(String policyName) {
1688                 this.policyName = policyName;
1689         }
1690         public String getDescription() {
1691                 return description;
1692         }
1693         public void setDescription(String description) {
1694                 this.description = description;
1695         }
1696         public String getConfigName() {
1697                 return configName;
1698         }
1699         public void setConfigName(String configName) {
1700                 this.configName = configName;
1701         }
1702         public Object getContent() {
1703                 return content;
1704         }
1705         public void setContent(Object content) {
1706                 this.content = content;
1707         }
1708
1709         public String getService() {
1710                 return service;
1711         }
1712         public void setService(String service) {
1713                 this.service = service;
1714         }
1715         public String getLocation() {
1716                 return location;
1717         }
1718         public void setLocation(String location) {
1719                 this.location = location;
1720         }
1721
1722         public String getUuid() {
1723                 return uuid;
1724         }
1725         public void setUuid(String uuid) {
1726                 this.uuid = uuid;
1727         }
1728         public String getTemplateVersion() {
1729                 return templateVersion;
1730         }
1731         public void setTemplateVersion(String templateVersion) {
1732                 this.templateVersion = templateVersion;
1733         }
1734
1735 }