001/*
002 * Copyright 2015 DuraSpace, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.fcrepo.migration;
017
018import java.io.File;
019import java.io.IOException;
020import java.io.InputStream;
021import java.util.Optional;
022
023/**
024 * An interface defining access to information about a version of a
025 * fedora datastream.
026 * @author mdurbin
027 */
028public interface DatastreamVersion {
029
030    /**
031     * Gets the information about the datastream for which this is
032     * a version.  (which in turn can be queried to get information about
033     * the object).
034     *
035     * @return {@link org.fcrepo.migration.DatastreamInfo}
036     */
037    public DatastreamInfo getDatastreamInfo();
038
039    /**
040     * Gets the id for this version.
041     *
042     * @return version id
043     */
044    public String getVersionId();
045
046    /**
047     * Gets the mime type for this version.
048     *
049     * @return mime-type
050     */
051    public String getMimeType();
052
053    /**
054     * Gets the label for this version.
055     *
056     * @return label
057     */
058    public String getLabel();
059
060    /**
061     * Gets the date when this version was created.
062     *
063     * @return creation date
064     */
065    public String getCreated();
066
067    /**
068     * Gets the altIDs value for this version.
069     *
070     * @return alternate IDs
071     */
072    public String getAltIds();
073
074    /**
075     * Gets the format URI for this version.
076     *
077     * @return format URI
078     */
079    public String getFormatUri();
080
081    /**
082     * Gets the size (in bytes) for the content of this datastream
083     * version.
084     *
085     * @return size
086     */
087    public long getSize();
088
089    /**
090     * Gets the content digest (if available) for this version.
091     *
092     * @return {@link org.fcrepo.migration.ContentDigest}
093     */
094    public ContentDigest getContentDigest();
095
096    /**
097     * Gets access to the content of this datastream.  When text, the
098     * encoding can be expected to be UTF-8.
099     *
100     * @return {@link java.io.InputStream of content}
101     * @throws IllegalStateException if invoked outside of the call
102     *         to @{link StreamingFedoraObjectHandler#processDatastreamVersion}
103     * @throws IOException when unable to access the stream
104     */
105    public InputStream getContent() throws IOException;
106
107    /**
108     * Get the file backing this datastream if it exists.
109     * Used by fcrepo-migration-validator in order to get direct access to files.
110     *
111     * @return the file
112     */
113    default Optional<File> getFile() {
114        return Optional.empty();
115    }
116
117    /**
118     * Returns the URL to which an External (X) or Redirect (R) datastream
119     * points.  Throws IllegalStateException if this isn't an external or
120     * redirect datastream.
121     *
122     * @return URL of datastream
123     */
124    public String getExternalOrRedirectURL();
125
126    /**
127     * Determines if this is the first version of a datastream.
128     *
129     * @param obj to be tested whether is first version
130     *
131     * @return  True if this is the first version, false otherwise.
132     */
133    public boolean isFirstVersionIn(ObjectReference obj);
134
135    /**
136     * Determines if this is the last version of a datastream.
137     *
138     * @param obj to be tested whether is last version
139     *
140     * @return  True if this is the last version, false otherwise.
141     */
142    public boolean isLastVersionIn(ObjectReference obj);
143}