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;
34 * Decision Policy Implementation
38 public class DecisionPolicyService{
39 private static Logger LOGGER = FlexLogger.getLogger(DecisionPolicyService.class.getName());
40 private static PAPServices papServices = null;
42 private String message = null;
43 private String policyScope = null;
44 private String policyName = null;
45 private PolicyParameters policyParameters = null;
46 private String onapName = null;
48 public DecisionPolicyService(String policyScope, String policyName,
49 PolicyParameters policyParameters) {
50 this.policyScope = policyScope;
51 this.policyName = policyName;
52 this.policyParameters = policyParameters;
53 papServices = new PAPServices();
56 public Boolean getValidation() {
57 onapName = policyParameters.getOnapName();
58 if (onapName==null||onapName.trim().isEmpty()){
59 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given.";
65 public String getMessage() {
69 public String getResult(boolean updateFlag) throws PolicyException {
70 String response = null;
71 String operation = null;
77 RuleProvider ruleProvider = policyParameters.getRuleProvider();
78 if (ruleProvider==null) {
79 ruleProvider = RuleProvider.CUSTOM ;
81 Map<String,String> matchingAttributes = null;
82 Map<String,String> settingsAttributes = null;
84 //Get the MATCHING and/or SETTINGS attributes
85 if (policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) {
86 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
87 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
88 }else if(policyParameters.getAttributes()!=null && !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){
89 settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS);
90 }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){
91 matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
93 // Create StdPAPPolicy object used to send policy data to PAP-REST.
94 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), onapName, ruleProvider.toString(), matchingAttributes, settingsAttributes,
95 policyParameters.getTreatments(), policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmFunctions(),
96 policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), null, null, null, updateFlag, policyScope, 0);
98 response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Decision"}, policyParameters.getRequestID(), "Decision");