2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.pap.xacml.rest.handler;
22 import java.io.IOException;
23 import java.sql.SQLException;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
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;
33 public class APIRequestHandler {
35 private OnapPDPGroup newGroup;
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);
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);
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);
56 if ("getMetrics".equalsIgnoreCase(apiflag)){
57 MetricService.doGetPolicyMetrics(response);
62 public void doPut(HttpServletRequest request, HttpServletResponse response, String service) throws IOException {
63 if ("MICROSERVICE".equalsIgnoreCase(service) || "BRMSPARAM".equalsIgnoreCase(service)){
64 ImportService importService = new ImportService();
65 importService.doImportMicroServicePut(request, response);
68 if ("dictionaryItem".equalsIgnoreCase(service)) {
69 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
70 dictionaryHandler.doDictionaryAPIPut(request, response);
73 SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
74 savePolicy.doPolicyAPIPut(request, response);
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);
83 } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
84 deleteHandler.doAPIDeleteFromPDP(request, response, loggingContext);
85 setNewGroup(deleteHandler.getDeletedGroup());
90 private void setNewGroup(OnapPDPGroup newGroup) {
91 this.newGroup = newGroup;
94 public OnapPDPGroup getNewGroup() {