diff --git a/pom.xml b/pom.xml index 77d7b13b3aa8001fe50feaaa5a8af5171237b978..bcfa7a10c28e88acedba10f8d01a3e1f06337e32 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ <groupId>au.edu.unimelb.mf</groupId> <artifactId>unimelb-mf-clients</artifactId> - <version>0.6.8</version> + <version>0.6.9</version> <packaging>jar</packaging> <name>unimelb-mf-clients</name> <url>https://gitlab.unimelb.edu.au/resplat-mediaflux/unimelb-mf-clients</url> diff --git a/src/main/java/unimelb/mf/client/instrument/cli/InstrumentUploadMissingFind.java b/src/main/java/unimelb/mf/client/instrument/cli/InstrumentUploadMissingFind.java index 9759c1935d33fd03ff5c2a54714606a865bcf1b9..5db1074e382782477e04c21c9e15321d3a2be7e8 100644 --- a/src/main/java/unimelb/mf/client/instrument/cli/InstrumentUploadMissingFind.java +++ b/src/main/java/unimelb/mf/client/instrument/cli/InstrumentUploadMissingFind.java @@ -10,10 +10,8 @@ import java.nio.file.attribute.FileTime; import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Set; @@ -111,25 +109,30 @@ public class InstrumentUploadMissingFind implements MFCommand { throw new IllegalArgumentException("No parent directory path is specified!"); } - List<Upload> uploads = UploadShareable.getUploads(session, settings.shareableId(), settings.shareableToken(), + List<Upload> allUploads = UploadShareable.getUploads(session, settings.shareableId(), settings.shareableToken(), false); - findMissingDirectories(settings.parentDirectories(), settings.levels(), settings.after(), settings.before(), - settings.compare(), uploads); + Set<Path> missingDirectories = findMissingDirectories(settings.parentDirectories(), settings.levels(), + settings.after(), settings.before(), settings.compare(), allUploads); + + for (Path srcPath : missingDirectories) { + System.out.printf("directory: %s%n", srcPath); + } + System.out.println("count: " + missingDirectories.size()); } - private Map<Path, Set<Upload>> findMissingDirectories(Collection<Path> parentDirectories, int levels, Date after, - Date before, boolean compare, List<Upload> uploads) throws Throwable { - Map<Path, Set<Upload>> result = new LinkedHashMap<>(); + private Set<Path> findMissingDirectories(Collection<Path> parentDirectories, int levels, Date after, Date before, + boolean compare, List<Upload> uploads) throws Throwable { + Set<Path> missingDirectories = new LinkedHashSet<>(); for (Path parentDir : parentDirectories) { - findMissingDirectories(parentDir, levels, after, before, compare, uploads, result); + findMissingDirectories(parentDir, levels, after, before, compare, uploads, missingDirectories); } - return result; + return missingDirectories; } private void findMissingDirectories(Path parentDir, int levels, Date after, Date before, boolean compare, - List<Upload> uploads, Map<Path, Set<Upload>> result) throws IOException { + List<Upload> uploads, Set<Path> missingDirectories) throws IOException { int rootDepth = parentDir.getNameCount(); @@ -145,9 +148,8 @@ public class InstrumentUploadMissingFind implements MFCommand { } if (depth > rootDepth) { if (lastModifiedTimeMatches(attrs.lastModifiedTime(), after, before)) { - Set<Upload> matchingUploads = getMatchingUploads(dir, uploads); - if (!matchingUploads.isEmpty()) { - result.put(dir, matchingUploads); + if (!hasMatchingUploads(dir, uploads)) { + missingDirectories.add(dir); } } } @@ -177,7 +179,7 @@ public class InstrumentUploadMissingFind implements MFCommand { return true; } - private static Set<Upload> getMatchingUploads(Path dir, Collection<Upload> uploads) { + static Set<Upload> getMatchingUploads(Path dir, Collection<Upload> uploads) { Set<Upload> matching = new LinkedHashSet<>(); for (Upload upload : uploads) { if (upload.pathContextMatches(dir.toAbsolutePath().toString())) { @@ -187,6 +189,15 @@ public class InstrumentUploadMissingFind implements MFCommand { return matching; } + static boolean hasMatchingUploads(Path dir, Collection<Upload> uploads) { + for (Upload upload : uploads) { + if (upload.pathContextMatches(dir.toAbsolutePath().toString())) { + return true; + } + } + return false; + } + public static class Settings { private Long _id; private String _token; @@ -280,7 +291,7 @@ public class InstrumentUploadMissingFind implements MFCommand { } public static void main(String[] args) { - CommandLine cl = new CommandLine(new InstrumentUploadList()); + CommandLine cl = new CommandLine(new InstrumentUploadMissingFind()); cl.setExecutionExceptionHandler(new IExecutionExceptionHandler() { @Override public int handleExecutionException(Exception ex, CommandLine commandLine, ParseResult parseResult) diff --git a/src/main/java/unimelb/picocli/converters/DateTimeConverter.java b/src/main/java/unimelb/picocli/converters/DateTimeConverter.java index 51a9ff50bd3bbda986f3e30c34f3c0cd435fe98a..b21fa01a97890de81de56269ed84d4608ed03ff4 100644 --- a/src/main/java/unimelb/picocli/converters/DateTimeConverter.java +++ b/src/main/java/unimelb/picocli/converters/DateTimeConverter.java @@ -3,6 +3,7 @@ package unimelb.picocli.converters; import java.text.SimpleDateFormat; import java.util.Date; +import arc.utils.DateTime; import picocli.CommandLine; public class DateTimeConverter implements CommandLine.ITypeConverter<Date> { @@ -16,7 +17,11 @@ public class DateTimeConverter implements CommandLine.ITypeConverter<Date> { } else if (value.matches("^\\d{1,2}-[a-zA-Z]{3}-\\d{4}.\\d{2}:\\d{2}:\\d{2}$")) { return new SimpleDateFormat("dd-MMM-yyyy.HH:mm:ss").parse(value); } else { - throw new IllegalArgumentException("'" + value + "' is not a valid date/time."); + try { + return DateTime.parse(value); + } catch (Throwable t) { + throw new IllegalArgumentException("'" + value + "' is not a valid date/time.", t); + } } } diff --git a/src/main/scripts/unix/instrument-upload-list b/src/main/scripts/unix/instrument-upload-list new file mode 100644 index 0000000000000000000000000000000000000000..0144440beefc2ff3294b6cd867b7498506636a1a --- /dev/null +++ b/src/main/scripts/unix/instrument-upload-list @@ -0,0 +1,31 @@ +#!/bin/bash + +# ${ROOT}/bin/ +BIN=$(dirname ${BASH_SOURCE[0]}) + +# current directory +CWD=$(pwd) + +# ${ROOT}/ +ROOT=$(cd ${BIN}/../../ && pwd && cd ${CWD}) + +# ${ROOT}/lib/ +LIB=${ROOT}/lib + +# ${ROOT}/lib/unimelb-mf-clients.jar +JAR=${LIB}/unimelb-mf-clients.jar + +# check if unimelb-mf-clients.jar exists +[[ ! -f $JAR ]] && echo "${JAR} is not found." >&2 && exit 2 + +# JRE included? +JRE=${ROOT}/jre +if [[ -d ${JRE} ]]; then + JAVA=${JRE}/bin/java +else + JAVA=$(which java) + [[ -z ${JAVA} ]] && echo "could not find java" && exit 1 +fi + +# execute the command +$JAVA -XX:+UseG1GC -XX:+UseStringDeduplication -Xmx1g -cp "${JAR}" unimelb.mf.client.instrument.cli.InstrumentUploadList ${1+"$@"} diff --git a/src/main/scripts/unix/instrument-upload-missing-find b/src/main/scripts/unix/instrument-upload-missing-find new file mode 100644 index 0000000000000000000000000000000000000000..a6bb3a4a682077acfce00c3232dae21e91bae21c --- /dev/null +++ b/src/main/scripts/unix/instrument-upload-missing-find @@ -0,0 +1,31 @@ +#!/bin/bash + +# ${ROOT}/bin/ +BIN=$(dirname ${BASH_SOURCE[0]}) + +# current directory +CWD=$(pwd) + +# ${ROOT}/ +ROOT=$(cd ${BIN}/../../ && pwd && cd ${CWD}) + +# ${ROOT}/lib/ +LIB=${ROOT}/lib + +# ${ROOT}/lib/unimelb-mf-clients.jar +JAR=${LIB}/unimelb-mf-clients.jar + +# check if unimelb-mf-clients.jar exists +[[ ! -f $JAR ]] && echo "${JAR} is not found." >&2 && exit 2 + +# JRE included? +JRE=${ROOT}/jre +if [[ -d ${JRE} ]]; then + JAVA=${JRE}/bin/java +else + JAVA=$(which java) + [[ -z ${JAVA} ]] && echo "could not find java" && exit 1 +fi + +# execute the command +$JAVA -XX:+UseG1GC -XX:+UseStringDeduplication -Xmx1g -cp "${JAR}" unimelb.mf.client.instrument.cli.InstrumentUploadMissingFind ${1+"$@"} diff --git a/src/main/scripts/windows/instrument-upload-list.cmd b/src/main/scripts/windows/instrument-upload-list.cmd new file mode 100644 index 0000000000000000000000000000000000000000..945cf7c709a3b5046bf409184b44fbcb1a453325 --- /dev/null +++ b/src/main/scripts/windows/instrument-upload-list.cmd @@ -0,0 +1,21 @@ +@echo off + +setlocal + +pushd "%~dp0..\..\" +set "ROOT=%cd%" +popd + +set "JRE=%ROOT%\jre" + +if exist "%JRE%\" ( + set "JAVA=%JRE%\bin\java" +) else ( + set JAVA=java +) + +set JAR=%ROOT%\lib\unimelb-mf-clients.jar + +"%JAVA%" -XX:+UseG1GC -XX:+UseStringDeduplication -Xmx1g -cp "%JAR%" unimelb.mf.client.instrument.cli.InstrumentUploadMissingFind %* + +endlocal diff --git a/src/main/scripts/windows/instrument-upload-missing-find.cmd b/src/main/scripts/windows/instrument-upload-missing-find.cmd new file mode 100644 index 0000000000000000000000000000000000000000..76db99b784799364f65385028840372f5e1a5580 --- /dev/null +++ b/src/main/scripts/windows/instrument-upload-missing-find.cmd @@ -0,0 +1,21 @@ +@echo off + +setlocal + +pushd "%~dp0..\..\" +set "ROOT=%cd%" +popd + +set "JRE=%ROOT%\jre" + +if exist "%JRE%\" ( + set "JAVA=%JRE%\bin\java" +) else ( + set JAVA=java +) + +set JAR=%ROOT%\lib\unimelb-mf-clients.jar + +"%JAVA%" -XX:+UseG1GC -XX:+UseStringDeduplication -Xmx1g -cp "%JAR%" unimelb.mf.client.instrument.cli.InstrumentUploadList %* + +endlocal