2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Modified 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.api.RuleProvider;
29 import org.onap.policy.common.logging.flexlogger.FlexLogger;
30 import org.onap.policy.common.logging.flexlogger.Logger;
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 * Decision Policy Implementation
40 public class DecisionPolicyService {
41 private static Logger LOGGER = FlexLogger.getLogger(DecisionPolicyService.class.getName());
42 private static PAPServices papServices = null;
44 private String message = null;
45 private String policyScope = null;
46 private String policyName = null;
47 private PolicyParameters policyParameters = null;
48 private String onapName = null;
50 public DecisionPolicyService(String policyScope, String policyName,
51 PolicyParameters policyParameters) {
52 this.policyScope = policyScope;
53 this.policyName = policyName;
54 this.policyParameters = policyParameters;
55 papServices = new PAPServices();
58 public Boolean getValidation() {
59 onapName = policyParameters.getOnapName();
60 if (onapName == null || onapName.trim().isEmpty()) {
61 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given.";
67 public String getMessage() {
71 public String getResult(boolean updateFlag) throws PolicyException {
72 String response = null;
73 String operation = null;
79 RuleProvider ruleProvider = policyParameters.getRuleProvider();
80 if (ruleProvider == null) {
81 ruleProvider = RuleProvider.CUSTOM;
83 Map<String, String> matchingAttributes = null;
84 Map<String, String> settingsAttributes = null;
86 //Get the MATCHING and/or SETTINGS attributes
87 if (policyParameters.getAttributes() != null &&
88 policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
89 policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
90 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
91 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
92 } else if (policyParameters.getAttributes() != null &&
93 !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
94 policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
95 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
96 } else if (policyParameters.getAttributes() != null &&
97 policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
98 !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
99 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
101 // Create StdPAPPolicy object used to send policy data to PAP-REST.
102 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
103 .policyName(policyName)
104 .description(policyParameters.getPolicyDescription())
106 .providerComboBox(ruleProvider.toString())
107 .dynamicFieldConfigAttributes(matchingAttributes)
108 .dynamicSettingsMap(settingsAttributes)
109 .treatments(policyParameters.getTreatments())
110 .dynamicRuleAlgorithmLabels(policyParameters.getDynamicRuleAlgorithmLabels())
111 .dynamicRuleAlgorithmCombo(policyParameters.getDynamicRuleAlgorithmFunctions())
112 .dynamicRuleAlgorithmField1(policyParameters.getDynamicRuleAlgorithmField1())
113 .dynamicRuleAlgorithmField2(policyParameters.getDynamicRuleAlgorithmField2())
114 .editPolicy(updateFlag)
117 .rawXacmlPolicy(policyParameters.getRawXacmlPolicy())
120 response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
121 "policyType=Decision"}, policyParameters.getRequestID(), "Decision");
122 LOGGER.info(message);