2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.pypdp;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.UUID;
27 import org.openecomp.policy.api.EventRequestParameters;
28 import org.openecomp.policy.api.PolicyResponse;
29 import org.openecomp.policy.api.PolicyResponseStatus;
30 import org.openecomp.policy.std.StdPolicyEngine;
31 import org.openecomp.policy.std.StdPolicyResponse;
33 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
35 public class EventRequest {
37 private StdPolicyEngine pe;
38 public EventRequest(StdPolicyEngine pe){
42 public Collection<PolicyResponse> run(EventRequestParameters pep, String requestID, String userID, String passcode){
43 StdPolicyResponse policyResponse = new StdPolicyResponse();
44 Collection<PolicyResponse> result = new ArrayList<PolicyResponse>();
45 // construct a UUID from the request string
46 if(pep.getRequestID()==null){
47 UUID requestUUID = null;
48 if (requestID != null && !requestID.isEmpty()) {
50 requestUUID = UUID.fromString(requestID);
52 catch (IllegalArgumentException e) {
53 requestUUID = UUID.randomUUID();
54 PolicyLogger.info("Generated Random UUID: " + requestUUID.toString());
57 pep.setRequestID(requestUUID);
60 Collection<PolicyResponse> pResponses = pe.event(pep.getEventAttributes(), pep.getRequestID(), userID, passcode);
61 for(PolicyResponse pResponse: pResponses){
62 pResponse = checkResponse(pResponse);
63 result.add(pResponse);
67 policyResponse.setPolicyResponseStatus(e.getMessage(), PolicyResponseStatus.NO_ACTION_REQUIRED);
68 policyResponse = checkResponse(policyResponse);
69 result.add(policyResponse);
74 private StdPolicyResponse checkResponse(PolicyResponse pResponse) {
75 StdPolicyResponse policyResponse= new StdPolicyResponse();
76 policyResponse.setActionAdvised(pResponse.getActionAdvised());
77 policyResponse.setActionTaken(pResponse.getActionTaken());
78 policyResponse.setPolicyResponseMessage(pResponse.getPolicyResponseMessage());
79 policyResponse.setPolicyResponseStatus(pResponse.getPolicyResponseStatus());
80 policyResponse.setRequestAttributes(pResponse.getRequestAttributes());
81 return policyResponse;