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