2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.policy.pap.xacml.rest.controller;
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;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
34 import org.apache.commons.lang.StringUtils;
35 import org.json.JSONObject;
36 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
37 import org.openecomp.policy.common.logging.flexlogger.Logger;
38 import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet;
39 import org.openecomp.policy.pap.xacml.rest.util.JsonMessage;
40 import org.openecomp.policy.rest.dao.CommonClassDao;
41 import org.openecomp.policy.rest.jpa.DCAEuuid;
42 import org.openecomp.policy.rest.jpa.MicroServiceAttribute;
43 import org.openecomp.policy.rest.jpa.MicroServiceConfigName;
44 import org.openecomp.policy.rest.jpa.MicroServiceLocation;
45 import org.openecomp.policy.rest.jpa.MicroServiceModels;
46 import org.openecomp.policy.rest.jpa.UserInfo;
47 import org.openecomp.policy.rest.util.MSAttributeObject;
48 import org.openecomp.policy.rest.util.MSModelUtils;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.http.MediaType;
51 import org.springframework.stereotype.Controller;
52 import org.springframework.web.bind.annotation.RequestMapping;
53 import org.springframework.web.servlet.ModelAndView;
55 import com.fasterxml.jackson.databind.DeserializationFeature;
56 import com.fasterxml.jackson.databind.JsonNode;
57 import com.fasterxml.jackson.databind.ObjectMapper;
60 public class MicroServiceDictionaryController {
61 private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceDictionaryController.class);
63 private static CommonClassDao commonClassDao;
66 public MicroServiceDictionaryController(CommonClassDao commonClassDao){
67 MicroServiceDictionaryController.commonClassDao = commonClassDao;
70 public MicroServiceDictionaryController(){}
72 public UserInfo getUserInfo(String loginId){
73 UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
77 private static String SUCCESSKEY= "successMapKey";
78 private static String SUCCESS = "success";
79 private static String OPERATION = "operation";
80 private static String GETDICTIONARY = "getDictionary";
81 private static String ERROR = "error";
82 private static String DICTIONARYDBQUERY = "dictionaryDBQuery";
83 private HashMap<String,MSAttributeObject > classMap;
84 private List<String> modelList = new ArrayList<String>();
88 MSModelUtils utils = new MSModelUtils(XACMLPapServlet.msEcompName, XACMLPapServlet.msPolicyName);
89 private MicroServiceModels newModel;
92 @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
93 public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
95 Map<String, Object> model = new HashMap<String, Object>();
96 ObjectMapper mapper = new ObjectMapper();
97 model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(DCAEuuid.class, "name")));
98 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
99 JSONObject j = new JSONObject(msg);
100 response.getWriter().write(j.toString());
107 @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
108 public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
110 Map<String, Object> model = new HashMap<String, Object>();
111 ObjectMapper mapper = new ObjectMapper();
112 model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)));
113 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
114 JSONObject j = new JSONObject(msg);
115 response.addHeader(SUCCESSKEY, SUCCESS);
116 response.addHeader(OPERATION, GETDICTIONARY);
117 response.getWriter().write(j.toString());
120 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
121 response.addHeader(ERROR, DICTIONARYDBQUERY);
122 LOGGER.error(e.getMessage());
126 @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
127 public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
129 boolean duplicateflag = false;
130 boolean isFakeUpdate = false;
131 boolean fromAPI = false;
132 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
135 ObjectMapper mapper = new ObjectMapper();
136 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
137 JsonNode root = mapper.readTree(request.getReader());
140 dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dictionaryFields").toString(), DCAEuuid.class);
142 //check if update operation or create, get id for data to be updated and update attributeData
143 if (request.getParameter(OPERATION).equals("update")) {
144 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
146 DCAEuuid data = (DCAEuuid) duplicateData.get(0);
156 dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class);
158 if(dCAEuuid.getId() == 0){
159 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
160 if(!duplicateData.isEmpty()){
161 duplicateflag = true;
163 commonClassDao.save(dCAEuuid);
167 commonClassDao.update(dCAEuuid);
170 String responseString = "";
172 responseString = "Duplicate";
174 responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
178 if (responseString!=null && !responseString.equals("Duplicate")) {
180 responseString = "Exists";
182 responseString = "Success";
185 ModelAndView result = new ModelAndView();
186 result.setViewName(responseString);
189 response.setCharacterEncoding("UTF-8");
190 response.setContentType("application / json");
191 request.setCharacterEncoding("UTF-8");
193 PrintWriter out = response.getWriter();
194 JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}");
195 out.write(j.toString());
198 }catch (Exception e){
199 response.setCharacterEncoding("UTF-8");
200 request.setCharacterEncoding("UTF-8");
201 PrintWriter out = response.getWriter();
202 out.write(e.getMessage());
207 @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
208 public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
210 ObjectMapper mapper = new ObjectMapper();
211 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
212 JsonNode root = mapper.readTree(request.getReader());
213 DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class);
214 commonClassDao.delete(dCAEuuid);
215 response.setCharacterEncoding("UTF-8");
216 response.setContentType("application / json");
217 request.setCharacterEncoding("UTF-8");
219 PrintWriter out = response.getWriter();
221 String responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
222 JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}");
223 out.write(j.toString());
228 System.out.println(e);
229 response.setCharacterEncoding("UTF-8");
230 request.setCharacterEncoding("UTF-8");
231 PrintWriter out = response.getWriter();
232 out.write(e.getMessage());
238 @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
239 public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
241 Map<String, Object> model = new HashMap<String, Object>();
242 ObjectMapper mapper = new ObjectMapper();
243 model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceConfigName.class, "name")));
244 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
245 JSONObject j = new JSONObject(msg);
246 response.getWriter().write(j.toString());
255 @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
256 public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
258 Map<String, Object> model = new HashMap<String, Object>();
259 ObjectMapper mapper = new ObjectMapper();
260 model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)));
261 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
262 JSONObject j = new JSONObject(msg);
263 response.addHeader(SUCCESSKEY, SUCCESS);
264 response.addHeader(OPERATION, GETDICTIONARY);
265 response.getWriter().write(j.toString());
268 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
269 response.addHeader(ERROR, DICTIONARYDBQUERY);
270 LOGGER.error(e.getMessage());
274 @RequestMapping(value={"/ms_dictionary/save_configName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
275 public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
277 boolean duplicateflag = false;
278 boolean isFakeUpdate = false;
279 boolean fromAPI = false;
280 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
283 ObjectMapper mapper = new ObjectMapper();
284 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
285 JsonNode root = mapper.readTree(request.getReader());
286 MicroServiceConfigName microServiceConfigName;
288 microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceConfigName.class);
290 //check if update operation or create, get id for data to be updated and update attributeData
291 if (request.getParameter(OPERATION).equals("update")) {
292 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
294 MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0);
299 microServiceConfigName.setId(1);
301 microServiceConfigName.setId(id);
305 microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("microServiceCongigNameDictionaryData").toString(), MicroServiceConfigName.class);
307 if(microServiceConfigName.getId() == 0){
308 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
309 if(!duplicateData.isEmpty()){
310 duplicateflag = true;
312 commonClassDao.save(microServiceConfigName);
316 commonClassDao.update(microServiceConfigName);
319 String responseString = "";
321 responseString = "Duplicate";
323 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
327 if (responseString!=null && !responseString.equals("Duplicate")) {
329 responseString = "Exists";
331 responseString = "Success";
334 ModelAndView result = new ModelAndView();
335 result.setViewName(responseString);
338 response.setCharacterEncoding("UTF-8");
339 response.setContentType("application / json");
340 request.setCharacterEncoding("UTF-8");
342 PrintWriter out = response.getWriter();
343 JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}");
344 out.write(j.toString());
347 }catch (Exception e){
348 response.setCharacterEncoding("UTF-8");
349 request.setCharacterEncoding("UTF-8");
350 PrintWriter out = response.getWriter();
351 out.write(e.getMessage());
356 @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
357 public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
359 ObjectMapper mapper = new ObjectMapper();
360 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
361 JsonNode root = mapper.readTree(request.getReader());
362 MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class);
363 commonClassDao.delete(microServiceConfigName);
364 response.setCharacterEncoding("UTF-8");
365 response.setContentType("application / json");
366 request.setCharacterEncoding("UTF-8");
368 PrintWriter out = response.getWriter();
370 String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
371 JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}");
372 out.write(j.toString());
377 System.out.println(e);
378 response.setCharacterEncoding("UTF-8");
379 request.setCharacterEncoding("UTF-8");
380 PrintWriter out = response.getWriter();
381 out.write(e.getMessage());
386 @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
387 public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
389 Map<String, Object> model = new HashMap<String, Object>();
390 ObjectMapper mapper = new ObjectMapper();
391 model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceLocation.class, "name")));
392 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
393 JSONObject j = new JSONObject(msg);
394 response.getWriter().write(j.toString());
401 @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
402 public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
404 Map<String, Object> model = new HashMap<String, Object>();
405 ObjectMapper mapper = new ObjectMapper();
406 model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)));
407 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
408 JSONObject j = new JSONObject(msg);
409 response.addHeader(SUCCESSKEY, SUCCESS);
410 response.addHeader(OPERATION, GETDICTIONARY);
411 response.getWriter().write(j.toString());
414 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
415 response.addHeader(ERROR, DICTIONARYDBQUERY);
416 LOGGER.error(e.getMessage());
420 @RequestMapping(value={"/ms_dictionary/save_location"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
421 public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
423 boolean duplicateflag = false;
424 boolean isFakeUpdate = false;
425 boolean fromAPI = false;
426 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
429 ObjectMapper mapper = new ObjectMapper();
430 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
431 JsonNode root = mapper.readTree(request.getReader());
432 MicroServiceLocation microServiceLocation;
434 microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceLocation.class);
436 //check if update operation or create, get id for data to be updated and update attributeData
437 if (request.getParameter(OPERATION).equals("update")) {
438 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
440 MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0);
445 microServiceLocation.setId(1);
447 microServiceLocation.setId(id);
451 microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class);
453 if(microServiceLocation.getId() == 0){
454 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
455 if(!duplicateData.isEmpty()){
456 duplicateflag = true;
458 commonClassDao.save(microServiceLocation);
462 commonClassDao.update(microServiceLocation);
465 String responseString = "";
467 responseString = "Duplicate";
469 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
473 if (responseString!=null && !responseString.equals("Duplicate")) {
475 responseString = "Exists";
477 responseString = "Success";
480 ModelAndView result = new ModelAndView();
481 result.setViewName(responseString);
484 response.setCharacterEncoding("UTF-8");
485 response.setContentType("application / json");
486 request.setCharacterEncoding("UTF-8");
488 PrintWriter out = response.getWriter();
489 JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}");
490 out.write(j.toString());
493 }catch (Exception e){
494 response.setCharacterEncoding("UTF-8");
495 request.setCharacterEncoding("UTF-8");
496 PrintWriter out = response.getWriter();
497 out.write(e.getMessage());
502 @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
503 public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
505 ObjectMapper mapper = new ObjectMapper();
506 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
507 JsonNode root = mapper.readTree(request.getReader());
508 MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
509 commonClassDao.delete(microServiceLocation);
510 response.setCharacterEncoding("UTF-8");
511 response.setContentType("application / json");
512 request.setCharacterEncoding("UTF-8");
514 PrintWriter out = response.getWriter();
516 String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
517 JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}");
518 out.write(j.toString());
523 System.out.println(e);
524 response.setCharacterEncoding("UTF-8");
525 request.setCharacterEncoding("UTF-8");
526 PrintWriter out = response.getWriter();
527 out.write(e.getMessage());
532 @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
533 public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
535 Map<String, Object> model = new HashMap<String, Object>();
536 ObjectMapper mapper = new ObjectMapper();
537 model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceAttribute.class, "name")));
538 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
539 JSONObject j = new JSONObject(msg);
540 response.getWriter().write(j.toString());
543 LOGGER.error(e.getMessage());
547 @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
548 public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
550 Map<String, Object> model = new HashMap<String, Object>();
551 ObjectMapper mapper = new ObjectMapper();
552 model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)));
553 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
554 JSONObject j = new JSONObject(msg);
555 response.addHeader(SUCCESSKEY, SUCCESS);
556 response.addHeader(OPERATION, GETDICTIONARY);
557 response.getWriter().write(j.toString());
561 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
562 response.addHeader(ERROR, DICTIONARYDBQUERY);
563 LOGGER.error(e.getMessage());
567 @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
568 public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
570 boolean duplicateflag = false;
571 boolean fromAPI = false;
572 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
576 ObjectMapper mapper = new ObjectMapper();
577 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
578 JsonNode root = mapper.readTree(request.getReader());
580 MicroServiceAttribute microServiceAttribute;
582 microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceAttribute.class);
584 //check if update operation or create, get id for data to be updated and update attributeData
585 if (request.getParameter(OPERATION).equals("update")) {
586 MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class);
588 String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName();
589 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
591 for (int i= 0; i<duplicateData.size(); i++){
592 MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0);
595 microServiceAttribute.setId(id);
598 microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroServiceAttribute.class);
601 if(microServiceAttribute.getId() == 0){
602 String checkValue = microServiceAttribute.getName() + ":" + microServiceAttribute.getValue() + ":" + microServiceAttribute.getModelName();
603 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
604 if(!duplicateData.isEmpty()){
605 duplicateflag = true;
607 commonClassDao.save(microServiceAttribute);
610 commonClassDao.update(microServiceAttribute);
613 String responseString = "";
615 responseString = "Duplicate";
617 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
621 if (responseString!=null && !responseString.equals("Duplicate")) {
622 responseString = "Success";
624 ModelAndView result = new ModelAndView();
625 result.setViewName(responseString);
628 response.setCharacterEncoding("UTF-8");
629 response.setContentType("application / json");
630 request.setCharacterEncoding("UTF-8");
632 PrintWriter out = response.getWriter();
633 JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
634 out.write(j.toString());
639 response.setCharacterEncoding("UTF-8");
640 request.setCharacterEncoding("UTF-8");
641 PrintWriter out = response.getWriter();
642 out.write(e.getMessage());
647 @RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
648 public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
650 ObjectMapper mapper = new ObjectMapper();
651 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
652 JsonNode root = mapper.readTree(request.getReader());
653 MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class);
654 commonClassDao.delete(microServiceAttribute);
655 response.setCharacterEncoding("UTF-8");
656 response.setContentType("application / json");
657 request.setCharacterEncoding("UTF-8");
659 PrintWriter out = response.getWriter();
661 String responseString = mapper.writeValueAsString(MicroServiceDictionaryController.commonClassDao.getData(MicroServiceAttribute.class));
662 JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
663 out.write(j.toString());
668 LOGGER.error(e.getMessage());
669 response.setCharacterEncoding("UTF-8");
670 request.setCharacterEncoding("UTF-8");
671 PrintWriter out = response.getWriter();
672 out.write(e.getMessage());
678 @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
679 public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
681 Map<String, Object> model = new HashMap<String, Object>();
682 ObjectMapper mapper = new ObjectMapper();
683 model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, "modelName")));
684 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
685 JSONObject j = new JSONObject(msg);
686 response.getWriter().write(j.toString());
689 LOGGER.error(e.getMessage());
693 @RequestMapping(value={"/get_MicroServiceModelsDataByVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
694 public void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request, HttpServletResponse response){
696 Map<String, Object> model = new HashMap<String, Object>();
697 ObjectMapper mapper = new ObjectMapper();
698 JsonNode root = mapper.readTree(request.getReader());
699 String modelName = null;
700 if (root.get("microServiceModelsDictionaryData").has("modelName")){
701 modelName = root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", "");
703 if (modelName!=null){
704 model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, "modelName", modelName)));
706 model.put(ERROR, "No model name given");
708 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
709 JSONObject j = new JSONObject(msg);
710 response.getWriter().write(j.toString());
713 LOGGER.error(e.getMessage());
717 @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
718 public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
720 Map<String, Object> model = new HashMap<String, Object>();
721 ObjectMapper mapper = new ObjectMapper();
722 model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)));
723 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
724 JSONObject j = new JSONObject(msg);
725 response.addHeader(SUCCESSKEY, SUCCESS);
726 response.addHeader(OPERATION, GETDICTIONARY);
727 response.getWriter().write(j.toString());
730 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
731 response.addHeader(ERROR, DICTIONARYDBQUERY);
732 LOGGER.error(e.getMessage());
736 @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
737 public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletRequest request, HttpServletResponse response){
739 Map<String, Object> model = new HashMap<String, Object>();
740 ObjectMapper mapper = new ObjectMapper();
741 List<String> data = new ArrayList<String>();
742 List<Object> datas = commonClassDao.getData(MicroServiceModels.class);
743 for(int i = 0; i < datas.size(); i++){
744 MicroServiceModels msmodel = (MicroServiceModels) datas.get(i);
745 if (!data.contains(msmodel.getModelName())){
746 data.add(msmodel.getModelName() + "-v" + msmodel.getVersion());
749 model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(data));
750 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
751 JSONObject j = new JSONObject(msg);
752 response.addHeader("successMapKey", "success");
753 response.addHeader("operation", "getDictionary");
754 response.getWriter().write(j.toString());
758 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
759 response.addHeader("error", "dictionaryDBQuery");
764 @RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
765 public void getMicroServiceModelsDictionaryClassEntityData(HttpServletRequest request, HttpServletResponse response){
767 Map<String, Object> model = new HashMap<String, Object>();
768 ObjectMapper mapper = new ObjectMapper();
769 model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList));
770 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
771 JSONObject j = new JSONObject(msg);
772 response.addHeader(SUCCESSKEY, SUCCESS);
773 response.addHeader(OPERATION, GETDICTIONARY);
774 response.getWriter().write(j.toString());
778 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
779 response.addHeader(ERROR, DICTIONARYDBQUERY);
780 LOGGER.error(e.getMessage());
784 @RequestMapping(value={"/ms_dictionary/save_model"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
785 public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception{
787 boolean duplicateflag = false;
788 boolean fromAPI = false;
789 this.newModel = new MicroServiceModels();
790 if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
793 ObjectMapper mapper = new ObjectMapper();
794 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
795 JsonNode root = mapper.readTree(request.getReader());
796 MicroServiceModels microServiceModels = new MicroServiceModels();
797 String userId = null;
799 microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class);
802 //check if update operation or create, get id for data to be updated and update attributeData
803 if (request.getParameter(OPERATION).equals("update")) {
804 String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
805 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
807 for (int i=0; i< duplicateData.size(); i++){
808 MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
811 microServiceModels.setId(id);
812 microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
816 //microServiceModels = (MicroServiceModels)mapper.readValue(root.get("microServiceModelsDictionaryData").toString(), MicroServiceModels.class);
817 if (root.has("microServiceModelsDictionaryData")){
818 if (root.get("microServiceModelsDictionaryData").has("description")){
819 microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
821 if (root.get("microServiceModelsDictionaryData").has("modelName")){
822 microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
823 this.newModel.setModelName(microServiceModels.getModelName());
825 if (root.get("microServiceModelsDictionaryData").has("version")){
826 microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
827 this.newModel.setVersion(microServiceModels.getVersion());
830 if(root.has("classMap")){
831 classMap = new HashMap<String, MSAttributeObject>();
832 JsonNode data = root.get("classMap");
833 ObjectMapper mapper1 = new ObjectMapper();
834 String data1 = data.toString().substring(1, data.toString().length()-1);
835 data1 = data1.replace("\\", "");
836 JSONObject jsonObject = new JSONObject(data1);
837 Set<String> keys = jsonObject.keySet();
838 for(String key : keys){
839 String value = jsonObject.get(key).toString();
840 MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
841 classMap.put(key, msAttributeObject);
844 userId = root.get("userid").textValue();
845 addValuesToNewModel(classMap);
847 microServiceModels.setAttributes(this.newModel.getAttributes());
848 microServiceModels.setRef_attributes(this.newModel.getRef_attributes());
849 microServiceModels.setDependency(this.newModel.getDependency());
850 microServiceModels.setModelName(this.newModel.getModelName());
851 microServiceModels.setSub_attributes(this.newModel.getSub_attributes());
852 microServiceModels.setVersion(this.newModel.getVersion());
853 microServiceModels.setEnumValues(this.newModel.getEnumValues());
854 microServiceModels.setAnnotation(this.newModel.getAnnotation());
856 if(microServiceModels.getId() == 0){
857 String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
858 List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
859 if(!duplicateData.isEmpty()){
860 duplicateflag = true;
862 microServiceModels.setUserCreatedBy(this.getUserInfo(userId));
863 commonClassDao.save(microServiceModels);
866 commonClassDao.update(microServiceModels);
868 String responseString = "";
870 responseString = "Duplicate";
872 responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class));
876 if (responseString!=null && !responseString.equals("Duplicate")) {
877 responseString = "Success";
879 ModelAndView result = new ModelAndView();
880 result.setViewName(responseString);
883 response.setCharacterEncoding("UTF-8");
884 response.setContentType("application / json");
885 request.setCharacterEncoding("UTF-8");
887 PrintWriter out = response.getWriter();
888 JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}");
889 out.write(j.toString());
892 }catch (Exception e){
893 response.setCharacterEncoding("UTF-8");
894 request.setCharacterEncoding("UTF-8");
895 PrintWriter out = response.getWriter();
896 out.write(e.getMessage());
901 @RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
902 public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws Exception {
904 ObjectMapper mapper = new ObjectMapper();
905 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
906 JsonNode root = mapper.readTree(request.getReader());
907 MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
908 commonClassDao.delete(microServiceModels);
909 response.setCharacterEncoding("UTF-8");
910 response.setContentType("application / json");
911 request.setCharacterEncoding("UTF-8");
913 PrintWriter out = response.getWriter();
915 String responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class));
916 JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}");
917 out.write(j.toString());
922 System.out.println(e);
923 response.setCharacterEncoding("UTF-8");
924 request.setCharacterEncoding("UTF-8");
925 PrintWriter out = response.getWriter();
926 out.write(e.getMessage());
935 private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
936 new MicroServiceModels();
937 //Loop through the classmap and pull out the required info for the new file.
938 MSAttributeObject mainClass = null;
939 ArrayList<String> dependency = null;
940 String subAttribute = null;
942 mainClass = classMap.get(this.newModel.getModelName());
944 if (mainClass !=null){
945 String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
946 dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(",")));
947 dependency = getFullDependencyList(dependency);
948 for (String element : dependency){
949 MSAttributeObject temp = new MSAttributeObject();
950 temp = classMap.get(element);
952 mainClass.addAllRefAttribute(temp.getRefAttribute());
953 mainClass.addAllAttribute(temp.getAttribute());
956 subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
959 this.newModel.setDependency("");
962 if (mainClass.getDependency()==null){
963 mainClass.setDependency("");
966 this.newModel.setDependency(mainClass.getDependency());
967 this.newModel.setSub_attributes(subAttribute.toString());
968 this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
969 this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
970 this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
971 this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
975 private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
976 ArrayList<String> returnList = new ArrayList<String>();
977 ArrayList<String> workingList = new ArrayList<String>();
978 returnList.addAll(dependency);
979 for (String element : dependency ){
980 if (classMap.containsKey(element)){
981 MSAttributeObject value = classMap.get(element);
982 String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
983 workingList = new ArrayList<String>(Arrays.asList(rawValue.split(",")));
984 for(String depend : workingList){
985 if (!returnList.contains(depend) && !depend.isEmpty()){
986 returnList.add(depend.trim());
987 //getFullDepedency(workingList)