Modify ONAP PAP REST classes basic checkstyle
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / handler / APIRequestHandler.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017-2018 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.handler;
21
22 import java.io.IOException;
23 import java.sql.SQLException;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.onap.policy.common.logging.ONAPLoggingContext;
29 import org.onap.policy.pap.xacml.rest.service.ImportService;
30 import org.onap.policy.pap.xacml.rest.service.MetricService;
31 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
32
33 public class APIRequestHandler {
34
35     private OnapPDPGroup newGroup;
36
37     public void doGet(HttpServletRequest request, HttpServletResponse response, String apiflag) throws IOException{
38         // Request from the API to get Dictionary Items
39         if ("api".equalsIgnoreCase(apiflag)) {
40             DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
41             dictionaryHandler.doDictionaryAPIGet(request, response);
42             return;
43         }
44         // Request from the API to get the ActiveVersion from the PolicyVersion table
45         if ("version".equalsIgnoreCase(apiflag)){
46             PushPolicyHandler pushHandler = new PushPolicyHandler();
47             pushHandler.getActiveVersion(request, response);
48             return;
49         }
50         // Request from the API to get the URI from the gitpath
51         if ("uri".equalsIgnoreCase(apiflag)){
52             PushPolicyHandler pushHandler = new PushPolicyHandler();
53             pushHandler.getSelectedURI(request, response);
54             return;
55         }
56         if ("getMetrics".equalsIgnoreCase(apiflag)){
57             MetricService.doGetPolicyMetrics(response);
58             return;
59         }
60     }
61
62     public void doPut(HttpServletRequest request, HttpServletResponse response, String service) throws IOException {
63         if ("MICROSERVICE".equalsIgnoreCase(service) || "BRMSPARAM".equalsIgnoreCase(service) || "OPTIMIZATION".equalsIgnoreCase(service)){
64             ImportService importService = new ImportService();
65             importService.doImportMicroServicePut(request, response);
66             return;
67         }
68         if ("dictionaryItem".equalsIgnoreCase(service)) {
69             DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
70             dictionaryHandler.doDictionaryAPIPut(request, response);
71             return;
72         } else {
73             SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
74             savePolicy.doPolicyAPIPut(request, response);
75         }
76     }
77
78     public void doDelete(HttpServletRequest request, HttpServletResponse response, ONAPLoggingContext loggingContext, String apiflag) throws IOException, SQLException{
79         DeleteHandler deleteHandler = DeleteHandler.getInstance();
80         if ("deletePapApi".equalsIgnoreCase(apiflag)) {
81             deleteHandler.doAPIDeleteFromPAP(request, response);
82             return;
83         } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
84             deleteHandler.doAPIDeleteFromPDP(request, response, loggingContext);
85             setNewGroup(deleteHandler.getDeletedGroup());
86             return;
87         }
88     }
89
90     private void setNewGroup(OnapPDPGroup newGroup) {
91         this.newGroup = newGroup;
92     }
93
94     public OnapPDPGroup getNewGroup() {
95         return newGroup;
96     }
97 }