001/*
002 * The contents of this file are subject to the license and copyright
003 * detailed in the LICENSE and NOTICE files at the root of the source
004 * tree.
005 */
006package org.fcrepo.kernel.impl.operations;
007
008import org.fcrepo.kernel.api.Transaction;
009import org.fcrepo.kernel.api.identifiers.FedoraId;
010
011import java.io.InputStream;
012import java.net.URI;
013
014/**
015 * Builder for operations to update non-rdf sources
016 *
017 * @author bbpennel
018 */
019public class UpdateNonRdfSourceOperationBuilder extends AbstractNonRdfSourceOperationBuilder {
020    protected UpdateNonRdfSourceOperationBuilder(final Transaction transaction, final FedoraId rescId,
021                                                 final InputStream stream) {
022        super(transaction, rescId, stream);
023    }
024
025    protected UpdateNonRdfSourceOperationBuilder(final Transaction transaction, final FedoraId rescId,
026                                                 final String handling,
027                                                 final URI contentUri) {
028        super(transaction, rescId, handling, contentUri);
029    }
030
031    @Override
032    public UpdateNonRdfSourceOperation build() {
033        final UpdateNonRdfSourceOperation operation;
034        if (externalURI != null && externalType != null) {
035            operation = new UpdateNonRdfSourceOperation(transaction, resourceId, externalURI, externalType);
036        } else {
037            operation = new UpdateNonRdfSourceOperation(transaction, resourceId, content);
038        }
039
040        operation.setUserPrincipal(userPrincipal);
041        operation.setDigests(digests);
042        operation.setFilename(filename);
043        operation.setContentSize(contentSize);
044        operation.setMimeType(mimeType);
045
046        return operation;
047    }
048}