summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java368
1 files changed, 186 insertions, 182 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
index 526e28649..0170a71e0 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
@@ -22,7 +22,6 @@ package org.onap.policy.pap.xacml.rest.controller;
import java.io.IOException;
import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -64,40 +63,52 @@ public class MicroServiceDictionaryController {
private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceDictionaryController.class);
private static CommonClassDao commonClassDao;
-
- public static void setCommonClassDao(CommonClassDao commonClassDao) {
- MicroServiceDictionaryController.commonClassDao = commonClassDao;
- }
-
+
+ private static String successMapKey= "successMapKey";
+ private static String successMsg = "success";
+ private static String operation = "operation";
+ private static String getDictionary = "getDictionary";
+ private static String errorMsg = "error";
+ private static String dictionaryDBQuery = "dictionaryDBQuery";
+ private HashMap<String,MSAttributeObject > classMap;
+ private List<String> modelList = new ArrayList<>();
+ private static String apiflag = "apiflag";
+ private static String dictionaryFields ="dictionaryFields";
+ private static String update = "update";
+ private static String duplicateResponseString = "Duplicate";
+ private static String successMessage = "Success";
+ private static String utf8 = "UTF-8";
+ private static String applicationJsonContentType = "application / json";
+ private static String existsResponseString = "Exists";
+ private static String microServiceModelsDictionaryDatas = "microServiceModelsDictionaryDatas";
+ private static String modelName = "modelName";
+ private static String microServiceModelsDictionaryData = "microServiceModelsDictionaryData";
+ private static String description = "description";
+ private static String version = "version";
+ private static String classMapData = "classMap";
+ /*
+ * This is an empty constructor
+ */
+ public MicroServiceDictionaryController(){}
+
@Autowired
public MicroServiceDictionaryController(CommonClassDao commonClassDao){
MicroServiceDictionaryController.commonClassDao = commonClassDao;
}
-
- public MicroServiceDictionaryController(){}
+ public static void setCommonClassDao(CommonClassDao commonClassDao) {
+ MicroServiceDictionaryController.commonClassDao = commonClassDao;
+ }
public UserInfo getUserInfo(String loginId){
- UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
- return name;
+ return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId);
}
-
- private static String SUCCESSKEY= "successMapKey";
- private static String SUCCESS = "success";
- private static String OPERATION = "operation";
- private static String GETDICTIONARY = "getDictionary";
- private static String ERROR = "error";
- private static String DICTIONARYDBQUERY = "dictionaryDBQuery";
- private HashMap<String,MSAttributeObject > classMap;
- private List<String> modelList = new ArrayList<>();
-
-
MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
private MicroServiceModels newModel;
@RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -112,31 +123,31 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getDCAEUUIDDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try {
boolean duplicateflag = false;
boolean isFakeUpdate = false;
boolean fromAPI = false;
- if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
fromAPI = true;
}
ObjectMapper mapper = new ObjectMapper();
@@ -144,14 +155,13 @@ public class MicroServiceDictionaryController {
JsonNode root = mapper.readTree(request.getReader());
DCAEuuid dCAEuuid;
if (fromAPI) {
- dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dictionaryFields").toString(), DCAEuuid.class);
+ dCAEuuid = (DCAEuuid)mapper.readValue(root.get(dictionaryFields).toString(), DCAEuuid.class);
//check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
+ if ((update).equals(request.getParameter(operation))) {
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
- int id = 0;
DCAEuuid data = (DCAEuuid) duplicateData.get(0);
- id = data.getId();
+ int id = data.getId();
if(id==0){
isFakeUpdate=true;
dCAEuuid.setId(1);
@@ -176,26 +186,26 @@ public class MicroServiceDictionaryController {
}
String responseString = "";
if(duplicateflag){
- responseString = "Duplicate";
+ responseString = duplicateResponseString;
}else{
responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
}
if (fromAPI) {
- if (responseString!=null && !responseString.equals("Duplicate")) {
+ if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
if(isFakeUpdate){
- responseString = "Exists";
+ responseString = existsResponseString;
} else {
- responseString = "Success";
+ responseString = successMessage;
}
}
ModelAndView result = new ModelAndView();
result.setViewName(responseString);
return result;
} else {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
JSONObject j = new JSONObject("{dcaeUUIDDictionaryDatas: " + responseString + "}");
@@ -203,8 +213,8 @@ public class MicroServiceDictionaryController {
return null;
}
}catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
LOGGER.error(e);
@@ -213,16 +223,16 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
+ public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class);
commonClassDao.delete(dCAEuuid);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
@@ -234,8 +244,8 @@ public class MicroServiceDictionaryController {
}
catch (Exception e){
LOGGER.error(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
@@ -244,7 +254,7 @@ public class MicroServiceDictionaryController {
@RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -261,31 +271,31 @@ public class MicroServiceDictionaryController {
@RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/ms_dictionary/save_configName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try {
boolean duplicateflag = false;
boolean isFakeUpdate = false;
boolean fromAPI = false;
- if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
fromAPI = true;
}
ObjectMapper mapper = new ObjectMapper();
@@ -293,14 +303,13 @@ public class MicroServiceDictionaryController {
JsonNode root = mapper.readTree(request.getReader());
MicroServiceConfigName microServiceConfigName;
if (fromAPI) {
- microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceConfigName.class);
+ microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceConfigName.class);
//check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
+ if ((update).equals(request.getParameter(operation))) {
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
- int id = 0;
MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0);
- id = data.getId();
+ int id = data.getId();
if(id==0){
isFakeUpdate=true;
@@ -326,26 +335,26 @@ public class MicroServiceDictionaryController {
}
String responseString = "";
if(duplicateflag){
- responseString = "Duplicate";
+ responseString = duplicateResponseString;
}else{
responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
}
if (fromAPI) {
- if (responseString!=null && !responseString.equals("Duplicate")) {
+ if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
if(isFakeUpdate){
- responseString = "Exists";
+ responseString = existsResponseString;
} else {
- responseString = "Success";
+ responseString = successMessage;
}
}
ModelAndView result = new ModelAndView();
result.setViewName(responseString);
return result;
} else {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
JSONObject j = new JSONObject("{microServiceCongigNameDictionaryDatas: " + responseString + "}");
@@ -353,8 +362,8 @@ public class MicroServiceDictionaryController {
return null;
}
}catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
LOGGER.error(e);
@@ -363,16 +372,16 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
+ public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class);
commonClassDao.delete(microServiceConfigName);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
@@ -384,8 +393,8 @@ public class MicroServiceDictionaryController {
}
catch (Exception e){
LOGGER.error(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
@@ -393,7 +402,7 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -408,31 +417,31 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/ms_dictionary/save_location"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException{
+ public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
try {
boolean duplicateflag = false;
boolean isFakeUpdate = false;
boolean fromAPI = false;
- if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
fromAPI = true;
}
ObjectMapper mapper = new ObjectMapper();
@@ -440,14 +449,13 @@ public class MicroServiceDictionaryController {
JsonNode root = mapper.readTree(request.getReader());
MicroServiceLocation microServiceLocation;
if (fromAPI) {
- microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceLocation.class);
+ microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceLocation.class);
//check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
+ if ((update).equals(request.getParameter(operation))) {
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
- int id = 0;
MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0);
- id = data.getId();
+ int id = data.getId();
if(id==0){
isFakeUpdate=true;
@@ -473,26 +481,26 @@ public class MicroServiceDictionaryController {
}
String responseString = "";
if(duplicateflag){
- responseString = "Duplicate";
+ responseString = duplicateResponseString;
}else{
responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
}
if (fromAPI) {
- if (responseString!=null && !responseString.equals("Duplicate")) {
+ if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
if(isFakeUpdate){
- responseString = "Exists";
+ responseString = existsResponseString;
} else {
- responseString = "Success";
+ responseString = successMessage;
}
}
ModelAndView result = new ModelAndView();
result.setViewName(responseString);
return result;
} else {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
JSONObject j = new JSONObject("{microServiceLocationDictionaryDatas: " + responseString + "}");
@@ -500,8 +508,8 @@ public class MicroServiceDictionaryController {
return null;
}
}catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
LOGGER.error(e);
@@ -510,16 +518,16 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
+ public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class);
commonClassDao.delete(microServiceLocation);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
@@ -531,8 +539,8 @@ public class MicroServiceDictionaryController {
}
catch (Exception e){
LOGGER.error(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
@@ -540,7 +548,7 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -555,31 +563,31 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try {
boolean duplicateflag = false;
boolean fromAPI = false;
- if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
fromAPI = true;
}
@@ -589,10 +597,10 @@ public class MicroServiceDictionaryController {
MicroServiceAttribute microServiceAttribute;
if (fromAPI) {
- microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceAttribute.class);
+ microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceAttribute.class);
//check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
+ if ((update).equals(request.getParameter(operation))) {
MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class);
String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName();
@@ -622,22 +630,22 @@ public class MicroServiceDictionaryController {
String responseString = "";
if(duplicateflag){
- responseString = "Duplicate";
+ responseString = duplicateResponseString;
}else{
responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
}
if (fromAPI) {
- if (responseString!=null && !responseString.equals("Duplicate")) {
- responseString = "Success";
+ if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
+ responseString = successMessage;
}
ModelAndView result = new ModelAndView();
result.setViewName(responseString);
return result;
} else {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
JSONObject j = new JSONObject("{microServiceAttributeDictionaryDatas: " + responseString + "}");
@@ -646,8 +654,8 @@ public class MicroServiceDictionaryController {
}
}
catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
LOGGER.error(e);
@@ -656,16 +664,16 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class);
commonClassDao.delete(microServiceAttribute);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
@@ -677,8 +685,8 @@ public class MicroServiceDictionaryController {
}
catch (Exception e){
LOGGER.error(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
@@ -687,11 +695,11 @@ public class MicroServiceDictionaryController {
@RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
- model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, "modelName")));
+ model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, modelName)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
response.getWriter().write(j.toString());
@@ -708,13 +716,13 @@ public class MicroServiceDictionaryController {
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(request.getReader());
String modelName = null;
- if (root.get("microServiceModelsDictionaryData").has("modelName")){
- modelName = root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", "");
+ if (root.get(microServiceModelsDictionaryData).has(modelName)){
+ modelName = root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", "");
}
if (modelName!=null){
- model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, "modelName", modelName)));
+ model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, modelName, modelName)));
} else{
- model.put(ERROR, "No model name given");
+ model.put(errorMsg, "No model name given");
}
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
@@ -726,26 +734,26 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
- model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)));
+ model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
@@ -757,7 +765,7 @@ public class MicroServiceDictionaryController {
data.add(msmodel.getModelName() + "-v" + msmodel.getVersion());
}
}
- model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(data));
+ model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(data));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
response.addHeader("successMapKey", "success");
@@ -773,32 +781,32 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getMicroServiceModelsDictionaryClassEntityData(HttpServletRequest request, HttpServletResponse response){
+ public void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response){
try{
Map<String, Object> model = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList));
JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model));
JSONObject j = new JSONObject(msg);
- response.addHeader(SUCCESSKEY, SUCCESS);
- response.addHeader(OPERATION, GETDICTIONARY);
+ response.addHeader(successMapKey, successMsg);
+ response.addHeader(operation, getDictionary);
response.getWriter().write(j.toString());
}
catch (Exception e){
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.addHeader(ERROR, DICTIONARYDBQUERY);
+ response.addHeader(errorMsg, dictionaryDBQuery);
LOGGER.error(e);
}
}
@RequestMapping(value={"/ms_dictionary/save_model"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{
+ public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
try {
boolean duplicateflag = false;
boolean fromAPI = false;
this.newModel = new MicroServiceModels();
- if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) {
+ if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) {
fromAPI = true;
}
ObjectMapper mapper = new ObjectMapper();
@@ -811,23 +819,22 @@ public class MicroServiceDictionaryController {
JsonNode dataType = root.get("modelType");
String modelType= dataType.toString();
if(modelType.contains("yml")){
- if (root.has("microServiceModelsDictionaryData")){
- if (root.get("microServiceModelsDictionaryData").has("description")){
- microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
+ if (root.has(microServiceModelsDictionaryData)){
+ if (root.get(microServiceModelsDictionaryData).has(description)){
+ microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
}
- if (root.get("microServiceModelsDictionaryData").has("modelName")){
- microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
+ if (root.get(microServiceModelsDictionaryData).has(modelName)){
+ microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
this.newModel.setModelName(microServiceModels.getModelName());
}
- if (root.get("microServiceModelsDictionaryData").has("version")){
- microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
+ if (root.get(microServiceModelsDictionaryData).has(version)){
+ microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
this.newModel.setVersion(microServiceModels.getVersion());
}
}
- MSAttributeObject mainClass = null;
classMap = new HashMap<>();
- JsonNode data = root.get("classMap");
+ JsonNode data = root.get(classMapData);
ObjectMapper mapper1 = new ObjectMapper();
String data1 = data.toString().substring(1, data.toString().length()-1);
data1 = data1.replace("\\", "");
@@ -842,7 +849,7 @@ public class MicroServiceDictionaryController {
}
userId = root.get("userid").textValue();
- mainClass = classMap.get(this.newModel.getModelName());
+ MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
this.newModel.setDependency("[]");
String value = new Gson().toJson(mainClass.getSubClass());
this.newModel.setSub_attributes(value);
@@ -859,11 +866,11 @@ public class MicroServiceDictionaryController {
}else{
if (fromAPI) {
- microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class);
+ microServiceModels = (MicroServiceModels)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class);
userId = "API";
//check if update operation or create, get id for data to be updated and update attributeData
- if (request.getParameter(OPERATION).equals("update")) {
+ if ((update).equals(request.getParameter(operation))) {
String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
int id = 0;
@@ -876,22 +883,22 @@ public class MicroServiceDictionaryController {
}
} else {
- if (root.has("microServiceModelsDictionaryData")){
- if (root.get("microServiceModelsDictionaryData").has("description")){
- microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", ""));
+ if (root.has(microServiceModelsDictionaryData)){
+ if (root.get(microServiceModelsDictionaryData).has(description)){
+ microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
}
- if (root.get("microServiceModelsDictionaryData").has("modelName")){
- microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""));
+ if (root.get(microServiceModelsDictionaryData).has(modelName)){
+ microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
this.newModel.setModelName(microServiceModels.getModelName());
}
- if (root.get("microServiceModelsDictionaryData").has("version")){
- microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", ""));
+ if (root.get(microServiceModelsDictionaryData).has(version)){
+ microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
this.newModel.setVersion(microServiceModels.getVersion());
}
}
- if(root.has("classMap")){
+ if(root.has(classMapData)){
classMap = new HashMap<>();
- JsonNode data = root.get("classMap");
+ JsonNode data = root.get(classMapData);
ObjectMapper mapper1 = new ObjectMapper();
String data1 = data.toString().substring(1, data.toString().length()-1);
data1 = data1.replace("\\", "");
@@ -932,22 +939,22 @@ public class MicroServiceDictionaryController {
}
String responseString = "";
if(duplicateflag){
- responseString = "Duplicate";
+ responseString = duplicateResponseString;
}else{
responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class));
}
if (fromAPI) {
- if (responseString!=null && !responseString.equals("Duplicate")) {
- responseString = "Success";
+ if (responseString!=null && !(duplicateResponseString).equals(responseString)) {
+ responseString = successMessage;
}
ModelAndView result = new ModelAndView();
result.setViewName(responseString);
return result;
} else {
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
JSONObject j = new JSONObject("{microServiceModelsDictionaryDatas: " + responseString + "}");
@@ -955,8 +962,8 @@ public class MicroServiceDictionaryController {
return null;
}
}catch (Exception e){
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
LOGGER.error(e);
@@ -965,16 +972,16 @@ public class MicroServiceDictionaryController {
}
@RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException {
+ public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class);
commonClassDao.delete(microServiceModels);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ response.setContentType(applicationJsonContentType);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
@@ -986,8 +993,8 @@ public class MicroServiceDictionaryController {
}
catch (Exception e){
LOGGER.error(e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(utf8);
+ request.setCharacterEncoding(utf8);
PrintWriter out = response.getWriter();
out.write(e.getMessage());
}
@@ -995,17 +1002,14 @@ public class MicroServiceDictionaryController {
}
private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
- new MicroServiceModels();
//Loop through the classmap and pull out the required info for the new file.
- MSAttributeObject mainClass = null;
- ArrayList<String> dependency = null;
String subAttribute = null;
- mainClass = classMap.get(this.newModel.getModelName());
+ MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
if (mainClass !=null){
String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
- dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(",")));
+ ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));
dependency = getFullDependencyList(dependency);
for (String element : dependency){
MSAttributeObject temp = new MSAttributeObject();
@@ -1042,7 +1046,7 @@ public class MicroServiceDictionaryController {
if (classMap.containsKey(element)){
MSAttributeObject value = classMap.get(element);
String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
- workingList = new ArrayList<String>(Arrays.asList(rawValue.split(",")));
+ workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
for(String depend : workingList){
if (!returnList.contains(depend) && !depend.isEmpty()){
returnList.add(depend.trim());