Skip to content

Commit ec46ec2

Browse files
committed
only set Photographer usage rights if no other processor has set usage rights first
1 parent e679789 commit ec46ec2

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

common-lib/src/main/scala/com/gu/mediaservice/lib/cleanup/SupplierProcessors.scala

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class SupplierProcessors(resources: ImageProcessorResources)
2222
ReutersParser,
2323
RexParser,
2424
RonaldGrantParser,
25-
new PhotographerParser(resources.commonConfiguration.usageRightsConfig),
2625
AllstarSportsphotoParser,
2726
AllStarParser,
27+
new PhotographerParser(resources.commonConfiguration.usageRightsConfig),
2828
UsageRightsToMetadataParser(resources) //This should come after processors that assign usage rights
2929
)
3030

@@ -52,21 +52,24 @@ case class UsageRightsToMetadataParser(resources: ImageProcessorResources) exten
5252
* Guardian specific logic to correctly identify Guardian and Observer photographers and their contracts
5353
*/
5454
class PhotographerParser(photographersConfig: UsageRightsConfigProvider) extends ImageProcessor {
55-
def apply(image: Image): Image = {
56-
image.metadata.byline.flatMap { byline =>
57-
photographersConfig.getPhotographer(byline, image.metadata.dateTaken.getOrElse(image.uploadTime)).map{
58-
case p: StaffPhotographer => image.copy(
59-
usageRights = p,
60-
metadata = image.metadata.copy(credit = Some(p.publication), byline = Some(p.photographer))
61-
)
62-
case p: ContractPhotographer => image.copy(
63-
usageRights = p,
64-
metadata = image.metadata.copy(credit = p.publication, byline = Some(p.photographer))
65-
)
66-
case _ => image
67-
}
68-
}
69-
}.getOrElse(image)
55+
def apply(image: Image): Image = image.usageRights match {
56+
// only attempt to set Photographer Usagerights if no other processor has already set usage rights
57+
case NoRights =>
58+
image.metadata.byline.flatMap { byline =>
59+
photographersConfig.getPhotographer(byline, image.metadata.dateTaken.getOrElse(image.uploadTime)).map{
60+
case p: StaffPhotographer => image.copy(
61+
usageRights = p,
62+
metadata = image.metadata.copy(credit = Some(p.publication), byline = Some(p.photographer))
63+
)
64+
case p: ContractPhotographer => image.copy(
65+
usageRights = p,
66+
metadata = image.metadata.copy(credit = p.publication, byline = Some(p.photographer))
67+
)
68+
case _ => image
69+
}
70+
}.getOrElse(image)
71+
case _ => image
72+
}
7073
}
7174

7275
object AapParser extends ImageProcessor {

0 commit comments

Comments
 (0)