/*
 * Copyright Amherst College
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package edu.amherst.acdc.trellis.spi;

import java.io.InputStream;
import java.util.List;
import java.util.Optional;

import edu.amherst.acdc.trellis.api.Datastream;
import org.apache.commons.rdf.api.IRI;

/**
 * The DatastreamService provides methods for retrieving, modifying and checking
 * the validity of binary content.
 *
 * @author acoburn
 */
public interface DatastreamService {

    /**
     * A datastream resolver, used by the DatastreamService
     */
    interface DatastreamResolver {
        /**
         * @return the uri schemes supported by this resolver
         */
        List<String> getUriSchemes();

        /**
         * Resolve the datastream
         * @param identifier the identifier
         * @return the content of the datastream
         */
        InputStream fetch(IRI identifier);
    }

    /**
     * Get the content of the datastream
     * @param identifier an identifier used for locating the datastream
     * @return the content
     */
    InputStream getContent(IRI identifier);

    /**
     * Test whether a datastream exists at the given URI
     * @param identifier the datastream identifier
     * @return whether the datastream exists
     */
    Boolean exists(IRI identifier);

    /**
     * Set the content for a datastream
     * @param identifier the datastream identifier
     * @param stream the content
     * @param contentType the contentType
     */
    void setContent(IRI identifier, InputStream stream, String contentType);

    /**
     * Calculate the digest for a datastream
     * @param algorithm the algorithm
     * @return the digest
     */
    Optional<String> calculateDigest(String algorithm);

    /**
     * Generate an identifier for a new datastream resource
     * @param identifier the resource identifier
     * @return an identifier for the datastream
     */
    default IRI generateIdentifier(IRI identifier) {
        return generateIdentifier(identifier, null);
    }

    /**
     * Generate an identifier for a new datastream resource using a particular
     * partition hint.
     * @param identifier the resource identifier
     * @param partition the partition to use
     * @return the new identifier for the datastream
     */
    IRI generateIdentifier(IRI identifier, Datastream.StoragePartition partition);
}

@@ -1067,26 +1067,16 @@
 terface 
-Datastream
 Resolver
@@ -1078,16 +1078,16 @@
 olver %7B%0A
+
         
@@ -1226,23 +1226,34 @@
       * 
-Resolve
+Get the content of
  the dat
@@ -1369,24 +1369,33 @@
  */%0A        
+Optional%3C
 InputStream 
@@ -1397,29 +1397,529 @@
 ream
- fetch(IRI identifier
+%3E getContent(IRI identifier);%0A%0A        /**%0A         * Check whether the datastream exists%0A         * @param identifier the identifier%0A         * @return whether the datastream exists%0A         */%0A        Boolean exists(IRI identifier);%0A%0A        /**%0A         * Set the content of the datastream%0A         * @param identifier the identifier%0A         * @param stream the content%0A         * @param contentType the datastream contentType%0A         */%0A        void setContent(IRI identifier, InputStream stream, String contentType
 );%0A 
@@ -2084,16 +2084,25 @@
  */%0A    
+Optional%3C
 InputStr
@@ -2104,16 +2104,17 @@
 utStream
+%3E
  getCont
@@ -2646,32 +2646,72 @@
 or a datastream%0A
+     * @param identifier the identifier%0A
      * @param al
@@ -2758,32 +2758,32 @@
  digest%0A     */%0A
-
     Optional%3CStr
@@ -2803,16 +2803,32 @@
 eDigest(
+IRI identifier, 
 String a

update datastream interface