Initial OpenECOMP policy/engine commit
[policy/engine.git] / PyPDPServer / src / main / java / org / openecomp / policy / pypdp / ListConfigRequest.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.ArrayList;
24 import java.util.Collection;
25 import java.util.UUID;
26
27 import org.openecomp.policy.api.ConfigRequestParameters;
28 import org.openecomp.policy.api.PolicyConfigStatus;
29 import org.openecomp.policy.std.StdPolicyConfig;
30 import org.openecomp.policy.std.StdPolicyEngine;
31
32 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
33
34 public class ListConfigRequest {
35         
36         private StdPolicyEngine pe;
37         public ListConfigRequest(StdPolicyEngine pe){
38                 this.pe= pe;
39         }
40         
41         public Collection<String> run(ConfigRequestParameters pep, String requestID, String userID, String passcode) {
42
43                 StdPolicyConfig policyConfig = new StdPolicyConfig();
44                 Collection<String> configList = new ArrayList<String>();
45
46                 // construct a UUID from the request string
47                 UUID requestUUID = null;
48                 if (requestID != null && !requestID.isEmpty()) {
49                         try {
50                                 requestUUID = UUID.fromString(requestID);
51                         }
52                         catch (IllegalArgumentException e) {
53                                 requestUUID = UUID.randomUUID();
54                                 PolicyLogger.info("Generated Random UUID: " + requestUUID.toString());
55                         }
56                 }
57                 pep.setRequestID(requestUUID);
58                 try {
59                         PolicyLogger.debug("\n\n calling PEP.. ");
60                         configList = pe.listConfigRequest(pep, userID, passcode);
61                         return configList;
62                 } catch(Exception e){
63                         policyConfig.setConfigStatus(e.getMessage(), PolicyConfigStatus.CONFIG_NOT_FOUND);
64                         configList.add(policyConfig.getPolicyConfigStatus().toString());
65                         return configList;
66                 }
67         }
68
69 }