private def leaseHasStarted: Query = filters.or()

in media-api/app/lib/elasticsearch/SyndicationFilter.scala [65:131]


  private def leaseHasStarted: Query = filters.or(
    filters.existsOrMissing("leases.leases.startDate", exists = false),
    filters.date("leases.leases.startDate", None, Some(DateTime.now)).get
  )

  private def leaseHasNotExpired: Query = filters.or(
    filters.existsOrMissing("leases.leases.endDate", exists = false),
    filters.date("leases.leases.endDate", Some(DateTime.now), None).get
  )

  private def syndicationRightsPublished: Query = filters.or(
    filters.existsOrMissing("syndicationRights.published", exists = false),
    filters.date("syndicationRights.published", None, Some(DateTime.now)).get
  )

  private val syndicatableCategory: Query = IsOwnedPhotograph(config.staffPhotographerOrganisation).query

  def statusFilter(status: SyndicationStatus): Query = status match {
    case SentForSyndication => filters.and(
      hasRightsAcquired,
      hasAllowLease,
      hasSyndicationUsage
    )
    case QueuedForSyndication => filters.and(
      hasRightsAcquired,
      filters.mustNot(hasSyndicationUsage),
      filters.and(
        hasAllowLease,
        leaseHasStarted,
        syndicationRightsPublished
      )
    )
    case BlockedForSyndication => filters.and(
      hasRightsAcquired,
      hasDenyLease
    )
    case AwaitingReviewForSyndication => {

      val mustNotClauses = List(
        hasAllowLease,
        filters.and(
          hasDenyLease,
          leaseHasNotExpired
        ),
      ) ++ (
        if(config.useRuntimeFieldsToFixSyndicationReviewQueueQuery)
          List(hasActiveDeny) // this is last, to ensure runtime field is not computed unnecessarily
        else
          Nil
      )

      val rightsAcquiredNoLeaseFilter = filters.and(
        hasRightsAcquired,
        syndicatableCategory,
        filters.mustNot(mustNotClauses:_*),
      )

      config.syndicationStartDate match {
        case Some(date) if config.isProd => filters.and(
          filters.date("uploadTime", Some(date), None).get,
          rightsAcquiredNoLeaseFilter
        )
        case _ => rightsAcquiredNoLeaseFilter
      }
    }
    case UnsuitableForSyndication => noRightsAcquired
  }