[VID-3] Setting docker image tag
[vid.git] / vid / src / main / java / org / openecomp / vid / controller / SearchExistingSIController.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 import java.io.File;
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;
29 import java.util.Map;
30
31 import javax.servlet.ServletContext;
32 import javax.servlet.http.HttpServletRequest;
33
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;
44
45 import org.openecomp.portalsdk.core.controller.RestrictedBaseController;
46 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
47
48 /**
49  * The Class SearchExistingSIController.
50  */
51 @RestController
52 public class SearchExistingSIController extends RestrictedBaseController{
53         
54         /** The view name. */
55         String viewName;
56         
57         /** The logger. */
58         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(SearchExistingSIController.class);
59         
60         /** The Constant dateFormat. */
61         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
62         
63         /** The trans id. */
64         protected String transId;
65         
66         /** The from app id. */
67         protected String fromAppId = "VID";
68         
69         /** The model. */
70         private Map<String, Object> model = new HashMap<String, Object>();
71         
72         /** The servlet context. */
73         private @Autowired ServletContext servletContext;
74         
75         /**
76          * Welcome.
77          *
78          * @param request the request
79          * @return the model and view
80          */
81         @RequestMapping(value = {"/searchexistingsi" }, method = RequestMethod.GET)
82         public ModelAndView welcome(HttpServletRequest request) {
83                 
84         return new ModelAndView(getViewName());         
85         }
86         
87         /* (non-Javadoc)
88          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#getViewName()
89          */
90         public String getViewName() {
91                 return viewName;
92         }
93         
94         /* (non-Javadoc)
95          * @see org.openecomp.portalsdk.core.controller.RestrictedBaseController#setViewName(java.lang.String)
96          */
97         public void setViewName(String viewName) {
98                 this.viewName = viewName;
99         }
100
101         /**
102          * Do get subscfriber list.
103          *
104          * @return the response entity
105          * @throws IOException Signals that an I/O exception has occurred.
106          */
107         @RequestMapping(value="/searchexistingsi_get_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)      
108         public ResponseEntity<Result> doGetSubscfriberList() throws IOException, UnsupportedEncodingException  {
109         
110            String  res1 = (String) model.get("subscribernames");
111            if (res1 == null)
112            {
113                    res1 = getSubscribers();
114            }
115                 
116           return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
117         
118         }
119         
120         /**
121          * Do refresh subscfriber list.
122          *
123          * @return the response entity
124          * @throws IOException Signals that an I/O exception has occurred.
125          */
126         @RequestMapping(value="/searchexistingsi_refresh_subscribers",method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)          
127         public ResponseEntity<Result> doRefreshSubscfriberList() throws IOException, UnsupportedEncodingException {
128         
129            
130       String res1 = getSubscribers();
131         
132           return new ResponseEntity<Result>(new Result(res1),HttpStatus.OK);
133         
134         }
135         
136         /**
137          * Gets the subscribers.
138          *
139          * @return the subscribers
140          */
141         private String getSubscribers() throws UnsupportedEncodingException
142         {
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);
147              
148              return res1;
149         }
150         
151         /**
152          * Gets the certificates path.
153          *
154          * @return the file
155          */
156         private File GetCertificatesPath()
157         {
158                 if (servletContext != null)
159                         return new File( servletContext.getRealPath("/WEB-INF/cert/") );
160          
161                 
162                 return null;
163         }
164         
165
166 }