2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.openecomp.policy.pdp.rest.api.services;
24 import org.openecomp.policy.api.AttributeType;
25 import org.openecomp.policy.api.PolicyException;
26 import org.openecomp.policy.api.PolicyParameters;
27 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
28 import org.openecomp.policy.common.logging.flexlogger.Logger;
29 import org.openecomp.policy.pdp.rest.api.utils.PolicyApiUtils;
30 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
31 import org.openecomp.policy.xacml.std.pap.StdPAPPolicy;
34 * BRMS Param Policy Implementation.
38 public class BRMSParamPolicyService{
39 private static Logger LOGGER = FlexLogger.getLogger(BRMSParamPolicyService.class.getName());
40 private static PAPServices papServices = null;
42 private PolicyParameters policyParameters = null;
43 private String message = null;
44 private String policyName = null;
45 private String policyScope = null;
46 private String date = null;
47 private boolean levelCheck = false;
48 private Map<AttributeType, Map<String, String>> drlRuleAndUIParams = null;
50 public BRMSParamPolicyService(String policyName, String policyScope,
51 PolicyParameters policyParameters, String date) {
52 this.policyParameters = policyParameters;
53 this.policyName = policyName;
54 this.policyScope = policyScope;
56 papServices = new PAPServices();
59 public Boolean getValidation() {
60 levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel());
62 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given.";
65 drlRuleAndUIParams = policyParameters.getAttributes();
66 if(drlRuleAndUIParams==null || drlRuleAndUIParams.isEmpty()){
67 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given.";
73 public String getMessage() {
77 public String getResult(boolean updateFlag) throws PolicyException {
78 String response = null;
79 String operation = null;
86 StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param",policyName, policyParameters.getPolicyDescription(),
87 "BRMS_PARAM_RULE",updateFlag,policyScope,
88 drlRuleAndUIParams.get(AttributeType.MATCHING), 0, "DROOLS",
89 null, drlRuleAndUIParams.get(AttributeType.RULE), policyParameters.getRiskLevel(),
90 policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date, policyParameters.getControllerName(), policyParameters.getDependencyNames());
92 response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsParam");
93 LOGGER.info(response);