X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2Fapi%2Fservices%2FCreateUpdatePolicyServiceImpl.java;h=f2cc16b1fc5b48125534cd4677e75e2d87542336;hb=refs%2Fchanges%2F84%2F98384%2F3;hp=b5797d13163c6c9325e35f5048c99513afb6f325;hpb=948367c08eb34ebaac24601cfc2b249b11925255;p=policy%2Fengine.git diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java index b5797d131..f2cc16b1f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-PDP-REST * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -176,8 +176,14 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService // Get Result. response = microServicesPolicyService.getResult(updateFlag); break; + case Optimization: + OptimizationPolicyService optimizationPolicyService = new OptimizationPolicyService(policyName, policyScope, policyParameters, date); + + // Get Result + response = optimizationPolicyService.getResult(updateFlag); + break; default: - String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present"; + message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present"; LOGGER.error(message); status = HttpStatus.BAD_REQUEST; return message; @@ -208,7 +214,7 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService break; } }else { - String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found."; + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found."; LOGGER.error(message); status = HttpStatus.BAD_REQUEST; response = message; @@ -242,23 +248,24 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService return false; } - if(policyParameters.getPolicyClass() != null){ - if ("Config".equals(policyParameters.getPolicyClass().toString())){ - String policyConfigType = policyParameters.getPolicyConfigType().toString(); - if(!"BRMS_Param".equalsIgnoreCase(policyConfigType)){ - if(Strings.isNullOrEmpty(policyParameters.getConfigBody())){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given"; - LOGGER.error("Common validation did not return success: " + message); - return false; - } - } - } + if(policyParameters.getPolicyClass() != null && "Config".equals(policyParameters.getPolicyClass().toString())){ + String policyConfigType = policyParameters.getPolicyConfigType().toString(); + if(!"BRMS_Param".equalsIgnoreCase(policyConfigType) && Strings.isNullOrEmpty(policyParameters.getConfigBody())){ + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given"; + LOGGER.error("Common validation did not return success: " + message); + return false; + } } try { PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper(); PolicyRestAdapter policyData = wrapper.populateRequestParameters(policyParameters); - responseString = validation.validatePolicy(policyData); + if(policyData!=null) { + responseString = validation.validatePolicy(policyData); + } else { + message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); + return false; + } } catch (Exception e) { LOGGER.error("Exception Occured during Policy Validation" +e); if(e.getMessage()!=null){ @@ -281,7 +288,8 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService } if (responseString!=null){ - if("success".equals(responseString.toString())||"success@#".equals(responseString.toString())){ + String response = responseString.toString().substring(0, 7); + if("success".equals(response)) { return true; } else { message = XACMLErrorConstants.ERROR_DATA_ISSUE + PolicyApiUtils.formatResponse(responseString);