-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove java-utils usage from OppijenumerorekisteriClient
- Loading branch information
Showing
7 changed files
with
77 additions
and
72 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
...in/java/fi/vm/sade/organisaatio/business/exception/OrganisaatioOppijanumeroException.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
organisaatio-service/src/main/java/fi/vm/sade/organisaatio/client/OppijanumeroClient.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
...tio-service/src/main/java/fi/vm/sade/organisaatio/client/OppijanumerorekisteriClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fi.vm.sade.organisaatio.client; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fi.vm.sade.organisaatio.cas.CasAuthenticatedServiceClient; | ||
import fi.vm.sade.organisaatio.cas.CasClient; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse; | ||
|
||
@Slf4j | ||
public class OppijanumerorekisteriClient extends CasAuthenticatedServiceClient { | ||
private final ObjectMapper mapper; | ||
private final String baseUrl; | ||
public OppijanumerorekisteriClient(HttpClient httpClient, CasClient casClient, String baseUrl, ObjectMapper mapper) { | ||
super(httpClient, casClient, baseUrl); | ||
this.mapper = mapper; | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
public Henkilo getHenkilo(String oid) throws IOException, InterruptedException { | ||
var response = get("/henkilo/" + oid); | ||
if (response.statusCode() == 200) { | ||
return mapper.readValue(response.body(), Henkilo.class); | ||
} else { | ||
throw new RuntimeException("Unexpected status code " + response.statusCode() + " when fetching henkilo " + oid); | ||
} | ||
} | ||
|
||
private HttpResponse<String> get(String path) throws IOException, InterruptedException { | ||
var uri = URI.create(baseUrl + path); | ||
log.info("Executing request GET {}", uri); | ||
var request = HttpRequest.newBuilder() | ||
.uri(uri) | ||
.method("GET", HttpRequest.BodyPublishers.noBody()) | ||
.header("Accept", "application/json"); | ||
var response = sendRequest(request); | ||
log.info("Received response {} {}", response.statusCode(), response.body()); | ||
return response; | ||
} | ||
|
||
public record Henkilo(String oidHenkilo, String etunimet, String sukunimi) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters