2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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=========================================================
21 package org.onap.policy.pap.xacml.rest.handler;
23 import java.io.IOException;
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;
40 * @param request the request
41 * @param response the response
42 * @param apiflag the apiflag
43 * @throws IOException Signals that an I/O exception has occurred.
45 public void doGet(HttpServletRequest request, HttpServletResponse response, String apiflag) throws IOException {
46 // Request from the API to get Dictionary Items
47 if ("api".equalsIgnoreCase(apiflag)) {
48 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
49 dictionaryHandler.doDictionaryAPIGet(request, response);
52 // Request from the API to get the ActiveVersion from the PolicyVersion table
53 if ("version".equalsIgnoreCase(apiflag)) {
54 PushPolicyHandler pushHandler = new PushPolicyHandler();
55 pushHandler.getActiveVersion(request, response);
58 // Request from the API to get the URI from the gitpath
59 if ("uri".equalsIgnoreCase(apiflag)) {
60 PushPolicyHandler pushHandler = new PushPolicyHandler();
61 pushHandler.getSelectedURI(request, response);
64 if ("getMetrics".equalsIgnoreCase(apiflag)) {
65 MetricService.doGetPolicyMetrics(response);
72 * @param request the request
73 * @param response the response
74 * @param service the service
75 * @throws IOException Signals that an I/O exception has occurred.
77 public void doPut(HttpServletRequest request, HttpServletResponse response, String service) throws IOException {
78 if ("MICROSERVICE".equalsIgnoreCase(service) || "BRMSPARAM".equalsIgnoreCase(service)
79 || "OPTIMIZATION".equalsIgnoreCase(service)) {
80 ImportService importService = new ImportService();
81 importService.doImportMicroServicePut(request, response);
84 if ("dictionaryItem".equalsIgnoreCase(service)) {
85 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
86 dictionaryHandler.doDictionaryAPIPut(request, response);
88 SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
89 savePolicy.doPolicyAPIPut(request, response);
96 * @param request the request
97 * @param response the response
98 * @param loggingContext the logging context
99 * @param apiflag the apiflag
100 * @throws IOException Signals that an I/O exception has occurred.
102 public void doDelete(HttpServletRequest request, HttpServletResponse response, OnapLoggingContext loggingContext,
103 String apiflag) throws IOException {
104 DeleteHandler deleteHandler = DeleteHandler.getInstance();
105 if ("deletePapApi".equalsIgnoreCase(apiflag)) {
106 deleteHandler.doApiDeleteFromPap(request, response);
107 } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
108 deleteHandler.doApiDeleteFromPdp(request, response, loggingContext);
109 setNewGroup(deleteHandler.getDeletedGroup());
113 private void setNewGroup(OnapPDPGroup newGroup) {
114 this.newGroup = newGroup;
117 public OnapPDPGroup getNewGroup() {