2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 Samsung Electronics Co., Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdp.rest.api.services;
25 import org.onap.policy.api.AttributeType;
26 import org.onap.policy.api.PolicyException;
27 import org.onap.policy.api.PolicyParameters;
28 import org.onap.policy.common.logging.flexlogger.FlexLogger;
29 import org.onap.policy.common.logging.flexlogger.Logger;
30 import org.onap.policy.pdp.rest.api.utils.PolicyApiUtils;
31 import org.onap.policy.xacml.api.XACMLErrorConstants;
32 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
33 import org.onap.policy.xacml.std.pap.StdPAPPolicyParams;
36 * BRMS Param Policy Implementation.
40 public class BRMSParamPolicyService {
41 private static final Logger LOGGER = FlexLogger.getLogger(BRMSParamPolicyService.class.getName());
42 private PAPServices papServices = null;
44 private PolicyParameters policyParameters = null;
45 private String message = null;
46 private String policyName = null;
47 private String policyScope = null;
48 private String date = null;
49 private Map<AttributeType, Map<String, String>> drlRuleAndUIParams = null;
51 public BRMSParamPolicyService(String policyName, String policyScope,
52 PolicyParameters policyParameters, String date) {
53 this.policyParameters = policyParameters;
54 this.policyName = policyName;
55 this.policyScope = policyScope;
57 papServices = new PAPServices();
60 public Boolean getValidation() {
61 boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel());
63 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given.";
66 drlRuleAndUIParams = policyParameters.getAttributes();
67 if (drlRuleAndUIParams == null || drlRuleAndUIParams.isEmpty()) {
68 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given.";
74 public String getMessage() {
78 public String getResult(boolean updateFlag) throws PolicyException {
79 String response = null;
80 String operation = null;
87 // Creating BRMS Param Policies from the Admin Console
88 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
89 .configPolicyType("BRMS_Param")
90 .policyName(policyName)
91 .description(policyParameters.getPolicyDescription())
92 .configName("BRMS_PARAM_RULE")
93 .editPolicy(updateFlag)
95 .dynamicFieldConfigAttributes(drlRuleAndUIParams.get(AttributeType.MATCHING))
99 .drlRuleAndUIParams(drlRuleAndUIParams.get(AttributeType.RULE))
100 .riskLevel(policyParameters.getRiskLevel())
101 .riskType(policyParameters.getRiskType())
102 .guard(String.valueOf(policyParameters.getGuard()))
104 .brmsController(policyParameters.getControllerName())
105 .brmsDependency(policyParameters.getDependencyNames())
108 response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
109 "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsParam");
110 LOGGER.info(response);