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