Skip to content

Commit

Permalink
Rename various parts in the codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Ewan Donovan committed Jan 27, 2025
1 parent 2af1a2e commit 58e3562
Show file tree
Hide file tree
Showing 20 changed files with 167 additions and 167 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This service is available at:

The service provides 2 endpoints to consumers.
* `/learners` - Search for a learner's ULN via their demographic data
* `/plr` - Request a learner's learning record via their ULN
* `/learner-events` - Request a learner's learning record via their ULN

### `POST:/learners`
This endpoint is to search for learners by their demographic information.
Expand All @@ -34,7 +34,7 @@ The search may yield varied results depending on the accuracy of the demographic
* Exact match
* Linked Learner Found

Assuming a successful search, the response should contain a ULN for each learner found. This ULN may be used on the`/plr` endpoint to retrieve their respective PLRs.
Assuming a successful search, the response should contain a ULN for each learner found. This ULN may be used on the`/learner-events` endpoint to retrieve their respective PLRs.

Example request body:
```json
Expand Down Expand Up @@ -97,7 +97,7 @@ Response codes:
* 401 - Unauthorised
* 403 - Forbidden

### `POST:/plr`
### `POST:/learner-events`
This endpoint is used to request a learner's learning events (or Personal Learning Record [PLR]) by their Unique Learner Number (ULN).

Generally when using a valid ULN there should be no issues with this request, but there are a few possible responses.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import retrofit2.http.POST
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.FindLearnerEnvelope
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.LearningEventsEnvelope

interface LRSApiServiceInterface {
interface LRSApiInterface {
@Headers("Accept: application/xml", "Content-Type: text/xml")
// This is the endpoint we want to call on the base url of the api
// Want to figure out how to use the config for this instead of hardcoding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.time.LocalDate

data class GetLearnerLearningEventsLRSRequest(
data class LearnerEventsLRSRequest(
@field:Size(max = 35)
val userName: String = "TEST",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.time.LocalDate
// We supply the ukprn and orgPassword - need to store this somewhere safe and call it
// When user first uses microservice the username will be in the header of the request, we need to store this value and then input this value in the request to the LRS API
// Need to investigate logs - everytime a request is made we want to store some logging information (i.e. username, request made). Need to speak to hmpps devs to understand what is the norm.
data class FindLearnerByDemographicsLRSRequest(
data class LearnersLRSRequest(
@field:Size(max = 35)
val userName: String = "TEST",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request
import com.google.gson.annotations.SerializedName
import jakarta.validation.constraints.Past
import jakarta.validation.constraints.Size
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.request.GetLearnerLearningEventsLRSRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.request.LearnerEventsLRSRequest
import java.time.LocalDate

class GetPLRByULNRequest(
class LearnerEventsRequest(
@field:Size(max = 35)
@SerializedName("givenName")
val givenName: String,
Expand All @@ -26,7 +26,7 @@ class GetPLRByULNRequest(
@SerializedName("gender")
val gender: Int?,
) {
fun extractFromRequest(): GetLearnerLearningEventsLRSRequest = GetLearnerLearningEventsLRSRequest(
fun extractFromRequest(): LearnerEventsLRSRequest = LearnerEventsLRSRequest(
givenName = givenName,
familyName = familyName,
uln = uln,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import com.google.gson.annotations.SerializedName
import jakarta.validation.constraints.Max
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.Pattern
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.request.FindLearnerByDemographicsLRSRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.request.LearnersLRSRequest
import java.time.LocalDate

// Example model for the request
// Checking number of characters
// Error handling for bad requests need to be added - add specific message and giving a 400 instead of a 500
// annotations support message = ''
data class FindLearnerByDemographicsRequest(
data class LearnersRequest(
// Mandatory
@field:Pattern(regexp = "^[A-Za-z]{3,35}\$")
@SerializedName("givenName")
Expand All @@ -34,7 +34,7 @@ data class FindLearnerByDemographicsRequest(
@SerializedName("lastKnownPostcode")
val lastKnownPostCode: String,
) {
fun extractFromRequest(): FindLearnerByDemographicsLRSRequest = FindLearnerByDemographicsLRSRequest(
fun extractFromRequest(): LearnersLRSRequest = LearnersLRSRequest(
givenName = givenName,
familyName = familyName,
dateOfBirth = dateOfBirth,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response

import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.LearningEvent
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.GetPLRByULNRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest

data class GetPLRByULNResponse(
val searchParameters: GetPLRByULNRequest,
data class LearnerEventsResponse(
val searchParameters: LearnerEventsRequest,
val responseType: LRSResponseType,
var foundUln: String,
var incomingUln: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response

import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.Learner

data class FindLearnerByDemographicsResponse(
val searchParameters: uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.FindLearnerByDemographicsRequest,
data class LearnersResponse(
val searchParameters: uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest,
val responseType: LRSResponseType,
val mismatchedFields: MutableMap<String, MutableList<String>>? = null,
val matchedLearners: List<Learner>? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.GetPLRByULNResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnerEventsResponse
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse

@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@Operation(
summary = "Get PLR by ULN",
summary = "Get learning events by learner ULN",
description = "Get personal learning records and events by a ULN",
requestBody = RequestBody(
description = "ULN and demographic details of the learner",
required = true,
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.GetPLRByULNRequest::class),
schema = Schema(implementation = uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest::class),
examples = [
ExampleObject(
name = "Exact Match",
Expand Down Expand Up @@ -83,7 +83,7 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = GetPLRByULNResponse::class),
schema = Schema(implementation = LearnerEventsResponse::class),
examples = [
ExampleObject(
name = "Exact Match Response",
Expand Down Expand Up @@ -213,4 +213,4 @@ import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
),
],
)
annotation class FindByULNApi
annotation class LearnerEventsApi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.parameters.RequestBody
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.FindLearnerByDemographicsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.FindLearnerByDemographicsResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnersResponse
import uk.gov.justice.hmpps.kotlin.common.ErrorResponse
import java.nio.file.Files
import java.nio.file.Paths
Expand All @@ -30,7 +30,7 @@ fun readResourceFile(fileName: String): String {
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = FindLearnerByDemographicsRequest::class),
schema = Schema(implementation = LearnersRequest::class),
examples = [
ExampleObject(
name = "Exact Match Example",
Expand Down Expand Up @@ -92,7 +92,7 @@ fun readResourceFile(fileName: String): String {
content = [
Content(
mediaType = "application/json",
schema = Schema(implementation = FindLearnerByDemographicsResponse::class),
schema = Schema(implementation = LearnersResponse::class),
examples = [
ExampleObject(
name = "Exact Match Response",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package uk.gov.justice.digital.hmpps.learnerrecordsapi.resource

import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.security.access.prepost.PreAuthorize
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi.LearnerEventsApi
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.LearnerEventsService

@RestController
@PreAuthorize("hasRole('ROLE_LEARNER_RECORDS_SEARCH__RO')")
@RequestMapping(value = ["/learner-events"], produces = ["application/json"])
class LearnerEventsResource(
private val learnerEventsService: LearnerEventsService,
) : BaseResource() {

@PostMapping
@Tag(name = "Learning Events")
@LearnerEventsApi
suspend fun findByUln(
@RequestBody @Valid learnerEventsRequest: LearnerEventsRequest,
): String {
log.inboundRequest(requestModelObject = learnerEventsRequest)
return gson.toJson(learnerEventsService.getLearningEvents(learnerEventsRequest))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.FindLearnerByDemographicsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnersRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.openapi.FindByDemographicApi
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.LRSService
import uk.gov.justice.digital.hmpps.learnerrecordsapi.service.LearnersService

@RestController
@PreAuthorize("hasRole('ROLE_LEARNER_RECORDS_SEARCH__RO')")
@RequestMapping(value = ["/learners"], produces = ["application/json"])
class LearnersResource(
private val lrsService: LRSService,
private val learnersService: LearnersService,
) : BaseResource() {

@PostMapping
@Tag(name = "Learners")
@FindByDemographicApi
suspend fun findByDemographic(
@RequestBody @Valid findLearnerByDemographicsRequest: FindLearnerByDemographicsRequest,
@RequestBody @Valid findLearnerByDemographicsRequest: LearnersRequest,
): String {
log.inboundRequest(requestModelObject = findLearnerByDemographicsRequest)
return gson.toJson(lrsService.findLearner(findLearnerByDemographicsRequest))
return gson.toJson(learnersService.getLearners(findLearnerByDemographicsRequest))
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.AppConfig
import uk.gov.justice.digital.hmpps.learnerrecordsapi.config.HttpClientConfiguration
import uk.gov.justice.digital.hmpps.learnerrecordsapi.interfaces.LRSApiServiceInterface
import uk.gov.justice.digital.hmpps.learnerrecordsapi.interfaces.LRSApiInterface
import uk.gov.justice.digital.hmpps.learnerrecordsapi.logging.LoggerUtil
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.LearningEventsResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.MIAPAPIException
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.lrsapi.response.exceptions.LRSException
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.GetPLRByULNRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.GetPLRByULNResponse
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.request.LearnerEventsRequest
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LRSResponseType
import uk.gov.justice.digital.hmpps.learnerrecordsapi.models.response.LearnerEventsResponse
import java.io.StringReader
import javax.xml.bind.JAXBContext

@Service
class PLRService(
class LearnerEventsService(
@Autowired
private val httpClientConfiguration: HttpClientConfiguration,
@Autowired
private val appConfig: AppConfig,
) {
private val log: LoggerUtil = LoggerUtil(javaClass)

private fun lrsClient(): LRSApiServiceInterface = httpClientConfiguration.retrofit().create(LRSApiServiceInterface::class.java)
private fun lrsClient(): LRSApiInterface = httpClientConfiguration.retrofit().create(LRSApiInterface::class.java)

private fun parseError(xmlString: String): MIAPAPIException? {
val regex = Regex("<ns10:MIAPAPIException[\\s\\S]*?</ns10:MIAPAPIException>")
Expand All @@ -35,29 +35,29 @@ class PLRService(
return unmarshaller.unmarshal(StringReader(relevantXml)) as MIAPAPIException
}

suspend fun getPLR(getPLRByULNRequest: GetPLRByULNRequest): GetPLRByULNResponse {
suspend fun getLearningEvents(learnerEventsRequest: LearnerEventsRequest): LearnerEventsResponse {
log.debug("Transforming inbound request object to LRS request object")
val requestBody = getPLRByULNRequest.extractFromRequest()
val requestBody = learnerEventsRequest.extractFromRequest()
.transformToLRSRequest(appConfig.ukprn(), appConfig.password(), appConfig.vendorId())
log.debug("Calling LRS API")

val plrResponse = lrsClient().getLearnerLearningEvents(requestBody)
val learningEvents = plrResponse.body()?.body?.learningEventsResponse
val learningEventsResponse = lrsClient().getLearnerLearningEvents(requestBody)
val learningEventsObject = learningEventsResponse.body()?.body?.learningEventsResponse

if (plrResponse.isSuccessful && learningEvents != null) {
return formatLRSResponse(getPLRByULNRequest, learningEvents)
if (learningEventsResponse.isSuccessful && learningEventsObject != null) {
return formatLRSResponse(learnerEventsRequest, learningEventsObject)
} else {
throw LRSException(parseError(plrResponse.errorBody()?.string().toString()))
throw LRSException(parseError(learningEventsResponse.errorBody()?.string().toString()))
}
}

private fun formatLRSResponse(
request: GetPLRByULNRequest,
request: LearnerEventsRequest,
response: LearningEventsResponse,
): GetPLRByULNResponse {
): LearnerEventsResponse {
val learningEventsResult = response.learningEventsResult
val responseType = LRSResponseType.fromLrsResponseCode(learningEventsResult.responseCode)
return GetPLRByULNResponse(
return LearnerEventsResponse(
searchParameters = request,
responseType = responseType,
incomingUln = learningEventsResult.incomingUln,
Expand Down
Loading

0 comments on commit 58e3562

Please sign in to comment.