2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.pdp.xacml.application.common.std;
25 import com.att.research.xacml.std.annotations.XACMLAction;
26 import com.att.research.xacml.std.annotations.XACMLRequest;
27 import com.att.research.xacml.std.annotations.XACMLResource;
28 import com.att.research.xacml.std.annotations.XACMLSubject;
29 import java.util.ArrayList;
30 import java.util.Collection;
32 import java.util.Map.Entry;
36 import lombok.ToString;
38 import org.onap.policy.models.decisions.concepts.DecisionRequest;
43 @XACMLRequest(ReturnPolicyIdList = true)
44 public class StdCombinedPolicyRequest {
46 @XACMLSubject(includeInResults = true)
47 private String onapName;
49 @XACMLSubject(attributeId = "urn:org:onap:onap-component", includeInResults = true)
50 private String onapComponent;
52 @XACMLSubject(attributeId = "urn:org:onap:onap-instance", includeInResults = true)
53 private String onapInstance;
56 private String action;
58 @XACMLResource(includeInResults = true)
59 private Collection<String> resource = new ArrayList<>();
61 @XACMLResource(attributeId = "urn:org:onap:policy-type", includeInResults = true)
62 private Collection<String> resourcePolicyType = new ArrayList<>();
64 public StdCombinedPolicyRequest() {
69 * Parses the DecisionRequest into a MonitoringRequest.
71 * @param decisionRequest Input DecisionRequest
72 * @return MonitoringRequest
74 @SuppressWarnings({"unchecked", "rawtypes"})
75 public static StdCombinedPolicyRequest createInstance(DecisionRequest decisionRequest) {
77 // Create our request object
79 StdCombinedPolicyRequest request = new StdCombinedPolicyRequest();
81 // Add the subject attributes
83 request.onapName = decisionRequest.getOnapName();
84 request.onapComponent = decisionRequest.getOnapComponent();
85 request.onapInstance = decisionRequest.getOnapInstance();
87 // Add the action attribute
89 request.action = decisionRequest.getAction();
91 // Add the resource attributes
93 Map<String, Object> resources = decisionRequest.getResource();
94 for (Entry<String, Object> entrySet : resources.entrySet()) {
95 if ("policy-id".equals(entrySet.getKey())) {
96 if (entrySet.getValue() instanceof Collection) {
97 addPolicyIds(request, (Collection) entrySet.getValue());
98 } else if (entrySet.getValue() instanceof String) {
99 request.resource.add(entrySet.getValue().toString());
103 if ("policy-type".equals(entrySet.getKey())) {
104 if (entrySet.getValue() instanceof Collection) {
105 addPolicyTypes(request, (Collection) entrySet.getValue());
106 } else if (entrySet.getValue() instanceof String) {
107 request.resourcePolicyType.add(entrySet.getValue().toString());
114 private static StdCombinedPolicyRequest addPolicyIds(StdCombinedPolicyRequest request, Collection<Object> ids) {
115 for (Object id : ids) {
116 request.resource.add(id.toString());
121 private static StdCombinedPolicyRequest addPolicyTypes(StdCombinedPolicyRequest request, Collection<Object> types) {
122 for (Object type : types) {
123 request.resourcePolicyType.add(type.toString());