Use Policy Translator abstract class
[policy/xacml-pdp.git] / applications / common / src / main / java / org / onap / policy / pdp / xacml / application / common / std / StdCombinedPolicyRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pdp.xacml.application.common.std;
24
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
30 import java.util.Map;
31 import java.util.Map.Entry;
32
33 import org.onap.policy.models.decisions.concepts.DecisionRequest;
34
35 @XACMLRequest(ReturnPolicyIdList = true)
36 public class StdCombinedPolicyRequest {
37
38     public StdCombinedPolicyRequest() {
39         super();
40     }
41
42     @XACMLSubject(includeInResults = true)
43     String onapName = "DCAE";
44
45     @XACMLResource(includeInResults = true)
46     String resource = "onap.policies.Monitoring";
47
48     @XACMLAction()
49     String action = "configure";
50
51
52     /**
53      * Parses the DecisionRequest into a MonitoringRequest.
54      *
55      * @param decisionRequest Input DecisionRequest
56      * @return MonitoringRequest
57      */
58     public static StdCombinedPolicyRequest createInstance(DecisionRequest decisionRequest) {
59         StdCombinedPolicyRequest request = new StdCombinedPolicyRequest();
60         request.onapName = decisionRequest.getOnapName();
61         request.action = decisionRequest.getAction();
62
63         Map<String, Object> resources = decisionRequest.getResource();
64         for (Entry<String, Object> entry : resources.entrySet()) {
65             if ("policy-id".equals(entry.getKey())) {
66                 //
67                 // TODO handle lists of policies
68                 //
69                 request.resource = entry.getValue().toString();
70                 continue;
71             }
72             if ("policy-type".equals(entry.getKey())) {
73                 //
74                 // TODO handle lists of policies
75                 //
76                 request.resource = entry.getValue().toString();
77             }
78         }
79         //
80         // TODO handle a bad incoming request. Do that here?
81         //
82         return request;
83     }
84 }