diff --git a/src/main/java/org/sead/uploader/AbstractUploader.java b/src/main/java/org/sead/uploader/AbstractUploader.java index 4acaf0a..bfc71a5 100644 --- a/src/main/java/org/sead/uploader/AbstractUploader.java +++ b/src/main/java/org/sead/uploader/AbstractUploader.java @@ -34,6 +34,7 @@ import org.apache.http.client.protocol.HttpClientContext; import org.json.JSONObject; import org.sead.uploader.util.FileResource; +import org.sead.uploader.util.ListResource; import org.sead.uploader.util.PublishedResource; import org.sead.uploader.util.Resource; import org.sead.uploader.util.ResourceFactory; @@ -183,7 +184,9 @@ public void processRequests() { importRO(oremapURL); } } else { - + //Gather files named individually + ListResource topLevel = new ListResource("Individual files on command line"); + for (String request : requests) { // It's a local path to a file or dir Resource file = new FileResource(request); @@ -222,6 +225,7 @@ public void processRequests() { String newUri = uploadDatafile(file, null, tagId); if (newUri != null) { println(" UPLOADED as: " + newUri); + topLevel.addResource(file); globalFileCount++; totalBytes += file.length(); println("CURRENT TOTAL: " + globalFileCount + " files :" + totalBytes + " bytes"); @@ -235,6 +239,9 @@ public void processRequests() { } } } + if(topLevel.iterator().hasNext()) { + postProcessChildren(topLevel); + } } if (pw != null) { pw.flush(); diff --git a/src/main/java/org/sead/uploader/util/ListResource.java b/src/main/java/org/sead/uploader/util/ListResource.java new file mode 100644 index 0000000..34a6de8 --- /dev/null +++ b/src/main/java/org/sead/uploader/util/ListResource.java @@ -0,0 +1,115 @@ +/** ***************************************************************************** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************** */ +package org.sead.uploader.util; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Iterator; + +import org.apache.http.entity.mime.content.ContentBody; +import org.json.JSONObject; + +/** + * A limited functionality class to collect any top-level individual files + * listed on the command line. In the Dataverse implementation, we need to + * post-process these files in some cases, e.g. with directupload and not doing + * singlefile registration with Dataverse. + * + * @author qqmye + */ +public class ListResource extends Resource { + + private final ArrayList fileResourceArray; + private final String name; + + public ListResource(String name) { + this.fileResourceArray = new ArrayList<>(); + this.name = name; + } + + @Override + public String getName() { + + return name; + } + + @Override + public boolean isDirectory() { + return true; + } + + @Override + public String getPath() { + return name; + } + + @Override + public String getMimeType() { + throw new UnsupportedOperationException(); + } + + @Override + public Iterator iterator() { + return fileResourceArray.iterator(); + } + + @Override + public Iterable listResources() { + return fileResourceArray; + } + + public void addResource(Resource fr) { + if (fr.isDirectory()) { + throw new UnsupportedOperationException(); + } else { + fileResourceArray.add(fr); + } + } + + @Override + public long length() { + throw new UnsupportedOperationException(); + } + + @Override + public String getAbsolutePath() { + return name; + } + + @Override + public ContentBody getContentBody() { + throw new UnsupportedOperationException(); + } + + @Override + public InputStream getInputStream() { + throw new UnsupportedOperationException(); + } + + @Override + public String getHash(String algorithm) { + throw new UnsupportedOperationException(); + } + + @Override + public JSONObject getMetadata() { + throw new UnsupportedOperationException(); + } + + @Override + public void setMetadata(JSONObject jo) { + throw new UnsupportedOperationException(); + } + +}