-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
240 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ on: | |
pull_request: | ||
push: | ||
branches-ignore: | ||
- master | ||
- main | ||
- release-* | ||
permissions: | ||
id-token: write | ||
|
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
32 changes: 32 additions & 0 deletions
32
...a/uk/gov/nationalarchives/tdr/transfer/service/services/dataload/DataLoadInitiation.scala
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,32 @@ | ||
package uk.gov.nationalarchives.tdr.transfer.service.services.dataload | ||
|
||
import cats.effect.IO | ||
import uk.gov.nationalarchives.tdr.keycloak.Token | ||
import uk.gov.nationalarchives.tdr.transfer.service.ApplicationConfig | ||
import uk.gov.nationalarchives.tdr.transfer.service.api.model.LoadModel.{AWSS3LoadDestination, LoadDetails} | ||
import uk.gov.nationalarchives.tdr.transfer.service.services.GraphQlApiService | ||
import uk.gov.nationalarchives.tdr.transfer.service.services.dataload.DataLoadInitiation.s3Config | ||
|
||
import java.util.UUID | ||
|
||
class DataLoadInitiation(graphQlApiService: GraphQlApiService) { | ||
def initiateConsignmentLoad(token: Token): IO[LoadDetails] = { | ||
for { | ||
addConsignmentResult <- graphQlApiService.addConsignment(token) | ||
consignmentId = addConsignmentResult.consignmentid.get | ||
_ <- graphQlApiService.startUpload(token, consignmentId) | ||
result <- loadDetails(consignmentId, token.userId) | ||
} yield result | ||
} | ||
|
||
private def loadDetails(transferId: UUID, userId: UUID): IO[LoadDetails] = { | ||
val recordsS3Bucket = AWSS3LoadDestination(s"${s3Config.recordsUploadBucket}", s"$userId/$transferId") | ||
val metadataS3Bucket = AWSS3LoadDestination(s"${s3Config.metadataUploadBucket}", s"$transferId/dataload") | ||
IO(LoadDetails(transferId, recordsLoadDestination = recordsS3Bucket, metadataLoadDestination = metadataS3Bucket)) | ||
} | ||
} | ||
|
||
object DataLoadInitiation { | ||
val s3Config: ApplicationConfig.S3 = ApplicationConfig.appConfig.s3 | ||
def apply() = new DataLoadInitiation(GraphQlApiService.service) | ||
} |
17 changes: 17 additions & 0 deletions
17
...la/uk/gov/nationalarchives/tdr/transfer/service/services/dataload/DataLoadProcessor.scala
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,17 @@ | ||
package uk.gov.nationalarchives.tdr.transfer.service.services.dataload | ||
|
||
import cats.effect.IO | ||
import uk.gov.nationalarchives.tdr.keycloak.Token | ||
|
||
import java.util.UUID | ||
|
||
class DataLoadProcessor { | ||
def trigger(transferId: UUID, token: Token): IO[String] = { | ||
// Trigger data load processing | ||
IO("Data Load Processor: Stubbed Response") | ||
} | ||
} | ||
|
||
object DataLoadProcessor { | ||
def apply() = new DataLoadProcessor | ||
} |
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
73 changes: 73 additions & 0 deletions
73
.../gov/nationalarchives/tdr/transfer/service/services/dataload/DataLoadInitiationSpec.scala
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,73 @@ | ||
package uk.gov.nationalarchives.tdr.transfer.service.services.dataload | ||
|
||
import cats.effect.IO | ||
import cats.effect.unsafe.implicits.global | ||
import com.nimbusds.oauth2.sdk.token.BearerAccessToken | ||
import graphql.codegen.AddConsignment.addConsignment.AddConsignment | ||
import uk.gov.nationalarchives.tdr.keycloak.Token | ||
import uk.gov.nationalarchives.tdr.transfer.service.BaseSpec | ||
import uk.gov.nationalarchives.tdr.transfer.service.api.model.LoadModel.{AWSS3LoadDestination, LoadDetails} | ||
import uk.gov.nationalarchives.tdr.transfer.service.services.GraphQlApiService | ||
|
||
import java.util.UUID | ||
|
||
class DataLoadInitiationSpec extends BaseSpec { | ||
private val mockToken = mock[Token] | ||
private val mockBearerAccessToken = mock[BearerAccessToken] | ||
private val consignmentId = UUID.fromString("6e3b76c4-1745-4467-8ac5-b4dd736e1b3e") | ||
private val userId = UUID.randomUUID() | ||
|
||
"'initiateConsignmentLoad'" should "create a consignment and return expected 'LoadDetails' object" in { | ||
val addConsignmentResponse = AddConsignment(Some(consignmentId), None) | ||
val mockGraphQlApiService = mock[GraphQlApiService] | ||
|
||
when(mockGraphQlApiService.addConsignment(mockToken)).thenReturn(IO(addConsignmentResponse)) | ||
when(mockGraphQlApiService.startUpload(mockToken, consignmentId)).thenReturn(IO("response string")) | ||
when(mockToken.bearerAccessToken).thenReturn(mockBearerAccessToken) | ||
when(mockToken.bearerAccessToken.getValue).thenReturn("some value") | ||
when(mockToken.userId).thenReturn(userId) | ||
|
||
val expectedResult = LoadDetails( | ||
consignmentId, | ||
AWSS3LoadDestination("s3BucketNameRecords", s"$userId/$consignmentId"), | ||
AWSS3LoadDestination("s3BucketNameMetadata", s"$consignmentId/dataload"), | ||
List() | ||
) | ||
|
||
val service = new DataLoadInitiation(mockGraphQlApiService) | ||
val result = service.initiateConsignmentLoad(mockToken).unsafeRunSync() | ||
result shouldBe expectedResult | ||
verify(mockGraphQlApiService, times(1)).addConsignment(mockToken) | ||
verify(mockGraphQlApiService, times(1)).startUpload(mockToken, consignmentId, None) | ||
} | ||
|
||
"'initiateConsignmentLoad'" should "throw an error if 'addConsignment' GraphQl service call fails" in { | ||
val mockGraphQlApiService = mock[GraphQlApiService] | ||
when(mockGraphQlApiService.addConsignment(mockToken)).thenThrow(new RuntimeException("Error adding consignment")) | ||
|
||
val service = new DataLoadInitiation(mockGraphQlApiService) | ||
|
||
val exception = intercept[RuntimeException] { | ||
service.initiateConsignmentLoad(mockToken).attempt.unsafeRunSync() | ||
} | ||
exception.getMessage shouldBe "Error adding consignment" | ||
verify(mockGraphQlApiService, times(1)).addConsignment(mockToken) | ||
verify(mockGraphQlApiService, times(0)).startUpload(mockToken, consignmentId, None) | ||
} | ||
|
||
"'initiateConsignmentLoad'" should "throw an error if 'startUpload' GraphQl service call fails" in { | ||
val addConsignmentResponse = AddConsignment(Some(consignmentId), None) | ||
val mockGraphQlApiService = mock[GraphQlApiService] | ||
|
||
when(mockGraphQlApiService.addConsignment(mockToken)).thenReturn(IO(addConsignmentResponse)) | ||
when(mockGraphQlApiService.startUpload(mockToken, consignmentId)).thenThrow(new RuntimeException("Error starting upload")) | ||
|
||
val service = new DataLoadInitiation(mockGraphQlApiService) | ||
val response = service.initiateConsignmentLoad(mockToken).attempt.unsafeRunSync() | ||
|
||
response.isLeft should equal(true) | ||
response.left.value.getMessage should equal("Error starting upload") | ||
verify(mockGraphQlApiService, times(1)).addConsignment(mockToken) | ||
verify(mockGraphQlApiService, times(1)).startUpload(mockToken, consignmentId, None) | ||
} | ||
} |
Oops, something went wrong.