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;
 
  30 import java.util.ArrayList;
 
  31 import java.util.Collection;
 
  33 import java.util.Map.Entry;
 
  37 import lombok.ToString;
 
  39 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 
  44 @XACMLRequest(ReturnPolicyIdList = true)
 
  45 public class StdCombinedPolicyRequest {
 
  47     @XACMLSubject(includeInResults = true)
 
  48     private String onapName;
 
  50     @XACMLSubject(attributeId = "urn:org:onap:onap-component", includeInResults = true)
 
  51     private String onapComponent;
 
  53     @XACMLSubject(attributeId = "urn:org:onap:onap-instance",  includeInResults = true)
 
  54     private String onapInstance;
 
  57     private String action;
 
  59     @XACMLResource(includeInResults = true)
 
  60     private Collection<String> resource = new ArrayList<>();
 
  62     public StdCombinedPolicyRequest() {
 
  67      * Parses the DecisionRequest into a MonitoringRequest.
 
  69      * @param decisionRequest Input DecisionRequest
 
  70      * @return MonitoringRequest
 
  72     @SuppressWarnings({"unchecked", "rawtypes"})
 
  73     public static StdCombinedPolicyRequest createInstance(DecisionRequest decisionRequest) {
 
  75         // Create our request object
 
  77         StdCombinedPolicyRequest request = new StdCombinedPolicyRequest();
 
  79         // Add the subject attributes
 
  81         request.onapName = decisionRequest.getOnapName();
 
  82         request.onapComponent = decisionRequest.getOnapComponent();
 
  83         request.onapInstance = decisionRequest.getOnapInstance();
 
  85         // Add the action attribute
 
  87         request.action = decisionRequest.getAction();
 
  89         // Add the resource attributes
 
  91         Map<String, Object> resources = decisionRequest.getResource();
 
  92         for (Entry<String, Object> entrySet : resources.entrySet()) {
 
  93             if ("policy-id".equals(entrySet.getKey())) {
 
  94                 if (entrySet.getValue() instanceof Collection) {
 
  95                     addPolicyIds(request, (Collection) entrySet.getValue());
 
  96                 } else if (entrySet.getValue() instanceof String) {
 
  97                     request.resource.add(entrySet.getValue().toString());
 
 101             if ("policy-type".equals(entrySet.getKey())) {
 
 102                 if (entrySet.getValue() instanceof Collection) {
 
 103                     addPolicyTypes(request, (Collection) entrySet.getValue());
 
 104                 } else if (entrySet.getValue() instanceof String) {
 
 105                     request.resource.add(entrySet.getValue().toString());
 
 112     private static StdCombinedPolicyRequest addPolicyIds(StdCombinedPolicyRequest request, Collection<Object> ids) {
 
 113         for (Object id : ids) {
 
 114             request.resource.add(id.toString());
 
 119     private static StdCombinedPolicyRequest addPolicyTypes(StdCombinedPolicyRequest request, Collection<Object> types) {
 
 120         for (Object type : types) {
 
 121             request.resource.add(type.toString());