Initial OpenECOMP policy/engine commit
[policy/engine.git] / PyPDPServer / src / main / java / org / openecomp / policy / pypdp / DeletePolicyRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
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.openecomp.policy.pypdp;
22
23 import java.util.UUID;
24
25 import org.openecomp.policy.api.DeletePolicyParameters;
26 import org.openecomp.policy.api.PolicyConfigException;
27 import org.openecomp.policy.std.StdPolicyEngine;
28
29 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
30
31 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
32
33 public class DeletePolicyRequest {
34         private StdPolicyEngine pe;
35         public DeletePolicyRequest(StdPolicyEngine pe){
36                 this.pe= pe;
37         }
38         
39         public String run(DeletePolicyParameters pep, String requestID, String userID, String passcode) {
40
41                 String result = null;
42                 
43                 // construct a UUID from the request string
44                 if(pep.getRequestID()==null){
45                         if (requestID != null && !requestID.isEmpty()) {
46                                 try {
47                                         pep.setRequestID(UUID.fromString(requestID));
48                                 }
49                                 catch (IllegalArgumentException e) {
50                                         pep.setRequestID(UUID.randomUUID());
51                                         PolicyLogger.info("Generated Random UUID: " + pep.getRequestID().toString());
52                                 }
53                         }
54                 }
55                 
56                 if (pep.getPolicyName()!= null && !pep.getPolicyName().isEmpty()) {
57                         if (pep.getPolicyComponent() != null && !pep.getPolicyComponent().isEmpty()) {
58                                                 
59                                 try {
60                                                         
61                                         result = pe.deletePolicy(pep, userID, passcode).getResponseMessage();
62
63                                         } catch (PolicyConfigException e) {
64                                                 result = e.getMessage();
65                                         } catch (Exception e) {
66                                                 // TODO Auto-generated catch block
67                                                 e.printStackTrace();
68                                         }
69
70                         } else {
71                                 result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST:  policyComponent was null or empty.";
72                         }
73                 } else {
74                         result = XACMLErrorConstants.ERROR_DATA_ISSUE + "BAD REQUEST:  policyName was null or empty.";
75                 }
76                 
77                 return result;
78                 
79         }
80 }