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