-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4143 from guardian/reaper/move-is-reapable-to-common
- Loading branch information
Showing
10 changed files
with
93 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
common-lib/src/main/scala/com/gu/mediaservice/lib/elasticsearch/PersistedQueries.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.gu.mediaservice.lib.elasticsearch | ||
|
||
import com.gu.mediaservice.lib.ImageFields | ||
import com.gu.mediaservice.model._ | ||
import scalaz.NonEmptyList | ||
import scalaz.syntax.std.list._ | ||
|
||
object PersistedQueries extends ImageFields { | ||
val photographerCategories = NonEmptyList( | ||
StaffPhotographer.category, | ||
ContractPhotographer.category, | ||
CommissionedPhotographer.category | ||
) | ||
|
||
val illustratorCategories = NonEmptyList( | ||
ContractIllustrator.category, | ||
StaffIllustrator.category, | ||
CommissionedIllustrator.category | ||
) | ||
|
||
val agencyCommissionedCategories = NonEmptyList( | ||
CommissionedAgency.category | ||
) | ||
|
||
val hasCrops = filters.bool.must(filters.existsOrMissing("exports", exists = true)) | ||
val usedInContent = filters.nested("usages", filters.exists(NonEmptyList("usages"))) | ||
|
||
def existedPreGrid(persistenceIdentifier: String) = filters.exists(NonEmptyList(identifierField(persistenceIdentifier))) | ||
|
||
val addedToLibrary = filters.bool.must(filters.boolTerm(editsField("archived"), value = true)) | ||
val hasUserEditsToImageMetadata = filters.exists(NonEmptyList(editsField("metadata"))) | ||
val hasPhotographerUsageRights = filters.bool.must(filters.terms(usageRightsField("category"), photographerCategories)) | ||
val hasIllustratorUsageRights = filters.bool.must(filters.terms(usageRightsField("category"), illustratorCategories)) | ||
val hasAgencyCommissionedUsageRights = filters.bool.must(filters.terms(usageRightsField("category"), agencyCommissionedCategories)) | ||
|
||
def addedGNMArchiveOrPersistedCollections(persistedRootCollections: List[String]) = filters.bool.must(filters.terms(collectionsField("path"), persistedRootCollections.toNel.get)) | ||
|
||
val addedToPhotoshoot = filters.exists(NonEmptyList(editsField("photoshoot"))) | ||
val hasLabels = filters.exists(NonEmptyList(editsField("labels"))) | ||
val hasLeases = filters.exists(NonEmptyList(leasesField("leases"))) | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
common-lib/src/main/scala/com/gu/mediaservice/lib/elasticsearch/ReapableEligibility.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.gu.mediaservice.lib.elasticsearch | ||
|
||
import com.sksamuel.elastic4s.ElasticDsl.matchAllQuery | ||
import com.sksamuel.elastic4s.requests.searches.queries.Query | ||
import org.joda.time.DateTime | ||
|
||
trait ReapableEligibility { | ||
|
||
val persistedRootCollections: List[String] // typically from config | ||
val persistenceIdentifier: String // typically from config | ||
|
||
private def moreThanTwentyDaysOld = | ||
filters.date("uploadTime", None, Some(DateTime.now().minusDays(20))).getOrElse(matchAllQuery()) | ||
|
||
private lazy val persistedQueries = filters.or( | ||
PersistedQueries.hasCrops, | ||
PersistedQueries.usedInContent, | ||
PersistedQueries.addedToLibrary, | ||
PersistedQueries.hasUserEditsToImageMetadata, | ||
PersistedQueries.hasPhotographerUsageRights, | ||
PersistedQueries.hasIllustratorUsageRights, | ||
PersistedQueries.hasAgencyCommissionedUsageRights, | ||
PersistedQueries.addedToPhotoshoot, | ||
PersistedQueries.hasLabels, | ||
PersistedQueries.hasLeases, | ||
PersistedQueries.existedPreGrid(persistenceIdentifier), | ||
PersistedQueries.addedGNMArchiveOrPersistedCollections(persistedRootCollections) | ||
) | ||
|
||
def query: Query = filters.and( | ||
moreThanTwentyDaysOld, | ||
filters.not(persistedQueries) | ||
) | ||
} |
4 changes: 2 additions & 2 deletions
4
...a-api/app/lib/elasticsearch/filters.scala → ...iaservice/lib/elasticsearch/filters.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters