T10: PwzRegistrySource with PwzLookupClient [checkpoint]
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.developx.szpitale.ingest.source;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PwzLookupClient {
|
||||
List<String> query(String fullName);
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package com.developx.szpitale.ingest.source;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class PwzRegistrySource {
|
||||
|
||||
private final PwzLookupClient client;
|
||||
|
||||
public PwzRegistrySource(PwzLookupClient client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public Optional<String> lookupPwz(String fullName) {
|
||||
if (client == null || fullName == null || fullName.isBlank()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
List<String> results = client.query(fullName);
|
||||
|
||||
if (results == null || results.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
if (results.size() == 1) {
|
||||
return Optional.of(results.get(0));
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user