changed the service id
This commit is contained in:
parent
7a6127b1f7
commit
b6378ae908
|
@ -34,7 +34,7 @@ public class ApiController extends DnetRestController {
|
|||
private ServiceRegistry registry;
|
||||
|
||||
@RequestMapping(value = "/register/{type}", method = { RequestMethod.GET, RequestMethod.POST })
|
||||
public ServiceStatus registerService(@PathVariable final ServiceType type, @RequestParam final String baseUrl) {
|
||||
public ServiceStatus registerService(@PathVariable final ServiceType type, @RequestParam final String baseUrl) throws Exception {
|
||||
return registry.registerService(type, baseUrl);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package eu.dnetlib.is.service;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -24,14 +24,14 @@ public class ServiceRegistry {
|
|||
return s != null ? s.getBaseUrl() : null;
|
||||
}
|
||||
|
||||
public synchronized ServiceStatus registerService(final ServiceType type, final String baseUrl) {
|
||||
public synchronized ServiceStatus registerService(final ServiceType type, final String baseUrl) throws MalformedURLException {
|
||||
|
||||
final ServiceStatus status = map.values()
|
||||
.stream()
|
||||
.filter(s -> s.getType() == type)
|
||||
.filter(s -> s.getBaseUrl().equals(baseUrl))
|
||||
.findFirst()
|
||||
.orElse(new ServiceStatus(type.getPrefix() + "-" + UUID.randomUUID(), type, baseUrl));
|
||||
.orElse(new ServiceStatus(type, baseUrl));
|
||||
|
||||
status.setDate(LocalDateTime.now());
|
||||
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package eu.dnetlib.domain.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ServiceStatus implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4913228769231373286L;
|
||||
|
@ -17,18 +21,25 @@ public class ServiceStatus implements Serializable {
|
|||
|
||||
public ServiceStatus() {}
|
||||
|
||||
public ServiceStatus(final String name, final ServiceType type, final String baseUrl, final LocalDateTime date) {
|
||||
this.name = name;
|
||||
public ServiceStatus(final ServiceType type, final String baseUrl) throws MalformedURLException {
|
||||
this.type = type;
|
||||
this.baseUrl = baseUrl;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public ServiceStatus(final String name, final ServiceType type, final String baseUrl) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.baseUrl = baseUrl;
|
||||
date = LocalDateTime.now();
|
||||
|
||||
final URL url = new URL(baseUrl);
|
||||
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(type.getPrefix());
|
||||
|
||||
for (final String p : url.getHost().split("\\.")) {
|
||||
sb.append("-");
|
||||
sb.append(StringUtils.leftPad(p, 3, "0"));
|
||||
}
|
||||
sb.append("-");
|
||||
sb.append(url.getPort());
|
||||
|
||||
name = sb.toString();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package eu.dnetlib.domain.service;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ServiceStatusTest {
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {}
|
||||
|
||||
@Test
|
||||
void test() throws MalformedURLException {
|
||||
|
||||
final ServiceType type = ServiceType.vocabulary_manager;
|
||||
|
||||
final ServiceStatus status = new ServiceStatus(type, "http://192.168.0.5:8080/vocs");
|
||||
|
||||
System.out.println(status.getName());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue