Skip to content

Commit

Permalink
Merge branch 'master' into TDRD-470-Content-Update
Browse files Browse the repository at this point in the history
  • Loading branch information
vimleshtna authored Sep 19, 2024
2 parents d753ae0 + 5a09323 commit 6106928
Show file tree
Hide file tree
Showing 21 changed files with 168 additions and 102 deletions.
2 changes: 1 addition & 1 deletion app/controllers/DownloadMetadataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DownloadMetadataController @Inject() (
}
}

val excelFile = ExcelUtils.writeExcel(metadata.consignmentReference, header :: fileMetadataRows, dataTypes)
val excelFile = ExcelUtils.writeExcel(s"Metadata for ${metadata.consignmentReference}", header :: fileMetadataRows, dataTypes)
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss")
val currentDateTime = dateTimeFormatter.format(LocalDateTime.now())
val excelContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Expand Down
33 changes: 31 additions & 2 deletions app/controllers/DraftMetadataChecksResultsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package controllers

import auth.TokenSecurity
import configuration.{ApplicationConfig, KeycloakConfiguration}
import controllers.util.ExcelUtils
import controllers.util.MetadataProperty.filePath
import graphql.codegen.GetConsignmentStatus.getConsignmentStatus.GetConsignment
import org.pac4j.play.scala.SecurityComponents
import play.api.i18n.{I18nSupport, Messages}
import play.api.mvc.{Action, AnyContent, Request}
import services.FileError.SCHEMA_VALIDATION
import services.Statuses._
import services.{FileError, _}
import viewsapi.Caching.preventCaching

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.UUID
import javax.inject.{Inject, Singleton}
import scala.concurrent.{ExecutionContext, Future}
Expand Down Expand Up @@ -86,8 +91,8 @@ class DraftMetadataChecksResultsController @Inject() (

private def isErrorReportAvailable(fileError: FileError.FileError): Boolean = {
fileError match {
case FileError.SCHEMA_VALIDATION => true
case _ => false
case SCHEMA_VALIDATION => true
case _ => false
}
}

Expand All @@ -103,6 +108,30 @@ class DraftMetadataChecksResultsController @Inject() (
Future.successful(FileError.UNKNOWN)
}
}

def downloadErrorReport(consignmentId: UUID): Action[AnyContent] = standardUserAndTypeAction(consignmentId) { implicit request: Request[AnyContent] =>
for {
reference <- consignmentService.getConsignmentRef(consignmentId, request.token.bearerAccessToken)
errorReport <- draftMetadataService.getErrorReport(consignmentId)
} yield {
val errorList = errorReport.fileError match {
case SCHEMA_VALIDATION =>
errorReport.validationErrors.flatMap { validationErrors =>
val data = validationErrors.data.map(metadata => metadata.name -> metadata.value).toMap
validationErrors.errors.map(error => List(data(filePath), error.property, data(error.property), error.message))
}
case _ => Nil
}
val header: List[String] = List(filePath, "Field", "Value", "Error Message")
val excelFile = ExcelUtils.writeExcel(s"Error report for $reference", header :: errorList)
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss")
val currentDateTime = dateTimeFormatter.format(LocalDateTime.now())
val excelContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
Ok(excelFile)
.as(excelContentType)
.withHeaders("Content-Disposition" -> s"attachment; filename=ErrorReport-${reference}-$currentDateTime.xlsx")
}
}
}

case class DraftMetadataProgress(value: String, colour: String)
1 change: 1 addition & 0 deletions app/controllers/util/CustomMetadataUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ object MetadataProperty {
val former_reference = "former_reference_department"
val language = "Language"
val filenameTranslated = "file_name_translation"
val filePath = "Filepath"
}
4 changes: 2 additions & 2 deletions app/controllers/util/ExcelUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import java.time.LocalDate

