Interface MediaService

  • All Known Implementing Classes:
    DefaultMediaService

    public interface MediaService
    Provides business functionality for media handling including search methods for medias, folder, formats.
    Since:
    4.0
    Spring Bean ID:
    mediaService
    • Method Detail

      • hasData

        boolean hasData​(MediaModel media)
        Returns information whether given media has binary data.
        Parameters:
        media - media to examine
        Returns:
        true if media has binary data, false otherwise
      • getDataStreamFromMedia

        @Deprecated
        java.io.DataInputStream getDataStreamFromMedia​(MediaModel media)
                                                throws NoDataAvailableException
        Deprecated.
        since ages - please usegetStreamFromMedia(MediaModel) instead
        Returns the stored file of given media as stream. This can only succeed if once data was set before.
        Parameters:
        media - media for which data is requested
        Returns:
        stream to data of media
        Throws:
        NoDataAvailableException - if no data was set before
      • getStreamFromMedia

        java.io.InputStream getStreamFromMedia​(MediaModel media)
                                        throws NoDataAvailableException,
                                               java.lang.IllegalArgumentException
        Returns the stored file of given media as stream. This can only succeed if once data was set before.
        Parameters:
        media - media for which data is requested
        Returns:
        stream to data of media
        Throws:
        NoDataAvailableException - if no data was set before or if underlying data is corrupted
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • getDataFromMedia

        byte[] getDataFromMedia​(MediaModel media)
                         throws NoDataAvailableException
        Returns the stored file of given media as raw data array. This can only succeed if once data was set before.
        Parameters:
        media - media for which data is requested
        Returns:
        raw data of media
        Throws:
        NoDataAvailableException - if no data was set before or if underlying data is corrupted
      • setDataForMedia

        void setDataForMedia​(MediaModel media,
                             byte[] data)
                      throws MediaIOException,
                             java.lang.IllegalArgumentException
        Sets given raw data to media by writing content of given stream to a new data file.
        Parameters:
        media - media for which data will be set
        data - raw data to set
        Throws:
        MediaIOException - if IO problems has occurred
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • setDataStreamForMedia

        @Deprecated
        void setDataStreamForMedia​(MediaModel media,
                                   java.io.DataInputStream data)
        Deprecated.
        since ages - please usesetStreamForMedia(MediaModel, InputStream) instead
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Parameters:
        media - media for which data will be set
        data - data to set
        Throws:
        MediaIOException - if IO problems has occurred
      • setStreamForMedia

        void setStreamForMedia​(MediaModel media,
                               java.io.InputStream data)
                        throws MediaIOException,
                               java.lang.IllegalArgumentException
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Parameters:
        media - media for which data will be set
        data - data to set
        Throws:
        MediaIOException - if IO problems has occurred
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • removeDataFromMediaQuietly

        boolean removeDataFromMediaQuietly​(MediaModel media)
        Removes binary data from provided media without throwing exception.
        Parameters:
        media -
        Returns:
        true when removal operation has succeeded, false otherwise.
      • removeDataFromMedia

        void removeDataFromMedia​(MediaModel media)
        Removes binary data from provided media. If data cannot be removed MediaRemovalException is thrown.
        Parameters:
        media - media from which data will be removed
        Throws:
        MediaRemovalException
      • addVersionStreamForMedia

        void addVersionStreamForMedia​(MediaModel media,
                                      java.lang.String versionId,
                                      java.io.InputStream data)
        Adds the additional version of data as stream for given base media. Mime type will be used from base media.
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        data - the data stream
      • addVersionStreamForMedia

        void addVersionStreamForMedia​(MediaModel media,
                                      java.lang.String mimeType,
                                      java.lang.String versionId,
                                      java.io.InputStream data)
        Adds the additional version of data as stream for given base media
        Parameters:
        media - the base media
        mimeType - the custom mime type
        versionId - the unique version id of data (like format name)
        data - the data stream
      • removeVersionForMedia

        void removeVersionForMedia​(MediaModel media,
                                   java.lang.String versionId)
        Removes the version of data for media.
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
      • getUrlForMediaVersion

        java.lang.String getUrlForMediaVersion​(MediaModel media,
                                               java.lang.String versionId)
        Gets the URL for media version rendered by configured URL strategy.
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        Returns:
        the URL for media version
      • getStreamForMediaVersion

        java.io.InputStream getStreamForMediaVersion​(MediaModel media,
                                                     java.lang.String versionId)
        Gets the stream for media version.
        Parameters:
        media - the base media
        versionId - the unique version id of data (like format name)
        Returns:
        the stream for media version
      • setStreamForMedia

        void setStreamForMedia​(MediaModel media,
                               java.io.InputStream data,
                               java.lang.String originalName,
                               java.lang.String mimeType)
                        throws MediaIOException,
                               java.lang.IllegalArgumentException
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Parameters:
        media - media for which data will be set
        data - data to set
        originalName - The file name that will be set to the media model
        mimeType - MIME type of the media that will be set to the media model
        Throws:
        MediaIOException - if IO problems has occurred
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • setStreamForMedia

        void setStreamForMedia​(MediaModel media,
                               java.io.InputStream data,
                               java.lang.String originalName,
                               java.lang.String mimeType,
                               MediaFolderModel folder)
                        throws MediaIOException,
                               java.lang.IllegalArgumentException
        Sets given data to media by writing content of given stream to a new data file. The stream will be closed afterwards.
        Parameters:
        media - media for which data will be set
        data - data to set
        originalName - The file name that will be set to the media model
        mimeType - MIME type of the media that will be set to the media model
        folder - The folder where media will be stored
        Throws:
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
        MediaStoreException - if any media store problems occurs
        java.lang.IllegalStateException - if media model is new
        MediaIOException
      • setUrlForMedia

        void setUrlForMedia​(MediaModel media,
                            java.lang.String url)
        Sets the external URL for the media. This method also automatically determines mime from URL as well as tries to set size if URL points to the file in classpath and contains specia "fromjar" flag.
        Parameters:
        media - media for which the url will be set
        url - the url
      • getUrlForMedia

        java.lang.String getUrlForMedia​(MediaModel media)
        Returns URL for to given media. Depending on the state of the media the URL can be URL which points to the binary data in underlying Media Storage or direct standard URL to the media in the network.
        Parameters:
        media - media for which the url will be obtained
        Returns:
        url
      • moveMediaToFolder

        void moveMediaToFolder​(MediaModel media,
                               MediaFolderModel targetFolder)
                        throws MediaIOException,
                               java.lang.IllegalArgumentException
        Changes the folder of media to given new folder and move the related media data to this folder. If old media data is referenced by another media object it will be preserved in old location.

        This method calls ModelService.save(Object) method.

        Parameters:
        media - media for which the folder will be changed
        targetFolder - folder where the data has to be moved to
        Throws:
        MediaIOException - if IO problems has occurred
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • moveData

        void moveData​(MediaModel fromMedia,
                      MediaModel toMedia)
               throws MediaIOException,
                      java.lang.IllegalArgumentException
        Moves a media data to another media. After this method, this media has no data anymore. Other medias linking same data will be still consistent.

        This method calls ModelService.save(Object) method.

        Parameters:
        fromMedia - source media to move data from
        toMedia - target media to move data to
        Throws:
        MediaIOException - in case of unexpected errors while move operation
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • copyData

        void copyData​(MediaModel fromMedia,
                      MediaModel toMedia)
               throws MediaIOException,
                      java.lang.IllegalArgumentException
        Copies data from a media to another media by linking the data (both medias will point to same data file). This method is optimized for reusing data files without actually copying them. See also duplicateData(MediaModel, MediaModel) which copies by duplicating the data file. In case the source media does not hold own data but points to a URL this media simply takes the URL - no real data is copied.

        This method calls ModelService.save(Object) method.

        Parameters:
        fromMedia - source media to copy data from
        toMedia - target media to copy data to
        Throws:
        MediaIOException - in case of unexpected errors while move operation
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • duplicateData

        void duplicateData​(MediaModel fromMedia,
                           MediaModel toMedia)
                    throws MediaIOException,
                           java.lang.IllegalArgumentException
        Copies data from a media to another media by duplicating the data (both medias will point to different data file). See also copyData(MediaModel, MediaModel) which only creates a link. In case the source media does not hold own data but points to a URL this media simply takes the URL - no real data is copied.

        This method calls ModelService.save(Object) method.

        Parameters:
        fromMedia - source media to copy data from
        toMedia - target media to copy data to
        Throws:
        MediaIOException - in case of unexpected errors while move operation
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • getMediaByContext

        MediaModel getMediaByContext​(MediaModel media,
                                     MediaContextModel context)
                              throws ModelNotFoundException,
                                     java.lang.IllegalArgumentException
        Gets related media for given media determined by target format of given context. Determines the format of the specified media and uses the specified MediaContext to determine the target format. Than it simply returns the specified media in this target format using the assigned container.
        Parameters:
        media - media for which the related media in specific format is needed
        context - context which defines the target format
        Returns:
        media in format specified by context
        Throws:
        ModelNotFoundException - if no container is assigned ( MediaModel.getMediaContainer() returns null) or the assigned MediaContainerModel does not provide a media in given format.
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • getMediaByFormat

        MediaModel getMediaByFormat​(MediaModel media,
                                    MediaFormatModel format)
                             throws ModelNotFoundException,
                                    java.lang.IllegalArgumentException
        Gets media in specified format related to given media.
        Parameters:
        media - media for which the related media in specific format is needed
        format - format the desired media has to have
        Returns:
        media in specified format or null if no corresponding media in specified format is available
        Throws:
        ModelNotFoundException - if no container is assigned ( MediaModel.getMediaContainer() returns null) or the assigned MediaContainerModel does not provide a media in given format.
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • getMediaByFormat

        MediaModel getMediaByFormat​(MediaContainerModel container,
                                    MediaFormatModel format)
                             throws ModelNotFoundException,
                                    java.lang.IllegalArgumentException
        Gets media in specified format related to given media container.
        Parameters:
        container - container for which the related media in specific format is needed
        format - format the desired media has to have
        Returns:
        MediaModel in specified format or null if no corresponding media in specified format is available
        Throws:
        ModelNotFoundException - if container is null or the assigned MediaContainerModel does not provide a media in given format.
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
      • getFiles

        @Deprecated
        java.util.Collection<java.io.File> getFiles​(MediaModel mediaModel)
                                             throws java.lang.IllegalArgumentException,
                                                    NoDataAvailableException
        Deprecated.
        since ages - Operating on files is no more supported. Use InputStream related methods.
        Gets file of given media (from all media replication directories) as collection of File's.
        Parameters:
        mediaModel - mediaModel used for searching
        Returns:
        Collection of files based on the given mediaModel
        Throws:
        java.lang.IllegalArgumentException - the illegal argument exception if any argument is null
        NoDataAvailableException - if no file was found
      • getMediaWithSameDataReference

        java.util.Collection<MediaModel> getMediaWithSameDataReference​(MediaModel media)
        Returns a collection of MediaModel objects that point to the same physical file.
        Parameters:
        media - media used for search
        Returns:
        collection of medias referencing the same file