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