diff --git a/app/controllers/DraftMetadataUploadController.scala b/app/controllers/DraftMetadataUploadController.scala index 1a2e0dce1..0590fda50 100644 --- a/app/controllers/DraftMetadataUploadController.scala +++ b/app/controllers/DraftMetadataUploadController.scala @@ -5,11 +5,13 @@ import cats.effect.IO import cats.effect.IO.fromOption import cats.effect.unsafe.implicits.global import configuration.{ApplicationConfig, KeycloakConfiguration} +import graphql.codegen.types.ConsignmentStatusInput import org.pac4j.play.scala.SecurityComponents import play.api._ import play.api.i18n.I18nSupport import play.api.libs.Files.TemporaryFile import play.api.mvc._ +import services.Statuses.{DraftMetadataType, InProgressValue} import services._ import viewsapi.Caching.preventCaching @@ -26,6 +28,7 @@ class DraftMetadataUploadController @Inject() ( val consignmentService: ConsignmentService, val uploadService: UploadService, val draftMetadataService: DraftMetadataService, + val consignmentStatusService: ConsignmentStatusService, val applicationConfig: ApplicationConfig )(implicit val ec: ExecutionContext) extends TokenSecurity @@ -54,8 +57,10 @@ class DraftMetadataUploadController @Inject() ( val uploadFileName = applicationConfig.draftMetadataFileName val uploadKey = s"$consignmentId/$uploadFileName" val noDraftMetadataFileUploaded: String = "No meta data file provided" + val consignmentStatusInput = ConsignmentStatusInput(consignmentId, DraftMetadataType.id, Some(InProgressValue.value)) def uploadDraftMetadata: IO[Result] = for { + _ <- IO.fromFuture(IO(consignmentStatusService.updateConsignmentStatus(consignmentStatusInput, token.bearerAccessToken))) firstFilePart <- fromOption(request.body.files.headOption)(new RuntimeException(noDraftMetadataFileUploaded)) file <- fromOption(request.body.file(firstFilePart.key))(new RuntimeException(noDraftMetadataFileUploaded)) draftMetadata <- fromOption(Using(scala.io.Source.fromFile(file.ref.getAbsoluteFile))(_.mkString).toOption)(new RuntimeException(noDraftMetadataFileUploaded)) diff --git a/build.sbt b/build.sbt index 9c397891e..8f9a2236f 100644 --- a/build.sbt +++ b/build.sbt @@ -27,17 +27,17 @@ libraryDependencies ++= Seq( "com.softwaremill.sttp.client" %% "core" % sttpVersion, "com.softwaremill.sttp.client" %% "circe" % sttpVersion, "com.softwaremill.sttp.client" %% "async-http-client-backend-future" % sttpVersion, - "uk.gov.nationalarchives" %% "tdr-graphql-client" % "0.0.190", - "uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.217", - "uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.390", + "uk.gov.nationalarchives" %% "tdr-graphql-client" % "0.0.194", + "uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.220", + "uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.391", "uk.gov.nationalarchives" %% "tdr-metadata-validation" % "0.0.60", - "uk.gov.nationalarchives" %% "s3-utils" % "0.1.215", - "uk.gov.nationalarchives" %% "sns-utils" % "0.1.215", - "ch.qos.logback" % "logback-classic" % "1.5.11", + "uk.gov.nationalarchives" %% "s3-utils" % "0.1.221", + "uk.gov.nationalarchives" %% "sns-utils" % "0.1.221", + "ch.qos.logback" % "logback-classic" % "1.5.12", ws, - "io.opentelemetry" % "opentelemetry-api" % "1.43.0", - "io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.43.0", - "io.opentelemetry" % "opentelemetry-sdk" % "1.43.0", + "io.opentelemetry" % "opentelemetry-api" % "1.44.1", + "io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.44.1", + "io.opentelemetry" % "opentelemetry-sdk" % "1.44.1", "io.opentelemetry" % "opentelemetry-extension-aws" % "1.20.1", "io.opentelemetry" % "opentelemetry-sdk-extension-aws" % "1.19.0", "io.opentelemetry.contrib" % "opentelemetry-aws-xray" % "1.40.0", @@ -48,8 +48,8 @@ libraryDependencies ++= Seq( ) libraryDependencies += "org.scala-lang.modules" %% "scala-java8-compat" % "1.0.2" -dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.17.0" -dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.17.0" +dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-databind" % "2.17.3" +dependencyOverrides += "com.fasterxml.jackson.core" % "jackson-core" % "2.17.3" disablePlugins(PlayLogback) scalacOptions ++= Seq("-language:implicitConversions") diff --git a/project/build.properties b/project/build.properties index caeacc5ee..c7450fc2a 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.10.3 \ No newline at end of file +sbt.version=1.10.5 \ No newline at end of file diff --git a/test/controllers/DraftMetadataUploadControllerSpec.scala b/test/controllers/DraftMetadataUploadControllerSpec.scala index 2c81ef6b9..1f4bdde14 100644 --- a/test/controllers/DraftMetadataUploadControllerSpec.scala +++ b/test/controllers/DraftMetadataUploadControllerSpec.scala @@ -15,7 +15,7 @@ import play.api.mvc.{MultipartFormData, Result} import play.api.test.CSRFTokenHelper._ import play.api.test.Helpers.{status => playStatus, _} import play.api.test.{FakeHeaders, FakeRequest} -import services.{ConsignmentService, DraftMetadataService, FileError, UploadService} +import services.{ConsignmentService, ConsignmentStatusService, DraftMetadataService, FileError, UploadService} import software.amazon.awssdk.services.s3.model.PutObjectResponse import testUtils.FrontEndTestHelper @@ -41,7 +41,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper { wiremockServer.stop() } - "DraftMetadataUploadControllerSpec GET" should { + "DraftMetadataUploadController GET" should { "render 'draft metadata upload' page when 'blockDraftMetadataUpload' set to 'false'" in { val controller = instantiateDraftMetadataUploadController(blockDraftMetadataUpload = false) @@ -101,12 +101,15 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper { .apply(FakeRequest(GET, "/draft-metadata/upload").withCSRFToken) playStatus(draftMetadataUploadPage) mustBe FORBIDDEN } + } + "DraftMetadataUploadController saveDraftMetadata" should { "redirect to draft metadata checks page when upload successful" in { val uploadServiceMock = mock[UploadService] when(configuration.get[String]("draftMetadata.fileName")).thenReturn(uploadFilename) val putObjectResponse = PutObjectResponse.builder().eTag("testEtag").build() when(uploadServiceMock.uploadDraftMetadata(anyString, anyString, anyString)).thenReturn(Future.successful(putObjectResponse)) + setUpdateConsignmentStatus(wiremockServer) val draftMetadataServiceMock = mock[DraftMetadataService] when(draftMetadataServiceMock.triggerDraftMetadataValidator(any[UUID], anyString, anyString)).thenReturn(Future.successful(true)) @@ -163,6 +166,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper { val applicationConfig: ApplicationConfig = new ApplicationConfig(configuration) val graphQLConfiguration = new GraphQLConfiguration(app.configuration) val consignmentService = new ConsignmentService(graphQLConfiguration) + val consignmentStatusService = new ConsignmentStatusService(graphQLConfiguration) new DraftMetadataUploadController( securityComponents, @@ -171,6 +175,7 @@ class DraftMetadataUploadControllerSpec extends FrontEndTestHelper { consignmentService, uploadService, draftMetadataService, + consignmentStatusService, applicationConfig ) }