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;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
26 import org.onap.policy.common.logging.ONAPLoggingContext;
27 import org.onap.policy.pap.xacml.rest.service.ImportService;
28 import org.onap.policy.pap.xacml.rest.service.MetricService;
29 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
31 public class APIRequestHandler {
33 private OnapPDPGroup newGroup;
38 * @param request the request
39 * @param response the response
40 * @param apiflag the apiflag
41 * @throws IOException Signals that an I/O exception has occurred.
43 public void doGet(HttpServletRequest request, HttpServletResponse response, String apiflag) throws IOException {
44 // Request from the API to get Dictionary Items
45 if ("api".equalsIgnoreCase(apiflag)) {
46 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
47 dictionaryHandler.doDictionaryAPIGet(request, response);
50 // Request from the API to get the ActiveVersion from the PolicyVersion table
51 if ("version".equalsIgnoreCase(apiflag)) {
52 PushPolicyHandler pushHandler = new PushPolicyHandler();
53 pushHandler.getActiveVersion(request, response);
56 // Request from the API to get the URI from the gitpath
57 if ("uri".equalsIgnoreCase(apiflag)) {
58 PushPolicyHandler pushHandler = new PushPolicyHandler();
59 pushHandler.getSelectedURI(request, response);
62 if ("getMetrics".equalsIgnoreCase(apiflag)) {
63 MetricService.doGetPolicyMetrics(response);
70 * @param request the request
71 * @param response the response
72 * @param service the service
73 * @throws IOException Signals that an I/O exception has occurred.
75 public void doPut(HttpServletRequest request, HttpServletResponse response, String service) throws IOException {
76 if ("MICROSERVICE".equalsIgnoreCase(service) || "BRMSPARAM".equalsIgnoreCase(service)
77 || "OPTIMIZATION".equalsIgnoreCase(service)) {
78 ImportService importService = new ImportService();
79 importService.doImportMicroServicePut(request, response);
82 if ("dictionaryItem".equalsIgnoreCase(service)) {
83 DictionaryHandler dictionaryHandler = DictionaryHandler.getInstance();
84 dictionaryHandler.doDictionaryAPIPut(request, response);
86 SavePolicyHandler savePolicy = SavePolicyHandler.getInstance();
87 savePolicy.doPolicyAPIPut(request, response);
94 * @param request the request
95 * @param response the response
96 * @param loggingContext the logging context
97 * @param apiflag the apiflag
98 * @throws IOException Signals that an I/O exception has occurred.
100 public void doDelete(HttpServletRequest request, HttpServletResponse response, ONAPLoggingContext loggingContext,
101 String apiflag) throws IOException {
102 DeleteHandler deleteHandler = DeleteHandler.getInstance();
103 if ("deletePapApi".equalsIgnoreCase(apiflag)) {
104 deleteHandler.doApiDeleteFromPap(request, response);
105 } else if ("deletePdpApi".equalsIgnoreCase(apiflag)) {
106 deleteHandler.doApiDeleteFromPdp(request, response, loggingContext);
107 setNewGroup(deleteHandler.getDeletedGroup());
111 private void setNewGroup(OnapPDPGroup newGroup) {
112 this.newGroup = newGroup;
115 public OnapPDPGroup getNewGroup() {