-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/OPHKIOS-85' into feature/OPHKIOS-35
- Loading branch information
Showing
10 changed files
with
144 additions
and
2 deletions.
There are no files selected for viewing
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
53 changes: 53 additions & 0 deletions
53
backend/vkt/src/main/java/fi/oph/vkt/service/koski/KoskiService.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,53 @@ | ||
package fi.oph.vkt.service.koski; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import fi.oph.vkt.service.koski.dto.KoskiResponseDTO; | ||
import fi.oph.vkt.service.koski.dto.RequestBody; | ||
import lombok.RequiredArgsConstructor; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import org.springframework.web.reactive.function.client.WebClientResponseException; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class KoskiService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(KoskiService.class); | ||
|
||
private final WebClient koskiClient; | ||
|
||
public KoskiResponseDTO findEducations(final String oid) { | ||
final ObjectMapper objectMapper = new ObjectMapper(); | ||
final RequestBody body = new RequestBody(oid); | ||
|
||
try { | ||
final String bodyJson = objectMapper.writeValueAsString(body); | ||
final String response = koskiClient | ||
.post() | ||
.uri("/oid") | ||
.bodyValue(bodyJson) | ||
.exchangeToMono(clientResponse -> { | ||
if (clientResponse.statusCode().isError()) { | ||
return clientResponse.createException().flatMap(Mono::error); | ||
} | ||
return clientResponse.bodyToMono(String.class); | ||
}) | ||
.block(); | ||
|
||
return objectMapper.readValue(response, KoskiResponseDTO.class); | ||
} catch (final WebClientResponseException e) { | ||
LOG.error( | ||
"KOSKI returned error status {}\n response body: {}", | ||
e.getStatusCode().value(), | ||
e.getResponseBodyAsString() | ||
); | ||
throw new RuntimeException(e); | ||
} catch (final Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
backend/vkt/src/main/java/fi/oph/vkt/service/koski/dto/KoskiResponseDTO.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,16 @@ | ||
package fi.oph.vkt.service.koski.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import java.util.List; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class KoskiResponseDTO { | ||
|
||
private List<OpiskeluoikeusDTO> opiskeluoikeudet; | ||
} |
15 changes: 15 additions & 0 deletions
15
backend/vkt/src/main/java/fi/oph/vkt/service/koski/dto/OpiskeluoikeusDTO.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,15 @@ | ||
package fi.oph.vkt.service.koski.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class OpiskeluoikeusDTO { | ||
|
||
private TyyppiDTO tyyppi; | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/vkt/src/main/java/fi/oph/vkt/service/koski/dto/RequestBody.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,8 @@ | ||
package fi.oph.vkt.service.koski.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Builder; | ||
import lombok.NonNull; | ||
|
||
@Builder | ||
public record RequestBody(@NonNull @NotNull String oid) {} |
15 changes: 15 additions & 0 deletions
15
backend/vkt/src/main/java/fi/oph/vkt/service/koski/dto/TyyppiDTO.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,15 @@ | ||
package fi.oph.vkt.service.koski.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class TyyppiDTO { | ||
|
||
private String koodiarvo; | ||
} |
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