From 34c40477133462850610d100515e8898dba2c265 Mon Sep 17 00:00:00 2001 From: TomJKing Date: Thu, 31 Oct 2024 13:15:48 +0000 Subject: [PATCH] Handle errors for duplicate columns --- app/controllers/DraftMetadataChecksResultsController.scala | 7 +++++-- app/services/DraftMetadataService.scala | 2 +- conf/messages | 2 ++ .../DraftMetadataChecksResultsControllerSpec.scala | 7 +++++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/controllers/DraftMetadataChecksResultsController.scala b/app/controllers/DraftMetadataChecksResultsController.scala index a8e92bdc0..bc3072843 100644 --- a/app/controllers/DraftMetadataChecksResultsController.scala +++ b/app/controllers/DraftMetadataChecksResultsController.scala @@ -97,8 +97,11 @@ class DraftMetadataChecksResultsController @Inject() ( private def getAffectedProperties(errorReport: Option[ErrorFileData]): Set[String] = { errorReport match { - case Some(er) if er.fileError == FileError.SCHEMA_REQUIRED => errorReport.get.validationErrors.flatMap(_.errors.map(_.property)).toSet - case _ => Set() + case Some(er) + if er.fileError == FileError.SCHEMA_REQUIRED + || er.fileError == FileError.DUPLICATE_HEADER => + errorReport.get.validationErrors.flatMap(_.errors.map(_.property)).toSet + case _ => Set() } } diff --git a/app/services/DraftMetadataService.scala b/app/services/DraftMetadataService.scala index aca45c3dc..4dc837c4d 100644 --- a/app/services/DraftMetadataService.scala +++ b/app/services/DraftMetadataService.scala @@ -17,7 +17,7 @@ import scala.concurrent.{ExecutionContext, Future} object FileError extends Enumeration { type FileError = Value - val UTF_8, INVALID_CSV, SCHEMA_REQUIRED, SCHEMA_VALIDATION, VIRUS, UNKNOWN, NONE = Value + val UTF_8, INVALID_CSV, DUPLICATE_HEADER, SCHEMA_REQUIRED, SCHEMA_VALIDATION, VIRUS, UNKNOWN, NONE = Value } case class Error(validationProcess: String, property: String, errorKey: String, message: String) diff --git a/conf/messages b/conf/messages index bf7523def..27cb633bb 100644 --- a/conf/messages +++ b/conf/messages @@ -46,3 +46,5 @@ draftMetadata.validation.details.VIRUS=A virus was found in your metadata file. draftMetadata.validation.action.VIRUS=Please get in touch on tdr@nationalarchives.gov.uk, so that we can validate this before contacting your own internal support. draftMetadata.validation.details.SCHEMA_REQUIRED=There was at least one missing column in your metadata file. The metadata file must contain specific column headers. draftMetadata.validation.action.SCHEMA_REQUIRED=Add the following column headers to your metadata file and re-load. +draftMetadata.validation.details.DUPLICATE_HEADER=There was at least one duplicate column in your metadata file. +draftMetadata.validation.action.DUPLICATE_HEADER=Ensure there is only one of the following duplicated columns. diff --git a/test/controllers/DraftMetadataChecksResultsControllerSpec.scala b/test/controllers/DraftMetadataChecksResultsControllerSpec.scala index bf2496a37..0b6aa6f04 100644 --- a/test/controllers/DraftMetadataChecksResultsControllerSpec.scala +++ b/test/controllers/DraftMetadataChecksResultsControllerSpec.scala @@ -198,6 +198,13 @@ class DraftMetadataChecksResultsControllerSpec extends FrontEndTestHelper { "There was at least one missing column in your metadata file. The metadata file must contain specific column headers.", "Add the following column headers to your metadata file and re-load.", Set("Closure Status", "Description") + ), + ( + CompletedWithIssuesValue.value, + FileError.DUPLICATE_HEADER, + "There was at least one duplicate column in your metadata file.", + "Ensure there is only one of the following duplicated columns.", + Set("Closure Status", "Description") ) ) forAll(draftMetadataStatuses) { (statusValue, fileError, detailsMessage, actionMessage, affectedProperties) =>