MicroserviceController up
[portal.git] / portal-BE / src / main / java / org / onap / portal / restTemplates / PortalWMSTemplate.java
1 package org.onap.portal.restTemplates;
2
3 import java.util.List;
4 import org.onap.portal.domain.dto.ecomp.WidgetCatalog;
5 import org.onap.portal.domain.dto.ecomp.WidgetServiceHeaders;
6 import org.onap.portal.service.WidgetMService;
7 import org.onap.portal.utils.EcompPortalUtils;
8 import org.onap.portalsdk.core.util.SystemProperties;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.core.ParameterizedTypeReference;
11 import org.springframework.http.HttpEntity;
12 import org.springframework.http.HttpMethod;
13 import org.springframework.http.ResponseEntity;
14 import org.springframework.stereotype.Component;
15 import org.springframework.web.client.RestTemplate;
16
17 @Component
18 public class PortalWMSTemplate {
19
20     private final RestTemplate template = new RestTemplate();
21     private final WidgetMService widgetMService;
22
23     @Autowired
24     public PortalWMSTemplate(WidgetMService widgetMService) {
25         this.widgetMService = widgetMService;
26     }
27
28
29     @SuppressWarnings("rawtypes")
30     public ResponseEntity<Long> proxyToDestinationByWidgetId(long widgetId) throws Exception {
31         return template.exchange(
32             EcompPortalUtils.widgetMsProtocol() + "://"
33                 + widgetMService.getServiceLocation("widgets-service",
34                 SystemProperties.getProperty("microservices.widget.local.port"))
35                 + "/widget/microservices/widgetCatalog/parameters/" + widgetId,
36             HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), Long.class);
37     }
38
39     public ResponseEntity<List<WidgetCatalog>> getWidgets(long serviceId,
40         ParameterizedTypeReference<List<WidgetCatalog>> typeRef)
41         throws Exception {
42         return template.exchange(
43             EcompPortalUtils.widgetMsProtocol() + "://" + widgetMService
44                 .getServiceLocation("widgets-service", SystemProperties.getProperty("microservices.widget.local.port"))
45                 + "/widget/microservices/widgetCatalog/service/" + serviceId,
46             HttpMethod.GET, new HttpEntity(WidgetServiceHeaders.getInstance()), typeRef);
47     }
48 }