Skip to content

Commit 84e1183

Browse files
committed
✨ create public endpoint to search services by service-ids from servicenavigator
1 parent eddbfa5 commit 84e1183

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package de.muenchen.dbs.personalization.configuration;
2+
3+
import jakarta.validation.constraints.NotBlank;
4+
import lombok.Data;
5+
import org.springframework.boot.context.properties.ConfigurationProperties;
6+
import org.springframework.context.annotation.Profile;
7+
import org.springframework.validation.annotation.Validated;
8+
9+
@ConfigurationProperties(prefix = "p13n")
10+
@Validated
11+
@Profile("!no-security")
12+
@Data
13+
public class P13nConfiguration {
14+
/**
15+
* ServiceNavigator API URL.
16+
*/
17+
@NotBlank
18+
private String serviceNavigatorUrl = "https://stadt.muenchen.de/service/rs/befi/navigator";
19+
20+
/**
21+
* (optional) Proxy Host used to call ServiceNavigator.
22+
*/
23+
private String proxyHost = null;
24+
25+
/**
26+
* (optional) Proxy Port used to call ServiceNavigator.
27+
*/
28+
private int proxyPort = 80;
29+
30+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package de.muenchen.dbs.personalization.serviceNavigator;
2+
3+
import de.muenchen.dbs.personalization.configuration.P13nConfiguration;
4+
import io.swagger.v3.oas.annotations.Operation;
5+
import io.swagger.v3.oas.annotations.tags.Tag;
6+
import java.net.InetSocketAddress;
7+
import java.net.Proxy;
8+
import java.util.List;
9+
import lombok.RequiredArgsConstructor;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.apache.commons.lang3.StringUtils;
12+
import org.springframework.beans.factory.annotation.Autowired;
13+
import org.springframework.http.HttpStatus;
14+
import org.springframework.http.ResponseEntity;
15+
import org.springframework.http.client.SimpleClientHttpRequestFactory;
16+
import org.springframework.web.bind.annotation.GetMapping;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RequestParam;
19+
import org.springframework.web.bind.annotation.ResponseStatus;
20+
import org.springframework.web.bind.annotation.RestController;
21+
import org.springframework.web.client.RestTemplate;
22+
23+
@RestController
24+
@RequestMapping("/public/servicenavigator")
25+
@Slf4j
26+
@RequiredArgsConstructor
27+
@Tag(name = "Public ServiceNavigator Endpoints", description = "Endpoints not requiring authentication")
28+
public class PublicServiceNavigatorController {
29+
30+
private static final String SERVICENAVIGATOR_QUERY_PARAMETER_ID = "?id=";
31+
32+
private final RestTemplate restTemplate;
33+
private final P13nConfiguration p13nConfiguration;
34+
35+
@Autowired
36+
public PublicServiceNavigatorController(P13nConfiguration p13nConfiguration) {
37+
this.p13nConfiguration = p13nConfiguration;
38+
39+
if(StringUtils.isBlank(p13nConfiguration.getProxyHost())) {
40+
this.restTemplate = new RestTemplate();
41+
} else {
42+
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(p13nConfiguration.getProxyHost(), p13nConfiguration.getProxyPort()));
43+
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
44+
requestFactory.setProxy(proxy);
45+
this.restTemplate = new RestTemplate(requestFactory);
46+
}
47+
}
48+
49+
@GetMapping
50+
@Operation(summary = "Lookup ServiceNavigator Services by ServiceID. Returns a list of services for the given service IDs.")
51+
@ResponseStatus(HttpStatus.OK)
52+
public List<Object> getServicesByIds(@RequestParam("ids")String serviceIds) {
53+
final String url = p13nConfiguration.getServiceNavigatorUrl() + SERVICENAVIGATOR_QUERY_PARAMETER_ID + serviceIds;
54+
ResponseEntity<List> forEntity = restTemplate.getForEntity(url, List.class);
55+
return forEntity.getBody();
56+
}
57+
58+
}

personalization-service/src/main/resources/application-local.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ sso:
4242

4343
security:
4444
user-info-uri: ${sso.url}/auth/realms/${sso.realm}/protocol/openid-connect/userinfo
45-
logging-mode: all
45+
logging-mode: all
46+
47+
p13n:
48+
service-navigator-url: "https://stadt.muenchen.de/service/rs/befi/navigator/"
49+
proxy-host: "internet-proxy-client.muenchen.de"
50+
proxy-port: 80

0 commit comments

Comments
 (0)