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.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;
37 import org.onap.policy.pdp.xacml.application.common.ToscaDictionary;
42 @XACMLRequest(ReturnPolicyIdList = true)
43 public class LegacyGuardPolicyRequest {
45 private static final String STR_GUARD = "guard";
46 private static final String URN_ONAP = ToscaDictionary.URN_ONAP;
48 @XACMLSubject(includeInResults = true)
49 private String onapName;
51 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-component")
52 private String onapComponent;
54 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:onap-instance")
55 private String onapInstance;
57 @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:guard:request:request-id")
58 private String requestId;
61 private String action = STR_GUARD;
63 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:clname:clname-id")
64 private String clnameId;
66 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:actor:actor-id")
67 private String actorId;
69 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:operation:operation-id")
70 private String operationId;
72 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:target-id")
73 private String targetId;
75 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:vf-count")
76 private Integer vfCount;
78 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:min")
81 @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:max")
85 public LegacyGuardPolicyRequest() {
90 * Parses the DecisionRequest into a StdMetadataPolicyRequest.
92 * @param decisionRequest Input DecisionRequest
93 * @return StdMetadataPolicyRequest
95 @SuppressWarnings("unchecked")
96 public static LegacyGuardPolicyRequest createInstance(DecisionRequest decisionRequest) {
98 // Create our return object
100 LegacyGuardPolicyRequest request = new LegacyGuardPolicyRequest();
102 // Add the subject attributes
104 request.onapName = decisionRequest.getOnapName();
105 request.onapComponent = decisionRequest.getOnapComponent();
106 request.onapInstance = decisionRequest.getOnapInstance();
107 request.requestId = decisionRequest.getRequestId();
109 // Now pull from the resources
111 Map<String, Object> resources = decisionRequest.getResource();
113 // Just in case nothing is in there
115 if (resources == null || resources.isEmpty() || ! resources.containsKey(STR_GUARD)) {
117 // Perhaps we throw an exception and then caller
118 // can put together a response
122 Map<String, Object> guard = (Map<String, Object>) resources.get(STR_GUARD);
123 if (guard == null || guard.isEmpty()) {
125 // again, same problem throw an exception?
132 if (guard.containsKey("actor")) {
133 request.actorId = guard.get("actor").toString();
135 if (guard.containsKey("recipe")) {
136 request.operationId = guard.get("recipe").toString();
138 if (guard.containsKey("clname")) {
139 request.clnameId = guard.get("clname").toString();
141 if (guard.containsKey("target")) {
142 request.targetId = guard.get("target").toString();
144 if (guard.containsKey("vfCount")) {
145 request.vfCount = Integer.decode(guard.get("vfCount").toString());
147 if (guard.containsKey("min")) {
148 request.min = Integer.decode(guard.get("min").toString());
150 if (guard.containsKey("max")) {
151 request.max = Integer.decode(guard.get("max").toString());