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