aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-10-22 07:53:44 -0400
committerPamela Dragosh <pdragosh@research.att.com>2019-10-23 13:33:56 -0400
commit1e61676b77dd09659027b8984f050df7e8538526 (patch)
tree115053dba12b4b27a0f92de0e7648a672a66893a /ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
parentf18fbfc026de9cf02126f57844c37abfee607394 (diff)
Consolidate PolicyRestAdapter setup
Put common code into PolicyEngineUtils that the controllers use to populate the PolicyRestController. Also some more sonar cleanup and formatting of XML files. Shortened 120 line characters. Removed some trailing spaces from comments. Fixed up one JUnit. Licenses. Issue-ID: POLICY-2133 Change-Id: Id7d8ac3ab60331535f048ec0f26aeb17a099414e Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java264
1 files changed, 142 insertions, 122 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
index d8a77269c..fd1764e69 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
@@ -21,6 +21,7 @@
package org.onap.policy.pap.xacml.rest.policycontroller;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.io.File;
import java.util.Date;
import java.util.HashMap;
@@ -28,8 +29,10 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
import org.apache.commons.lang.StringUtils;
import org.onap.policy.common.logging.eelf.PolicyLogger;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -68,12 +71,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
-
@RestController
@RequestMapping("/")
-public class PolicyCreation extends AbstractPolicyCreation{
+public class PolicyCreation extends AbstractPolicyCreation {
- private static final Logger LOGGER = FlexLogger.getLogger(PolicyCreation.class);
+ private static final Logger LOGGER = FlexLogger.getLogger(PolicyCreation.class);
private String ruleID = "";
private PolicyDBDao policyDBDao;
@@ -90,15 +92,16 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
@Autowired
- public PolicyCreation(CommonClassDao commonClassDao){
+ public PolicyCreation(CommonClassDao commonClassDao) {
PolicyCreation.commonClassDao = commonClassDao;
}
- public PolicyCreation(){}
+ public PolicyCreation() {
+ }
- @RequestMapping(value="/policycreation/save_policy", method = RequestMethod.POST)
+ @RequestMapping(value = "/policycreation/save_policy", method = RequestMethod.POST)
@ResponseBody
- public ResponseEntity<String> savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response){
+ public ResponseEntity<String> savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response) {
String body = null;
HttpStatus status = HttpStatus.BAD_REQUEST;
Map<String, String> successMap = new HashMap<>();
@@ -110,9 +113,9 @@ public class PolicyCreation extends AbstractPolicyCreation{
String policyConfigType = null;
String userId = policyData.getUserId();
- if (policyData.getTtlDate()==null){
+ if (policyData.getTtlDate() == null) {
policyData.setTtlDate("NA");
- }else{
+ } else {
String dateTTL = policyData.getTtlDate();
String newDate = convertDate(dateTTL);
policyData.setTtlDate(newDate);
@@ -125,19 +128,19 @@ public class PolicyCreation extends AbstractPolicyCreation{
policyConfigType = policyData.getConfigPolicyType();
if ("Firewall Config".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_FW_";
- }else if ("ClosedLoop_Fault".equalsIgnoreCase(policyConfigType)) {
+ } else if ("ClosedLoop_Fault".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_Fault_";
- }else if ("ClosedLoop_PM".equalsIgnoreCase(policyConfigType)) {
+ } else if ("ClosedLoop_PM".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_PM_";
- }else if ("Micro Service".equalsIgnoreCase(policyConfigType)) {
+ } else if ("Micro Service".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_MS_";
- }else if ("Optimization".equalsIgnoreCase(policyConfigType)) {
+ } else if ("Optimization".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_OOF_";
- }else if ("BRMS_Raw".equalsIgnoreCase(policyConfigType)) {
+ } else if ("BRMS_Raw".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_BRMS_Raw_";
- }else if ("BRMS_Param".equalsIgnoreCase(policyConfigType)) {
+ } else if ("BRMS_Param".equalsIgnoreCase(policyConfigType)) {
filePrefix = "Config_BRMS_Param_";
- }else {
+ } else {
filePrefix = "Config_";
}
} else if ("Action".equalsIgnoreCase(policyType)) {
@@ -151,8 +154,9 @@ public class PolicyCreation extends AbstractPolicyCreation{
String createdBy;
String modifiedBy;
String scopeCheck = policyData.getDomainDir().replace(".", File.separator);
- PolicyEditorScopes policyEditorScope = (PolicyEditorScopes) commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", scopeCheck);
- if(policyEditorScope == null){
+ PolicyEditorScopes policyEditorScope = (PolicyEditorScopes) commonClassDao
+ .getEntityItem(PolicyEditorScopes.class, "scopeName", scopeCheck);
+ if (policyEditorScope == null) {
UserInfo userInfo = new UserInfo();
userInfo.setUserName("API");
userInfo.setUserLoginId("API");
@@ -162,21 +166,22 @@ public class PolicyCreation extends AbstractPolicyCreation{
editorScope.setUserModifiedBy(userInfo);
commonClassDao.save(editorScope);
}
- //get the highest version of policy from policy version table.
- String dbCheckPolicyName = policyData.getDomainDir() + File.separator + filePrefix + policyData.getPolicyName();
+ // get the highest version of policy from policy version table.
+ String dbCheckPolicyName =
+ policyData.getDomainDir() + File.separator + filePrefix + policyData.getPolicyName();
PolicyVersion policyVersion = getPolicyVersionData(dbCheckPolicyName);
- if(policyVersion == null){
+ if (policyVersion == null) {
highestVersion = 0;
- }else{
+ } else {
highestVersion = policyVersion.getHigherVersion();
}
- if(highestVersion != 0 && policyVersion != null){
- if(policyData.isEditPolicy()){
- version = highestVersion +1;
- if(userId ==null){
+ if (highestVersion != 0 && policyVersion != null) {
+ if (policyData.isEditPolicy()) {
+ version = highestVersion + 1;
+ if (userId == null) {
modifiedBy = "API";
- }else{
+ } else {
modifiedBy = userId;
}
policyData.setUserId("API");
@@ -186,7 +191,7 @@ public class PolicyCreation extends AbstractPolicyCreation{
policyVersionDao.setHigherVersion(version);
policyVersionDao.setModifiedBy(modifiedBy);
policyVersionDao.setModifiedDate(new Date());
- }else{
+ } else {
body = "policyExists";
status = HttpStatus.CONFLICT;
response.setStatus(HttpServletResponse.SC_CONFLICT);
@@ -194,22 +199,23 @@ public class PolicyCreation extends AbstractPolicyCreation{
response.addHeader("policyName", policyData.getPolicyName());
return new ResponseEntity<>(body, status);
}
- }else{
+ } else {
// if policy does not exist and the request is updatePolicy return error
- if(policyData.isEditPolicy()){
+ if (policyData.isEditPolicy()) {
body = "policyNotAvailableForEdit";
status = HttpStatus.NOT_FOUND;
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.addHeader("error", body);
- response.addHeader("message", policyData.getPolicyName() + " does not exist on the PAP and cannot be updated.");
+ response.addHeader("message",
+ policyData.getPolicyName() + " does not exist on the PAP and cannot be updated.");
return new ResponseEntity<>(body, status);
}
version = 1;
- if(userId == null){
+ if (userId == null) {
createdBy = "API";
modifiedBy = "API";
policyData.setUserId("API");
- }else{
+ } else {
createdBy = userId;
modifiedBy = userId;
policyData.setUserId("API");
@@ -225,15 +231,16 @@ public class PolicyCreation extends AbstractPolicyCreation{
policyData.setPolicyID(newPolicyID());
policyData.setRuleID(ruleID);
- String policyFileName = dbCheckPolicyName.replace(File.separator, ".")+ "." + version + ".xml";
+ String policyFileName = dbCheckPolicyName.replace(File.separator, ".") + "." + version + ".xml";
policyData.setNewFileName(policyFileName);
- policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:");
+ policyData.setPolicyDescription(policyData.getPolicyDescription() + "@CreatedBy:" + createdBy
+ + "@CreatedBy:" + "@ModifiedBy:" + modifiedBy + "@ModifiedBy:");
policyData.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
- if(policyData.getApiflag() == null){
- //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON
- if(policyData.getAttributes() != null && !policyData.getAttributes().isEmpty()){
- for(Object attribute : policyData.getAttributes()){
- if(attribute instanceof LinkedHashMap<?, ?>){
+ if (policyData.getApiflag() == null) {
+ // set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON
+ if (policyData.getAttributes() != null && !policyData.getAttributes().isEmpty()) {
+ for (Object attribute : policyData.getAttributes()) {
+ if (attribute instanceof LinkedHashMap<?, ?>) {
String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
String value = ((LinkedHashMap<?, ?>) attribute).get("value").toString();
attributeMap.put(key, value);
@@ -250,34 +257,37 @@ public class PolicyCreation extends AbstractPolicyCreation{
if ("Config".equalsIgnoreCase(policyType)) {
if ("Firewall Config".equalsIgnoreCase(policyConfigType)) {
newPolicy = new FirewallConfigPolicy(policyData);
- }else if ("BRMS_Raw".equalsIgnoreCase(policyConfigType)) {
+ } else if ("BRMS_Raw".equalsIgnoreCase(policyConfigType)) {
policyData.setOnapName("DROOLS");
policyData.setConfigName("BRMS_RAW_RULE");
newPolicy = new CreateBrmsRawPolicy(policyData);
- }else if ("BRMS_Param".equalsIgnoreCase(policyConfigType)) {
+ } else if ("BRMS_Param".equalsIgnoreCase(policyConfigType)) {
policyData.setOnapName("DROOLS");
policyData.setConfigName("BRMS_PARAM_RULE");
Map<String, String> drlRuleAndUIParams = new HashMap<>();
- if(policyData.getApiflag() == null){
+ if (policyData.getApiflag() == null) {
// If there is any dynamic field create the matches here
- String key="templateName";
- String value= policyData.getRuleName();
+ String key = "templateName";
+ String value = policyData.getRuleName();
drlRuleAndUIParams.put(key, value);
- if(policyData.getRuleData().size() > 0){
- for(Object keyValue: policyData.getRuleData().keySet()){
- drlRuleAndUIParams.put(keyValue.toString(), policyData.getRuleData().get(keyValue).toString());
+ if (policyData.getRuleData().size() > 0) {
+ for (Object keyValue : policyData.getRuleData().keySet()) {
+ drlRuleAndUIParams.put(keyValue.toString(),
+ policyData.getRuleData().get(keyValue).toString());
}
}
policyData.setBrmsParamBody(drlRuleAndUIParams);
- }else{
- drlRuleAndUIParams=policyData.getBrmsParamBody();
- String modelName= drlRuleAndUIParams.get("templateName");
- PolicyLogger.info("Template name from API is: "+modelName);
-
- BRMSParamTemplate template = (BRMSParamTemplate) commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", modelName);
- if(template == null){
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Template. The template name, "
- + modelName + " was not found in the dictionary.";
+ } else {
+ drlRuleAndUIParams = policyData.getBrmsParamBody();
+ String modelName = drlRuleAndUIParams.get("templateName");
+ PolicyLogger.info("Template name from API is: " + modelName);
+
+ BRMSParamTemplate template = (BRMSParamTemplate) commonClassDao
+ .getEntityItem(BRMSParamTemplate.class, "ruleName", modelName);
+ if (template == null) {
+ String message =
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Template. The template name, "
+ + modelName + " was not found in the dictionary.";
body = message;
status = HttpStatus.BAD_REQUEST;
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@@ -287,40 +297,44 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
}
newPolicy = new CreateBrmsParamPolicy(policyData);
- }else if ("Base".equalsIgnoreCase(policyConfigType)) {
- newPolicy = new ConfigPolicy(policyData);
- }else if ("ClosedLoop_Fault".equalsIgnoreCase(policyConfigType)) {
+ } else if ("Base".equalsIgnoreCase(policyConfigType)) {
+ newPolicy = new ConfigPolicy(policyData);
+ } else if ("ClosedLoop_Fault".equalsIgnoreCase(policyConfigType)) {
newPolicy = new ClosedLoopPolicy(policyData);
- }else if ("ClosedLoop_PM".equalsIgnoreCase(policyConfigType)) {
- if(policyData.getApiflag() == null){
- policyData.setServiceType(policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString());
+ } else if ("ClosedLoop_PM".equalsIgnoreCase(policyConfigType)) {
+ if (policyData.getApiflag() == null) {
+ policyData.setServiceType(
+ policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString());
ObjectMapper jsonMapper = new ObjectMapper();
String jsonBody = jsonMapper.writeValueAsString(policyData.getJsonBodyData());
- jsonBody = jsonBody.replaceFirst("\\{", "\\{\"serviceTypePolicyName\": \"serviceTypeFieldValue\",");
+ jsonBody = jsonBody.replaceFirst("\\{",
+ "\\{\"serviceTypePolicyName\": \"serviceTypeFieldValue\",");
jsonBody = jsonBody.replace("serviceTypeFieldValue", policyData.getServiceType());
policyData.setJsonBody(jsonBody);
}
newPolicy = new CreateClosedLoopPerformanceMetrics(policyData);
- }else if ("Micro Service".equalsIgnoreCase(policyConfigType)) {
+ } else if ("Micro Service".equalsIgnoreCase(policyConfigType)) {
newPolicy = new MicroServiceConfigPolicy(policyData);
- }else if ("Optimization".equalsIgnoreCase(policyConfigType)) {
+ } else if ("Optimization".equalsIgnoreCase(policyConfigType)) {
newPolicy = new OptimizationConfigPolicy(policyData);
}
- }else if("Action".equalsIgnoreCase(policyType)) {
- if(policyData.getApiflag() == null){
+ } else if ("Action".equalsIgnoreCase(policyType)) {
+ if (policyData.getApiflag() == null) {
List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
List<String> dynamicRuleAlgorithmCombo = new LinkedList<>();
List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
-
- if(!policyData.getRuleAlgorithmschoices().isEmpty()){
- for(Object attribute : policyData.getRuleAlgorithmschoices()){
- if(attribute instanceof LinkedHashMap<?, ?>){
+ if (!policyData.getRuleAlgorithmschoices().isEmpty()) {
+ for (Object attribute : policyData.getRuleAlgorithmschoices()) {
+ if (attribute instanceof LinkedHashMap<?, ?>) {
String label = ((LinkedHashMap<?, ?>) attribute).get("id").toString();
- String key = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
- String rule = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
- String value = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
+ String key =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
+ String rule =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
+ String value =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
dynamicRuleAlgorithmLabels.add(label);
dynamicRuleAlgorithmField1.add(key);
dynamicRuleAlgorithmCombo.add(rule);
@@ -330,8 +344,9 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
String actionDictValue = policyData.getActionAttributeValue();
- ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", actionDictValue));
- if(jsonData!=null){
+ ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class,
+ "attributeName", actionDictValue));
+ if (jsonData != null) {
String actionBodyString = jsonData.getBody();
String actionDictHeader = jsonData.getHeader();
String actionDictType = jsonData.getType();
@@ -350,11 +365,12 @@ public class PolicyCreation extends AbstractPolicyCreation{
policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
- }else{
+ } else {
// API request.
String comboDictValue = policyData.getActionAttribute();
- ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", comboDictValue));
- if(jsonData!=null){
+ ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class,
+ "attributeName", comboDictValue));
+ if (jsonData != null) {
policyData.setActionBody(jsonData.getBody());
policyData.setActionDictHeader(jsonData.getHeader());
policyData.setActionDictType(jsonData.getType());
@@ -364,7 +380,7 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
newPolicy = new ActionPolicy(policyData, commonClassDao);
} else if ("Decision".equalsIgnoreCase(policyType)) {
- if(policyData.getApiflag() == null){
+ if (policyData.getApiflag() == null) {
Map<String, String> settingsMap = new HashMap<>();
Map<String, String> treatmentMap = new HashMap<>();
List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
@@ -376,22 +392,26 @@ public class PolicyCreation extends AbstractPolicyCreation{
List<String> errorCodeList = new LinkedList<>();
List<String> treatmentList = new LinkedList<>();
- if(!policyData.getSettings().isEmpty()){
- for(Object settingsData : policyData.getSettings()){
- if(settingsData instanceof LinkedHashMap<?, ?>){
+ if (!policyData.getSettings().isEmpty()) {
+ for (Object settingsData : policyData.getSettings()) {
+ if (settingsData instanceof LinkedHashMap<?, ?>) {
String key = ((LinkedHashMap<?, ?>) settingsData).get("key").toString();
String value = ((LinkedHashMap<?, ?>) settingsData).get("value").toString();
settingsMap.put(key, value);
}
}
}
- if(policyData.getRuleAlgorithmschoices()!=null && policyData.getRuleAlgorithmschoices().size() > 0){
- for(Object attribute : policyData.getRuleAlgorithmschoices()){
- if(attribute instanceof LinkedHashMap<?, ?>){
+ if (policyData.getRuleAlgorithmschoices() != null
+ && policyData.getRuleAlgorithmschoices().size() > 0) {
+ for (Object attribute : policyData.getRuleAlgorithmschoices()) {
+ if (attribute instanceof LinkedHashMap<?, ?>) {
String label = ((LinkedHashMap<?, ?>) attribute).get("id").toString();
- String key = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
- String rule = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
- String value = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
+ String key =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
+ String rule =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
+ String value =
+ ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
dynamicRuleAlgorithmLabels.add(label);
dynamicRuleAlgorithmField1.add(key);
dynamicRuleAlgorithmCombo.add(rule);
@@ -470,9 +490,9 @@ public class PolicyCreation extends AbstractPolicyCreation{
newPolicy = new DecisionPolicy(policyData);
}
- if(newPolicy != null){
+ if (newPolicy != null) {
newPolicy.prepareToSave();
- }else{
+ } else {
body = "error";
status = HttpStatus.INTERNAL_SERVER_ERROR;
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@@ -481,23 +501,23 @@ public class PolicyCreation extends AbstractPolicyCreation{
}
PolicyDBDaoTransaction policyDBDaoTransaction = null;
- try{
+ try {
policyDBDao = PolicyDBDao.getPolicyDBDaoInstance();
policyDBDaoTransaction = policyDBDao.getNewTransaction();
policyDBDaoTransaction.createPolicy(newPolicy, policyData.getUserId());
successMap = newPolicy.savePolicies();
- if(successMap.containsKey("success")){
+ if (successMap.containsKey("success")) {
policyDBDaoTransaction.commitTransaction();
- if(policyData.isEditPolicy()){
+ if (policyData.isEditPolicy()) {
commonClassDao.update(policyVersionDao);
- }else{
+ } else {
commonClassDao.save(policyVersionDao);
}
- try{
- PolicyElasticSearchController search= new PolicyElasticSearchController();
+ try {
+ PolicyElasticSearchController search = new PolicyElasticSearchController();
search.updateElk(policyData);
- }catch(Exception e){
- LOGGER.error("Error Occured while saving policy to Elastic Database"+e);
+ } catch (Exception e) {
+ LOGGER.error("Error Occured while saving policy to Elastic Database" + e);
}
body = "success";
status = HttpStatus.OK;
@@ -505,12 +525,12 @@ public class PolicyCreation extends AbstractPolicyCreation{
response.addHeader("successMapKey", "success");
response.addHeader("policyName", policyData.getNewFileName());
- //get message from the SafetyCheckerResults if present
+ // get message from the SafetyCheckerResults if present
String safetyCheckerResponse = policyData.getClWarning();
String existingCLName = policyData.getExistingCLName();
- //if safetyCheckerResponse is not null add a header to send back with response
- if(safetyCheckerResponse!=null) {
+ // if safetyCheckerResponse is not null add a header to send back with response
+ if (safetyCheckerResponse != null) {
PolicyLogger.info("SafetyCheckerResponse message: " + safetyCheckerResponse);
response.addHeader("safetyChecker", safetyCheckerResponse);
response.addHeader("newCLName", CLName);
@@ -519,16 +539,17 @@ public class PolicyCreation extends AbstractPolicyCreation{
PolicyLogger.info("SafetyCheckerResponse was empty or null.");
}
- }else if (successMap.containsKey("invalidAttribute")) {
+ } else if (successMap.containsKey("invalidAttribute")) {
String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Attribute";
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not fine " + policyData.getActionAttribute() + " in the ActionPolicyDict table.");
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not fine "
+ + policyData.getActionAttribute() + " in the ActionPolicyDict table.");
body = "invalidAttribute";
status = HttpStatus.BAD_REQUEST;
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.addHeader("invalidAttribute", policyData.getActionAttribute());
response.addHeader("error", message);
response.addHeader("policyName", policyData.getPolicyName());
- }else if (successMap.containsKey("fwdberror")) {
+ } else if (successMap.containsKey("fwdberror")) {
policyDBDaoTransaction.rollbackTransaction();
body = "fwdberror";
status = HttpStatus.BAD_REQUEST;
@@ -540,30 +561,28 @@ public class PolicyCreation extends AbstractPolicyCreation{
response.addHeader("policyName", policyData.getPolicyName());
} else if (successMap.get("error").equals("Validation Failed")) {
policyDBDaoTransaction.rollbackTransaction();
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Error Validating the Policy on the PAP.";
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Validating the Policy on the PAP.";
PolicyLogger.error(message);
body = "Validation";
status = HttpStatus.BAD_REQUEST;
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.addHeader("error", message);
response.addHeader("policyName", policyData.getPolicyName());
- }else {
+ } else {
policyDBDaoTransaction.rollbackTransaction();
body = "error";
status = HttpStatus.INTERNAL_SERVER_ERROR;
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.addHeader("error", "error");
}
- }catch(Exception e){
- LOGGER.error("Exception Occured : ",e);
- if(policyDBDaoTransaction != null){
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured : ", e);
+ if (policyDBDaoTransaction != null) {
policyDBDaoTransaction.rollbackTransaction();
}
}
- }
- catch (Exception e){
- LOGGER.error("Exception Occured : "+e.getMessage(),e);
+ } catch (Exception e) {
+ LOGGER.error("Exception Occured : " + e.getMessage(), e);
body = "error";
response.addHeader("error", e.getMessage());
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
@@ -571,22 +590,23 @@ public class PolicyCreation extends AbstractPolicyCreation{
return new ResponseEntity<>(body, status);
}
- @ExceptionHandler({ HttpMessageNotReadableException.class })
- public ResponseEntity<String> messageNotReadableExceptionHandler(HttpServletRequest req, HttpMessageNotReadableException exception) {
+ @ExceptionHandler({HttpMessageNotReadableException.class})
+ public ResponseEntity<String> messageNotReadableExceptionHandler(HttpServletRequest req,
+ HttpMessageNotReadableException exception) {
LOGGER.error("Request not readable: {}", exception);
StringBuilder message = new StringBuilder();
message.append(exception.getMessage());
if (exception.getCause() != null) {
- message.append(" Reason Caused: "
- + exception.getCause().getMessage());
+ message.append(" Reason Caused: " + exception.getCause().getMessage());
}
return new ResponseEntity<>(message.toString(), HttpStatus.BAD_REQUEST);
}
- public PolicyVersion getPolicyVersionData(String dbCheckPolicyName){
- PolicyVersion entityItem = (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", dbCheckPolicyName);
+ public PolicyVersion getPolicyVersionData(String dbCheckPolicyName) {
+ PolicyVersion entityItem =
+ (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", dbCheckPolicyName);
if (entityItem != null) {
- if(entityItem.getPolicyName().equals(dbCheckPolicyName)){
+ if (entityItem.getPolicyName().equals(dbCheckPolicyName)) {
return entityItem;
}
}