Skip to content

Commit

Permalink
New service methods to add uploaded metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJKing committed Mar 12, 2024
1 parent 4fe2814 commit c99b411
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ class FileMetadataService(

def getSumOfFileSizes(consignmentId: UUID): Future[Long] = fileMetadataRepository.getSumOfFileSizes(consignmentId)

def updateFileMetadata(consignmentId: UUID, input: AddFileMetadataWithFileIdInput, userId: UUID): Future[List[FileMetadataWithFileId]] = {
val inputValues = input.metadataInputValues
val fileIds = inputValues.map(_.fileId)
val propertyNames = inputValues.map(_.filePropertyName)
val deleteFileMetadataInput = DeleteFileMetadataInput(fileIds, propertyNames, consignmentId)

for {
//Need to delete safely, ie reset to default values. Should probably not validate statuses as will do that when adding the metadata back in?
_ <- deleteFileMetadata(deleteFileMetadataInput, userId)
result <- addFileMetadata(input, userId)
_ <- updateMetadataStatuses(fileIds.toSet, propertyNames.toSet, consignmentId)
} yield result
}

def addFileMetadata(input: AddFileMetadataWithFileIdInput, userId: UUID): Future[List[FileMetadataWithFileId]] = {
val metadataRow = input.metadataInputValues
.map(addFileMetadataInput => {
Expand Down Expand Up @@ -97,6 +111,13 @@ class FileMetadataService(
} yield DeleteFileMetadata(fileIds.toSeq, allPropertiesToDelete.toSeq)
}

private def updateMetadataStatuses(uniqueFileIds: Set[UUID], uniquePropertyNames: Set[String], consignmentId: UUID) = {
for {
updatedFileStatuses <- validateFileMetadataService.validateAndAddAdditionalMetadataStatuses(uniqueFileIds, uniquePropertyNames)
updatedConsignmentStatuses <- consignmentStatusService.updateMetadataConsignmentStatus(consignmentId, List(DescriptiveMetadata, ClosureMetadata))
} yield (updatedFileStatuses, updatedConsignmentStatuses)
}

private def descriptionDeletionHandler(originalPropertyNames: Seq[String]): Seq[String] = {
// Ensure that the file metadata is returned to the correct state if the 'description' property is deleted
// Cannot have a 'DescriptionAlternate' property without a 'description' property
Expand Down

0 comments on commit c99b411

Please sign in to comment.