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;
25 import java.io.IOException;
26 import java.io.UnsupportedEncodingException;
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
32 import java.util.HashMap;
35 import javax.servlet.ServletContext;
36 import javax.servlet.http.HttpServletRequest;
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
40 import org.openecomp.aai.util.AAIRestInterface;
41 import org.openecomp.vid.model.Result;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.http.HttpStatus;
44 import org.springframework.http.MediaType;
45 import org.springframework.http.ResponseEntity;
46 import org.springframework.web.bind.annotation.PathVariable;
47 import org.springframework.web.bind.annotation.RequestMapping;
48 import org.springframework.web.bind.annotation.RequestMethod;
49 import org.springframework.web.bind.annotation.RestController;
50 import org.springframework.web.servlet.ModelAndView;
52 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
56 * The Class CreateNewServiceInstanceController.
59 public class CreateNewServiceInstanceController extends RestrictedBaseController{
65 EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CreateNewServiceInstanceController.class);
67 /** The Constant dateFormat. */
68 final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
71 protected String transId;
73 /** The from app id. */
74 protected String fromAppId = "VID";
77 private Map<String, Object> model = new HashMap<String, Object>();
79 /** The servlet context. */
80 private @Autowired ServletContext servletContext;
85 * @param request the request
86 * @return the model and view
88 @RequestMapping(value = {"/createnewserviceinstance" }, method = RequestMethod.GET)
89 public ModelAndView welcome(HttpServletRequest request) {
91 return new ModelAndView(getViewName());
95 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
97 public String getViewName() {
102 * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
104 public void setViewName(String viewName) {
105 this.viewName = viewName;
109 * Do get subscfriber list.
111 * @return the response entity
112 * @throws IOException Signals that an I/O exception has occurred.
114 @RequestMapping(value="/get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
115 public ResponseEntity<Result> doGetSubscfriberList() throws IOException {
117 String res1 = (String) model.get("subscribernames");
120 res1 = getSubscribers();
123 return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
128 * Do refresh subscfriber list.
130 * @return the response entity
131 * @throws IOException Signals that an I/O exception has occurred.
133 @RequestMapping(value="/refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
134 public ResponseEntity<Result> doRefreshSubscfriberList() throws IOException {
137 String res1 = getSubscribers();
139 return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
144 * Gets the subscriber.
146 * @param subscriberId the subscriber id
148 @RequestMapping(value="/createsubscriber/{subscriberId}", method = RequestMethod.GET)
149 public void GetSubscriber(@PathVariable("subscriberId") String subscriberId) throws UnsupportedEncodingException {
152 File certiPath = GetCertificatesPath();
153 AAIRestInterface restContrller = new AAIRestInterface(certiPath.getAbsolutePath());
155 subscriberId = restContrller.encodeURL(subscriberId);
161 String res1 = restContrller.RestGet(fromAppId, transId, "business/customers/customer/" + subscriberId, false);
162 model.put("customerInfo", res1);
167 * Gets the subscribers.
169 * @return the subscribers
171 private String getSubscribers() throws UnsupportedEncodingException
173 File certiPath = GetCertificatesPath();
174 AAIRestInterface restContrller = new AAIRestInterface(certiPath.getAbsolutePath());
175 String res1 = restContrller.RestGet(fromAppId, transId, "business/customers?depth=0", false);
176 model.put("subscribernames", res1);
182 * Gets the certificates path.
186 private File GetCertificatesPath()
188 if (servletContext != null)
189 return new File( servletContext.getRealPath("/WEB-INF/cert/") );