Class AssetManagerImpl

java.lang.Object
org.opencastproject.elasticsearch.index.rebuild.AbstractIndexProducer
org.opencastproject.assetmanager.impl.AssetManagerImpl
All Implemented Interfaces:
AssetManager, AbstractADeleteQuery.DeleteEpisodeHandler, IndexProducer

public class AssetManagerImpl extends AbstractIndexProducer implements AssetManager, AbstractADeleteQuery.DeleteEpisodeHandler
The Asset Manager implementation.
  • Field Details

  • Constructor Details

    • AssetManagerImpl

      public AssetManagerImpl()
  • Method Details

    • activate

      public void activate(org.osgi.service.component.ComponentContext cc)
      OSGi callback.
    • setEntityManagerFactory

      public void setEntityManagerFactory(javax.persistence.EntityManagerFactory emf)
      OSGi dependencies
    • setDBSessionFactory

      public void setDBSessionFactory(DBSessionFactory dbSessionFactory)
    • setSecurityService

      public void setSecurityService(SecurityService securityService)
    • setAuthorizationService

      public void setAuthorizationService(AuthorizationService authorizationService)
    • setOrgDir

      public void setOrgDir(OrganizationDirectoryService orgDir)
    • setWorkspace

      public void setWorkspace(Workspace workspace)
    • setAssetStore

      public void setAssetStore(AssetStore assetStore)
    • addEventHandler

      public void addEventHandler(AssetManagerUpdateHandler handler)
    • removeEventHandler

      public void removeEventHandler(AssetManagerUpdateHandler handler)
    • addRemoteAssetStore

      public void addRemoteAssetStore(RemoteAssetStore assetStore)
    • removeRemoteAssetStore

      public void removeRemoteAssetStore(RemoteAssetStore store)
    • setHttpAssetProvider

      public void setHttpAssetProvider(HttpAssetProvider httpAssetProvider)
    • setAclServiceFactory

      public void setAclServiceFactory(AclServiceFactory aclServiceFactory)
    • setIndex

      public void setIndex(ElasticsearchIndex index)
    • addCatalogUIAdapter

      public void addCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter)
    • removeCatalogUIAdapter

      public void removeCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter)
    • getMediaPackage

      public Optional<MediaPackage> getMediaPackage(String mediaPackageId)
      AssetManager implementation
      Specified by:
      getMediaPackage in interface AssetManager
      Parameters:
      mediaPackageId -
      Returns:
      mediapackage
    • getAsset

      public Optional<Asset> getAsset(Version version, String mpId, String mpElementId)
      Description copied from interface: AssetManager
      Get the asset that is uniquely identified by the triple {version, media package ID, media package element ID}.
      Specified by:
      getAsset in interface AssetManager
      Parameters:
      version - the version
      mpId - the media package ID
      mpElementId - the media package element ID
      Returns:
      the asset or none, if no such asset exists
    • getAssetStore

      public Optional<AssetStore> getAssetStore(String storeId)
      Description copied from interface: AssetManager
      Get an asset store by id (local or remote).
      Specified by:
      getAssetStore in interface AssetManager
      Parameters:
      storeId - the store id
      Returns:
      the asset store if it exists
    • getLocalAssetStore

      public AssetStore getLocalAssetStore()
      Description copied from interface: AssetManager
      Get the local asset store.
      Specified by:
      getLocalAssetStore in interface AssetManager
      Returns:
      the asset store
    • getRemoteAssetStores

      public List<AssetStore> getRemoteAssetStores()
      Description copied from interface: AssetManager
      Get the remote asset stores as a list.
      Specified by:
      getRemoteAssetStores in interface AssetManager
      Returns:
      a list of asset stores
    • snapshotExists

      public boolean snapshotExists(String mediaPackageId)
      Snapshots
      Specified by:
      snapshotExists in interface AssetManager
      Parameters:
      mediaPackageId - The media package identifier to check for
      Returns:
      If a snapshot exists for the given media package
    • snapshotExists

      public boolean snapshotExists(String mediaPackageId, String organization)
      Description copied from interface: AssetManager
      Check if any snapshot with the given media package identifier exists.
      Specified by:
      snapshotExists in interface AssetManager
      Parameters:
      mediaPackageId - The media package identifier to check for
      organization - The organization to limit the search to
      Returns:
      If a snapshot exists for the given media package
    • takeSnapshot

      public Snapshot takeSnapshot(MediaPackage mp)
      Description copied from interface: AssetManager
      Take a versioned snapshot of a media package using the owner of the last snapshot or the default owner if it does not exist.
      Specified by:
      takeSnapshot in interface AssetManager
      Parameters:
      mp - The media package to snapshot
      Returns:
      A new snapshot
    • takeSnapshot

      public Snapshot takeSnapshot(String owner, MediaPackage mp)
      Description copied from interface: AssetManager
      Take a versioned snapshot of a media package.

      Snapshot are tagged with string identifying the owner. Only the owner of a snapshot is allowed to delete it. Ownership only affects the deletion of a snapshot.

      Specified by:
      takeSnapshot in interface AssetManager
      Parameters:
      owner - the owner of the snapshot, e.g. the name of the calling service
    • triggerIndexUpdate

      public void triggerIndexUpdate(String mediaPackageId) throws NotFoundException, UnauthorizedException
      Description copied from interface: AssetManager
      Trigger search index update for event.
      Specified by:
      triggerIndexUpdate in interface AssetManager
      Parameters:
      mediaPackageId - The event ID to trigger an index update for
      Throws:
      NotFoundException
      UnauthorizedException
    • getSnapshotsById

      public RichAResult getSnapshotsById(String mpId)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by mediapackage IDs
      Specified by:
      getSnapshotsById in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter results for
      Returns:
      The RichAResult stream filtered by mediapackage ID
    • getSnapshotsByIdOrderedByVersion

      public RichAResult getSnapshotsByIdOrderedByVersion(String mpId, boolean asc)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by mediapackage IDs. This stream consists of all versions of all mediapackage ordered by the Version
      Specified by:
      getSnapshotsByIdOrderedByVersion in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter results for
      asc - The asc Boolean decides if to order ascending (true) or descending (false)
      Returns:
      The RichAResult stream filtered by mediapackage ID
    • getSnapshotsByIdAndVersion

      public RichAResult getSnapshotsByIdAndVersion(String mpId, Version version)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by mediapackage ID and version
      Specified by:
      getSnapshotsByIdAndVersion in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter results for
      version - The version to filter results for
      Returns:
      The RichAResult stream filtered by mediapackage ID
    • getSnapshotsByDate

      public RichAResult getSnapshotsByDate(Date start, Date end)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by date. This stream consists of all versions of all mediapackages archived within the date range.
      Specified by:
      getSnapshotsByDate in interface AssetManager
      Parameters:
      start - The start Date to filter by
      end - The endDate to filter by
      Returns:
      The RichAResult stream filtered by date
    • getSnapshotsByDateOrderedById

      public RichAResult getSnapshotsByDateOrderedById(Date start, Date end)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by date. This stream consists of all a mediapackages which have at least one version archived within the date range.
      Specified by:
      getSnapshotsByDateOrderedById in interface AssetManager
      Parameters:
      start - The start Date to filter by
      end - The endDate to filter by
      Returns:
      The RichAResult stream filtered by date
    • getSnapshotsByIdAndDate

      public RichAResult getSnapshotsByIdAndDate(String mpId, Date start, Date end)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by date and mediapackage. This stream consists of all versions of a mediapackage archived within the date range.
      Specified by:
      getSnapshotsByIdAndDate in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter for
      start - The start Date to filter by
      end - The endDate to filter by
      Returns:
      The RichAResult stream filtered by date
    • getSnapshotsByIdAndDateOrderedByVersion

      public RichAResult getSnapshotsByIdAndDateOrderedByVersion(String mpId, Date start, Date end, boolean asc)
      Description copied from interface: AssetManager
      Returns a stream of RichAResult filtered by date and mediapackage. This stream consists of all versions of a mediapackage archived within the date range ordered by there Version.
      Specified by:
      getSnapshotsByIdAndDateOrderedByVersion in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter for
      start - The start Date to filter by
      end - The end Date to filter by
      asc - The asc Boolean decides if to order ascending (true) or descending (false)
      Returns:
      The RichAResult stream filtered by date
    • moveSnapshotsById

      public void moveSnapshotsById(String mpId, String targetStore) throws NotFoundException
      Description copied from interface: AssetManager
      Moves all versions of a given mediapackage ID from their respective source stores to a single target store
      Specified by:
      moveSnapshotsById in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to move
      targetStore - The store ID to move all versions of this mediapackage to
      Throws:
      NotFoundException
    • moveSnapshotsByIdAndVersion

      public void moveSnapshotsByIdAndVersion(String mpId, Version version, String targetStore) throws NotFoundException
      Description copied from interface: AssetManager
      Moves a specific version of a given mediapackage ID to a new store
      Specified by:
      moveSnapshotsByIdAndVersion in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to move
      version - The version to move
      targetStore - The store ID to move this version of the mediapackage to
      Throws:
      NotFoundException
    • moveSnapshotsByDate

      public void moveSnapshotsByDate(Date start, Date end, String targetStore) throws NotFoundException
      Description copied from interface: AssetManager
      Moves all versions of all mediapackages archived within a data range to a new storage location.
      Specified by:
      moveSnapshotsByDate in interface AssetManager
      Parameters:
      start - The start Date to filter by
      end - The endDate to filter by
      targetStore - THe store ID to move the snapshots to
      Throws:
      NotFoundException
    • moveSnapshotsByIdAndDate

      public void moveSnapshotsByIdAndDate(String mpId, Date start, Date end, String targetStore) throws NotFoundException
      Description copied from interface: AssetManager
      Moves all versions of a mediapackage archived within a data range to a new storage location.
      Specified by:
      moveSnapshotsByIdAndDate in interface AssetManager
      Parameters:
      mpId - The mediapackage ID to filter for
      start - The start Date to filter by
      end - The endDate to filter by
      targetStore - THe store ID to move the snapshots to
      Throws:
      NotFoundException
    • moveSnapshotToStore

      public void moveSnapshotToStore(Version version, String mpId, String storeId) throws NotFoundException
      Description copied from interface: AssetManager
      Move snapshot from current store to new store Note: This may require downloading and re-uploading
      Specified by:
      moveSnapshotToStore in interface AssetManager
      Parameters:
      version - The version to move
      mpId - The media package to move
      storeId - The store to move to
      Throws:
      NotFoundException
    • getSnapshotStorageLocation

      public Optional<String> getSnapshotStorageLocation(Version version, String mpId)
    • getSnapshotStorageLocation

      public Optional<String> getSnapshotStorageLocation(Snapshot snap)
    • setProperty

      public boolean setProperty(Property property)
      Properties
      Specified by:
      setProperty in interface AssetManager
      Returns:
      false, if the referenced episode does not exist.
    • selectProperties

      public List<Property> selectProperties(String mediaPackageId, String namespace)
      Description copied from interface: AssetManager
      Select all properties for a specific media package.
      Specified by:
      selectProperties in interface AssetManager
      Parameters:
      mediaPackageId - Media package identifier to check for
      namespace - Namespace to limit the search to
      Returns:
      List of properties
    • deleteProperties

      public int deleteProperties(String mediaPackageId)
      Description copied from interface: AssetManager
      Delete all properties for a given media package identifier
      Specified by:
      deleteProperties in interface AssetManager
      Parameters:
      mediaPackageId - Media package identifier
      Returns:
      Number of deleted properties
    • deleteProperties

      public int deleteProperties(String mediaPackageId, String namespace)
      Description copied from interface: AssetManager
      Delete all properties for a given media package identifier and namespace.
      Specified by:
      deleteProperties in interface AssetManager
      Parameters:
      mediaPackageId - Media package identifier
      namespace - A namespace prefix to use for deletion
      Returns:
      Number of deleted properties
    • createQuery

      public AQueryBuilder createQuery()
      Misc.
      Specified by:
      createQuery in interface AssetManager
    • toVersion

      public Optional<Version> toVersion(String version)
      Description copied from interface: AssetManager
      Deserialize a version from a string. This is the inverse function of Version.toString().
      Specified by:
      toVersion in interface AssetManager
      Returns:
      a version or none, if no version can be archived from the given string
    • countEvents

      public long countEvents(String organization)
      Description copied from interface: AssetManager
      Count the number of events stored for a given organization.
      Specified by:
      countEvents in interface AssetManager
      Parameters:
      organization - The organization to check. This may be `null` to not filter for an organization which is significantly faster.
      Returns:
      Number of events
    • handleDeletedEpisode

      public void handleDeletedEpisode(String mpId)
      Specified by:
      handleDeletedEpisode in interface AbstractADeleteQuery.DeleteEpisodeHandler
    • getService

      public IndexRebuildService.Service getService()
      AbstractIndexProducer Implementation
      Specified by:
      getService in interface IndexProducer
      Returns:
      service The service that implements IndexProducer.
    • getSupportedDataTypes

      public IndexRebuildService.DataType[] getSupportedDataTypes()
      Description copied from interface: IndexProducer
      Get supported data types for reindexing. Default: All. Should be overridden if a service offers partial index rebuilds.
      Specified by:
      getSupportedDataTypes in interface IndexProducer
      Returns:
      Array of supported data types
    • repopulate

      public void repopulate(IndexRebuildService.DataType dataType) throws IndexRebuildException
      Description copied from interface: IndexProducer
      Re-add the data of this service to the index.
      Specified by:
      repopulate in interface IndexProducer
      Parameters:
      dataType - Limit the data added to the index. Use ALL to re-index all data.
      Throws:
      IndexRebuildException
    • setAvailability

      public void setAvailability(Version version, String mpId, Availability availability)
      Used for testing
    • setDatabase

      public void setDatabase(Database database)
    • getDatabase

      public Database getDatabase()
    • getHttpAssetProvider

      public HttpAssetProvider getHttpAssetProvider()
    • getFileNameFromUrn

      public static Optional<String> getFileNameFromUrn(MediaPackageElement mpe)
      Extract the file name from a media package elements URN.
      Returns:
      the file name or none if it could not be determined
    • rewriteUris

      public static Snapshot rewriteUris(Snapshot snapshot, com.entwinemedia.fn.Fn<MediaPackageElement,URI> uriCreator)
      Rewrite URIs of all asset elements of a snapshot's media package. This method does not mutate anything.
    • fireEventHandlers

      public void fireEventHandlers(AssetManagerItem item)