[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-BE-common / src / main / java / org / openecomp / portalapp / portal / controller / WidgetsCatalogController.java
index f69a648..9ac81e9 100644 (file)
-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- *      http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-package org.openecomp.portalapp.portal.controller;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.OutputStream;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-import javax.servlet.ServletContext;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.openecomp.portalapp.controller.EPRestrictedBaseController;\r
-import org.openecomp.portalapp.portal.domain.EPUser;\r
-import org.openecomp.portalapp.portal.domain.MicroserviceData;\r
-import org.openecomp.portalapp.portal.domain.MicroserviceParameter;\r
-import org.openecomp.portalapp.portal.domain.WidgetCatalog;\r
-import org.openecomp.portalapp.portal.domain.WidgetCatalogParameter;\r
-import org.openecomp.portalapp.portal.domain.WidgetParameterResult;\r
-import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;\r
-import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;\r
-import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;\r
-import org.openecomp.portalapp.portal.service.ConsulHealthService;\r
-import org.openecomp.portalapp.portal.service.MicroserviceService;\r
-import org.openecomp.portalapp.portal.service.WidgetParameterService;\r
-import org.openecomp.portalapp.util.EPUserUtils;\r
-import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.context.annotation.Bean;\r
-import org.springframework.context.annotation.EnableAspectJAutoProxy;\r
-import org.springframework.core.io.FileSystemResource;\r
-import org.springframework.http.HttpEntity;\r
-import org.springframework.http.HttpHeaders;\r
-import org.springframework.http.HttpMethod;\r
-import org.springframework.http.MediaType;\r
-import org.springframework.http.ResponseEntity;\r
-import org.springframework.util.LinkedMultiValueMap;\r
-import org.springframework.util.MultiValueMap;\r
-import org.springframework.web.bind.annotation.PathVariable;\r
-import org.springframework.web.bind.annotation.RequestBody;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-import org.springframework.web.bind.annotation.RestController;\r
-import org.springframework.web.client.RestClientException;\r
-import org.springframework.web.client.RestTemplate;\r
-import org.springframework.web.multipart.MultipartFile;\r
-import org.springframework.web.multipart.MultipartHttpServletRequest;\r
-import org.springframework.web.multipart.commons.CommonsMultipartResolver;\r
-\r
-@SuppressWarnings("unchecked")\r
-@RestController\r
-@org.springframework.context.annotation.Configuration\r
-@EnableAspectJAutoProxy\r
-@EPAuditLog\r
-public class WidgetsCatalogController extends EPRestrictedBaseController {\r
-       \r
-       private static final String HTTPS = "https://";\r
-       \r
-       EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogController.class);\r
-       RestTemplate template = new RestTemplate();\r
-       String whatService = "widgets-service";\r
-\r
-       @Autowired\r
-       private ConsulHealthService consulHealthService;\r
-\r
-       @Autowired\r
-       private MicroserviceService microserviceService;\r
-\r
-       @Autowired\r
-       private WidgetParameterService widgetParameterService;\r
-\r
-       @Bean\r
-       public CommonsMultipartResolver multipartResolver() {\r
-               return new CommonsMultipartResolver();\r
-       }\r
-\r
-       static {\r
-               // for localhost testing only\r
-               javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {\r
-\r
-                       public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {\r
-                               if (hostname.equals("localhost")) {\r
-                                       return true;\r
-                               }\r
-                               return false;\r
-                       }\r
-               });\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{loginName}" }, method = RequestMethod.GET)\r
-       public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("loginName") String loginName) throws RestClientException, Exception {\r
-               List<WidgetCatalog> widgets = new ArrayList<>();\r
-               try {\r
-                       ResponseEntity<ArrayList> ans = template.exchange(\r
-                                       HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                                       + "/widget/microservices/widgetCatalog/" + loginName,\r
-                                       HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class);\r
-                       widgets = ans.getBody();\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getUserWidgetCatalog failed", e);\r
-                       // returning null because null help check on the UI if there was a\r
-                       // communication problem with Microservice.\r
-                       return null;\r
-               }\r
-               return widgets;\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog" }, method = RequestMethod.GET)\r
-       public List<WidgetCatalog> getWidgetCatalog(HttpServletRequest request, HttpServletResponse response)\r
-                       throws RestClientException, Exception {\r
-               List<WidgetCatalog> widgets = new ArrayList<>();\r
-               try {\r
-                       ResponseEntity<ArrayList> ans = template.exchange(\r
-                                       HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                                       + "/widget/microservices/widgetCatalog",\r
-                                       HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class);\r
-                       widgets = ans.getBody();\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "getWidgetCatalog failed", e);\r
-                       // returning null because null help check on the UI if there was a\r
-                       // communication problem with Microservice.\r
-                       return null;\r
-               }\r
-               return widgets;\r
-       }\r
-\r
-       @RequestMapping(value = {\r
-                       "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.PUT, produces = "application/json")\r
-       public void updateWidgetCatalog(HttpServletRequest request, HttpServletResponse response,\r
-                       @RequestBody WidgetCatalog newWidgetCatalog, @PathVariable("widgetId") long widgetId)\r
-                       throws RestClientException, Exception {\r
-               template.exchange(\r
-                               HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                               + "/widget/microservices/widgetCatalog/" + widgetId,\r
-                               HttpMethod.PUT, new HttpEntity(newWidgetCatalog, WidgetServiceHeaders.getInstance()), String.class);\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.DELETE)\r
-       public void deleteOnboardingWidget(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-               template.exchange(\r
-                               HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                               + "/widget/microservices/widgetCatalog/" + widgetId,\r
-                               HttpMethod.DELETE, new HttpEntity(WidgetServiceHeaders.getInstance()), String.class);\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.POST)\r
-       public String updateWidgetCatalogWithFiles(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-               MultipartHttpServletRequest mRequest;\r
-               MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();\r
-               String fileName;\r
-               String tmp_folder = "/tmp/";\r
-               String respond = null;\r
-               FileOutputStream fo = null;\r
-               try {\r
-                       mRequest = (MultipartHttpServletRequest) request;\r
-                       MultipartFile mFile = mRequest.getFile("file");\r
-                       fileName = mFile.getOriginalFilename();\r
-                       fo = new FileOutputStream(tmp_folder + fileName);\r
-                       fo.write(mFile.getBytes());\r
-\r
-                       HttpHeaders header = new HttpHeaders();\r
-                       header.setContentType(MediaType.MULTIPART_FORM_DATA);\r
-                       multipartRequest.add("file", new FileSystemResource(tmp_folder + fileName));\r
-                       multipartRequest.add("widget", request.getParameter("newWidget"));\r
-                       respond = template.postForObject(\r
-                                       HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                                       + "/widget/microservices/widgetCatalog/" + widgetId,\r
-                                       new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class);\r
-                       File f = new File(tmp_folder + fileName);\r
-                       f.delete();\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "updateWidgetCatalogWithFiles failed", e);\r
-               } finally {\r
-                       try {\r
-                               if (fo != null)\r
-                                       fo.close();\r
-                       } catch (IOException e) {\r
-                               logger.error(EELFLoggerDelegate.errorLogger, "updateWidgetCatalogWithFiles failed 2", e);\r
-                       }\r
-               }\r
-               return respond;\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog" }, method = RequestMethod.POST)\r
-       public String createWidgetCatalog(HttpServletRequest request, HttpServletResponse response)\r
-                       throws RestClientException, Exception {\r
-               MultipartHttpServletRequest mRequest;\r
-               MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();\r
-               String fileName;\r
-               String tmp_folder = "/tmp/";\r
-               String respond = null;\r
-               FileOutputStream fo = null;\r
-               try {\r
-                       mRequest = (MultipartHttpServletRequest) request;\r
-                       MultipartFile mFile = mRequest.getFile("file");\r
-                       fileName = mFile.getOriginalFilename();\r
-                       fo = new FileOutputStream(tmp_folder + fileName);\r
-                       fo.write(mFile.getBytes());\r
-\r
-                       HttpHeaders header = new HttpHeaders();\r
-                       header.setContentType(MediaType.MULTIPART_FORM_DATA);\r
-                       multipartRequest.add("file", new FileSystemResource(tmp_folder + fileName));\r
-                       multipartRequest.add("widget", request.getParameter("newWidget"));\r
-\r
-                       respond = template.postForObject(\r
-                                       HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                                       + "/widget/microservices/widgetCatalog",\r
-                                       new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class);\r
-                       File f = new File(tmp_folder + fileName);\r
-                       f.delete();\r
-               } catch (Exception e) {\r
-                       logger.error(EELFLoggerDelegate.errorLogger, "createWidgetCatalog failed", e);\r
-               } finally {\r
-                       try {\r
-                               if (fo != null)\r
-                                       fo.close();\r
-                       } catch (IOException e) {\r
-                               logger.error(EELFLoggerDelegate.errorLogger, "createWidgetCatalog failed 2", e);\r
-                       }\r
-               }\r
-               return respond;\r
-       }\r
-\r
-       @RequestMapping(value = "/portalApi/microservices/{widgetId}/framework.js", method = RequestMethod.GET)\r
-       public String getWidgetFramework(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-               return template.getForObject(HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                               + "/widget/microservices/" + widgetId + "/framework.js", String.class,\r
-                               WidgetServiceHeaders.getInstance());\r
-       }\r
-\r
-       @RequestMapping(value = "/portalApi/microservices/{widgetId}/controller.js", method = RequestMethod.GET)\r
-       public String getWidgetController(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-               return template.getForObject(HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                               + "/widget/microservices/" + widgetId + "/controller.js", String.class,\r
-                               WidgetServiceHeaders.getInstance());\r
-       }\r
-\r
-       @RequestMapping(value = "/portalApi/microservices/{widgetId}/style.css", method = RequestMethod.GET)\r
-       public String getWidgetCSS(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-               return template.getForObject(HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                               + "/widget/microservices/" + widgetId + "/styles.css", String.class,\r
-                               WidgetServiceHeaders.getInstance());\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/parameters/{widgetId}" }, method = RequestMethod.GET)\r
-       public PortalRestResponse<List<WidgetParameterResult>> getWidgetParameterResult(HttpServletRequest request,\r
-                       HttpServletResponse response, @PathVariable("widgetId") long widgetId) throws Exception {\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-\r
-               List<WidgetParameterResult> list = new ArrayList<>();\r
-               Long serviceId = template.exchange(\r
-                               HTTPS + consulHealthService.getServiceLocation(whatService)\r
-                                               + "/widget/microservices/widgetCatalog/parameters/" + widgetId,\r
-                               HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), Long.class).getBody();\r
-               if (serviceId == null) {\r
-                       // return ok/sucess and no service parameter for this widget\r
-                       return new PortalRestResponse<List<WidgetParameterResult>>(PortalRestStatusEnum.WARN,\r
-                                       "No service parameters for this widget", list);\r
-               } else {\r
-                       List<MicroserviceParameter> defaultParam = microserviceService.getParametersById(serviceId);\r
-                       for (MicroserviceParameter param : defaultParam) {\r
-                               WidgetParameterResult user_result = new WidgetParameterResult();\r
-                               user_result.setParam_id(param.getId());\r
-                               user_result.setDefault_value(param.getPara_value());\r
-                               user_result.setParam_key(param.getPara_key());\r
-                               WidgetCatalogParameter userValue = widgetParameterService.getUserParamById(widgetId, user.getId(),\r
-                                               param.getId());\r
-                               if (userValue == null)\r
-                                       user_result.setUser_value(param.getPara_value());\r
-                               else {\r
-                                       user_result.setUser_value(userValue.getUser_value());\r
-                               }\r
-                               list.add(user_result);\r
-                       }\r
-               }\r
-               return new PortalRestResponse<List<WidgetParameterResult>>(PortalRestStatusEnum.OK, "SUCCESS", list);\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/services/{paramId}" }, method = RequestMethod.GET)\r
-       public List<WidgetCatalogParameter> getUserParameterById(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("paramId") long paramId) throws Exception {\r
-               List<WidgetCatalogParameter> list = widgetParameterService.getUserParameterById(paramId);\r
-               return list;\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/services/{paramId}" }, method = RequestMethod.DELETE)\r
-       public void deleteUserParameterById(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("paramId") long paramId) throws Exception {\r
-               widgetParameterService.deleteUserParameterById(paramId);\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/download/{widgetId}" }, method = RequestMethod.GET)\r
-       public void doDownload(HttpServletRequest request, HttpServletResponse response,\r
-                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {\r
-       \r
-               ServletContext context = request.getServletContext();\r
-               byte[] byteFile = template.exchange(HTTPS + consulHealthService.getServiceLocation(whatService) + "/widget/microservices/download/" + widgetId,\r
-                               HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), byte[].class).getBody();\r
-               String fileLocation = widgetId + ".zip";\r
-               FileOutputStream stream = new FileOutputStream(fileLocation);\r
-               stream.write(byteFile);\r
-               stream.close();\r
-\r
-               File downloadFile = new File(fileLocation);\r
-               FileInputStream inputStream = new FileInputStream(downloadFile);\r
-               String mimeType = context.getMimeType(downloadFile.getPath());\r
-               if (mimeType == null) {\r
-                       mimeType = "application/octet-stream";\r
-               }\r
-\r
-               response.setContentType(mimeType);\r
-               response.setContentLength((int) downloadFile.length());\r
-               String headerKey = "Content-Disposition";\r
-               String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());\r
-               downloadFile.delete();\r
-               response.setHeader(headerKey, headerValue);\r
-\r
-               OutputStream outStream = response.getOutputStream();\r
-               byte[] buffer = new byte[32 * 1024];\r
-               int bytesRead = -1;\r
-               while ((bytesRead = inputStream.read(buffer)) != -1) {\r
-                       outStream.write(buffer, 0, bytesRead);\r
-               }\r
-\r
-               inputStream.close();\r
-               outStream.close();\r
-       }\r
-\r
-       @RequestMapping(value = { "/portalApi/microservices/parameters" }, method = RequestMethod.POST)\r
-       public PortalRestResponse<String> saveWidgetParameter(HttpServletRequest request, HttpServletResponse response,\r
-                       @RequestBody WidgetCatalogParameter widgetParameters) throws Exception {\r
-               EPUser user = EPUserUtils.getUserSession(request);\r
-               widgetParameters.setUserId(user.getId());\r
-               try {\r
-                       WidgetCatalogParameter oldParam = widgetParameterService.getUserParamById(widgetParameters.getWidgetId(),\r
-                                       widgetParameters.getUserId(), widgetParameters.getParamId());\r
-                       if (oldParam != null) {\r
-                               widgetParameters.setId(oldParam.getId());\r
-                       }\r
-                       widgetParameterService.saveUserParameter(widgetParameters);\r
-\r
-               } catch (Exception e) {\r
-                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", e.getMessage());\r
-               }\r
-               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");\r
-       }\r
-\r
-}\r
+/*-
+ * ================================================================================
+ * ECOMP Portal
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ================================================================================
+ */
+package org.openecomp.portalapp.portal.controller;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.openecomp.portalapp.controller.EPRestrictedBaseController;
+import org.openecomp.portalapp.portal.domain.EPUser;
+import org.openecomp.portalapp.portal.domain.MicroserviceParameter;
+import org.openecomp.portalapp.portal.domain.WidgetCatalog;
+import org.openecomp.portalapp.portal.domain.WidgetCatalogParameter;
+import org.openecomp.portalapp.portal.domain.WidgetParameterResult;
+import org.openecomp.portalapp.portal.domain.WidgetServiceHeaders;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestResponse;
+import org.openecomp.portalapp.portal.ecomp.model.PortalRestStatusEnum;
+import org.openecomp.portalapp.portal.logging.aop.EPAuditLog;
+import org.openecomp.portalapp.portal.service.ConsulHealthService;
+import org.openecomp.portalapp.portal.service.MicroserviceService;
+import org.openecomp.portalapp.portal.service.WidgetParameterService;
+import org.openecomp.portalapp.util.EPUserUtils;
+import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.openecomp.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
+
+@SuppressWarnings("unchecked")
+@RestController
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+@EPAuditLog
+public class WidgetsCatalogController extends EPRestrictedBaseController {
+
+       private static final String HTTPS = "https://";
+
+       EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WidgetsCatalogController.class);
+       RestTemplate template = new RestTemplate();
+       String whatService = "widgets-service";
+
+       @Autowired
+       private ConsulHealthService consulHealthService;
+
+       @Autowired
+       private MicroserviceService microserviceService;
+
+       @Autowired
+       private WidgetParameterService widgetParameterService;
+
+       @Bean
+       public CommonsMultipartResolver multipartResolver() {
+               return new CommonsMultipartResolver();
+       }
+
+       static {
+               // for localhost testing only
+               javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
+
+                       public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
+                               if (hostname.equals("localhost")) {
+                                       return true;
+                               }
+                               return false;
+                       }
+               });
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{loginName}" }, method = RequestMethod.GET)
+       public List<WidgetCatalog> getUserWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("loginName") String loginName) throws RestClientException, Exception {
+               List<WidgetCatalog> widgets = new ArrayList<>();
+               try {
+                       ResponseEntity<ArrayList> ans = template.exchange(
+                                       HTTPS + consulHealthService.getServiceLocation(whatService,
+                                                       SystemProperties.getProperty("microservices.widget.local.port"))
+                                                       + "/widget/microservices/widgetCatalog/" + loginName,
+                                       HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class);
+                       widgets = ans.getBody();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getUserWidgetCatalog failed", e);
+                       // returning null because null help check on the UI if there was a
+                       // communication problem with Microservice.
+                       return null;
+               }
+               return widgets;
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog" }, method = RequestMethod.GET)
+       public List<WidgetCatalog> getWidgetCatalog(HttpServletRequest request, HttpServletResponse response)
+                       throws RestClientException, Exception {
+               List<WidgetCatalog> widgets = new ArrayList<>();
+               try {
+                       ResponseEntity<ArrayList> ans = template.exchange(
+                                       HTTPS + consulHealthService.getServiceLocation(whatService,
+                                                       SystemProperties.getProperty("microservices.widget.local.port"))
+                                                       + "/widget/microservices/widgetCatalog",
+                                       HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), ArrayList.class);
+                       widgets = ans.getBody();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "getWidgetCatalog failed", e);
+                       // returning null because null help check on the UI if there was a
+                       // communication problem with Microservice.
+                       return null;
+               }
+               return widgets;
+       }
+
+       @RequestMapping(value = {
+                       "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.PUT, produces = "application/json")
+       public void updateWidgetCatalog(HttpServletRequest request, HttpServletResponse response,
+                       @RequestBody WidgetCatalog newWidgetCatalog, @PathVariable("widgetId") long widgetId)
+                       throws RestClientException, Exception {
+               template.exchange(
+                               HTTPS + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                                               + "/widget/microservices/widgetCatalog/" + widgetId,
+                               HttpMethod.PUT, new HttpEntity(newWidgetCatalog, WidgetServiceHeaders.getInstance()), String.class);
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.DELETE)
+       public void deleteOnboardingWidget(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+               template.exchange(
+                               HTTPS + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                                               + "/widget/microservices/widgetCatalog/" + widgetId,
+                               HttpMethod.DELETE, new HttpEntity(WidgetServiceHeaders.getInstance()), String.class);
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog/{widgetId}" }, method = RequestMethod.POST)
+       public String updateWidgetCatalogWithFiles(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+               MultipartHttpServletRequest mRequest;
+               MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();
+               String fileName;
+               String tmp_folder = "/tmp/";
+               String respond = null;
+               FileOutputStream fo = null;
+               try {
+                       mRequest = (MultipartHttpServletRequest) request;
+                       MultipartFile mFile = mRequest.getFile("file");
+                       fileName = mFile.getOriginalFilename();
+                       fo = new FileOutputStream(tmp_folder + fileName);
+                       fo.write(mFile.getBytes());
+
+                       HttpHeaders header = new HttpHeaders();
+                       header.setContentType(MediaType.MULTIPART_FORM_DATA);
+                       multipartRequest.add("file", new FileSystemResource(tmp_folder + fileName));
+                       multipartRequest.add("widget", request.getParameter("newWidget"));
+                       respond = template.postForObject(
+                                       HTTPS + consulHealthService.getServiceLocation(whatService,
+                                                       SystemProperties.getProperty("microservices.widget.local.port"))
+                                                       + "/widget/microservices/widgetCatalog/" + widgetId,
+                                       new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class);
+                       File f = new File(tmp_folder + fileName);
+                       f.delete();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "updateWidgetCatalogWithFiles failed", e);
+               } finally {
+                       try {
+                               if (fo != null)
+                                       fo.close();
+                       } catch (IOException e) {
+                               logger.error(EELFLoggerDelegate.errorLogger, "updateWidgetCatalogWithFiles failed 2", e);
+                       }
+               }
+               return respond;
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/widgetCatalog" }, method = RequestMethod.POST)
+       public String createWidgetCatalog(HttpServletRequest request, HttpServletResponse response)
+                       throws RestClientException, Exception {
+               MultipartHttpServletRequest mRequest;
+               MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();
+               String fileName;
+               String tmp_folder = "/tmp/";
+               String respond = null;
+               FileOutputStream fo = null;
+               try {
+                       mRequest = (MultipartHttpServletRequest) request;
+                       MultipartFile mFile = mRequest.getFile("file");
+                       fileName = mFile.getOriginalFilename();
+                       fo = new FileOutputStream(tmp_folder + fileName);
+                       fo.write(mFile.getBytes());
+
+                       HttpHeaders header = new HttpHeaders();
+                       header.setContentType(MediaType.MULTIPART_FORM_DATA);
+                       multipartRequest.add("file", new FileSystemResource(tmp_folder + fileName));
+                       multipartRequest.add("widget", request.getParameter("newWidget"));
+
+                       respond = template.postForObject(
+                                       HTTPS + consulHealthService.getServiceLocation(whatService,
+                                                       SystemProperties.getProperty("microservices.widget.local.port"))
+                                                       + "/widget/microservices/widgetCatalog",
+                                       new HttpEntity<>(multipartRequest, WidgetServiceHeaders.getInstance()), String.class);
+                       File f = new File(tmp_folder + fileName);
+                       f.delete();
+               } catch (Exception e) {
+                       logger.error(EELFLoggerDelegate.errorLogger, "createWidgetCatalog failed", e);
+               } finally {
+                       try {
+                               if (fo != null)
+                                       fo.close();
+                       } catch (IOException e) {
+                               logger.error(EELFLoggerDelegate.errorLogger, "createWidgetCatalog failed 2", e);
+                       }
+               }
+               return respond;
+       }
+
+       @RequestMapping(value = "/portalApi/microservices/{widgetId}/framework.js", method = RequestMethod.GET)
+       public String getWidgetFramework(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+               return template.getForObject(HTTPS
+                               + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                               + "/widget/microservices/" + widgetId + "/framework.js", String.class,
+                               WidgetServiceHeaders.getInstance());
+       }
+
+       @RequestMapping(value = "/portalApi/microservices/{widgetId}/controller.js", method = RequestMethod.GET)
+       public String getWidgetController(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+               return template.getForObject(HTTPS
+                               + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                               + "/widget/microservices/" + widgetId + "/controller.js", String.class,
+                               WidgetServiceHeaders.getInstance());
+       }
+
+       @RequestMapping(value = "/portalApi/microservices/{widgetId}/style.css", method = RequestMethod.GET)
+       public String getWidgetCSS(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+               return template.getForObject(HTTPS
+                               + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                               + "/widget/microservices/" + widgetId + "/styles.css", String.class,
+                               WidgetServiceHeaders.getInstance());
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/parameters/{widgetId}" }, method = RequestMethod.GET)
+       public PortalRestResponse<List<WidgetParameterResult>> getWidgetParameterResult(HttpServletRequest request,
+                       HttpServletResponse response, @PathVariable("widgetId") long widgetId) throws Exception {
+               EPUser user = EPUserUtils.getUserSession(request);
+
+               List<WidgetParameterResult> list = new ArrayList<>();
+               Long serviceId = template.exchange(
+                               HTTPS + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                                               + "/widget/microservices/widgetCatalog/parameters/" + widgetId,
+                               HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), Long.class).getBody();
+               if (serviceId == null) {
+                       // return ok/sucess and no service parameter for this widget
+                       return new PortalRestResponse<List<WidgetParameterResult>>(PortalRestStatusEnum.WARN,
+                                       "No service parameters for this widget", list);
+               } else {
+                       List<MicroserviceParameter> defaultParam = microserviceService.getParametersById(serviceId);
+                       for (MicroserviceParameter param : defaultParam) {
+                               WidgetParameterResult user_result = new WidgetParameterResult();
+                               user_result.setParam_id(param.getId());
+                               user_result.setDefault_value(param.getPara_value());
+                               user_result.setParam_key(param.getPara_key());
+                               WidgetCatalogParameter userValue = widgetParameterService.getUserParamById(widgetId, user.getId(),
+                                               param.getId());
+                               if (userValue == null)
+                                       user_result.setUser_value(param.getPara_value());
+                               else {
+                                       user_result.setUser_value(userValue.getUser_value());
+                               }
+                               list.add(user_result);
+                       }
+               }
+               return new PortalRestResponse<List<WidgetParameterResult>>(PortalRestStatusEnum.OK, "SUCCESS", list);
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/services/{paramId}" }, method = RequestMethod.GET)
+       public List<WidgetCatalogParameter> getUserParameterById(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("paramId") long paramId) throws Exception {
+               List<WidgetCatalogParameter> list = widgetParameterService.getUserParameterById(paramId);
+               return list;
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/services/{paramId}" }, method = RequestMethod.DELETE)
+       public void deleteUserParameterById(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("paramId") long paramId) throws Exception {
+               widgetParameterService.deleteUserParameterById(paramId);
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/download/{widgetId}" }, method = RequestMethod.GET)
+       public void doDownload(HttpServletRequest request, HttpServletResponse response,
+                       @PathVariable("widgetId") long widgetId) throws RestClientException, Exception {
+
+               ServletContext context = request.getServletContext();
+               byte[] byteFile = template.exchange(
+                               HTTPS + consulHealthService.getServiceLocation(whatService,
+                                               SystemProperties.getProperty("microservices.widget.local.port"))
+                                               + "/widget/microservices/download/" + widgetId,
+                               HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), byte[].class).getBody();
+
+               File downloadFile = File.createTempFile("temp", ".zip");
+               FileOutputStream stream = new FileOutputStream(downloadFile.getPath());
+               stream.write(byteFile);
+               stream.close();
+
+               FileInputStream inputStream = new FileInputStream(downloadFile);
+               String mimeType = context.getMimeType(downloadFile.getPath());
+               if (mimeType == null) {
+                       mimeType = "application/octet-stream";
+               }
+
+               response.setContentType(mimeType);
+               response.setContentLength((int) downloadFile.length());
+               String headerKey = "Content-Disposition";
+               String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
+               downloadFile.delete();
+               response.setHeader(headerKey, headerValue);
+
+               OutputStream outStream = response.getOutputStream();
+               byte[] buffer = new byte[32 * 1024];
+               int bytesRead = -1;
+               while ((bytesRead = inputStream.read(buffer)) != -1) {
+                       outStream.write(buffer, 0, bytesRead);
+               }
+
+               inputStream.close();
+               outStream.close();
+       }
+
+       @RequestMapping(value = { "/portalApi/microservices/parameters" }, method = RequestMethod.POST)
+       public PortalRestResponse<String> saveWidgetParameter(HttpServletRequest request, HttpServletResponse response,
+                       @RequestBody WidgetCatalogParameter widgetParameters) throws Exception {
+               EPUser user = EPUserUtils.getUserSession(request);
+               widgetParameters.setUserId(user.getId());
+               try {
+                       WidgetCatalogParameter oldParam = widgetParameterService.getUserParamById(widgetParameters.getWidgetId(),
+                                       widgetParameters.getUserId(), widgetParameters.getParamId());
+                       if (oldParam != null) {
+                               widgetParameters.setId(oldParam.getId());
+                       }
+                       widgetParameterService.saveUserParameter(widgetParameters);
+
+               } catch (Exception e) {
+                       return new PortalRestResponse<String>(PortalRestStatusEnum.ERROR, "FAILURE", e.getMessage());
+               }
+               return new PortalRestResponse<String>(PortalRestStatusEnum.OK, "SUCCESS", "");
+       }
+
+}