Modify ONAP PAP REST classes basic checkstyle
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / elk / client / ElkConnector.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
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 package org.onap.policy.pap.xacml.rest.elk.client;
21
22
23 import java.util.Map;
24
25 import org.onap.policy.rest.adapter.PolicyRestAdapter;
26
27 import io.searchbox.client.JestResult;
28
29 public interface ElkConnector {
30
31     public static final String ELK_URL = "http://localhost:9200";
32     public static final String ELK_INDEX_POLICY = "policy";
33
34     public enum PolicyIndexType {
35         config,
36         action,
37         decision,
38         closedloop,
39         all,
40     }
41
42     public enum PolicyType {
43         Config,
44         Action,
45         Decision,
46         Config_Fault,
47         Config_PM,
48         Config_FW,
49         Config_MS,
50         Config_OOF,
51         none,
52     }
53
54     public enum PolicyBodyType {
55         json,
56         xml,
57         properties,
58         txt,
59         none,
60     }
61
62     public boolean delete(PolicyRestAdapter policyData)
63             throws IllegalStateException;
64
65     public JestResult search(PolicyIndexType type, String text)
66            throws IllegalStateException, IllegalArgumentException;
67
68     public JestResult search(PolicyIndexType type, String text,
69             Map<String, String> searchKeyValue)
70                throws IllegalStateException, IllegalArgumentException;
71
72     public boolean update(PolicyRestAdapter policyData) throws IllegalStateException;
73
74     public ElkConnector singleton = new ElkConnectorImpl();
75
76     public static PolicyIndexType toPolicyIndexType(String policyName)
77             throws IllegalArgumentException {
78         if (policyName == null)
79             throw new IllegalArgumentException("Unsupported NULL policy name conversion");
80
81         if (policyName.startsWith("Config_Fault")) {
82             return PolicyIndexType.closedloop;
83         } else if (policyName.startsWith("Config_PM")) {
84             return PolicyIndexType.closedloop;
85         } else if (policyName.startsWith("Config_FW")) {
86             return PolicyIndexType.config;
87         } else if (policyName.startsWith("Config_MS")) {
88             return PolicyIndexType.config;
89         } else if (policyName.startsWith("Config_OOF")) {
90             return PolicyIndexType.config;
91         }else if (policyName.startsWith("Action")) {
92             return PolicyIndexType.action;
93         } else if (policyName.startsWith("Decision")) {
94             return PolicyIndexType.decision;
95         } else if (policyName.startsWith("Config")) {
96             return PolicyIndexType.config;
97         } else {
98             throw new IllegalArgumentException
99             ("Unsupported policy name conversion to index: " +
100                     policyName);
101         }
102     }
103
104 }