Skip to content

Commit

Permalink
TDR-68 CSV Metadata download adjustments (#3768)
Browse files Browse the repository at this point in the history
*Include `clientSideOriginalFilepath` , `clientSideFileLastModifiedDate` `UUID` to the download metadata csv
*Removed time from date.
  • Loading branch information
thanhz authored Mar 7, 2024
1 parent aceecb7 commit 217d9f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
6 changes: 4 additions & 2 deletions app/controllers/DownloadMetadataController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import auth.TokenSecurity
import configuration.KeycloakConfiguration
import controllers.util.CsvUtils
import controllers.util.MetadataProperty.{clientSideFileLastModifiedDate, clientSideOriginalFilepath, fileName, fileUUID}
import graphql.codegen.GetConsignmentFilesMetadata.getConsignmentFilesMetadata.GetConsignment.Files.FileMetadata
import graphql.codegen.GetCustomMetadata.customMetadata.CustomMetadata
import graphql.codegen.types.DataType
Expand Down Expand Up @@ -44,8 +45,9 @@ class DownloadMetadataController @Inject() (
displayProperties <- displayPropertiesService.getDisplayProperties(consignmentId, request.token.bearerAccessToken, None, showInactive = true)
} yield {
val parseFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd[ ]['T']HH:mm:ss[.SSS][.SS][.S]")
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
val nameMap = displayProperties.filter(dp => dp.active || dp.propertyName == "Filename").map(dp => (dp.propertyName, dp.displayName)).toMap
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val systemValues = List(fileUUID, fileName, clientSideOriginalFilepath, clientSideFileLastModifiedDate)
val nameMap = displayProperties.filter(dp => dp.active || systemValues.contains(dp.propertyName)).map(dp => (dp.propertyName, dp.displayName)).toMap
val filteredMetadata: List[CustomMetadata] = customMetadata.filter(cm => nameMap.keySet.contains(cm.name) && cm.allowExport).sortBy(_.exportOrdinal.getOrElse(Int.MaxValue))
val header: List[String] = filteredMetadata.map(f => nameMap.getOrElse(f.name, f.name))
val fileMetadataRows: List[List[String]] = metadata.files.map { file =>
Expand Down
1 change: 1 addition & 0 deletions app/controllers/util/CustomMetadataUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object MetadataProperty {
val closureStartDate = "ClosureStartDate"
val closurePeriod = "ClosurePeriod"
val foiExemptionCode = "FoiExemptionCode"
val fileUUID = "UUID"
val fileName = "Filename"
val titleClosed = "TitleClosed"
val descriptionClosed = "DescriptionClosed"
Expand Down
62 changes: 27 additions & 35 deletions test/controllers/DownloadMetadataControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.{containing, okJson, post, urlEqualTo}
import com.github.tototoshi.csv.CSVReader
import configuration.GraphQLConfiguration
import controllers.util.MetadataProperty.{clientSideFileLastModifiedDate, clientSideOriginalFilepath, fileName, fileUUID}
import graphql.codegen.GetConsignmentFilesMetadata.getConsignmentFilesMetadata.GetConsignment.Files
import graphql.codegen.GetConsignmentFilesMetadata.getConsignmentFilesMetadata.GetConsignment.Files.FileMetadata
import graphql.codegen.GetCustomMetadata.{customMetadata => cm}
Expand Down Expand Up @@ -35,7 +36,7 @@ class DownloadMetadataControllerSpec extends FrontEndTestHelper {
val checkPageForStaticElements = new CheckPageForStaticElements()

def customMetadata(name: String, fullName: String, exportOrdinal: Int = Int.MaxValue, allowExport: Boolean = true): cm.CustomMetadata = {
if (name == "DateTimeProperty") {
if (name == "DateTimeProperty" || name == clientSideFileLastModifiedDate) {
cm.CustomMetadata(name, None, Option(fullName), Supplied, None, DateTime, editable = false, multiValue = false, None, 1, Nil, Option(exportOrdinal), allowExport)
} else if (name.contains("BooleanProperty")) {
cm.CustomMetadata(name, None, Option(fullName), Supplied, None, DataType.Boolean, editable = false, multiValue = false, None, 1, Nil, Option(exportOrdinal), allowExport)
Expand Down Expand Up @@ -65,28 +66,42 @@ class DownloadMetadataControllerSpec extends FrontEndTestHelper {
"DownloadMetadataController downloadMetadataCsv GET" should {
"download the csv for a multiple properties and rows" in {
val lastModified = LocalDateTime.parse("2021-02-03T10:33:30.414")
val uuid1 = UUID.randomUUID().toString
val uuid2 = UUID.randomUUID().toString
val displayProperties = List(
displayProperty("TestProperty1", "Test Property 1 Name"),
displayProperty("TestProperty2", "Test Property 2 Name"),
displayProperty("DateTimeProperty", "Date Time Property Name", DataType.DateTime),
displayProperty("FileName", "File Name")
displayProperty(fileUUID, "UUID"),
displayProperty(fileName, "File Name"),
displayProperty(clientSideOriginalFilepath, "Filepath"),
displayProperty(clientSideFileLastModifiedDate, "Date last modified", DataType.DateTime)
)
val customProperties = List(
customMetadata("TestProperty1", "TestProperty1"),
customMetadata("TestProperty2", "TestProperty2"),
customMetadata("DateTimeProperty", "DateTimeProperty"),
customMetadata("FileName", "FileName")
customMetadata(fileUUID, "UUID"),
customMetadata(fileName, "FileName"),
customMetadata(clientSideOriginalFilepath, "Filepath"),
customMetadata(clientSideFileLastModifiedDate, "Date last modified")
)
val metadataFileOne = List(
FileMetadata("TestProperty1", "TestValue1File1"),
FileMetadata("TestProperty2", "TestValue2File1"),
FileMetadata("DateTimeProperty", lastModified.format(DateTimeFormatter.ISO_DATE_TIME)),
FileMetadata("FileName", "FileName1")
FileMetadata(fileUUID, uuid1),
FileMetadata(fileName, "FileName1"),
FileMetadata(clientSideOriginalFilepath, "test/path1"),
FileMetadata(clientSideFileLastModifiedDate, lastModified.format(DateTimeFormatter.ISO_DATE_TIME))
)
val metadataFileTwo = List(
FileMetadata("TestProperty1", "TestValue1File2"),
FileMetadata("TestProperty2", "TestValue2File2"),
FileMetadata("FileName", "FileName2")
FileMetadata(fileUUID, uuid2),
FileMetadata(fileName, "FileName2"),
FileMetadata(clientSideOriginalFilepath, "test/path2"),
FileMetadata(clientSideFileLastModifiedDate, lastModified.format(DateTimeFormatter.ISO_DATE_TIME))
)
val files = List(
gcfm.GetConsignment.Files(UUID.randomUUID(), Some("FileName"), metadataFileOne, Nil),
Expand All @@ -98,11 +113,17 @@ class DownloadMetadataControllerSpec extends FrontEndTestHelper {
csvList.size must equal(2)
csvList.head("Test Property 1 Name") must equal("TestValue1File1")
csvList.head("Test Property 2 Name") must equal("TestValue2File1")
csvList.head("Date Time Property Name") must equal("2021-02-03T10:33:30")
csvList.head("Date Time Property Name") must equal("2021-02-03")
csvList.head("UUID") must equal(uuid1)
csvList.head("File Name") must equal("FileName1")
csvList.head("Filepath") must equal("test/path1")
csvList.head("Date last modified") must equal("2021-02-03")
csvList.last("Test Property 1 Name") must equal("TestValue1File2")
csvList.last("Test Property 2 Name") must equal("TestValue2File2")
csvList.last("UUID") must equal(uuid2)
csvList.last("File Name") must equal("FileName2")
csvList.last("Filepath") must equal("test/path2")
csvList.last("Date last modified") must equal("2021-02-03")
}

"download the csv for rows with different numbers of metadata" in {
Expand Down Expand Up @@ -173,35 +194,6 @@ class DownloadMetadataControllerSpec extends FrontEndTestHelper {
csvList.head("File Name") must equal("FileName1")
}

"download the csv for datetime rows to include the seconds to the file when the input seconds are zero" in {
val lastModified = LocalDateTime.parse("2021-02-03T10:33:00.0")
val customProperties = List(
customMetadata("TestProperty1", "TestProperty1"),
customMetadata("DateTimeProperty", "DateTimeProperty"),
customMetadata("FileName", "FileName")
)
val displayProperties = List(
displayProperty("TestProperty1", "Test Property 1 Name"),
displayProperty("DateTimeProperty", "Date Time Property Name", DataType.DateTime),
displayProperty("FileName", "File Name")
)
val metadataFileOne = List(
FileMetadata("TestProperty1", "TestValue1File1"),
FileMetadata("DateTimeProperty", lastModified.format(DateTimeFormatter.ISO_DATE_TIME)),
FileMetadata("FileName", "FileName1")
)
val files = List(
gcfm.GetConsignment.Files(UUID.randomUUID(), Some("FileName"), metadataFileOne, Nil)
)

val csvList: List[Map[String, String]] = getCsvFromController(customProperties, files, displayProperties).toLazyListWithHeaders().toList

csvList.size must equal(1)
csvList.head("Test Property 1 Name") must equal("TestValue1File1")
csvList.head("Date Time Property Name") must equal("2021-02-03T10:33:00")
csvList.head("File Name") must equal("FileName1")
}

"ignore fields set with allowExport set to false" in {
val customProperties = List(
customMetadata("TestProperty1", "TestProperty1", allowExport = false),
Expand Down

0 comments on commit 217d9f2

Please sign in to comment.