Class MediaObjects

java.lang.Object
nl.vpro.domain.media.MediaObjects

public class MediaObjects extends Object
Various methods related to dealing with MediaObjects, like copying and filling.

See TextualObjects, and Embargos for methods like this (because media objects are TextualObject and MutableEmbargo

Since:
1.5
  • Field Details

    • autoCorrectPredictions

      public static boolean autoCorrectPredictions
  • Method Details

    • equalsOnAnyId

      public static boolean equalsOnAnyId(MediaObject first, MediaObject second)
    • equalsOnCrid

      public static boolean equalsOnCrid(MediaObject first, MediaObject second)
    • forOwner

      public static void forOwner(MediaObject media, nl.vpro.domain.media.support.OwnerType owner)
      Sets the owner of all titles, descriptions, locations and images found in given MediaObject
    • deepCopy

      public static <T extends MediaObject> T deepCopy(T media)
      Perfomrs of deep copy of the media object, this is currently implemented by serializing/deserializing it.
    • copy

      public static void copy(@NonNull MediaObject from, @NonNull MediaObject to)
      Copies most field values from one media object to another.

      Principally, this should be all fields of which the value logically can exist on more than one mediaobject the same time, so not unique fields like id and mid.

      Also, membership of groups will not be automatically filled. This would need write access on those objects.

      ScheduleEvents, workflow, subtitles status are not copied too, since this would not make sense.

      See Also:
    • copyFull

      public static void copyFull(@NonNull MediaObject from, @NonNull MediaObject to)
      A more full copy, also copying field that you could normally would not copy, like MID.

      The assumption is that both objects are not yet persistent, or e.g. a type conversion is happening

      Since:
      5.11
      See Also:
    • copyFullProgram

      public static void copyFullProgram(@NonNull Program from, @NonNull Program to)
      A more full copy, also copying field that you could normally not copy, like MID.

      The assumption is that both objects are not yet persistent

      Since:
      5.11
    • matchBroadcasters

      public static void matchBroadcasters(BroadcasterService broadcasterService, MediaObject mediaObject) throws NotFoundException
      Throws:
      NotFoundException
    • hasChannel

      public static boolean hasChannel(Program media, Channel... channels)
    • hasChannel

      public static boolean hasChannel(Program media, Collection<Channel> channels)
    • findScheduleEventHonoringOffset

      public static ScheduleEvent findScheduleEventHonoringOffset(Program media, ScheduleEvent source)
    • findScheduleEvent

      public static ScheduleEvent findScheduleEvent(Channel channel, Date start, Collection<ScheduleEvent> events)
    • findScheduleEvent

      public static ScheduleEvent findScheduleEvent(Channel channel, LocalDateTime start, Collection<ScheduleEvent> events)
    • filterScheduleEvents

      public static SortedSet<ScheduleEvent> filterScheduleEvents(Collection<ScheduleEvent> events, Channel... channels)
    • filterScheduleEvents

      public static SortedSet<ScheduleEvent> filterScheduleEvents(Collection<ScheduleEvent> events, Collection<Channel> channelList)
    • getChannel

      public static Channel getChannel(@NonNull Program program)
      Returns the channel associated with this program. That is the channel of the earliest schedule event that is not a rerun.
    • getScheduleEvents

      public static SortedSet<ScheduleEvent> getScheduleEvents(MediaObject media)
      Returns the ScheduleEvents associated with the media object.

      An empty collection for all non programs.

      Since:
      5.11
    • getRelationText

      public static String getRelationText(@NonNull MediaObject object, String relationType)
      Since:
      2.2.3
    • getRelation

      public static Relation getRelation(@NonNull MediaObject object, String relationType)
      Since:
      3.3.0
    • getTwitterHash

      public static TwitterRef getTwitterHash(@NonNull MediaObject object)
    • getTwitterAccount

      public static TwitterRef getTwitterAccount(@NonNull MediaObject object)
    • getKijkwijzer

      public static String getKijkwijzer(@NonNull MediaObject media)
    • idFromUrn

      public static Long idFromUrn(String urn)
    • removeLocations

      public static void removeLocations(@NonNull MediaObject mediaObject)
    • addAll

      public static void addAll(@NonNull MediaObject mediaObject, Iterable<Location> i)
    • getSortInstant

      public static Instant getSortInstant(@NonNull MediaObject mo)
    • trim

      public static boolean trim(@NonNull Collection<?> collection)
    • integrate

      public static <T extends UpdatableIdentifiable<?, T>> void integrate(@NonNull List<T> existing, @NonNull List<T> updates)
    • markForRepublication

      public static boolean markForRepublication(@NonNull MediaObject media, String reason, Object... args)
    • markForDeletionIfNeeded

      public static boolean markForDeletionIfNeeded(@NonNull MediaObject media, @Pattern(regexp="[a-z, ]+",flags=CASE_INSENSITIVE) @Pattern(regexp="[a-z, ]+",flags=CASE_INSENSITIVE) String reason)
    • appendReason

      protected static void appendReason(MediaObject media, String reason, Object... args)
    • markForUnDeletionIfNeeded

      public static boolean markForUnDeletionIfNeeded(@NonNull MediaObject media, String reason)
    • markPublished

      public static void markPublished(@NonNull MediaObject media, @NonNull Instant now)
      Marks the fields of the media object related to publishing as published.

      the last publish instant will be set, and the reason and destinations will be cleared.

      The workflow itself will remain untouched, and would be set to Workflow.PUBLISHED, Workflow.REVOKED or Workflow.MERGED

    • markPublishedAndSetCorrectWorkflow

      public static void markPublishedAndSetCorrectWorkflow(@NonNull MediaObject media, @NonNull Instant now)
      Sets the workflow of the media object to the 'published' state version of the workflow (Workflow.isPublishable() ()}

      And calls markPublished(MediaObject, Instant)

      Since:
      5.20.2
    • getPrediction

      public static Prediction getPrediction(Platform platform, Collection<Prediction> preds)
    • getAvailableLocation

      public static Optional<Location> getAvailableLocation(Platform platform, MediaObject m, Instant now)
      Determines if for a given platform, the media object has a location, and returns (one) if there is. If there is no location for a certain platform the Prediction.getState() should be Prediction.State.REVOKED, Prediction.State.ANNOUNCED or Prediction.State.NOT_ANNOUNCED.

      Otherwise, it must be Prediction.State.REALIZED;

      Since:
      5.32
    • getPlannedPlatformNamesInLowerCaseOrAll

      public static List<String> getPlannedPlatformNamesInLowerCaseOrAll(MediaObject media)
    • getPredictionOrNew

      public static Prediction getPredictionOrNew(Platform platform, Collection<Prediction> preds, Function<Platform,Prediction> constructor)
    • updatePrediction

      public static Prediction updatePrediction(MediaObject media, Platform platform, Prediction.State state)
    • updatePrediction

      public static Prediction updatePrediction(MediaObject media, Platform platform, Embargo embargo, Encryption drm)
    • subtitlesMayBePublished

      public static boolean subtitlesMayBePublished(MediaObject media)
    • filterPublishable

      public static <T extends PublishableObject<?>> T filterPublishable(T object, Instant now)
      Filters a PublishableObject. Removes all subobject which dont' have a correct workflow.

      TODO work in progress. This may replace the hibernate filter solution now in place.

    • filterOnWorkflow

      public static <T extends PublishableObject<?>> T filterOnWorkflow(T object, Predicate<Workflow> predicate)
    • isWebonly

      public static boolean isWebonly(MediaObject media)
    • getPath

      public static Optional<List<MemberRef>> getPath(MediaObject parent, MediaObject child, List<? extends MediaObject> descendants)
      TODO: javadoc
    • updateLocationsForOwner

      public static <T extends MediaObject> void updateLocationsForOwner(T incomingMedia, T mediaToUpdate, Predicate<nl.vpro.domain.media.support.Ownable> owns, nl.vpro.domain.media.support.OwnerType owner, boolean steal)
    • updateLocationsForOwner

      public static <T extends MediaObject> void updateLocationsForOwner(T incomingMedia, T mediaToUpdate, nl.vpro.domain.media.support.OwnerType owner, boolean steal)
    • updateAndRemoveLocationsForOwner

      public static <T extends MediaObject> List<Location> updateAndRemoveLocationsForOwner(T incomingMedia, T mediaToUpdate, Predicate<nl.vpro.domain.media.support.Ownable> owns, nl.vpro.domain.media.support.OwnerType owner)
    • updateAndRemoveLocationsForOwner

      public static <T extends MediaObject> List<Location> updateAndRemoveLocationsForOwner(T incomingMedia, T mediaToUpdate, nl.vpro.domain.media.support.OwnerType owner)
    • mergeAvAttributes

      public static void mergeAvAttributes(Location incomingLocation, Location locationToUpdate)
    • mergeAudioAttributes

      public static void mergeAudioAttributes(AVAttributes incomingAttributes, AVAttributes attributesToUpdate)
    • mergeVideoAttributes

      public static void mergeVideoAttributes(AVAttributes incomingAttributes, AVAttributes attributesToUpdate)
    • getPath

      protected static Optional<List<MemberRef>> getPath(MediaObject parent, MediaObject child, Map<String,MediaObject> descendants)
    • getMemberRefs

      protected static Iterable<MemberRef> getMemberRefs(MediaObject o)
    • getPersons

      public static List<Person> getPersons(MediaObject o)
    • revokeRelatedPublishables

      public static <T extends PublishableObject<?>> boolean revokeRelatedPublishables(MediaObject media, Collection<T> publishables, Instant now, Runnable callbackOnChange)
    • revokeRelatedPublishables

      public static boolean revokeRelatedPublishables(MediaObject media, Instant now)
    • getGTAARecords

      public static Stream<GTAARecord> getGTAARecords(MediaObject media)
    • isPlayable

      public static boolean isPlayable(MediaObject media)
      Whether this mediaobject is playable in a NPO player.
      Since:
      5.11
    • nowPlayable

      public static boolean nowPlayable(@NonNull Platform platform, @NonNull MediaObject mediaObject)
      Whether the given mediaobject is now playable at given platform
      Since:
      5.31
    • nowPlayable

      public static Set<Platform> nowPlayable(@NonNull MediaObject mediaObject)
      Since:
      5.31
    • wasPlayable

      public static boolean wasPlayable(@NonNull Platform platform, @NonNull MediaObject mediaObject)
      Since:
      5.31
    • wasPlayable

      public static Set<Platform> wasPlayable(@NonNull MediaObject mediaObject)
      Since:
      5.31
    • willBePlayable

      public static boolean willBePlayable(@NonNull Platform platform, @NonNull MediaObject mediaObject)
      Returns whether the mediaobject for given platform is now not playable, but will be.
      Since:
      5.31
    • willBePlayableAt

      public static Optional<LocalDateTime> willBePlayableAt(Platform platform, MediaObject mediaObject)
      Determines for a certain Platforms and MediaObject when it might become playable.
      Since:
      5.31
    • willBePlayable

      public static Set<Platform> willBePlayable(@NonNull MediaObject mediaObject)
      Determines on which Platforms the given MediaObject will be playable.
      Since:
      5.31
    • playableRange

      public static Optional<com.google.common.collect.Range<Instant>> playableRange(@NonNull Platform platform, @NonNull MediaObject mediaObject)
      Returns for a certain platform the range it which a mediaobject is playable.
      Returns:
      An Optional of a Range of Instant. The optional is empty if the mediaobject was never announced, and is, was and probably will be unplayable.
      Since:
      5.31
    • playableRanges

      public static Map<Platform,com.google.common.collect.Range<LocalDateTime>> playableRanges(@NonNull MediaObject mediaObject, ZoneId zoneId)
      Given a MediaObject returns a map with for every platform for which that is relevant a Range of LocalDateTime is return indicating the period this object is playable at that platform
      Parameters:
      zoneId - The timezone for which this must be evaluated or null, to fall back to Schedule.ZONE_ID
      Since:
      5.31
    • playableRanges

      public static Map<Platform,com.google.common.collect.Range<Instant>> playableRanges(@NonNull MediaObject mediaObject)
      As playableRanges(MediaObject, ZoneId), but returning ranges of Instant, indicating absolute times.
      Since:
      5.31
      See Also:
    • locationFilter

      protected static boolean locationFilter(Location l)
      Return false if the given location is not actually playable.

      Either it is PublishableObject.isDeleted(), which may occur if dealing with unpublished data, or we're dealing with some legacy and the location has a format which is known not to be playable any more (like WMV)

      Since:
      5.31
    • playabilityCheck

      protected static boolean playabilityCheck(@NonNull Platform platform, @NonNull MediaObject mediaObject, @NonNull Predicate<Prediction> predictionPredicate, @NonNull Predicate<Location> locationPredicate)
      Since:
      5.31
    • playability

      protected static Optional<? extends Embargo> playability(@NonNull Platform platform, @NonNull MediaObject mediaObject, @NonNull Predicate<Prediction> predictionPredicate, @NonNull Predicate<Location> locationPredicate)
      Since:
      5.31
    • correctPrediction

      protected static void correctPrediction(Prediction prediction, MediaObject mediaObject)
      // TODO: I think is is a bit odd that this kind of logic happens here. It ensures consistency, that's the good thing, but it seems a patch any way!