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=========================================================
21 package org.openecomp.vid.controller;
24 import java.io.IOException;
25 import java.io.UnsupportedEncodingException;
26 import java.text.DateFormat;
27 import java.text.SimpleDateFormat;
28 import java.util.HashMap;
31 import javax.servlet.ServletContext;
32 import javax.servlet.http.HttpServletRequest;
34 import org.openecomp.aai.util.AAIRestInterface;
35 import org.openecomp.vid.model.Result;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.MediaType;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.RequestMapping;
41 import org.springframework.web.bind.annotation.RequestMethod;
42 import org.springframework.web.bind.annotation.RestController;
43 import org.springframework.web.servlet.ModelAndView;
45 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
46 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 * The Class SearchExistingSIController.
52 public class SearchExistingSIController extends RestrictedBaseController{
58 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SearchExistingSIController.class);
60 /** The Constant dateFormat. */
61 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
64 protected String transId;
66 /** The from app id. */
67 protected String fromAppId = "VID";
70 private Map<String, Object> model = new HashMap<String, Object>();
72 /** The servlet context. */
73 private @Autowired ServletContext servletContext;
78 * @param request the request
79 * @return the model and view
81 @RequestMapping(value = {"/searchexistingsi" }, method = RequestMethod.GET)
82 public ModelAndView welcome(HttpServletRequest request) {
84 return new ModelAndView(getViewName());
88 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
90 public String getViewName() {
95 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
97 public void setViewName(String viewName) {
98 this.viewName = viewName;
102 * Do get subscfriber list.
104 * @return the response entity
105 * @throws IOException Signals that an I/O exception has occurred.
107 @RequestMapping(value="/searchexistingsi_get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
108 public ResponseEntity<Result> doGetSubscfriberList() throws IOException, UnsupportedEncodingException {
110 String res1 = (String) model.get("subscribernames");
113 res1 = getSubscribers();
116 return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
121 * Do refresh subscfriber list.
123 * @return the response entity
124 * @throws IOException Signals that an I/O exception has occurred.
126 @RequestMapping(value="/searchexistingsi_refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
127 public ResponseEntity<Result> doRefreshSubscfriberList() throws IOException, UnsupportedEncodingException {
130 String res1 = getSubscribers();
132 return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
137 * Gets the subscribers.
139 * @return the subscribers
141 private String getSubscribers() throws UnsupportedEncodingException
143 File certiPath = GetCertificatesPath();
144 AAIRestInterface restContrller = new AAIRestInterface(certiPath.getAbsolutePath());
145 String res1 = restContrller.RestGet(fromAppId, transId, "business/customers?depth=0", false);
146 model.put("subscribernames", res1);
152 * Gets the certificates path.
156 private File GetCertificatesPath()
158 if (servletContext != null)
159 return new File( servletContext.getRealPath("/WEB-INF/cert/") );