2 * ============LICENSE_START=======================================================
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
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;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
27 import org.onap.policy.common.logging.ONAPLoggingContext;
28 import org.onap.policy.pap.xacml.rest.service.ImportService;
29 import org.onap.policy.pap.xacml.rest.service.MetricService;
30 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
32 public class APIRequestHandler {
34 private OnapPDPGroup newGroup;
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);
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);
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);
55 if ("getMetrics".equalsIgnoreCase(apiflag)){
56 MetricService.doGetPolicyMetrics(request, response);
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);
67 if ("dictionaryItem".equalsIgnoreCase(service)) {
68 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
69 dictionaryHandler.doDictionaryAPIPut(request, response);
72 SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
73 savePolicy.doPolicyAPIPut(request, response);
77 public void doDelete(HttpServletRequest request, HttpServletResponse response, ONAPLoggingContext loggingContext, String apiflag) throws Exception {
78 DeleteHandler deleteHandler = DeleteHandler.getInstance();
79 if ("deletePapApi".equalsIgnoreCase(apiflag)) {
80 deleteHandler.doAPIDeleteFromPAP(request, response, loggingContext);
82 } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
83 deleteHandler.doAPIDeleteFromPDP(request, response, loggingContext);
84 setNewGroup(deleteHandler.getDeletedGroup());
89 private void setNewGroup(OnapPDPGroup newGroup) {
90 this.newGroup = newGroup;
93 public OnapPDPGroup getNewGroup() {