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;
010import org.fcrepo.kernel.api.operations.CreateNonRdfSourceOperationBuilder;
011
012import java.io.InputStream;
013import java.net.URI;
014import java.util.Collection;
015
016
017/**
018 * Builder for operations to create new non-rdf sources
019 *
020 * @author bbpennel
021 */
022public class CreateNonRdfSourceOperationBuilderImpl extends AbstractNonRdfSourceOperationBuilder
023        implements CreateNonRdfSourceOperationBuilder {
024
025    private FedoraId parentId;
026
027    /**
028     * Constructor for external binary.
029     *
030     * @param transaction the transaction
031     * @param rescId      the internal identifier
032     * @param handling    the external content handling type.
033     * @param externalUri the external content URI.
034     */
035    protected CreateNonRdfSourceOperationBuilderImpl(final Transaction transaction, final FedoraId rescId,
036                                                     final String handling,
037                                                     final URI externalUri) {
038        super(transaction, rescId, handling, externalUri);
039    }
040
041    /**
042     * Constructor for internal binary.
043     *
044     * @param transaction the transaction
045     * @param rescId the internal identifier.
046     * @param stream the content stream.
047     */
048    protected CreateNonRdfSourceOperationBuilderImpl(final Transaction transaction, final FedoraId rescId,
049                                                     final InputStream stream) {
050        super(transaction, rescId, stream);
051    }
052
053    @Override
054    public CreateNonRdfSourceOperationBuilder mimeType(final String mimeType) {
055        return (CreateNonRdfSourceOperationBuilder) super.mimeType(mimeType);
056    }
057
058    @Override
059    public CreateNonRdfSourceOperationBuilder filename(final String filename) {
060        return (CreateNonRdfSourceOperationBuilder) super.filename(filename);
061    }
062
063    @Override
064    public CreateNonRdfSourceOperationBuilder contentDigests(final Collection<URI> digests) {
065        return (CreateNonRdfSourceOperationBuilder) super.contentDigests(digests);
066    }
067
068    @Override
069    public CreateNonRdfSourceOperationBuilder contentSize(final long size) {
070        return (CreateNonRdfSourceOperationBuilder) super.contentSize(size);
071    }
072
073    @Override
074    public CreateNonRdfSourceOperationBuilder userPrincipal(final String userPrincipal) {
075        return (CreateNonRdfSourceOperationBuilder) super.userPrincipal(userPrincipal);
076    }
077
078    @Override
079    public CreateNonRdfSourceOperationBuilder parentId(final FedoraId parentId) {
080        this.parentId = parentId;
081        return this;
082    }
083
084    @Override
085    public CreateNonRdfSourceOperation build() {
086        final CreateNonRdfSourceOperation operation;
087        if (externalURI != null && externalType != null) {
088            operation = new CreateNonRdfSourceOperation(transaction, resourceId, externalURI, externalType);
089        } else {
090            operation = new CreateNonRdfSourceOperation(transaction, resourceId, content);
091        }
092
093        operation.setUserPrincipal(userPrincipal);
094        operation.setDigests(digests);
095        operation.setFilename(filename);
096        operation.setContentSize(contentSize);
097        operation.setMimeType(mimeType);
098        operation.setParentId(parentId);
099
100        return operation;
101    }
102}