object ExcelUtils {

def writeExcel(consignmentRef: String, rows: List[List[Any]], dataTypes: List[DataType]): Array[Byte] = {
def writeExcel(worksheetName: String, rows: List[List[Any]], dataTypes: List[DataType] = Nil): Array[Byte] = {
val xlBas = new ByteArrayOutputStream()
val wb = new Workbook(xlBas, "TNA - Transfer Digital Records", "1.0")
val ws: Worksheet = wb.newWorksheet(s"Metadata for ${consignmentRef}")
val ws: Worksheet = wb.newWorksheet(worksheetName)

rows.head.zipWithIndex.foreach { case (header, col) =>
ws.value(0, col, header.toString)
Expand Down
13 changes: 9 additions & 4 deletions app/services/DraftMetadataService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DraftMetadataService @Inject() (val wsClient: WSClient, val configuration:
implicit val executionContext: ExecutionContext
) extends Logging {

implicit val FileErrorDecoder: Decoder[FileError.Value] = Decoder.decodeEnumeration(FileError)

def triggerDraftMetadataValidator(consignmentId: UUID, uploadFileName: String, token: String): Future[Boolean] = {
val url = s"${configuration.get[String]("metadatavalidation.baseUrl")}/draft-metadata/validate/$consignmentId/$uploadFileName"
wsClient
Expand All @@ -45,15 +47,18 @@ class DraftMetadataService @Inject() (val wsClient: WSClient, val configuration:
}

def getErrorTypeFromErrorJson(consignmentId: UUID): Future[FileError.FileError] = {
implicit val FileErrorDecoder: Decoder[FileError.Value] = Decoder.decodeEnumeration(FileError)
getErrorReport(consignmentId).map(_.fileError)
}

def getErrorReport(consignmentId: UUID): Future[ErrorFileData] = {
val errorFile: Future[ResponseBytes[GetObjectResponse]] =
downloadService.downloadFile(applicationConfig.draft_metadata_s3_bucket_name, s"$consignmentId/${applicationConfig.draftMetadataErrorFileName}")

val unknownError = ErrorFileData(consignmentId, date = "", FileError.UNKNOWN, validationErrors = Nil)
errorFile
.map(responseBytes => {
val errorJson = new String(responseBytes.asByteArray(), StandardCharsets.UTF_8)
decode[ErrorFileData](errorJson).fold(_ => FileError.UNKNOWN, errorFileData => errorFileData.fileError)
decode[ErrorFileData](errorJson).getOrElse(unknownError)
})
.recoverWith(_ => Future.successful(FileError.UNKNOWN))
.recoverWith(_ => Future.successful(unknownError))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@
@import java.util.UUID
@(consignmentId: UUID, consignmentRef: String, name: String, actionMessage: String, detailsMessage: String)(implicit request: RequestHeader, messages: Messages)

@main("Results of CSV Checks", name = name) {
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
@draftMetadataChecksActionProcess(actionMessage, detailsMessage)
@main("Results of CSV Checks", name = name) {
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
@draftMetadataChecksActionProcess(actionMessage, detailsMessage)

<p class="govuk-body">The report below contains details about issues found.</p>
<p class="govuk-body">The report below contains details about issues found.</p>

<button class="govuk-button govuk-button--secondary govuk-!-margin-bottom-8" data-module="govuk-button">
<span aria-hidden="true" class="tna-button-icon tna-button-icon--download">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 23 23">
<path fill="#020202" d="m11.5 16.75-6.563-6.563 1.838-1.903 3.412 3.413V1h2.626v10.697l3.412-3.413 1.837 1.903L11.5 16.75ZM3.625 22c-.722 0-1.34-.257-1.853-.77A2.533 2.533 0 0 1 1 19.375v-3.938h2.625v3.938h15.75v-3.938H22v3.938c0 .722-.257 1.34-.77 1.855a2.522 2.522 0 0 1-1.855.77H3.625Z"/>
</svg>
</span>
Download report
</button>

<p class="govuk-body">Once you have addressed this issue upload a revised metadata file.</p>

<div class="govuk-button-group">
<a class="govuk-button" href="@{
routes.DraftMetadataUploadController.draftMetadataUploadPage(consignmentId)
}" role="button" draggable="false" data-module="govuk-button">Re-upload metadata</a>
</div>
@downloadMetadataLink(consignmentId, "Download report", routes.DraftMetadataChecksResultsController.downloadErrorReport(consignmentId).url)
<p class="govuk-body">Once you have addressed this issue upload a revised metadata file.</p>

<div class="govuk-button-group">
<a class="govuk-button" href="@{
routes.DraftMetadataUploadController.draftMetadataUploadPage(consignmentId)
}" role="button" draggable="false" data-module="govuk-button">Re-upload metadata</a>
</div>
@transferReference(consignmentRef, isJudgmentUser = false)

</div>
}
@transferReference(consignmentRef, isJudgmentUser = false)
</div>
}
2 changes: 1 addition & 1 deletion app/views/draftmetadata/draftMetadataUpload.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 class="govuk-heading-l">Upload a metadata CSV</h1>
<p>In your CSV, include a header row for the column titles and one row for every record that requires metadata.</p>
</div>
<div>
@downloadMetadataLink(consignmentId, "Download metadata Excel template")
@downloadMetadataLink(consignmentId, "Download metadata Excel template", routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)
</div>

<div class="govuk-form-group">
Expand Down
4 changes: 2 additions & 2 deletions app/views/partials/downloadMetadataLink.scala.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import java.util.UUID
@(consignmentId: UUID, linkLabel: String = "Download metadata")
<a class="govuk-button govuk-button--secondary govuk-!-margin-bottom-8 download-metadata" href="/consignment/@consignmentId/additional-metadata/download-metadata/csv">
@(consignmentId: UUID, linkLabel: String = "Download metadata", url: String)
<a class="govuk-button govuk-button--secondary govuk-!-margin-bottom-8 download-metadata" href="@url">
<span aria-hidden="true" class="tna-button-icon">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 23 23">
<path fill="#020202" d="m11.5 16.75-6.563-6.563 1.838-1.903 3.412 3.413V1h2.626v10.697l3.412-3.413 1.837 1.903L11.5 16.75ZM3.625 22c-.722 0-1.34-.257-1.853-.77A2.533 2.533 0 0 1 1 19.375v-3.938h2.625v3.938h15.75v-3.938H22v3.938c0 .722-.257 1.34-.77 1.855a2.522 2.522 0 0 1-1.855.77H3.625Z"></path>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/metadataReviewFailure.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ <h2 class="da-alert__heading">We found issues in your metadata</h2>

<p class="govuk-body">Follow the guidance to amend your metadata. You can download a copy of the metadata we reviewed below.</p>

@downloadMetadataLink(consignmentId)
@downloadMetadataLink(consignmentId, url = routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)

<div class="govuk-button-group">
<a class="govuk-button" href="@routes.AdditionalMetadataController.start(consignmentId)" role="button" draggable="false" data-module="govuk-button">
Expand Down
2 changes: 1 addition & 1 deletion app/views/partials/metadataReviewInProgress.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h2 class="da-alert__heading">Your review is in progress</h2>

<p class="govuk-body">Download a copy of the metadata you submitted below.</p>

@downloadMetadataLink(consignmentId)
@downloadMetadataLink(consignmentId, url = routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)

<p class="govuk-body">
If you have any queries email <a href="mailto:@Messages("nationalArchives.email")">@Messages("nationalArchives.email")</a>
Expand Down
2 changes: 1 addition & 1 deletion app/views/standard/downloadMetadata.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h1 class="govuk-heading-l">Download and review metadata</h1>
<p class="govuk-body">
You can review the metadata added to your records by downloading the CSV file. If you would like to add or amend the metadata, return to the previous step.
</p>
@downloadMetadataLink(consignmentId)
@downloadMetadataLink(consignmentId, url = routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)
</div>
<div class="govuk-button-group">
@if(blockMetadataReview) {
Expand Down
2 changes: 1 addition & 1 deletion app/views/standard/transferComplete.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1 class="govuk-panel__title">
<p class="govuk-body">Your records are not yet preserved so you must not delete the original records.</p>

<p class="govuk-body">
@downloadMetadataLink(consignmentId)
@downloadMetadataLink(consignmentId, url = routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)
</p>

<h2 class="govuk-heading-m">What happens next</h2>
Expand Down
2 changes: 1 addition & 1 deletion app/views/tna/metadataReviewAction.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 class="govuk-label-wrapper">
</label>
</h2>

@downloadMetadataLink(consignmentId)
@downloadMetadataLink(consignmentId, url = routes.DownloadMetadataController.downloadMetadataFile(consignmentId).url)

@if(isTransferAdvisor) {
<h2 class="govuk-label-wrapper">
Expand Down
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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.179",
"uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.212",
"uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.386",
"uk.gov.nationalarchives" %% "tdr-metadata-validation" % "0.0.53",
"uk.gov.nationalarchives" %% "s3-utils" % "0.1.204",
"uk.gov.nationalarchives" %% "sns-utils" % "0.1.204",
"uk.gov.nationalarchives" %% "tdr-graphql-client" % "0.0.180",
"uk.gov.nationalarchives" %% "tdr-auth-utils" % "0.0.213",
"uk.gov.nationalarchives" %% "tdr-generated-graphql" % "0.0.387",
"uk.gov.nationalarchives" %% "tdr-metadata-validation" % "0.0.55",
"uk.gov.nationalarchives" %% "s3-utils" % "0.1.205",
"uk.gov.nationalarchives" %% "sns-utils" % "0.1.205",
"ch.qos.logback" % "logback-classic" % "1.5.8",
ws,
"io.opentelemetry" % "opentelemetry-api" % "1.42.0",
"io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.42.0",
"io.opentelemetry" % "opentelemetry-sdk" % "1.42.0",
"io.opentelemetry" % "opentelemetry-api" % "1.42.1",
"io.opentelemetry" % "opentelemetry-exporter-otlp" % "1.42.1",
"io.opentelemetry" % "opentelemetry-sdk" % "1.42.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.38.0",
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ GET /consignment/:consignmentId/draft-metadata/upload
GET /consignment/:consignmentId/draft-metadata/checks controllers.DraftMetadataChecksController.draftMetadataChecksPage(consignmentId: java.util.UUID)
POST /consignment/:consignmentId/draft-metadata/validation-progress controllers.DraftMetadataChecksController.draftMetadataValidationProgress(consignmentId: java.util.UUID)
GET /consignment/:consignmentId/draft-metadata/checks-results controllers.DraftMetadataChecksResultsController.draftMetadataChecksResultsPage(consignmentId: java.util.UUID)
GET /consignment/:consignmentId/draft-metadata/download-report controllers.DraftMetadataChecksResultsController.downloadErrorReport(consignmentId: java.util.UUID)
GET /consignment/:consignmentId/metadata-review/request controllers.RequestMetadataReviewController.requestMetadataReviewPage(consignmentId: java.util.UUID)
POST /consignment/:consignmentId/metadata-review/request controllers.RequestMetadataReviewController.submitMetadataForReview(consignmentId: java.util.UUID)
GET /consignment/:consignmentId/metadata-review/review-progress controllers.MetadataReviewStatusController.metadataReviewStatusPage(consignmentId: java.util.UUID)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.10.1
sbt.version=1.10.2
Loading

0 comments on commit 6106928

Please sign in to comment.