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.onap.policy.pdp.rest.api.services;
24 import org.onap.policy.api.AttributeType;
25 import org.onap.policy.api.PolicyException;
26 import org.onap.policy.api.PolicyParameters;
27 import org.onap.policy.api.RuleProvider;
28 import org.onap.policy.common.logging.flexlogger.FlexLogger;
29 import org.onap.policy.common.logging.flexlogger.Logger;
30 import org.onap.policy.xacml.api.XACMLErrorConstants;
31 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
32 import org.onap.policy.xacml.std.pap.StdPAPPolicyParams;
35 * Decision Policy Implementation
39 public class DecisionPolicyService {
40 private static Logger LOGGER = FlexLogger.getLogger(DecisionPolicyService.class.getName());
41 private static PAPServices papServices = null;
43 private String message = null;
44 private String policyScope = null;
45 private String policyName = null;
46 private PolicyParameters policyParameters = null;
47 private String onapName = null;
49 public DecisionPolicyService(String policyScope, String policyName,
50 PolicyParameters policyParameters) {
51 this.policyScope = policyScope;
52 this.policyName = policyName;
53 this.policyParameters = policyParameters;
54 papServices = new PAPServices();
57 public Boolean getValidation() {
58 onapName = policyParameters.getOnapName();
59 if (onapName == null || onapName.trim().isEmpty()) {
60 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given.";
66 public String getMessage() {
70 public String getResult(boolean updateFlag) throws PolicyException {
71 String response = null;
72 String operation = null;
78 RuleProvider ruleProvider = policyParameters.getRuleProvider();
79 if (ruleProvider == null) {
80 ruleProvider = RuleProvider.CUSTOM;
82 Map<String, String> matchingAttributes = null;
83 Map<String, String> settingsAttributes = null;
85 //Get the MATCHING and/or SETTINGS attributes
86 if (policyParameters.getAttributes() != null &&
87 policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
88 policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
89 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
90 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
91 } else if (policyParameters.getAttributes() != null &&
92 !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
93 policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
94 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
95 } else if (policyParameters.getAttributes() != null &&
96 policyParameters.getAttributes().containsKey(AttributeType.MATCHING) &&
97 !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
98 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
100 // Create StdPAPPolicy object used to send policy data to PAP-REST.
101 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
102 .policyName(policyName)
103 .description(policyParameters.getPolicyDescription())
105 .providerComboBox(ruleProvider.toString())
106 .dyanamicFieldConfigAttributes(matchingAttributes)
107 .dynamicSettingsMap(settingsAttributes)
108 .treatments(policyParameters.getTreatments())
109 .dynamicRuleAlgorithmLabels(policyParameters.getDynamicRuleAlgorithmLabels())
110 .dynamicRuleAlgorithmCombo(policyParameters.getDynamicRuleAlgorithmFunctions())
111 .dynamicRuleAlgorithmField1(policyParameters.getDynamicRuleAlgorithmField1())
112 .dynamicRuleAlgorithmField2(policyParameters.getDynamicRuleAlgorithmField2())
113 .editPolicy(updateFlag)
118 response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
119 "policyType=Decision"}, policyParameters.getRequestID(), "Decision");
120 LOGGER.info(message);