* ============LICENSE_START=======================================================
* ONAP-PAP-REST
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
package org.onap.policy.pap.xacml.rest.controller;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-
import org.onap.policy.pap.xacml.rest.util.DictionaryUtils;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.DecisionSettings;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
@Controller
public class DecisionPolicyDictionaryController {
private static String duplicateResponseString = "Duplicate";
private static String settingDatas = "settingsDictionaryDatas";
private static String rainDayDatas = "rainyDayDictionaryDatas";
- private static String dictionaryFields ="dictionaryFields";
+ private static String dictionaryFields = "dictionaryFields";
@Autowired
- public DecisionPolicyDictionaryController(CommonClassDao commonClassDao){
+ public DecisionPolicyDictionaryController(CommonClassDao commonClassDao) {
DecisionPolicyDictionaryController.commonClassDao = commonClassDao;
}
- public DecisionPolicyDictionaryController(){
+ public DecisionPolicyDictionaryController() {
super();
}
- private DictionaryUtils getDictionaryUtilsInstance(){
+ private DictionaryUtils getDictionaryUtilsInstance() {
return DictionaryUtils.getDictionaryUtils();
}
- @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+ @RequestMapping(value = {"/get_SettingsDictionaryDataByName"}, method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getSettingsDictionaryByNameEntityData(HttpServletRequest request,
+ HttpServletResponse response) {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.getDataByEntity(response, settingDatas, xacmlId, DecisionSettings.class);
}
- @RequestMapping(value={"/get_SettingsDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getSettingsDictionaryEntityData(HttpServletResponse response){
+ @RequestMapping(value = {"/get_SettingsDictionaryData"}, method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getSettingsDictionaryEntityData(HttpServletResponse response) {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.getData(response, settingDatas, DecisionSettings.class);
}
- @RequestMapping(value={"/decision_dictionary/save_Settings"}, method={RequestMethod.POST})
- public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+ @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST})
+ public ModelAndView saveSettingsDictionary(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
DictionaryUtils utils = getDictionaryUtilsInstance();
try {
boolean fromAPI = utils.isRequestFromAPI(request);
DecisionSettings decisionSettings;
String userId = null;
- if(fromAPI){
- decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class);
+ if (fromAPI) {
+ decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(),
+ DecisionSettings.class);
userId = "API";
- }else{
- decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class);
+ } else {
+ decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(),
+ DecisionSettings.class);
userId = root.get("userid").textValue();
}
UserInfo userInfo = utils.getUserInfo(userId);
- List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class);
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
+ decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class);
boolean duplicateflag = false;
- if(!duplicateData.isEmpty()){
+ if (!duplicateData.isEmpty()) {
DecisionSettings data = (DecisionSettings) duplicateData.get(0);
- if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+ if (request.getParameter(operation) != null
+ && "update".equals(request.getParameter(operation))) {
decisionSettings.setId(data.getId());
- }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
- (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))){
+ } else if ((request.getParameter(operation) != null
+ && !"update".equals(request.getParameter(operation)))
+ || (request.getParameter(operation) == null
+ && (data.getId() != decisionSettings.getId()))) {
duplicateflag = true;
}
}
- if(decisionSettings.getDatatypeBean().getShortName() != null){
+ if (decisionSettings.getDatatypeBean().getShortName() != null) {
String datatype = decisionSettings.getDatatypeBean().getShortName();
decisionSettings.setDatatypeBean(utils.getDataType(datatype));
}
String responseString = null;
- if(!duplicateflag){
+ if (!duplicateflag) {
decisionSettings.setUserModifiedBy(userInfo);
- if(decisionSettings.getId() == 0){
+ if (decisionSettings.getId() == 0) {
decisionSettings.setUserCreatedBy(userInfo);
commonClassDao.save(decisionSettings);
- }else{
+ } else {
decisionSettings.setModifiedDate(new Date());
commonClassDao.update(decisionSettings);
}
- responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class));
- }else{
+ responseString =
+ mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class));
+ } else {
responseString = duplicateResponseString;
}
- if(fromAPI){
+ if (fromAPI) {
return utils.getResultForApi(responseString);
- }else{
+ } else {
utils.setResponseData(response, settingDatas, responseString);
}
- }catch (Exception e){
+ } catch (Exception e) {
utils.setErrorResponseData(response, e);
}
return null;
}
- @RequestMapping(value={"/settings_dictionary/remove_settings"}, method={RequestMethod.POST})
- public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @RequestMapping(value = {"/settings_dictionary/remove_settings"}, method = {RequestMethod.POST})
+ public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.removeData(request, response, settingDatas, DecisionSettings.class);
}
- @RequestMapping(value={"/get_RainyDayDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+ @RequestMapping(value = {"/get_RainyDayDictionaryDataByName"}, method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request,
+ HttpServletResponse response) {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.getDataByEntity(response, rainDayDatas, bbID, RainyDayTreatments.class);
}
- @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
- public void getRainyDayDictionaryEntityData(HttpServletResponse response){
+ @RequestMapping(value = {"/get_RainyDayDictionaryData"}, method = {RequestMethod.GET},
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public void getRainyDayDictionaryEntityData(HttpServletResponse response) {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.getData(response, rainDayDatas, RainyDayTreatments.class);
}
- @RequestMapping(value={"/decision_dictionary/save_RainyDay"}, method={RequestMethod.POST})
- public ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+ @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST})
+ public ModelAndView saveRainyDayDictionary(HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
DictionaryUtils utils = getDictionaryUtilsInstance();
try {
boolean fromAPI = utils.isRequestFromAPI(request);
JsonNode root = mapper.readTree(request.getReader());
RainyDayTreatments decisionRainyDay;
TreatmentValues treatmentsData = null;
- if(fromAPI){
- decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), RainyDayTreatments.class);
- treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), TreatmentValues.class);
- }else{
- decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class);
- treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class);
+ if (fromAPI) {
+ decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(),
+ RainyDayTreatments.class);
+ treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(),
+ TreatmentValues.class);
+ } else {
+ decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(),
+ RainyDayTreatments.class);
+ treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(),
+ TreatmentValues.class);
}
- decisionRainyDay.setTreatments(utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ","));
+ decisionRainyDay.setTreatments(
+ utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ","));
- List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class);
+ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(
+ decisionRainyDay.getBbid() + ":" + decisionRainyDay.getWorkstep(),
+ "bbid:workstep", RainyDayTreatments.class);
boolean duplicateflag = false;
- if(!duplicateData.isEmpty()){
+ if (!duplicateData.isEmpty()) {
RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0);
- if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+ if (request.getParameter(operation) != null
+ && "update".equals(request.getParameter(operation))) {
decisionRainyDay.setId(data.getId());
- }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
- (request.getParameter(operation) == null && (data.getId() != decisionRainyDay.getId()))){
+ } else if ((request.getParameter(operation) != null
+ && !"update".equals(request.getParameter(operation)))
+ || (request.getParameter(operation) == null
+ && (data.getId() != decisionRainyDay.getId()))) {
duplicateflag = true;
}
}
String responseString = null;
- if(!duplicateflag){
- if(decisionRainyDay.getId() == 0){
+ if (!duplicateflag) {
+ if (decisionRainyDay.getId() == 0) {
commonClassDao.save(decisionRainyDay);
- }else{
+ } else {
commonClassDao.update(decisionRainyDay);
}
- responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class));
- }else{
+ responseString =
+ mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class));
+ } else {
responseString = duplicateResponseString;
}
- if(fromAPI){
+ if (fromAPI) {
return utils.getResultForApi(responseString);
- }else{
+ } else {
utils.setResponseData(response, rainDayDatas, responseString);
}
- }catch (Exception e){
+ } catch (Exception e) {
utils.setErrorResponseData(response, e);
}
return null;
}
- @RequestMapping(value={"/decision_dictionary/remove_rainyDay"}, method={RequestMethod.POST})
- public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+ @RequestMapping(value = {"/decision_dictionary/remove_rainyDay"}, method = {RequestMethod.POST})
+ public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response)
+ throws IOException {
DictionaryUtils utils = getDictionaryUtilsInstance();
utils.removeData(request, response, rainDayDatas, RainyDayTreatments.class);
}
}
-class TreatmentValues {
+
+class TreatmentValues {
private List<Object> userDataTypeValues = new ArrayList<>();
public List<Object> getUserDataTypeValues() {