Skip to content

Commit

Permalink
fix direct upload, singlefile=false not registering indv. files issue
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmyers committed Aug 15, 2023
1 parent e1ca944 commit 26f6785
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main/java/org/sead/uploader/AbstractUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand All @@ -235,6 +239,9 @@ public void processRequests() {
}
}
}
if(topLevel.iterator().hasNext()) {
postProcessChildren(topLevel);
}
}
if (pw != null) {
pw.flush();
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/org/sead/uploader/util/ListResource.java
Original file line number Diff line number Diff line change
@@ -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<Resource> 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<Resource> iterator() {
return fileResourceArray.iterator();
}

@Override
public Iterable<Resource> 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();
}

}

0 comments on commit 26f6785

Please sign in to comment.