001/*
002 * Licensed to DuraSpace under one or more contributor license agreements.
003 * See the NOTICE file distributed with this work for additional information
004 * regarding copyright ownership.
005 *
006 * DuraSpace licenses this file to you under the Apache License,
007 * Version 2.0 (the "License"); you may not use this file except in
008 * compliance with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.fcrepo.kernel.impl.operations;
019
020import java.io.InputStream;
021import java.net.URI;
022import java.util.Collection;
023
024import org.fcrepo.kernel.api.Transaction;
025import org.fcrepo.kernel.api.identifiers.FedoraId;
026import org.fcrepo.kernel.api.operations.NonRdfSourceOperationBuilder;
027
028/**
029 * An abstract operation for interacting with a non-rdf source
030 *
031 * @author bbpennel
032 */
033public abstract class AbstractNonRdfSourceOperationBuilder implements NonRdfSourceOperationBuilder {
034
035    protected FedoraId resourceId;
036
037    protected InputStream content;
038
039    protected URI externalURI;
040
041    protected String externalType;
042
043    protected String mimeType;
044
045    protected String filename;
046
047    protected Collection<URI> digests;
048
049    protected long contentSize = -1;
050
051    protected String userPrincipal;
052
053    protected Transaction transaction;
054
055    /**
056     * Constructor for external binary.
057     *
058     * @param transaction the transaction
059     * @param rescId the internal identifier
060     * @param handling the external content handling type.
061     * @param externalUri the external content URI.
062     */
063    protected AbstractNonRdfSourceOperationBuilder(final Transaction transaction, final FedoraId rescId,
064                                                   final String handling,
065                                                   final URI externalUri) {
066        this.transaction = transaction;
067        this.resourceId = rescId;
068        this.externalURI = externalUri;
069        this.externalType = handling;
070    }
071
072    /**
073     * Constructor for internal binary.
074     *
075     * @param transaction the transaction
076     * @param rescId the internal identifier.
077     * @param stream the content stream.
078     */
079    protected AbstractNonRdfSourceOperationBuilder(final Transaction transaction, final FedoraId rescId,
080                                                   final InputStream stream) {
081        this.transaction = transaction;
082        this.resourceId = rescId;
083        this.content = stream;
084    }
085
086    @Override
087    public NonRdfSourceOperationBuilder mimeType(final String mimetype) {
088        this.mimeType = mimetype;
089        return this;
090    }
091
092    @Override
093    public NonRdfSourceOperationBuilder filename(final String filename) {
094        this.filename = filename;
095        return this;
096    }
097
098    @Override
099    public NonRdfSourceOperationBuilder contentDigests(final Collection<URI> digests) {
100        this.digests = digests;
101        return this;
102    }
103
104    @Override
105    public NonRdfSourceOperationBuilder contentSize(final long size) {
106        this.contentSize = size;
107        return this;
108    }
109
110    @Override
111    public NonRdfSourceOperationBuilder userPrincipal(final String userPrincipal) {
112        this.userPrincipal = userPrincipal;
113        return this;
114    }
115}