2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.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 * Action Policy Implementation.
39 public class ActionPolicyService {
40 private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicyService.class.getName());
41 private PAPServices papServices = null;
43 private PolicyParameters policyParameters = null;
44 private String message = null;
45 private String policyName = null;
46 private String policyScope = null;
47 private Map<String, String> componentAttributes = null;
48 private String actionAttribute = null;
49 private String actionPerformer = null;
51 public ActionPolicyService(String policyScope, String policyName,
52 PolicyParameters policyParameters) {
53 this.policyParameters = policyParameters;
54 this.policyName = policyName;
55 this.policyScope = policyScope;
56 papServices = new PAPServices();
59 public Boolean getValidation() {
60 if (policyParameters.getAttributes() == null || policyParameters.getAttributes().isEmpty()) {
61 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given.";
64 componentAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING);
65 if (componentAttributes == null || componentAttributes.isEmpty()) {
66 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given.";
69 actionAttribute = policyParameters.getActionAttribute();
70 if (actionAttribute == null || actionAttribute.trim().isEmpty()) {
71 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Attribute given.";
74 actionPerformer = policyParameters.getActionPerformer();
75 if (actionPerformer == null || actionPerformer.trim().isEmpty()) {
76 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Performer given.";
79 if (!"PEP".equalsIgnoreCase(actionPerformer) && !"PDP".equalsIgnoreCase(actionPerformer)) {
80 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Performer given.";
86 public String getMessage() {
90 public String getResult(boolean updateFlag) throws PolicyException {
91 String response = null;
92 String operation = null;
99 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder().policyName(policyName)
100 .description(policyParameters.getPolicyDescription())
101 .dynamicFieldConfigAttributes(componentAttributes)
102 .dynamicRuleAlgorithmLabels(policyParameters.getDynamicRuleAlgorithmLabels())
103 .dynamicRuleAlgorithmCombo(policyParameters.getDynamicRuleAlgorithmFunctions())
104 .dynamicRuleAlgorithmField1(policyParameters.getDynamicRuleAlgorithmField1())
105 .dynamicRuleAlgorithmField2(policyParameters.getDynamicRuleAlgorithmField2())
106 .actionPerformer(actionPerformer)
107 .actionAttribute(actionAttribute)
108 .editPolicy(updateFlag)
113 response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
114 "policyType=Action"}, policyParameters.getRequestID(), "Action");
115 LOGGER.info(response);