Started with test decision JSON objects.
[policy/xacml-pdp.git] / applications / monitoring / src / main / java / org / onap / policy / xacml / pdp / application / monitoring / MonitoringRequest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Decision Models
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.xacml.pdp.application.monitoring;
22
23 import com.att.research.xacml.std.annotations.XACMLAction;
24 import com.att.research.xacml.std.annotations.XACMLRequest;
25 import com.att.research.xacml.std.annotations.XACMLResource;
26 import com.att.research.xacml.std.annotations.XACMLSubject;
27
28 import java.util.Map;
29 import java.util.Map.Entry;
30
31 import org.onap.policy.models.decisions.concepts.DecisionRequest;
32
33 @XACMLRequest(ReturnPolicyIdList = true)
34 public class MonitoringRequest {
35
36     @XACMLSubject(includeInResults = true)
37     String onapName = "DCAE";
38
39     @XACMLResource(includeInResults = true)
40     String resource = "onap.policies.Monitoring";
41
42     @XACMLAction()
43     String action = "configure";
44
45
46     /**
47      * Parses the DecisionRequest into a MonitoringRequest.
48      *
49      * @param decisionRequest Input DecisionRequest
50      * @return MonitoringRequest
51      */
52     public static MonitoringRequest createInstance(DecisionRequest decisionRequest) {
53         MonitoringRequest request = new MonitoringRequest();
54         request.onapName = decisionRequest.getOnapName();
55         request.action = decisionRequest.getAction();
56
57         Map<String, Object> resources = decisionRequest.getResource();
58         for (Entry<String, Object> entry : resources.entrySet()) {
59             if (entry.getKey().equals("policy-id")) {
60                 //
61                 // TODO handle lists of policies
62                 //
63                 request.resource = entry.getValue().toString();
64                 continue;
65             }
66             if (entry.getKey().equals("policy-type")) {
67                 //
68                 // TODO handle lists of policies
69                 //
70                 request.resource = entry.getValue().toString();
71             }
72         }
73         //
74         // TODO handle a bad incoming request. Do that here?
75         //
76         return request;
77     }
78 }