Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

NO JIRA. Added support for zipped bags #21

Merged
merged 3 commits into from May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions run.sh
Expand Up @@ -27,14 +27,14 @@ PASSWORD=$4
JARFILE=$(ls -1 target/*SNAPSHOT.jar)

if (( $# < 5 )); then
echo "Usage: ./run.sh <program> <COL-IRI> <user> <password> [<chunksize>] <bagdir>..."
echo "Usage: ./run.sh <program> <COL-IRI> <user> <password> [<chunksize>] <bag>..."
echo "Where:"
echo "<program> = one of Simple,Continued,SequenceSimple,SequenceContinued"
echo "<COL-IRI> = the collection IRI to post to"
echo "<user> = EASY user account"
echo "<password> = password for <user>"
echo "<chunksize> = size in byte of each chunk (only for the Continued variants)"
echo "<bagdir> = one bag directory to send or multiple (only for Sequence variants)"
echo "<bag> = one bag directory or zip file to send or multiple (only for Sequence variants)"
exit
fi

Expand Down
Expand Up @@ -30,7 +30,7 @@
public class ContinuedDeposit {
public static void main(String[] args) throws Exception {
if (args.length != 5) {
System.err.println("Usage: java nl.knaw.dans.easy.sword2examples.ContinuedDeposit <Col-IRI> <EASY uid> <EASY passwd> <chunk size> <bag dirname>");
System.err.println("Usage: java nl.knaw.dans.easy.sword2examples.ContinuedDeposit <Col-IRI> <EASY uid> <EASY passwd> <chunk size> <bag file/dir>");
System.exit(1);
}

Expand All @@ -39,16 +39,20 @@ public static void main(String[] args) throws Exception {
final String uid = args[1];
final String pw = args[2];
final int chunkSize = Integer.parseInt(args[3]);
final String bagFileName = args[4];
final String bagFile = args[4];

depositPackage(new File(bagFileName), colIri, uid, pw, chunkSize);
depositPackage(new File(bagFile), colIri, uid, pw, chunkSize);
}

public static URI depositPackage(File bagDir, IRI colIri, String uid, String pw, int chunkSize) throws Exception {
// 0. Zip the bagDir
File zipFile = new File(bagDir.getAbsolutePath() + ".zip");
zipFile.delete();
Common.zipDirectory(bagDir, zipFile);
public static URI depositPackage(File bag, IRI colIri, String uid, String pw, int chunkSize) throws Exception {
File zipFile = null;
if (bag.isDirectory()) {
zipFile = new File(bag.getAbsolutePath() + ".zip");
zipFile.delete();
Common.zipDirectory(bag, zipFile);
} else {
zipFile = bag;
}

// 1. Set up stream for calculating MD5
FileInputStream fis = new FileInputStream(zipFile);
Expand All @@ -75,7 +79,7 @@ public static URI depositPackage(File bagDir, IRI colIri, String uid, String pw,
Link seIriLink = receipt.getLink("edit");
URI seIri = seIriLink.getHref().toURI();

int remaining = (int) zipFile.length() - chunkSize;
long remaining = zipFile.length() - chunkSize;
int count = 2;
while (remaining > 0) {
System.out.print(String.format("POST-ing chunk of %d bytes to SE-IRI (remaining: %d) ... ", chunkSize, remaining));
Expand Down
23 changes: 14 additions & 9 deletions src/main/java/nl/knaw/dans/easy/sword2examples/SimpleDeposit.java
Expand Up @@ -34,29 +34,34 @@ public class SimpleDeposit {
* Sends a bag to the easy-sword2 service and tracks its status until it is archived or failure is reported.
*
* @param args
* 0. collection URL (Col-IRI), 1. EASY user name, 2. EASY password, 3. zipped bag to send,
* 0. collection URL (Col-IRI), 1. EASY user name, 2. EASY password, 3. bag to send (a directory or a zip file),
*/
public static void main(String[] args) throws Exception {
if (args.length != 4) {
System.err.println("Usage: java nl.knaw.dans.easy.sword2examples.SimpleDeposit <Col-IRI> <EASY uid> <EASY passwd> <bag dirname>");
System.err.println("Usage: java nl.knaw.dans.easy.sword2examples.SimpleDeposit <Col-IRI> <EASY uid> <EASY passwd> <bag file/dir>");
System.exit(1);
}

// Read command line arguments
final IRI colIri = new IRI(args[0]);
final String uid = args[1];
final String pw = args[2];
final String bagDirName = args[3];
final String bagFile = args[3];

File tempCopy = Common.copyToTarget(new File(bagDirName));
File tempCopy = Common.copyToTarget(new File(bagFile));
depositPackage(tempCopy, colIri, uid, pw);
}

public static URI depositPackage(File bagDir, IRI colIri, String uid, String pw) throws Exception {
// 0. Zip the bagDir
File zipFile = new File(bagDir.getAbsolutePath() + ".zip");
zipFile.delete();
Common.zipDirectory(bagDir, zipFile);
public static URI depositPackage(File bag, IRI colIri, String uid, String pw) throws Exception {
// 0. Zip the bag if it isn't yet.
File zipFile = null;
if (bag.isDirectory()) {
zipFile = new File(bag.getAbsolutePath() + ".zip");
zipFile.delete();
Common.zipDirectory(bag, zipFile);
} else {
zipFile = bag;
}

// 1. Set up stream for calculating MD5
MessageDigest md = MessageDigest.getInstance("MD5");
Expand Down