[VID-3] Setting docker image tag
[vid.git] / vid / src / main / java / org / openecomp / vid / controller / CreateNewServiceInstanceController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.vid.controller;
22
23
24 import java.io.File;
25 import java.io.IOException;
26 import java.io.UnsupportedEncodingException;
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
29
30
31
32 import java.util.HashMap;
33 import java.util.Map;
34
35 import javax.servlet.ServletContext;
36 import javax.servlet.http.HttpServletRequest;
37
38 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
39
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;
51
52 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
53
54
55 /**
56  * The Class CreateNewServiceInstanceController.
57  */
58 @RestController
59 public class CreateNewServiceInstanceController extends RestrictedBaseController{
60         
61         /** The view name. */
62         String viewName;
63         
64         /** The logger. */
65         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CreateNewServiceInstanceController.class);
66         
67         /** The Constant dateFormat. */
68         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
69         
70         /** The trans id. */
71         protected String transId;
72         
73         /** The from app id. */
74         protected String fromAppId = "VID";
75         
76         /** The model. */
77         private Map<String, Object> model = new HashMap<String, Object>();
78         
79         /** The servlet context. */
80         private @Autowired ServletContext servletContext;
81         
82         /**
83          * Welcome.
84          *
85          * @param request the request
86          * @return the model and view
87          */
88         @RequestMapping(value = {"/createnewserviceinstance" }, method = RequestMethod.GET)
89         public ModelAndView welcome(HttpServletRequest request) {
90                 
91         return new ModelAndView(getViewName());         
92         }
93         
94         /* (non-Javadoc)
95          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
96          */
97         public String getViewName() {
98                 return viewName;
99         }
100         
101         /* (non-Javadoc)
102          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
103          */
104         public void setViewName(String viewName) {
105                 this.viewName = viewName;
106         }
107
108         /**
109          * Do get subscfriber list.
110          *
111          * @return the response entity
112          * @throws IOException Signals that an I/O exception has occurred.
113          */
114         @RequestMapping(value="/get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)       
115         public ResponseEntity<Result> doGetSubscfriberList() throws IOException {
116         
117            String  res1 = (String) model.get("subscribernames");
118            if (res1 == null)
119            {
120                    res1 = getSubscribers();
121            }
122                 
123           return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
124         
125         }
126         
127         /**
128          * Do refresh subscfriber list.
129          *
130          * @return the response entity
131          * @throws IOException Signals that an I/O exception has occurred.
132          */
133         @RequestMapping(value="/refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)   
134         public ResponseEntity<Result> doRefreshSubscfriberList() throws IOException {
135         
136            
137       String res1 = getSubscribers();
138         
139           return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
140         
141         }
142         
143         /**
144          * Gets the subscriber.
145          *
146          * @param subscriberId the subscriber id
147          */
148         @RequestMapping(value="/createsubscriber/{subscriberId}", method = RequestMethod.GET)
149         public void GetSubscriber(@PathVariable("subscriberId") String subscriberId) throws UnsupportedEncodingException {
150                  
151                 
152                    File certiPath = GetCertificatesPath();
153                    AAIRestInterface restContrller = new AAIRestInterface(certiPath.getAbsolutePath());
154                    try {
155                            subscriberId = restContrller.encodeURL(subscriberId);
156                    }
157                    catch (Exception e)
158                    {
159                            
160                    }
161                    String res1 = restContrller.RestGet(fromAppId, transId, "business/customers/customer/" + subscriberId, false);
162                model.put("customerInfo", res1);
163         
164         }
165         
166         /**
167          * Gets the subscribers.
168          *
169          * @return the subscribers
170          */
171         private String getSubscribers() throws UnsupportedEncodingException
172         {
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);
177              
178              return res1;
179         }
180         
181         /**
182          * Gets the certificates path.
183          *
184          * @return the file
185          */
186         private File GetCertificatesPath()
187         {
188                 if (servletContext != null)
189                         return new File( servletContext.getRealPath("/WEB-INF/cert/") );
190          
191                 
192                 return null;
193         }
194
195 }