aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP
diff options
context:
space:
mode:
Diffstat (limited to 'POLICY-SDK-APP')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java7
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java25
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java30
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSRawController.java24
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java34
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java21
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java53
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java32
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateOptimizationController.java53
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java29
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java5
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java7
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java58
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java20
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java5
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java15
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java7
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java8
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java5
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java5
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java18
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java22
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java2
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java5
-rw-r--r--POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java7
-rw-r--r--POLICY-SDK-APP/src/test/resources/xacml.admin.properties8
27 files changed, 196 insertions, 311 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java
index e9190968d..139b2b87f 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AdminTabController.java
@@ -52,7 +52,6 @@ import org.springframework.web.servlet.ModelAndView;
public class AdminTabController extends RestrictedBaseController {
private static final Logger LOGGER = FlexLogger.getLogger(AdminTabController.class);
- private static final String CHARACTER_ENCODING = "UTF-8";
private static CommonClassDao commonClassDao;
@@ -107,8 +106,8 @@ public class AdminTabController extends RestrictedBaseController {
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
public ModelAndView saveAdminTabLockdownValue(HttpServletRequest request, HttpServletResponse response)
throws IOException {
- response.setCharacterEncoding(CHARACTER_ENCODING);
- request.setCharacterEncoding(CHARACTER_ENCODING);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -124,7 +123,7 @@ public class AdminTabController extends RestrictedBaseController {
globalRole.setRole("super-admin");
commonClassDao.update(globalRole);
- response.setContentType("application / json");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
String responseString = mapper.writeValueAsString(commonClassDao.getData(GlobalRoleSettings.class));
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java
index b5e17f2e0..b26709ff4 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/AutoPushController.java
@@ -79,7 +79,6 @@ import org.springframework.web.servlet.ModelAndView;
public class AutoPushController extends RestrictedBaseController {
private static final Logger logger = FlexLogger.getLogger(AutoPushController.class);
- private static final String UTF8 = "UTF-8";
@Autowired
CommonClassDao commonClassDao;
@@ -194,6 +193,11 @@ public class AutoPushController extends RestrictedBaseController {
public ModelAndView pushPolicyToPDPGroup(HttpServletRequest request, HttpServletResponse response)
throws IOException {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
ArrayList<Object> selectedPdps = new ArrayList<>();
ArrayList<String> selectedPoliciesInUI = new ArrayList<>();
PolicyController controller = getPolicyControllerInstance();
@@ -333,18 +337,12 @@ public class AutoPushController extends RestrictedBaseController {
currentPoliciesInGroup.addAll(selectedPolicies);
updatedGroupObject.setPolicies(currentPoliciesInGroup);
this.container.updateGroup(updatedGroupObject, userId);
-
- response.setCharacterEncoding(UTF8);
- response.setContentType("application / json");
- request.setCharacterEncoding(UTF8);
-
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups();
response.getWriter().write(new JSONObject(
new JsonMessage(mapper.writeValueAsString(groups))).toString());
}
} catch (Exception e) {
- response.setCharacterEncoding(UTF8);
- request.setCharacterEncoding(UTF8);
logger.error(e);
response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);
}
@@ -358,6 +356,11 @@ public class AutoPushController extends RestrictedBaseController {
@RequestMapping(value = {"/auto_Push/remove_GroupPolicies.htm"}, method = {RequestMethod.POST})
public ModelAndView removePDPGroup(HttpServletRequest request, HttpServletResponse response) throws IOException {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
PolicyController controller = getPolicyControllerInstance();
this.container = new PDPGroupContainer(controller.getPapEngine());
ObjectMapper mapper = new ObjectMapper();
@@ -390,15 +393,11 @@ public class AutoPushController extends RestrictedBaseController {
this.container.updateGroup(updatedGroupObject);
}
- response.setCharacterEncoding(UTF8);
- response.setContentType("application / json");
- request.setCharacterEncoding(UTF8);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups();
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
} catch (Exception e) {
- response.setCharacterEncoding(UTF8);
- request.setCharacterEncoding(UTF8);
logger.error(e);
response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
index 1adeb6d96..244b7fd95 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java
@@ -64,6 +64,7 @@ import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.BRMSParamTemplate;
import org.onap.policy.rest.jpa.PolicyEntity;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.beans.factory.annotation.Autowired;
@@ -244,10 +245,14 @@ public class CreateBRMSParamController extends RestrictedBaseController {
dynamicLayoutMap.put(caption, type);
}
- /*
+ /**
+ * prePopulateBRMSParamPolicyData.
* When the User Click Edit or View Policy the following method will get invoked for setting the data to
* PolicyRestAdapter.
- * Which is used to bind the data in GUI
+ * Which is used to bind the data in GUI.
+ *
+ * @param policyAdapter PolicyRestAdapter
+ * @param entity PolicyEntity
*/
public void prePopulateBRMSParamPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
dynamicLayoutMap = new HashMap<>();
@@ -351,20 +356,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
String value = (String) attributeValue.getContent().get(0);
AttributeDesignatorType designator = match.getAttributeDesignator();
String attributeId = designator.getAttributeId();
- if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- }
- if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- }
- if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- }
- if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(attributeId, value);
}
}
@@ -535,9 +527,9 @@ public class CreateBRMSParamController extends RestrictedBaseController {
// Replacing the value with the inputs provided by the user in the editor.
body = matcher.replaceAll(copyMap.get(input));
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
response.getWriter().write(new JSONObject("{policyData: " + mapper.writeValueAsString(body)
+ "}").toString());
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSRawController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSRawController.java
index 214cb3244..487165b56 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSRawController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSRawController.java
@@ -36,7 +36,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
@@ -53,6 +52,12 @@ public class CreateBRMSRawController {
protected PolicyRestAdapter policyAdapter = null;
+ /**
+ * prePopulateBRMSRawPolicyData.
+ *
+ * @param policyAdapter PolicyRestAdapter
+ * @param entity PolicyEntity
+ */
public void prePopulateBRMSRawPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
if (! (policyAdapter.getPolicyData() instanceof PolicyType)) {
@@ -97,21 +102,8 @@ public class CreateBRMSRawController {
.forEach(match -> {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- } else if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- } else if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}));
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java
index 9f19e4c71..a7a03c021 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopFaultController.java
@@ -39,8 +39,6 @@ import lombok.Getter;
import lombok.Setter;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -52,9 +50,9 @@ import org.onap.policy.rest.adapter.ClosedLoopFaultTriggerUISignatures;
import org.onap.policy.rest.adapter.ClosedLoopSignatures;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.dao.CommonClassDao;
-import org.onap.policy.rest.jpa.OnapName;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.VarbindDictionary;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -74,7 +72,6 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController {
private static final String CONNECT_TRAP_2 = "connectTrap2";
private static final String TRAP_COUNT_2 = "trapCount2";
private static final String TRIGGER_1 = "trigger1";
- private static final String ENC_UTF_8 = "UTF-8";
private static final String TRIGGER_2 = "trigger2";
protected PolicyRestAdapter policyAdapter = null;
@@ -346,7 +343,8 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController {
} catch (NumberFormatException e) {
try {
trap1Attrib = getVarbindOid(trap1Attrib);
- attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib, ENC_UTF_8) + ")";
+ attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib,
+ PolicyUtils.CHARACTER_ENCODING) + ")";
} catch (UnsupportedEncodingException e1) {
policyLogger.error("Caused Exception while Encoding Varbind Dictionary Values", e1);
}
@@ -354,7 +352,8 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController {
} else {
try {
trap1Attrib = getVarbindOid(trap1Attrib);
- attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib, ENC_UTF_8) + ")";
+ attributesStr = attributesStr + "(" + URLEncoder.encode(trap1Attrib,
+ PolicyUtils.CHARACTER_ENCODING) + ")";
} catch (UnsupportedEncodingException e) {
policyLogger.error("Caused Exception while Encoding Varbind Dictionary Values", e);
}
@@ -515,27 +514,8 @@ public class CreateClosedLoopFaultController extends RestrictedBaseController {
.forEach(match -> {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- // First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- OnapName onapName = new OnapName();
- onapName.setOnapName(value);
- policyAdapter.setOnapNameField(onapName);
- } else if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- } else if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- } else if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}));
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java
index 8d47be76c..058542590 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java
@@ -52,6 +52,12 @@ public class CreateClosedLoopPMController {
protected PolicyRestAdapter policyAdapter = null;
+ /**
+ * prePopulateClosedLoopPMPolicyData.
+ *
+ * @param policyAdapter PolicyRestAdapter
+ * @param entity PolicyEntity
+ */
public void prePopulateClosedLoopPMPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
if (! (policyAdapter.getPolicyData() instanceof PolicyType)) {
return;
@@ -116,19 +122,8 @@ public class CreateClosedLoopPMController {
AttributeDesignatorType designator = match.getAttributeDesignator();
String attributeId = designator.getAttributeId();
// First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- } else if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- } else if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- } else if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- } else if ("ServiceType".equals(attributeId)) {
+ policyAdapter.setupUsingAttribute(attributeId, value);
+ if ("ServiceType".equals(attributeId)) {
LinkedHashMap<String, String> serviceTypePolicyName1 = new LinkedHashMap<>();
serviceTypePolicyName1.put(KEY_SERVICE_TYPE_POLICY_NAME, value);
policyAdapter.setServiceTypePolicyName(serviceTypePolicyName1);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java
index 2549e2167..f0b3313a6 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java
@@ -72,8 +72,6 @@ import lombok.Getter;
import lombok.Setter;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -99,6 +97,7 @@ import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.util.MSAttributeObject;
import org.onap.policy.rest.util.MSModelUtils;
import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.web.support.JsonMessage;
import org.springframework.beans.factory.annotation.Autowired;
@@ -960,9 +959,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
}
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
List<Object> list = new ArrayList<>();
String responseString = mapper.writeValueAsString(returnModel);
@@ -1183,6 +1182,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
return keys;
}
+ /**
+ * getModelServiceVersionData.
+ *
+ * @param request HttpServletRequest
+ * @param response HttpServletResponse
+ * @return ModelAndView
+ * @throws IOException IOException
+ */
@RequestMapping(
value = {"/policyController/getModelServiceVersioneData.htm"},
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
@@ -1191,9 +1198,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
List<Object> list = new ArrayList<>();
String value = mapper.readTree(request.getReader()).get("policyData").toString().replaceAll("^\"|\"$", "");
String servicename = value.split("-v")[0];
@@ -1311,29 +1318,9 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
//
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
// First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- } else if ("ConfigName".equals(attributeId)) {
- policyAdapter.setConfigName(value);
- } else if ("uuid".equals(attributeId)) {
- policyAdapter.setUuid(value);
- } else if ("location".equals(attributeId)) {
- policyAdapter.setLocation(value);
- } else if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- } else if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- } else if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- } else if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- String newDate = new PolicyController().convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}
readFile(policyAdapter, entity);
}
@@ -1397,6 +1384,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController {
}
+ /**
+ * readRecursivlyJSONContent.
+ *
+ * @param map Map of String to something
+ * @param data Map of String to Object
+ */
@SuppressWarnings({"rawtypes", "unchecked"})
public void readRecursivlyJSONContent(Map<String, ?> map, Map<String, Object> data) {
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java
index 0fbc34d71..cb0263f2f 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java
@@ -39,8 +39,6 @@ import javax.servlet.http.HttpServletResponse;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -75,6 +73,7 @@ import org.onap.policy.rest.jpa.PrefixList;
import org.onap.policy.rest.jpa.SecurityZone;
import org.onap.policy.rest.jpa.ServiceList;
import org.onap.policy.rest.jpa.TermList;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.beans.factory.annotation.Autowired;
@@ -278,27 +277,8 @@ public class CreateFirewallController extends RestrictedBaseController {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
//
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- if (("ConfigName").equals(attributeId)) {
- policyAdapter.setConfigName(value);
- }
- if (("RiskType").equals(attributeId)) {
- policyAdapter.setRiskType(value);
- }
- if (("RiskLevel").equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- }
- if (("guard").equals(attributeId)) {
- policyAdapter.setGuard(value);
- }
- if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}
}
}
@@ -457,9 +437,9 @@ public class CreateFirewallController extends RestrictedBaseController {
}
}
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
String responseString = mapper.writeValueAsString(displayString);
response.getWriter().write(new JSONObject("{policyData: " + responseString + "}").toString());
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateOptimizationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateOptimizationController.java
index afe2ce193..eb3b3246a 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateOptimizationController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateOptimizationController.java
@@ -55,8 +55,6 @@ import lombok.Getter;
import lombok.Setter;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -80,6 +78,7 @@ import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.util.MSAttributeObject;
import org.onap.policy.rest.util.MSModelUtils;
import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@@ -121,9 +120,7 @@ public class CreateOptimizationController extends RestrictedBaseController {
public static final String MANYFALSE = ":MANY-false";
public static final String MODEL = "model";
public static final String MANY = "MANY-";
- public static final String UTF8 = "UTF-8";
public static final String MODELNAME = "modelName";
- public static final String APPLICATIONJSON = "application / json";
@Autowired
private CreateOptimizationController(CommonClassDao commonClassDao) {
@@ -296,9 +293,9 @@ public class CreateOptimizationController extends RestrictedBaseController {
jsonModel = finalJsonObject.toString();
}
- response.setCharacterEncoding(UTF8);
- response.setContentType(APPLICATIONJSON);
- request.setCharacterEncoding(UTF8);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
List<Object> list = new ArrayList<>();
String responseString = mapper.writeValueAsString(returnModel);
JSONObject json = null;
@@ -485,9 +482,9 @@ public class CreateOptimizationController extends RestrictedBaseController {
final String value = root.get("policyData").toString().replaceAll("^\"|\"$", "");
final String servicename = value.split("-v")[0];
- response.setCharacterEncoding(UTF8);
- response.setContentType(APPLICATIONJSON);
- request.setCharacterEncoding(UTF8);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
List<Object> list = new ArrayList<>();
list.add(new JSONObject("{optimizationModelVersionData: "
+ mapper.writeValueAsString(getVersionList(servicename)) + "}"));
@@ -572,28 +569,8 @@ public class CreateOptimizationController extends RestrictedBaseController {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
//
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- // First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- }
- if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- }
- if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- }
- if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- }
- if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
+ policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+ (String) match.getAttributeValue().getContent().get(0));
}
readFile(policyAdapter, entity);
}
@@ -683,9 +660,9 @@ public class CreateOptimizationController extends RestrictedBaseController {
}
if (!errorMsg.isEmpty()) {
- response.setCharacterEncoding(UTF8);
- response.setContentType(APPLICATIONJSON);
- request.setCharacterEncoding(UTF8);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
response.getWriter().write(new JSONObject().put("errorMsg", errorMsg).toString());
return;
}
@@ -753,9 +730,9 @@ public class CreateOptimizationController extends RestrictedBaseController {
}
- response.setCharacterEncoding(UTF8);
- response.setContentType(APPLICATIONJSON);
- request.setCharacterEncoding(UTF8);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
ObjectMapper mapper = new ObjectMapper();
JSONObject json = new JSONObject();
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java
index 711228574..a2cf20834 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java
@@ -27,8 +27,6 @@ import java.util.Map;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
@@ -99,31 +97,10 @@ public class CreatePolicyController extends RestrictedBaseController {
// Under the match we have attribute value and
// attributeDesignator. So,finally down to the actual attribute.
//
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
+ String value = (String) match.getAttributeValue().getContent().get(0);
+ String attributeId = match.getAttributeDesignator().getAttributeId();
// First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- }
- if ("RiskType".equals(attributeId)) {
- policyAdapter.setRiskType(value);
- }
- if ("RiskLevel".equals(attributeId)) {
- policyAdapter.setRiskLevel(value);
- }
- if ("guard".equals(attributeId)) {
- policyAdapter.setGuard(value);
- }
- if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
- PolicyController controller = new PolicyController();
- String newDate = controller.convertDate(value);
- policyAdapter.setTtlDate(newDate);
- }
- if ("ConfigName".equals(attributeId)) {
- policyAdapter.setConfigName(value);
- }
+ policyAdapter.setupUsingAttribute(attributeId, value);
// After Onap and Config it is optional to have attributes, so
// check weather dynamic values or there or not.
if (index >= 7) {
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java
index 891398aef..dee92925a 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DashboardController.java
@@ -188,7 +188,7 @@ public class DashboardController extends RestrictedBaseController {
model.put("policyStatusCRUDData", mapper.writeValueAsString(policyStatusCrudData));
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(model))).toString());
} catch (Exception e) {
- response.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
PrintWriter out = response.getWriter();
out.write(PolicyUtils.CATCH_EXCEPTION);
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
index 8ecf3692d..c3b474521 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
@@ -25,7 +25,6 @@ import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -170,9 +169,7 @@ public class DecisionPolicyController extends RestrictedBaseController {
AttributeDesignatorType designator = match.getAttributeDesignator();
String attributeId = designator.getAttributeId();
// First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- }
+ policyAdapter.setupUsingAttribute(attributeId, value);
// Component attributes are saved under Target here we are fetching them back.
// One row is default so we are not adding dynamic component at index 0.
if (index >= 1) {
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java
index b50ca6d94..0c0c15f05 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ExportAndImportDecisionBlackListEntries.java
@@ -61,6 +61,7 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.adapter.ReturnBlackList;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.web.support.JsonMessage;
@@ -146,9 +147,9 @@ public class ExportAndImportDecisionBlackListEntries extends RestrictedBaseContr
workBook.write(fos);
fos.flush();
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
PrintWriter out = response.getWriter();
String successMap = file.substring(file.lastIndexOf("webapps") + 8);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java
index ae866c44a..f2f7d57af 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PDPController.java
@@ -27,7 +27,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -44,6 +43,7 @@ import org.onap.policy.admin.RESTfulPAPEngine;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.model.PDPGroupContainer;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.utils.UserUtils.Pair;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.api.pap.OnapPDPGroup;
@@ -195,6 +195,11 @@ public class PDPController extends RestrictedBaseController {
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
public void savePDPGroup(HttpServletRequest request, HttpServletResponse response) {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
ObjectMapper mapper = new ObjectMapper();
PolicyController controller = getPolicyControllerInstance();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
@@ -223,20 +228,14 @@ public class PDPController extends RestrictedBaseController {
+ message + e);
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups(request);
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
} catch (Exception e) {
policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Saving the PDP Group" + e);
- response.setCharacterEncoding("UTF-8");
- PrintWriter out = null;
try {
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
+ response.getWriter().write(e.getMessage());
} catch (Exception e1) {
policyLogger
.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Saving the PDP Group" + e1);
@@ -255,6 +254,11 @@ public class PDPController extends RestrictedBaseController {
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
public void removePDPGroup(HttpServletRequest request, HttpServletResponse response) {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
@@ -275,19 +279,13 @@ public class PDPController extends RestrictedBaseController {
this.container.removeGroup(pdpGroupData, null);
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups(request);
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
} catch (Exception e) {
policyLogger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Removing the PDP Group" + e);
- PrintWriter out;
try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
+ response.getWriter().write(e.getMessage());
} catch (Exception e1) {
policyLogger.error("Exception Occured" + e1);
}
@@ -305,6 +303,11 @@ public class PDPController extends RestrictedBaseController {
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
public void savePDPToGroup(HttpServletRequest request, HttpServletResponse response) {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
@@ -336,20 +339,14 @@ public class PDPController extends RestrictedBaseController {
+ "Error Occured while Creating Pdp in PDP Group" + message + e);
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups(request);
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
} catch (Exception e) {
policyLogger
.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Creating Pdp in PDP Group" + e);
- PrintWriter out;
try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- out = response.getWriter();
- out.write(e.getMessage());
+ response.getWriter().write(e.getMessage());
} catch (Exception e1) {
policyLogger.error("Exception Occured" + e1);
}
@@ -367,6 +364,11 @@ public class PDPController extends RestrictedBaseController {
method = {org.springframework.web.bind.annotation.RequestMethod.POST})
public void removePDPFromGroup(HttpServletRequest request, HttpServletResponse response) {
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(request.getReader());
@@ -384,9 +386,7 @@ public class PDPController extends RestrictedBaseController {
StdPDP deletePdp = mapper.readValue(root.get("data").toString(), StdPDP.class);
StdPDPGroup activeGroupData = mapper.readValue(root.get("activePDP").toString(), StdPDPGroup.class);
this.container.removePDP(deletePdp, activeGroupData);
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
refreshGroups(request);
response.getWriter().write(new JSONObject(new JsonMessage(mapper.writeValueAsString(groups))).toString());
@@ -394,8 +394,6 @@ public class PDPController extends RestrictedBaseController {
policyLogger.error(
XACMLErrorConstants.ERROR_DATA_ISSUE + "Error Occured while Removing Pdp from PDP Group" + e);
try {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
response.getWriter().write(e.getMessage());
} catch (Exception e1) {
policyLogger.error("Exception Occured" + e1);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java
index 7769ac7d0..5e957c40c 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyController.java
@@ -64,6 +64,7 @@ import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.PolicyVersion;
import org.onap.policy.rest.jpa.UserInfo;
import org.onap.policy.utils.PeCryptoUtils;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.utils.UserUtils.Pair;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
@@ -112,8 +113,6 @@ public class PolicyController extends RestrictedBaseController {
// Constant variables used across Policy-sdk
private static final String policyData = "policyData";
- private static final String characterEncoding = "UTF-8";
- private static final String contentType = "application/json";
private static final String file = "file";
private static final String SUPERADMIN = "super-admin";
private static final String POLICYGUEST = "Policy Guest";
@@ -945,11 +944,11 @@ public class PolicyController extends RestrictedBaseController {
}
public static String getCharacterencoding() {
- return characterEncoding;
+ return PolicyUtils.CHARACTER_ENCODING;
}
public static String getContenttype() {
- return contentType;
+ return PolicyUtils.APPLICATION_JSON;
}
public static String getFile() {
@@ -974,17 +973,4 @@ public class PolicyController extends RestrictedBaseController {
return fileSizeLimit;
}
- /**
- * Function to convert date.
- *
- * @param dateTimeToLive input date value.
- * @return
- */
- public String convertDate(String dateTimeToLive) {
- String formatDate = null;
- if (dateTimeToLive.contains("-")) {
- formatDate = dateTimeToLive.replace("-", "/");
- }
- return formatDate;
- }
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java
index 380341ffa..8f508ca31 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyExportAndImportController.java
@@ -64,6 +64,7 @@ import org.onap.policy.rest.jpa.PolicyEditorScopes;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.PolicyVersion;
import org.onap.policy.rest.jpa.UserInfo;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.policy.utils.UserUtils.Pair;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
@@ -174,8 +175,8 @@ public class PolicyExportAndImportController extends RestrictedBaseController {
workBook2.write(fos);
fos.flush();
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
PrintWriter out = response.getWriter();
String successMap = file.substring(file.lastIndexOf("webapps") + 8);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java
index 51bc3e987..ebd24dce3 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java
@@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import java.io.File;
import java.io.IOException;
-import java.io.PrintWriter;
import java.util.List;
import javax.script.SimpleBindings;
@@ -71,6 +70,11 @@ public class PolicyNotificationController extends RestrictedBaseController {
StringBuilder path = new StringBuilder();
String responseValue = "";
try {
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ //
+ //
+ //
String userId = UserUtils.getUserSession(request).getOrgUserId();
logger.info("userid info: " + userId);
ObjectMapper mapper = new ObjectMapper();
@@ -118,18 +122,13 @@ public class PolicyNotificationController extends RestrictedBaseController {
responseValue = "You have UnSubscribed Successfully";
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
response.getWriter().write(new JSONObject("{watchData: "
+ mapper.writeValueAsString(responseValue) + "}").toString());
} catch (Exception e) {
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
logger.error("Error druing watchPolicy function " + e);
- PrintWriter out = response.getWriter();
- out.write(PolicyUtils.CATCH_EXCEPTION);
+ response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);
}
return null;
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java
index 4fa848edd..c1c784083 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyRolesController.java
@@ -42,6 +42,7 @@ import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.PolicyEditorScopes;
import org.onap.policy.rest.jpa.PolicyRoles;
import org.onap.policy.rest.jpa.UserInfo;
+import org.onap.policy.utils.PolicyUtils;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.web.support.JsonMessage;
import org.onap.portalsdk.core.web.support.UserUtils;
@@ -147,9 +148,9 @@ public class PolicyRolesController extends RestrictedBaseController {
} else {
commonClassDao.update(roles);
}
- response.setCharacterEncoding("UTF-8");
- response.setContentType("application / json");
- request.setCharacterEncoding("UTF-8");
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.setContentType(PolicyUtils.APPLICATION_JSON);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
response.getWriter().write(new JSONObject("{rolesDatas: "
+ mapper.writeValueAsString(commonClassDao.getUserRoles()) + "}").toString());
} catch (Exception e) {
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
index 0c29f8fb7..05264c8b6 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
@@ -23,7 +23,6 @@ package org.onap.policy.controller;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
-import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -73,10 +72,9 @@ public class PolicyValidationController extends RestrictedBaseController {
new JsonMessage(mapper.writeValueAsString(responseString.toString()))).toString());
} catch (Exception e) {
LOGGER.error("Exception Occured During Policy Validation" + e);
- response.setCharacterEncoding("UTF-8");
- request.setCharacterEncoding("UTF-8");
- PrintWriter out = response.getWriter();
- out.write(PolicyUtils.CATCH_EXCEPTION);
+ response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+ response.getWriter().write(PolicyUtils.CATCH_EXCEPTION);
}
return null;
}
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
index 0325c8d8f..244901a3f 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyManagerServletTest.java
@@ -71,6 +71,11 @@ public class PolicyManagerServletTest extends Mockito {
private HttpServletRequest request;
private MockHttpServletResponse response;
+ /**
+ * setUp.
+ *
+ * @throws Exception should not get one
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java
index 4449676d3..5111ef2a8 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/admin/PolicyNotificationMailTest.java
@@ -45,6 +45,11 @@ public class PolicyNotificationMailTest {
private CommonClassDao commonClassDao;
private List<Object> data = null;
+ /**
+ * setUp.
+ *
+ * @throws Exception should not throw one
+ */
@Before
public void setUp() throws Exception {
PolicyController.setjUnit(true);
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java
index 96320e7bc..1a99fdf92 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java
@@ -74,10 +74,9 @@ import org.springframework.mock.web.MockHttpServletResponse;
/**
* The class <code>CreateDcaeMicroServiceControllerTest</code> contains tests for the class
- * {@link <code>CreateDcaeMicroServiceController</code>}*
*
- * All JUnits are designed to run in the local development environment where they have write privileges and can execute
- * time-sensitive tasks.
+ * <p/>All JUnits are designed to run in the local development environment where they have write privileges
+ * and can execute time-sensitive tasks.
*
*/
@@ -89,11 +88,15 @@ public class CreateDcaeMicroServiceControllerTest {
private String configBodyString = null;
private HttpServletRequest request = null;
+ /**
+ * setUp.
+ *
+ * @throws Exception should not throw one
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
- List<Object> microServiceModelsData = new ArrayList<Object>();
MicroServiceModels testData = new MicroServiceModels();
testData.setVersion("OpenOnap-Junit");
testData.setModelName("modelName");
@@ -140,6 +143,7 @@ public class CreateDcaeMicroServiceControllerTest {
testData.setDataOrderInfo("triggerSignature.signaturesAlarm.alarmSignatures.alarmSignature[VnfType, Contains, "
+ "FilterValue]@SymptomTriggerSignature.signaturesSymptom.symptomSignatures."
+ "symptomSignature[symptomVnfType, symptomContains, symptomFilterValue]");
+ List<Object> microServiceModelsData = new ArrayList<Object>();
microServiceModelsData.add(testData);
// mock the getDataById() call
@@ -353,11 +357,8 @@ public class CreateDcaeMicroServiceControllerTest {
try {
root = JsonLoader.fromString(jsonString);
restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(), PolicyRestAdapter.class);
- TargetType target = new TargetType();
// create guard attribute
- AnyOfType anyOfType = new AnyOfType();
- AllOfType alltype = new AllOfType();
MatchType matchType = new MatchType();
// set value
AttributeValueType attributeValue1 = new AttributeValueType();
@@ -367,6 +368,7 @@ public class CreateDcaeMicroServiceControllerTest {
AttributeDesignatorType designator = new AttributeDesignatorType();
designator.setAttributeId("guard");
matchType.setAttributeDesignator(designator);
+ AllOfType alltype = new AllOfType();
alltype.getMatch().add(matchType);
// add a dummy MatchType object since while (matchList.size()>1 ...)
@@ -381,8 +383,10 @@ public class CreateDcaeMicroServiceControllerTest {
matchDummy.setAttributeDesignator(designatorDummy);
alltype.getMatch().add(matchDummy);
+ AnyOfType anyOfType = new AnyOfType();
anyOfType.getAllOf().add(alltype);
+ TargetType target = new TargetType();
target.getAnyOf().add(anyOfType);
// create RiskType attribute
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java
index 6a5e83f4e..8e1b8be87 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateOptimizationControllerTest.java
@@ -66,14 +66,12 @@ import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ConfigurationDataEntity;
import org.onap.policy.rest.jpa.OptimizationModels;
import org.onap.policy.rest.jpa.PolicyEntity;
-import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
/**
* The class <code>CreateOptimizationControllerTest</code> contains tests for the class
- * {@link <code>CreateOptimizationController</code>}*
*
- * All JUnits are designed to run in the local development environment where they have write
+ * <p/>All JUnits are designed to run in the local development environment where they have write
* privileges and can execute time-sensitive tasks.
*/
public class CreateOptimizationControllerTest {
@@ -126,7 +124,7 @@ public class CreateOptimizationControllerTest {
}
/**
- * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test
+ * Run the PolicyRestAdapter setDataToPolicyRestAdapter(PolicyRestAdapter, JsonNode) method test.
*/
@Test
@@ -143,7 +141,7 @@ public class CreateOptimizationControllerTest {
PolicyRestAdapter policyData = null;
try {
root = JsonLoader.fromString(jsonString);
- policyData = (PolicyRestAdapter) mapper.readValue(root.get("policyData").get("policy").toString(),
+ policyData = mapper.readValue(root.get("policyData").get("policy").toString(),
PolicyRestAdapter.class);
} catch (Exception e) {
logger.error("testSetDataToPolicyRestAdapter", e);
@@ -158,7 +156,7 @@ public class CreateOptimizationControllerTest {
/**
* Run the ModelAndView getOptimizationTemplateData(HttpServletRequest, HttpServletResponse)
- * method test
+ * method test.
*/
@Test
@@ -201,7 +199,7 @@ public class CreateOptimizationControllerTest {
/**
* Run the ModelAndView getModelServiceVersionData(HttpServletRequest, HttpServletResponse)
- * method test
+ * method test.
*/
@Test
@@ -244,7 +242,7 @@ public class CreateOptimizationControllerTest {
}
/**
- * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test
+ * Run the void prePopulateDCAEMSPolicyData(PolicyRestAdapter, PolicyEntity) method test.
*/
@Test
@@ -267,7 +265,7 @@ public class CreateOptimizationControllerTest {
try {
root = JsonLoader.fromString(jsonString);
- restAdapter = (PolicyRestAdapter) mapper.readValue(root.get("policyData").get("policy").toString(),
+ restAdapter = mapper.readValue(root.get("policyData").get("policy").toString(),
PolicyRestAdapter.class);
PolicyType policyType = new PolicyType();
TargetType target = new TargetType();
@@ -387,7 +385,7 @@ public class CreateOptimizationControllerTest {
}
/**
- * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test
+ * Run the void SetMSModelData(HttpServletRequest, HttpServletResponse) method test.
*/
@Test
@@ -429,9 +427,7 @@ public class CreateOptimizationControllerTest {
}
/**
- *
- * @ Get File Stream
- *
+ * @ Get File Stream.
*/
private class MockServletInputStream extends ServletInputStream {
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java
index 6a431a0af..79277d81d 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreatePolicyControllerTest.java
@@ -20,9 +20,9 @@
package org.onap.policy.controller;
-import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.att.research.xacml.api.XACML3;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java
index f86f3532c..413849cd3 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/DashboardControllerTest.java
@@ -54,6 +54,11 @@ public class DashboardControllerTest {
private Path repo;
StdEngine engine = null;
+ /**
+ * setUp.
+ *
+ * @throws Exception should not get one
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
index af3c88257..554c40f90 100644
--- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
+++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/PolicyControllerTest.java
@@ -47,12 +47,16 @@ public class PolicyControllerTest {
private static Logger logger = FlexLogger.getLogger(PolicyControllerTest.class);
private static CommonClassDao commonClassDao;
+ /**
+ * setUp.
+ *
+ * @throws Exception Should not throw one
+ */
@Before
public void setUp() throws Exception {
logger.info("setUp: Entering");
commonClassDao = mock(CommonClassDao.class);
PolicyController.setCommonClassDao(commonClassDao);
- List<Object> data = new ArrayList<>();
String policyData = "";
try {
ClassLoader classLoader = getClass().getClassLoader();
@@ -64,6 +68,7 @@ public class PolicyControllerTest {
entity.setPolicyName("Config_SampleTest.1.xml");
entity.setPolicyData(policyData);
entity.setScope("com");
+ List<Object> data = new ArrayList<>();
data.add(entity);
when(commonClassDao.getDataByQuery(
diff --git a/POLICY-SDK-APP/src/test/resources/xacml.admin.properties b/POLICY-SDK-APP/src/test/resources/xacml.admin.properties
index 363ab621f..1147ce6eb 100644
--- a/POLICY-SDK-APP/src/test/resources/xacml.admin.properties
+++ b/POLICY-SDK-APP/src/test/resources/xacml.admin.properties
@@ -2,7 +2,7 @@
# ============LICENSE_START=======================================================
# ONAP Policy Engine
# ================================================================================
-# Copyright (C) 2017 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.
@@ -111,9 +111,9 @@ xacml.max.priority.count=10
#
# You can test authorization within the Admin Console by changing the user id.
# There are 3 supported user ids:
-# guest - Read only access
-# editor - Read/Write access
-# admin - Read/Write/Admin access
+# guest - Read only access
+# editor - Read/Write access
+# admin - Read/Write/Admin access
#
# An empty or null value for xacml.rest.admin.user.id results in no access to the application at all.
#