Initial OpenECOMP policy/engine commit
[policy/engine.git] / PolicyEngineClient / src / main / java / org / openecomp / policyEngine / ListConfigPoliciesClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineClient
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.policyEngine;
22
23 import java.io.IOException;
24 import java.io.OutputStream;
25 import java.io.OutputStreamWriter;
26 import java.util.Collection;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.UUID;
30
31 import javax.xml.transform.OutputKeys;
32 import javax.xml.transform.Transformer;
33 import javax.xml.transform.TransformerException;
34 import javax.xml.transform.TransformerFactory;
35 import javax.xml.transform.dom.DOMSource;
36 import javax.xml.transform.stream.StreamResult;
37
38 import org.openecomp.policy.api.ConfigRequestParameters;
39 import org.openecomp.policy.api.PolicyConfigException;
40 import org.openecomp.policy.api.PolicyEngine;
41 import org.openecomp.policy.api.PolicyEngineException;
42 import org.w3c.dom.Document;
43
44 public class ListConfigPoliciesClient {
45         public static void main(String[] args) {
46                 PolicyEngine policyEngine;
47
48                 // List Config Policies Example 
49                 try {
50                         policyEngine = new PolicyEngine("config.properties");
51                         ConfigRequestParameters parameters = new ConfigRequestParameters();
52                         
53                         parameters.setPolicyName(".*");
54                         parameters.setEcompName(".*");
55                         parameters.setConfigName(".*");
56                         
57                         Map<String, String> configAttributes = new HashMap<String,String>();
58                         configAttributes.put("java", "java");
59                         configAttributes.put("peach", "Tar");
60                         configAttributes.put("true", "false");
61                         configAttributes.put("small", "testPass");
62                         parameters.setConfigAttributes(configAttributes);
63                         
64                         parameters.setRequestID(UUID.randomUUID());
65                         
66                         Collection<String> response = policyEngine.listConfig(parameters);
67                 if(response!=null && !response.contains("PE300")){
68                         for(String configList : response){
69                                 System.out.println(configList.toString()+"\n");
70                         }
71                 }else{
72                     System.out.println("Error! " +response);
73                 }
74
75                 } catch (PolicyConfigException e) {
76                         e.printStackTrace();
77                 } catch (PolicyEngineException e) {
78                         // TODO Auto-generated catch block
79                         e.printStackTrace();
80                 }
81         }
82         
83 }