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