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.openecomp.policy.pap.xacml.rest.elk.client;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
25 import org.json.JSONObject;
26 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
27 import org.openecomp.policy.common.logging.flexlogger.Logger;
28 import org.openecomp.policy.pap.xacml.rest.util.JsonMessage;
29 import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
30 import org.springframework.stereotype.Controller;
31 import org.springframework.web.bind.annotation.RequestMapping;
32 import org.springframework.web.bind.annotation.RequestMethod;
34 import com.fasterxml.jackson.databind.DeserializationFeature;
35 import com.fasterxml.jackson.databind.ObjectMapper;
39 public class PolicySearchController {
41 private static final Logger LOGGER = FlexLogger.getLogger(PolicySearchController.class);
43 @RequestMapping(value="/searchPolicy", method= RequestMethod.POST)
44 public void elkTransaction(HttpServletRequest request, HttpServletResponse response) {
46 boolean result = false;
47 ObjectMapper mapper = new ObjectMapper();
48 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
49 PolicyRestAdapter policyData = new PolicyRestAdapter();
50 if(request.getParameter("policyName") != null){
51 String policyName = request.getParameter("policyName");
52 policyData.setNewFileName(policyName);
53 PolicyElasticSearchController controller = new PolicyElasticSearchController();
54 if("delete".equalsIgnoreCase(request.getParameter("action"))){
55 result = controller.deleteElk(policyData);
57 result = controller.updateElk(policyData);
62 message = "Elastic Server Transaction is success";
64 message = "Elastic Server Transaction is failed, please check the logs";
66 JsonMessage msg = new JsonMessage(mapper.writeValueAsString(message));
67 JSONObject j = new JSONObject(msg);
68 response.setStatus(HttpServletResponse.SC_OK);
69 response.addHeader("success", "success");
70 response.getWriter().write(j.toString());
72 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
73 response.addHeader("error", "Exception Occured While Performing Elastic Transaction");
74 LOGGER.error("Exception Occured While Performing Elastic Transaction"+e.getMessage());