- public String getResult(boolean updateFlag) throws PolicyException{
- String response = null;
- String operation = null;
- if (updateFlag){
- operation = "update";
- } else {
- operation = "create";
- }
- // get values and attributes from the JsonObject
- if(!configBody.containsKey("onapname")){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given.";
- LOGGER.error(message);
- return message;
- }
- if(!configBody.containsKey("serviceTypePolicyName")){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Service Type Policy Name given.";
- LOGGER.error(message);
- return message;
- }
- String onapName = configBody.get("onapname").toString().trim().replace("\"", "");
- if (onapName==null||onapName.trim().isEmpty()){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given.";
- LOGGER.error(message);
- return message;
- }
- boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel());
- if (!levelCheck){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given.";
- LOGGER.error(message);
- return message;
- }
- String jsonBody = configBody.toString();
- String serviceType = configBody.get("serviceTypePolicyName").toString().replace("\"", "");
- // Create Policy.
- StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", policyName, policyParameters.getPolicyDescription(), onapName,
- jsonBody, false, null, serviceType, updateFlag, policyScope, 0, policyParameters.getRiskLevel(),
- policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date);
- //send JSON object to PAP
- response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop");
- return response;
- }
+ public Boolean getValidation() {
+ if (policyParameters.getConfigBody() == null) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Config Body Present";
+ return false;
+ }
+ if (!PolicyApiUtils.validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())) {
+ message =
+ XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " +
+ policyParameters.getConfigBody();
+ return false;
+ }
+ try {
+ configBody = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody());
+ } catch (JsonException | IllegalStateException e) {
+ message =
+ XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " +
+ policyParameters.getConfigBody();
+ LOGGER.error("Error during parsing JSON config body for Closed loop PM policy ", e);
+ return false;
+ }
+ return true;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public String getResult(boolean updateFlag) throws PolicyException {
+ String response = null;
+ String operation = null;
+ if (updateFlag) {
+ operation = "update";
+ } else {
+ operation = "create";
+ }
+ // get values and attributes from the JsonObject
+ if (!configBody.containsKey("onapname")) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given.";
+ LOGGER.error(message);
+ return message;
+ }
+ if (!configBody.containsKey("serviceTypePolicyName")) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Service Type Policy Name given.";
+ LOGGER.error(message);
+ return message;
+ }
+ String onapName = configBody.get("onapname").toString().trim().replace("\"", "");
+ if (onapName == null || onapName.trim().isEmpty()) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given.";
+ LOGGER.error(message);
+ return message;
+ }
+ boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel());
+ if (!levelCheck) {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given.";
+ LOGGER.error(message);
+ return message;
+ }
+ String jsonBody = configBody.toString();
+ String serviceType = configBody.get("serviceTypePolicyName").toString().replace("\"", "");
+ // Create Policy.
+ StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", policyName,
+ policyParameters.getPolicyDescription(), onapName,
+ jsonBody, false, null, serviceType, updateFlag, policyScope, 0, policyParameters.getRiskLevel(),
+ policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date);
+ //send JSON object to PAP
+ response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
+ "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop");
+ return response;
+ }