2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 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.xacml.pdp.application.guard;
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;
34 import lombok.ToString;
36 import org.onap.policy.models.decisions.concepts.DecisionRequest;
41 @XACMLRequest(ReturnPolicyIdList = true)
42 public class GuardPolicyRequest {
44 private static final String STR_GUARD = "guard";
46 @XACMLSubject(includeInResults = true)
47 private String onapName;
49 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-component")
50 private String onapComponent;
52 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-instance")
53 private String onapInstance;
55 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:guard:request:request-id")
56 private String requestId;
59 private String action = STR_GUARD;
61 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:clname:clname-id")
62 private String clnameId;
64 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:actor:actor-id")
65 private String actorId;
67 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:operation:operation-id")
68 private String operationId;
70 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:target-id")
71 private String targetId;
73 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:vf-count")
74 private Integer vfCount;
76 public GuardPolicyRequest() {
81 * Parses the DecisionRequest into a StdMetadataPolicyRequest.
83 * @param decisionRequest Input DecisionRequest
84 * @return StdMetadataPolicyRequest
86 @SuppressWarnings("unchecked")
87 public static GuardPolicyRequest createInstance(DecisionRequest decisionRequest) {
89 // Create our return object
91 GuardPolicyRequest request = new GuardPolicyRequest();
93 // Add the subject attributes
95 request.onapName = decisionRequest.getOnapName();
96 request.onapComponent = decisionRequest.getOnapComponent();
97 request.onapInstance = decisionRequest.getOnapInstance();
98 request.requestId = decisionRequest.getRequestId();
100 // Now pull from the resources
102 Map<String, Object> resources = decisionRequest.getResource();
104 // Just in case nothing is in there
106 if (resources == null || resources.isEmpty() || ! resources.containsKey(STR_GUARD)) {
108 // Perhaps we throw an exception and then caller
109 // can put together a response
113 Map<String, Object> guard = (Map<String, Object>) resources.get(STR_GUARD);
114 if (guard == null || guard.isEmpty()) {
116 // again, same problem throw an exception?
123 if (guard.containsKey("actor")) {
124 request.actorId = guard.get("actor").toString();
126 if (guard.containsKey("recipe")) {
127 request.operationId = guard.get("recipe").toString();
129 if (guard.containsKey("clname")) {
130 request.clnameId = guard.get("clname").toString();
132 if (guard.containsKey("target")) {
133 request.targetId = guard.get("target").toString();
135 if (guard.containsKey("vfCount")) {
137 // TODO this can potentially throw a NumberFormatException. Fix this to
138 // throw the exception when you fix the ConvertRequest to throw exceptions also.
140 request.vfCount = Integer.decode(guard.get("vfCount").toString());