Policy 1707 commit to LF
[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 gitPath
44                 if ("gitPath".equalsIgnoreCase(apiflag)) {
45                         PushPolicyHandler pushHandler = new PushPolicyHandler();
46                         pushHandler.getGitPath(request, response);
47                         return;
48                 }
49                 // Request from the API to get the ActiveVersion from the PolicyVersion table
50                 if ("version".equalsIgnoreCase(apiflag)){
51                         PushPolicyHandler pushHandler = new PushPolicyHandler();
52                         pushHandler.getActiveVersion(request, response);
53                         return;
54                 }
55                 // Request from the API to get the URI from the gitpath
56                 if ("uri".equalsIgnoreCase(apiflag)){
57                         PushPolicyHandler pushHandler = new PushPolicyHandler();
58                         pushHandler.getSelectedURI(request, response);
59                         return;
60                 }
61                 if ("getMetrics".equalsIgnoreCase(apiflag)){
62                         MetricService.doGetPolicyMetrics(request, response);
63                         return;
64                 }
65         }
66
67         public void doPut(HttpServletRequest request, HttpServletResponse response, String service) throws IOException {
68                 if ("MICROSERVICE".equalsIgnoreCase(service) || "BRMSPARAM".equalsIgnoreCase(service)){
69                         ImportService importService = new ImportService();
70                         importService.doImportMicroServicePut(request, response);
71                         return;
72                 }
73                 if ("dictionaryItem".equalsIgnoreCase(service)) {
74                         DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
75                         dictionaryHandler.doDictionaryAPIPut(request, response);
76                         return;
77                 } else {
78                         SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
79                         savePolicy.doPolicyAPIPut(request, response);
80                 }
81         }
82
83         public void doDelete(HttpServletRequest request, HttpServletResponse response, ECOMPLoggingContext loggingContext, String apiflag) throws Exception {
84                 DeleteHandler deleteHandler = DeleteHandler.getInstance();
85                 if ("deletePapApi".equalsIgnoreCase(apiflag)) {
86                         deleteHandler.doAPIDeleteFromPAP(request, response, loggingContext);
87                         return;
88                 } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
89                         deleteHandler.doAPIDeleteFromPDP(request, response, loggingContext);
90                         setNewGroup(deleteHandler.getDeletedGroup());
91                         return;
92                 }
93         }
94         
95         private void setNewGroup(EcompPDPGroup newGroup) {
96                 this.newGroup = newGroup;
97         }
98
99         public EcompPDPGroup getNewGroup() {
100                 return newGroup;
101         }
102 }