diff --git a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessor.scala b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessor.scala index 7537167226..cccc4989a7 100644 --- a/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessor.scala +++ b/ship/src/main/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessor.scala @@ -30,8 +30,6 @@ import ch.epfl.bluebrain.nexus.ship.files.FileWiring._ import ch.epfl.bluebrain.nexus.ship.storages.StorageWiring import io.circe.Decoder -import java.time.Instant - class FileProcessor private ( files: Files, projectMapper: ProjectMapper, @@ -73,7 +71,7 @@ class FileProcessor private ( val newMediaType = patchMediaType(attrs.filename, attrs.mediaType) val newAttrs = e.attributes.copy(mediaType = newMediaType) val customMetadata = Some(getCustomMetadata(newAttrs)) - val fct = forceMediaType(attrs.mediaType, e.instant, newMediaType) + val fct = forceMediaType(attrs.mediaType, newMediaType) fileCopier.copyFile(e.project, newAttrs, fct).flatMap { case FileCopySuccess(newPath) => val linkRequest = FileLinkRequest(newPath, newMediaType, customMetadata) @@ -87,7 +85,7 @@ class FileProcessor private ( val newMediaType = patchMediaType(attrs.filename, attrs.mediaType) val newAttrs = e.attributes.copy(mediaType = newMediaType) val customMetadata = Some(getCustomMetadata(newAttrs)) - val fct = forceMediaType(attrs.mediaType, e.instant, newMediaType) + val fct = forceMediaType(attrs.mediaType, newMediaType) fileCopier.copyFile(e.project, newAttrs, fct).flatMap { case FileCopySuccess(newPath) => val linkRequest = FileLinkRequest(newPath, newMediaType, customMetadata) @@ -139,21 +137,10 @@ object FileProcessor { .map(ContentType(_, () => HttpCharsets.`UTF-8`)) .orElse(original) - private val pngMediaType = Some("image/png") - private val tiffMediaType = Some("image/tiff") - private val instant = Instant.parse("2021-04-11T19:19:16.579Z") - def forceMediaType( originalMediaType: Option[ContentType], - eventInstant: Instant, newMediaType: Option[ContentType] - ) = { - val originalMediaTypeAsString = originalMediaType.map(_.toString()) - (originalMediaType != newMediaType) || - eventInstant.isBefore(instant) && - (originalMediaTypeAsString == pngMediaType || - originalMediaTypeAsString == tiffMediaType) - } + ): Boolean = originalMediaType != newMediaType private val noop = new EventProcessor[FileEvent] { override def resourceType: EntityType = Files.entityType diff --git a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessorSuite.scala b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessorSuite.scala index 4a82c316b8..c4b1ebd0c4 100644 --- a/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessorSuite.scala +++ b/ship/src/test/scala/ch/epfl/bluebrain/nexus/ship/files/FileProcessorSuite.scala @@ -4,8 +4,6 @@ import akka.http.scaladsl.model.{ContentTypes, MediaTypes} import ch.epfl.bluebrain.nexus.delta.kernel.http.MediaTypeDetectorConfig import ch.epfl.bluebrain.nexus.testkit.mu.NexusSuite -import java.time.Instant - class FileProcessorSuite extends NexusSuite { implicit private val mediaTypeDetector: MediaTypeDetectorConfig = MediaTypeDetectorConfig( @@ -31,41 +29,18 @@ class FileProcessorSuite extends NexusSuite { assertEquals( FileProcessor.forceMediaType( Some(ContentTypes.`application/octet-stream`), - Instant.now, Some(ContentTypes.`application/json`) ), true ) } - test("Patching media type for a png file older than the given instant") { - val imagePng = MediaTypes.`image/png`.toContentType - assertEquals( - FileProcessor.forceMediaType(Some(imagePng), Instant.parse("2021-04-11T19:19:16.578Z"), Some(imagePng)), - true - ) - } - - test("Not patching media type for a png file after the given instant") { - val imagePng = MediaTypes.`image/png`.toContentType + test("Patching media type for a media type that does not change") { assertEquals( - FileProcessor.forceMediaType(Some(imagePng), Instant.parse("2021-04-11T19:19:16.580Z"), Some(imagePng)), - false - ) - } - - test("Patching media type for a tiff file older than the given instant") { - val imageTiff = MediaTypes.`image/tiff`.toContentType - assertEquals( - FileProcessor.forceMediaType(Some(imageTiff), Instant.parse("2021-04-11T19:19:16.578Z"), Some(imageTiff)), - true - ) - } - - test("Not patching media type for a fiff file after the given instant") { - val imageTiff = MediaTypes.`image/tiff`.toContentType - assertEquals( - FileProcessor.forceMediaType(Some(imageTiff), Instant.parse("2021-04-11T19:19:16.580Z"), Some(imageTiff)), + FileProcessor.forceMediaType( + Some(ContentTypes.`application/json`), + Some(ContentTypes.`application/json`) + ), false ) }