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