Merge "Technical debt reduction"
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / controller / MicroServiceDictionaryController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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.pap.xacml.rest.controller;
22
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Set;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34
35 import org.apache.commons.lang.StringUtils;
36 import org.json.JSONObject;
37 import org.onap.policy.common.logging.flexlogger.FlexLogger;
38 import org.onap.policy.common.logging.flexlogger.Logger;
39 import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
40 import org.onap.policy.pap.xacml.rest.util.JsonMessage;
41 import org.onap.policy.rest.dao.CommonClassDao;
42 import org.onap.policy.rest.jpa.DCAEuuid;
43 import org.onap.policy.rest.jpa.MicroServiceAttribute;
44 import org.onap.policy.rest.jpa.MicroServiceConfigName;
45 import org.onap.policy.rest.jpa.MicroServiceLocation;
46 import org.onap.policy.rest.jpa.MicroServiceModels;
47 import org.onap.policy.rest.jpa.UserInfo;
48 import org.onap.policy.rest.util.MSAttributeObject;
49 import org.onap.policy.rest.util.MSModelUtils;
50 import org.onap.policy.utils.PolicyUtils;
51 import org.springframework.beans.factory.annotation.Autowired;
52 import org.springframework.http.MediaType;
53 import org.springframework.stereotype.Controller;
54 import org.springframework.web.bind.annotation.RequestMapping;
55 import org.springframework.web.servlet.ModelAndView;
56
57 import com.fasterxml.jackson.databind.DeserializationFeature;
58 import com.fasterxml.jackson.databind.JsonNode;
59 import com.fasterxml.jackson.databind.ObjectMapper;
60 import com.google.gson.Gson;
61
62 @Controller
63 public class MicroServiceDictionaryController {
64         private static final Logger LOGGER  = FlexLogger.getLogger(MicroServiceDictionaryController.class);
65
66         private static CommonClassDao commonClassDao;
67         
68     private static String successMapKey= "successMapKey";
69     private static String successMsg = "success";
70     private static String operation = "operation";
71     private static String getDictionary = "getDictionary";
72     private static String errorMsg = "error";
73     private static String dictionaryDBQuery = "dictionaryDBQuery";
74     private HashMap<String,MSAttributeObject > classMap;
75     private List<String> modelList = new ArrayList<>();
76     private static String apiflag = "apiflag";
77         private static String dictionaryFields ="dictionaryFields";
78         private static String update = "update";
79         private static String duplicateResponseString = "Duplicate";
80         private static String successMessage = "Success";
81         private static String utf8 = "UTF-8";
82         private static String applicationJsonContentType = "application / json";
83         private static String existsResponseString = "Exists";
84         private static String microServiceModelsDictionaryDatas = "microServiceModelsDictionaryDatas";
85         private static String modelName = "modelName";
86         private static String microServiceModelsDictionaryData = "microServiceModelsDictionaryData";
87         private static String description = "description";
88         private static String version = "version";
89         private static String classMapData = "classMap";
90         /*
91          * This is an empty constructor
92          */
93     public MicroServiceDictionaryController(){} 
94         
95         @Autowired
96         public MicroServiceDictionaryController(CommonClassDao commonClassDao){
97                 MicroServiceDictionaryController.commonClassDao = commonClassDao;
98         }
99         public static void setCommonClassDao(CommonClassDao commonClassDao) {
100                 MicroServiceDictionaryController.commonClassDao = commonClassDao;
101         }
102         
103         public UserInfo getUserInfo(String loginId){
104                 return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
105         }
106
107         MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
108         private MicroServiceModels newModel;
109         
110         
111         @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
112         public void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response){
113                 try{
114                         Map<String, Object> model = new HashMap<>();
115                         ObjectMapper mapper = new ObjectMapper();
116                         model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DCAEuuid.class, "name")));
117                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
118                         JSONObject j = new JSONObject(msg);
119                         response.getWriter().write(j.toString());
120                 }
121                 catch (Exception e){
122                         LOGGER.error(e);
123                 }
124         }
125
126         @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
127         public void getDCAEUUIDDictionaryEntityData(HttpServletResponse response){
128                 try{
129                         Map<String, Object> model = new HashMap<>();
130                         ObjectMapper mapper = new ObjectMapper();
131                         model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)));
132                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
133                         JSONObject j = new JSONObject(msg);
134             response.addHeader(successMapKey, successMsg);    
135             response.addHeader(operation, getDictionary);
136                         response.getWriter().write(j.toString());
137                 }
138                 catch (Exception e){
139             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
140             response.addHeader(errorMsg, dictionaryDBQuery);
141             LOGGER.error(e);
142                 }
143         }
144         
145         @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
146         public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
147                 try {
148                         boolean duplicateflag = false;
149             boolean isFakeUpdate = false;
150             boolean fromAPI = false;
151             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
152                 fromAPI = true;
153             }
154                         ObjectMapper mapper = new ObjectMapper();
155                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
156                         JsonNode root = mapper.readTree(request.getReader());
157             DCAEuuid dCAEuuid;
158             if (fromAPI) {
159                 dCAEuuid = (DCAEuuid)mapper.readValue(root.get(dictionaryFields).toString(), DCAEuuid.class);
160                 
161                 //check if update operation or create, get id for data to be updated and update attributeData
162                 if ((update).equals(request.getParameter(operation))) {
163                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
164                         DCAEuuid data = (DCAEuuid) duplicateData.get(0);
165                         int id = data.getId();
166                         if(id==0){
167                                 isFakeUpdate=true;
168                                 dCAEuuid.setId(1);
169                         } else {
170                                 dCAEuuid.setId(id);
171                         }       
172                 }
173             } else {
174                 dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class);
175             }
176                         if(dCAEuuid.getId() == 0){
177                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
178                                 if(!duplicateData.isEmpty()){
179                                         duplicateflag = true;
180                                 }else{
181                                         commonClassDao.save(dCAEuuid);
182                                 }
183                         }else{
184                                 if(!isFakeUpdate) {
185                                         commonClassDao.update(dCAEuuid); 
186                                 }
187                         } 
188             String responseString = "";
189             if(duplicateflag){
190                 responseString = duplicateResponseString;
191             }else{
192                 responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
193             } 
194             
195             if (fromAPI) {
196                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
197                     if(isFakeUpdate){
198                         responseString = existsResponseString;
199                     } else {
200                         responseString = successMessage;
201                     }
202                 }
203                 ModelAndView result = new ModelAndView();
204                 result.setViewName(responseString);
205                 return result;
206             } else {
207                 response.setCharacterEncoding(utf8);
208                 response.setContentType(applicationJsonContentType);
209                 request.setCharacterEncoding(utf8);
210  
211                 PrintWriter out = response.getWriter();
212                 JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}");
213                 out.write(j.toString());
214                 return null;
215             }
216         }catch (Exception e){
217                         response.setCharacterEncoding(utf8);
218                         request.setCharacterEncoding(utf8);
219                         PrintWriter out = response.getWriter();
220                         out.write(PolicyUtils.CATCH_EXCEPTION);
221                         LOGGER.error(e);
222                 }
223                 return null;
224         }
225
226         @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
227         public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
228                 try{
229                         ObjectMapper mapper = new ObjectMapper();
230                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
231                         JsonNode root = mapper.readTree(request.getReader());
232                         DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class);
233                         commonClassDao.delete(dCAEuuid);
234                         response.setCharacterEncoding(utf8);
235                         response.setContentType(applicationJsonContentType);
236                         request.setCharacterEncoding(utf8);
237
238                         PrintWriter out = response.getWriter();
239
240                         String responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
241                         JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}");
242                         out.write(j.toString());
243
244                         return null;
245                 }
246                 catch (Exception e){
247                         LOGGER.error(e);
248                         response.setCharacterEncoding(utf8);
249                         request.setCharacterEncoding(utf8);
250                         PrintWriter out = response.getWriter();
251                         out.write(PolicyUtils.CATCH_EXCEPTION);
252                 }
253                 return null;
254         }
255         
256         
257         @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
258         public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response){
259                 try{
260                         Map<String, Object> model = new HashMap<>();
261                         ObjectMapper mapper = new ObjectMapper();
262                         model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceConfigName.class, "name")));
263                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
264                         JSONObject j = new JSONObject(msg);
265                         response.getWriter().write(j.toString());
266                 }
267                 catch (Exception e){
268                         LOGGER.error(e);
269                 }
270         }
271         
272         
273         
274         @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
275         public void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response){
276                 try{
277                         Map<String, Object> model = new HashMap<>();
278                         ObjectMapper mapper = new ObjectMapper();
279                         model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)));
280                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
281                         JSONObject j = new JSONObject(msg);
282             response.addHeader(successMapKey, successMsg);    
283             response.addHeader(operation, getDictionary);
284                         response.getWriter().write(j.toString());
285                 }
286                 catch (Exception e){
287             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
288             response.addHeader(errorMsg, dictionaryDBQuery);
289             LOGGER.error(e);
290                 }
291         }
292         
293         @RequestMapping(value={"/ms_dictionary/save_configName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
294         public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
295                 try {
296                         boolean duplicateflag = false;
297             boolean isFakeUpdate = false;
298             boolean fromAPI = false;
299             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
300                 fromAPI = true;
301             }
302                         ObjectMapper mapper = new ObjectMapper();
303                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
304                         JsonNode root = mapper.readTree(request.getReader());
305             MicroServiceConfigName microServiceConfigName;
306             if (fromAPI) {
307                 microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceConfigName.class);
308                 
309                 //check if update operation or create, get id for data to be updated and update attributeData
310                 if ((update).equals(request.getParameter(operation))) {
311                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
312                     MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0);
313                     int id = data.getId();
314                 
315                     if(id==0){
316                         isFakeUpdate=true;
317                         microServiceConfigName.setId(1);
318                     } else {
319                         microServiceConfigName.setId(id);
320                     }  
321                 }
322             } else {
323                 microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("microServiceCongigNameDictionaryData").toString(), MicroServiceConfigName.class);
324             }
325                         if(microServiceConfigName.getId() == 0){
326                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
327                                 if(!duplicateData.isEmpty()){
328                                         duplicateflag = true;
329                                 }else{
330                                         commonClassDao.save(microServiceConfigName);
331                                 }
332                         }else{
333                                 if(!isFakeUpdate) {
334                                         commonClassDao.update(microServiceConfigName); 
335                                 }
336                         } 
337             String responseString = "";
338             if(duplicateflag){
339                 responseString = duplicateResponseString;
340             }else{
341                 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
342             }
343             
344             if (fromAPI) {
345                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
346                     if(isFakeUpdate){
347                         responseString = existsResponseString;
348                     } else {
349                         responseString = successMessage;
350                     }
351                 }
352                 ModelAndView result = new ModelAndView();
353                 result.setViewName(responseString);
354                 return result;
355             } else {
356                 response.setCharacterEncoding(utf8);
357                 response.setContentType(applicationJsonContentType);
358                 request.setCharacterEncoding(utf8);
359  
360                 PrintWriter out = response.getWriter();
361                 JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}");
362                 out.write(j.toString());
363                 return null;
364             }
365         }catch (Exception e){
366                         response.setCharacterEncoding(utf8);
367                         request.setCharacterEncoding(utf8);
368                         PrintWriter out = response.getWriter();
369                         out.write(PolicyUtils.CATCH_EXCEPTION);
370                         LOGGER.error(e);
371                 }
372                 return null;
373         }
374
375         @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
376         public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
377                 try{
378                         ObjectMapper mapper = new ObjectMapper();
379                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
380                         JsonNode root = mapper.readTree(request.getReader());
381                         MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class);
382                         commonClassDao.delete(microServiceConfigName);
383                         response.setCharacterEncoding(utf8);
384                         response.setContentType(applicationJsonContentType);
385                         request.setCharacterEncoding(utf8);
386
387                         PrintWriter out = response.getWriter();
388
389                         String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
390                         JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}");
391                         out.write(j.toString());
392
393                         return null;
394                 }
395                 catch (Exception e){
396                         LOGGER.error(e);
397                         response.setCharacterEncoding(utf8);
398                         request.setCharacterEncoding(utf8);
399                         PrintWriter out = response.getWriter();
400                         out.write(PolicyUtils.CATCH_EXCEPTION);
401                 }
402                 return null;
403         }
404         
405         @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
406         public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response){
407                 try{
408                         Map<String, Object> model = new HashMap<>();
409                         ObjectMapper mapper = new ObjectMapper();
410                         model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")));
411                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
412                         JSONObject j = new JSONObject(msg);
413                         response.getWriter().write(j.toString());
414                 }
415                 catch (Exception e){
416                         LOGGER.error(e);
417                 }
418         }
419         
420         @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
421         public void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response){
422                 try{
423                         Map<String, Object> model = new HashMap<>();
424                         ObjectMapper mapper = new ObjectMapper();
425                         model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)));
426                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
427                         JSONObject j = new JSONObject(msg);
428             response.addHeader(successMapKey, successMsg);    
429             response.addHeader(operation, getDictionary);
430                         response.getWriter().write(j.toString());
431                 }
432                 catch (Exception e){
433             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
434             response.addHeader(errorMsg, dictionaryDBQuery);
435             LOGGER.error(e);
436                 }
437         }
438         
439         @RequestMapping(value={"/ms_dictionary/save_location"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
440         public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
441                 try {
442                         boolean duplicateflag = false;
443             boolean isFakeUpdate = false;
444             boolean fromAPI = false;
445             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
446                 fromAPI = true;
447             }
448                         ObjectMapper mapper = new ObjectMapper();
449                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
450                         JsonNode root = mapper.readTree(request.getReader());
451             MicroServiceLocation microServiceLocation;
452             if (fromAPI) {
453                 microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceLocation.class);
454                 
455                 //check if update operation or create, get id for data to be updated and update attributeData
456                 if ((update).equals(request.getParameter(operation))) {
457                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
458                     MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0);
459                     int id = data.getId();
460                   
461                     if(id==0){
462                         isFakeUpdate=true;
463                         microServiceLocation.setId(1);
464                     } else {
465                         microServiceLocation.setId(id);
466                     }
467                 }
468             } else {
469                 microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class);
470             }
471                         if(microServiceLocation.getId() == 0){
472                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
473                                 if(!duplicateData.isEmpty()){
474                                         duplicateflag = true;
475                                 }else{
476                                         commonClassDao.save(microServiceLocation);
477                                 }
478                         }else{
479                                 if(!isFakeUpdate) {
480                                         commonClassDao.update(microServiceLocation); 
481                                 }
482                         } 
483             String responseString = "";
484             if(duplicateflag){
485                 responseString = duplicateResponseString;
486             }else{
487                 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
488             }
489             
490             if (fromAPI) {
491                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
492                     if(isFakeUpdate){
493                         responseString = existsResponseString;
494                     } else {
495                         responseString = successMessage;
496                     }
497                 }
498                 ModelAndView result = new ModelAndView();
499                 result.setViewName(responseString);
500                 return result;
501             } else {
502                 response.setCharacterEncoding(utf8);
503                 response.setContentType(applicationJsonContentType);
504                 request.setCharacterEncoding(utf8);
505  
506                 PrintWriter out = response.getWriter();
507                 JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}");
508                 out.write(j.toString());
509                 return null;
510             }
511                 }catch (Exception e){
512                         response.setCharacterEncoding(utf8);
513                         request.setCharacterEncoding(utf8);
514                         PrintWriter out = response.getWriter();
515                         out.write(PolicyUtils.CATCH_EXCEPTION);
516                         LOGGER.error(e);
517                 }
518                 return null;
519         }
520
521         @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
522         public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
523                 try{
524                         ObjectMapper mapper = new ObjectMapper();
525                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
526                         JsonNode root = mapper.readTree(request.getReader());
527                         MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
528                         commonClassDao.delete(microServiceLocation);
529                         response.setCharacterEncoding(utf8);
530                         response.setContentType(applicationJsonContentType);
531                         request.setCharacterEncoding(utf8);
532
533                         PrintWriter out = response.getWriter();
534
535                         String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
536                         JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}");
537                         out.write(j.toString());
538
539                         return null;
540                 }
541                 catch (Exception e){
542                         LOGGER.error(e);
543                         response.setCharacterEncoding(utf8);
544                         request.setCharacterEncoding(utf8);
545                         PrintWriter out = response.getWriter();
546                         out.write(PolicyUtils.CATCH_EXCEPTION);
547                 }
548                 return null;
549         }
550         
551     @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
552     public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response){
553         try{
554             Map<String, Object> model = new HashMap<>();
555             ObjectMapper mapper = new ObjectMapper();
556             model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceAttribute.class, "name")));
557             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
558             JSONObject j = new JSONObject(msg);
559             response.getWriter().write(j.toString());
560         }
561         catch (Exception e){
562             LOGGER.error(e);
563         }
564     }
565     
566     @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
567     public void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response){
568         try{
569             Map<String, Object> model = new HashMap<>();
570             ObjectMapper mapper = new ObjectMapper();
571             model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)));
572             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
573             JSONObject j = new JSONObject(msg);
574             response.addHeader(successMapKey, successMsg);    
575             response.addHeader(operation, getDictionary);
576             response.getWriter().write(j.toString());
577  
578         }
579         catch (Exception e){
580             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
581             response.addHeader(errorMsg, dictionaryDBQuery);
582             LOGGER.error(e);
583         }
584     }
585     
586     @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
587     public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
588         try {
589             boolean duplicateflag = false;
590             boolean fromAPI = false;
591             if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
592                 fromAPI = true;
593             }
594             
595             ObjectMapper mapper = new ObjectMapper();
596             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
597             JsonNode root = mapper.readTree(request.getReader());
598             
599             MicroServiceAttribute microServiceAttribute;
600             if (fromAPI) {
601                 microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceAttribute.class);
602                 
603                 //check if update operation or create, get id for data to be updated and update attributeData
604                 if ((update).equals(request.getParameter(operation))) {
605                     MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class);
606  
607                     String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName();
608                     List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
609                     int id=0;
610                     for (int i= 0; i<duplicateData.size(); i++){
611                         MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0);
612                         id = data.getId();
613                     }
614                     microServiceAttribute.setId(id);                
615                 }
616             } else {
617                 microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroServiceAttribute.class);
618             }
619             
620             if(microServiceAttribute.getId() == 0){
621                 String checkValue = microServiceAttribute.getName() + ":" + microServiceAttribute.getValue() + ":" + microServiceAttribute.getModelName();
622                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
623                 if(!duplicateData.isEmpty()){
624                     duplicateflag = true;
625                 }else{
626                         commonClassDao.save(microServiceAttribute);
627                 }
628             }else{
629                 commonClassDao.update(microServiceAttribute); 
630             } 
631  
632             String responseString = "";
633             if(duplicateflag){
634                 responseString = duplicateResponseString;
635             }else{
636                 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
637             }
638             
639             if (fromAPI) {
640                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
641                     responseString = successMessage;
642                 }
643                 ModelAndView result = new ModelAndView();
644                 result.setViewName(responseString);
645                 return result;
646             } else {
647                 response.setCharacterEncoding(utf8);
648                 response.setContentType(applicationJsonContentType);
649                 request.setCharacterEncoding(utf8);
650  
651                 PrintWriter out = response.getWriter();
652                 JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
653                 out.write(j.toString());
654                 return null;
655             }
656         }
657         catch (Exception e){
658             response.setCharacterEncoding(utf8);
659             request.setCharacterEncoding(utf8);
660             PrintWriter out = response.getWriter();
661             out.write(PolicyUtils.CATCH_EXCEPTION);
662             LOGGER.error(e);
663         }
664         return null;
665     }
666  
667     @RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
668     public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
669         try{
670             ObjectMapper mapper = new ObjectMapper();
671             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
672             JsonNode root = mapper.readTree(request.getReader());
673             MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class);
674             commonClassDao.delete(microServiceAttribute);
675             response.setCharacterEncoding(utf8);
676             response.setContentType(applicationJsonContentType);
677             request.setCharacterEncoding(utf8);
678  
679             PrintWriter out = response.getWriter();
680  
681             String responseString = mapper.writeValueAsString(MicroServiceDictionaryController.commonClassDao.getData(MicroServiceAttribute.class));
682             JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
683             out.write(j.toString());
684  
685             return null;
686         }
687         catch (Exception e){
688             LOGGER.error(e);
689             response.setCharacterEncoding(utf8);
690             request.setCharacterEncoding(utf8);
691             PrintWriter out = response.getWriter();
692             out.write(PolicyUtils.CATCH_EXCEPTION);
693         }
694         return null;
695     }
696  
697         
698         @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
699         public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response){
700                 try{
701                         Map<String, Object> model = new HashMap<>();
702                         ObjectMapper mapper = new ObjectMapper();
703                         model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, modelName)));
704                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
705                         JSONObject j = new JSONObject(msg);
706                         response.getWriter().write(j.toString());
707                 }
708                 catch (Exception e){
709                          LOGGER.error(e);
710                 }
711         }
712         
713     @RequestMapping(value={"/get_MicroServiceModelsDataByVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
714     public void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request, HttpServletResponse response){
715         try{
716             Map<String, Object> model = new HashMap<>();
717             ObjectMapper mapper = new ObjectMapper();
718             JsonNode root = mapper.readTree(request.getReader());
719             String modelName = null;
720             if (root.get(microServiceModelsDictionaryData).has(modelName)){
721                 modelName = root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", "");
722             }
723              if (modelName!=null){
724                     model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, modelName, modelName)));
725              } else{
726                  model.put(errorMsg, "No model name given");
727              }
728             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
729             JSONObject j = new JSONObject(msg);
730             response.getWriter().write(j.toString());
731         }
732         catch (Exception e){
733             LOGGER.error(e);
734         }
735     }
736     
737         @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
738         public void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response){
739                 try{
740                         Map<String, Object> model = new HashMap<>();
741                         ObjectMapper mapper = new ObjectMapper();
742                         model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)));
743                         JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
744                         JSONObject j = new JSONObject(msg);
745             response.addHeader(successMapKey, successMsg);    
746             response.addHeader(operation, getDictionary);
747                         response.getWriter().write(j.toString());
748                 }
749                 catch (Exception e){
750             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
751             response.addHeader(errorMsg, dictionaryDBQuery);
752             LOGGER.error(e);
753                 }
754         }
755         
756     @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
757     public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response){
758         try{
759             Map<String, Object> model = new HashMap<>();
760             ObjectMapper mapper = new ObjectMapper();
761             List<String> data = new ArrayList<>();
762             List<Object> datas = commonClassDao.getData(MicroServiceModels.class);
763             for(int i = 0; i < datas.size(); i++){
764                 MicroServiceModels msmodel = (MicroServiceModels) datas.get(i);
765                 if (!data.contains(msmodel.getModelName())){
766                         data.add(msmodel.getModelName() + "-v" + msmodel.getVersion());
767                 }
768             }
769             model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(data));
770             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
771             JSONObject j = new JSONObject(msg);
772             response.addHeader("successMapKey", "success"); 
773             response.addHeader("operation", "getDictionary");
774             response.getWriter().write(j.toString());
775  
776         }
777         catch (Exception e){
778             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
779             response.addHeader("error", "dictionaryDBQuery");
780             LOGGER.error(e);
781         }
782     }
783     
784     @RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
785     public void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response){
786         try{
787             Map<String, Object> model = new HashMap<>();
788             ObjectMapper mapper = new ObjectMapper();
789             model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList));
790             JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
791             JSONObject j = new JSONObject(msg);
792             response.addHeader(successMapKey, successMsg);    
793             response.addHeader(operation, getDictionary);
794             response.getWriter().write(j.toString());
795  
796         }
797         catch (Exception e){
798             response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                             
799             response.addHeader(errorMsg, dictionaryDBQuery);
800             LOGGER.error(e);
801         }
802     }
803     
804         @RequestMapping(value={"/ms_dictionary/save_model"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
805         public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
806                 try {
807                         boolean duplicateflag = false;
808                         boolean fromAPI = false;
809                         this.newModel = new MicroServiceModels();
810                         if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
811                                 fromAPI = true;
812                         }
813                         ObjectMapper mapper = new ObjectMapper();
814                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
815                         JsonNode root = mapper.readTree(request.getReader());
816                         MicroServiceModels microServiceModels = new MicroServiceModels();
817                         String userId = null;
818
819                         if(root.has("modelType")){
820                                 JsonNode dataType = root.get("modelType");
821                                 String modelType= dataType.toString();
822                                 if(modelType.contains("yml")){
823                                         if (root.has(microServiceModelsDictionaryData)){
824                                                 if (root.get(microServiceModelsDictionaryData).has(description)){
825                                                         microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
826                                                 }
827                                                 if (root.get(microServiceModelsDictionaryData).has(modelName)){
828                                                         microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
829                                                         this.newModel.setModelName(microServiceModels.getModelName());
830                                                 }
831                                                 if (root.get(microServiceModelsDictionaryData).has(version)){
832                                                         microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
833                                                         this.newModel.setVersion(microServiceModels.getVersion());
834                                                 }
835                                         }
836
837                                         classMap = new HashMap<>();
838                                         JsonNode data = root.get(classMapData);
839                                         ObjectMapper mapper1 = new ObjectMapper();
840                                         String data1 = data.toString().substring(1, data.toString().length()-1);
841                                         data1 = data1.replace("\\", "");
842                                         data1=data1.replace("\"{","{");
843                                         data1=data1.replace("}\"","}");
844                                         JSONObject jsonObject = new JSONObject(data1);
845                                         Set<String> keys = jsonObject.keySet();
846                                         for(String key : keys){
847                                                 String value = jsonObject.get(key).toString();
848                                                 MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
849                                                 classMap.put(key, msAttributeObject);
850                                         }
851
852                                         userId = root.get("userid").textValue();
853                                         MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
854                                         this.newModel.setDependency("[]");
855                                         String value = new Gson().toJson(mainClass.getSubClass());
856                                         this.newModel.setSub_attributes(value);
857                                         String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
858                                         int equalsIndexForAttributes= attributes.indexOf("=");
859                                         String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
860                                         this.newModel.setAttributes(atttributesAfterFirstEquals);
861                                         String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
862                                         int equalsIndex= refAttributes.indexOf("=");
863                                         String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
864                                         this.newModel.setRef_attributes(refAttributesAfterFirstEquals);
865                                         this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
866                                         this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
867
868                                 }else{
869                                         if (fromAPI) {
870                                                 microServiceModels = (MicroServiceModels)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class);
871                                                 userId = "API";
872
873                                                 //check if update operation or create, get id for data to be updated and update attributeData
874                                                 if ((update).equals(request.getParameter(operation))) {
875                                                         String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
876                                                         List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
877                                                         int id = 0;
878                                                         for (int i=0; i< duplicateData.size(); i++){
879                                                                 MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
880                                                                 id = data.getId();
881                                                         }
882                                                         microServiceModels.setId(id);
883                                                         microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
884
885                                                 }
886                                         } else {
887                                                 if (root.has(microServiceModelsDictionaryData)){
888                                                         if (root.get(microServiceModelsDictionaryData).has(description)){
889                                                                 microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
890                                                         }
891                                                         if (root.get(microServiceModelsDictionaryData).has(modelName)){
892                                                                 microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
893                                                                 this.newModel.setModelName(microServiceModels.getModelName());
894                                                         }
895                                                         if (root.get(microServiceModelsDictionaryData).has(version)){
896                                                                 microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
897                                                                 this.newModel.setVersion(microServiceModels.getVersion());
898                                                         }
899                                                 }
900                                                 if(root.has(classMapData)){
901                                                         classMap = new HashMap<>();
902                                                         JsonNode data = root.get(classMapData);
903                                                         ObjectMapper mapper1 = new ObjectMapper();
904                                                         String data1 = data.toString().substring(1, data.toString().length()-1);
905                                                         data1 = data1.replace("\\", "");
906                                                         JSONObject jsonObject = new JSONObject(data1);
907                                                         Set<String> keys = jsonObject.keySet();
908                                                         for(String key : keys){
909                                                                 String value = jsonObject.get(key).toString();
910                                                                 MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
911                                                                 classMap.put(key, msAttributeObject);
912                                                         }
913                                                 }
914                                                 userId = root.get("userid").textValue();
915                                                 addValuesToNewModel(classMap);
916                                         }
917                                 }               
918
919                         }
920                         microServiceModels.setAttributes(this.newModel.getAttributes());
921                         microServiceModels.setRef_attributes(this.newModel.getRef_attributes());
922                         microServiceModels.setDependency(this.newModel.getDependency());
923                         microServiceModels.setModelName(this.newModel.getModelName());
924                         microServiceModels.setSub_attributes(this.newModel.getSub_attributes());
925                         microServiceModels.setVersion(this.newModel.getVersion());
926                         microServiceModels.setEnumValues(this.newModel.getEnumValues());
927                         microServiceModels.setAnnotation(this.newModel.getAnnotation());
928
929                         if(microServiceModels.getId() == 0){
930                                 String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
931                                 List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
932                                 if(!duplicateData.isEmpty()){
933                                         duplicateflag = true;
934                                 }else{
935                                         microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
936                                         commonClassDao.save(microServiceModels);
937                                 }
938                         }else{
939                                 commonClassDao.update(microServiceModels); 
940                         } 
941                         String responseString = "";
942                         if(duplicateflag){
943                                 responseString = duplicateResponseString;
944                         }else{
945                                 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class));
946                         } 
947
948                         if (fromAPI) {
949                                 if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
950                                         responseString = successMessage;
951                                 }
952                                 ModelAndView result = new ModelAndView();
953                                 result.setViewName(responseString);
954                                 return result;
955                         } else {
956                                 response.setCharacterEncoding(utf8);
957                                 response.setContentType(applicationJsonContentType);
958                                 request.setCharacterEncoding(utf8);
959
960                                 PrintWriter out = response.getWriter();
961                                 JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}");
962                                 out.write(j.toString());
963                                 return null;
964                         }
965                 }catch (Exception e){
966                         response.setCharacterEncoding(utf8);
967                         request.setCharacterEncoding(utf8);
968                         PrintWriter out = response.getWriter();
969                         out.write(PolicyUtils.CATCH_EXCEPTION);
970                         LOGGER.error(e);
971                 }
972                 return null;
973         }
974
975         @RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
976         public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
977                 try{
978                         ObjectMapper mapper = new ObjectMapper();
979                         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
980                         JsonNode root = mapper.readTree(request.getReader());
981                         MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
982                         commonClassDao.delete(microServiceModels);
983                         response.setCharacterEncoding(utf8);
984                         response.setContentType(applicationJsonContentType);
985                         request.setCharacterEncoding(utf8);
986
987                         PrintWriter out = response.getWriter();
988
989                         String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class));
990                         JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}");
991                         out.write(j.toString());
992
993                         return null;
994                 }
995                 catch (Exception e){
996                         LOGGER.error(e);
997                         response.setCharacterEncoding(utf8);
998                         request.setCharacterEncoding(utf8);
999                         PrintWriter out = response.getWriter();
1000                         out.write(PolicyUtils.CATCH_EXCEPTION);
1001                 }
1002                 return null;
1003         }
1004                 
1005         private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
1006                 //Loop  through the classmap and pull out the required info for the new file.
1007                 String subAttribute = null;
1008                 
1009                 MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
1010                 
1011                 if (mainClass !=null){
1012                         String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
1013                         ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));   
1014                         dependency = getFullDependencyList(dependency);
1015                         for (String element : dependency){
1016                                 MSAttributeObject temp = new MSAttributeObject();
1017                                 temp = classMap.get(element);
1018                                 if (temp!=null){
1019                                         mainClass.addAllRefAttribute(temp.getRefAttribute());
1020                                         mainClass.addAllAttribute(temp.getAttribute());
1021                                 }
1022                         }
1023                         subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
1024                 }else{
1025                         subAttribute = "{}";
1026                         this.newModel.setDependency("");
1027                 }
1028
1029                 if (mainClass != null && mainClass.getDependency()==null){
1030                         mainClass.setDependency("");
1031                 }
1032                 if(mainClass != null){
1033                         this.newModel.setDependency(mainClass.getDependency());
1034                         this.newModel.setSub_attributes(subAttribute);
1035                         this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
1036                         this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
1037                         this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
1038                         this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
1039                 }
1040         } 
1041         
1042         private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
1043                 ArrayList<String> returnList = new ArrayList<>();
1044                 ArrayList<String> workingList = new ArrayList<>();
1045                 returnList.addAll(dependency);
1046                 for (String element : dependency ){
1047                         if (classMap.containsKey(element)){
1048                                 MSAttributeObject value = classMap.get(element);                        
1049                                 String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
1050                                 workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));      
1051                                 for(String depend : workingList){
1052                                         if (!returnList.contains(depend) && !depend.isEmpty()){
1053                                                 returnList.add(depend.trim());
1054                                                 //getFullDepedency(workingList)
1055                                         }
1056                                 }
1057                         }
1058                 }
1059                 
1060                 return returnList;
1061         }
1062
1063 }