Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class SupplierProcessors(resources: ImageProcessorResources)
ReutersParser,
RexParser,
RonaldGrantParser,
new PhotographerParser(resources.commonConfiguration.usageRightsConfig),
AllstarSportsphotoParser,
AllStarParser,
new PhotographerParser(resources.commonConfiguration.usageRightsConfig),
UsageRightsToMetadataParser(resources) //This should come after processors that assign usage rights
)

Expand Down Expand Up @@ -52,21 +52,24 @@ case class UsageRightsToMetadataParser(resources: ImageProcessorResources) exten
* Guardian specific logic to correctly identify Guardian and Observer photographers and their contracts
*/
class PhotographerParser(photographersConfig: UsageRightsConfigProvider) extends ImageProcessor {
def apply(image: Image): Image = {
image.metadata.byline.flatMap { byline =>
photographersConfig.getPhotographer(byline, image.metadata.dateTaken.getOrElse(image.uploadTime)).map{
case p: StaffPhotographer => image.copy(
usageRights = p,
metadata = image.metadata.copy(credit = Some(p.publication), byline = Some(p.photographer))
)
case p: ContractPhotographer => image.copy(
usageRights = p,
metadata = image.metadata.copy(credit = p.publication, byline = Some(p.photographer))
)
case _ => image
}
}
}.getOrElse(image)
def apply(image: Image): Image = image.usageRights match {
// only attempt to set Photographer Usagerights if no other processor has already set usage rights
case NoRights =>
image.metadata.byline.flatMap { byline =>
photographersConfig.getPhotographer(byline, image.metadata.dateTaken.getOrElse(image.uploadTime)).map{
case p: StaffPhotographer => image.copy(
usageRights = p,
metadata = image.metadata.copy(credit = Some(p.publication), byline = Some(p.photographer))
)
case p: ContractPhotographer => image.copy(
usageRights = p,
metadata = image.metadata.copy(credit = p.publication, byline = Some(p.photographer))
)
case _ => image
}
}.getOrElse(image)
case _ => image
}
}

object AapParser extends ImageProcessor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ class SupplierProcessorsTest extends AnyFunSpec with Matchers with MetadataHelpe
processedImage.usageRights should be(ContractPhotographer("Murdo MacLeod", Option("The Guardian")))
processedImage.metadata.byline should be(Some("Murdo MacLeod"))
}

it("should only assign Photographer rights if agency rights not already assigned") {
val image = createImageFromMetadata(
"byline" -> "Murdo MacLeod",
"credit" -> "PA Wire/PA Images"
)
val processedImage = applyProcessors(image)
// UsageRights assigned to PA agency rather than ContractPhotographer("Murdo MacLeod") as PA
// runs first, and Staff/ContractPhotographer only assign rights if nothing else has first.
processedImage.usageRights should be(Agency("PA"))
processedImage.metadata.byline should be(Some("Murdo MacLeod"))
}
}

describe("AAP") {
Expand Down
Loading