Skip to content

Commit

Permalink
Convert content uris to base paths during deregistration since it req…
Browse files Browse the repository at this point in the history
…uires the logical path for the file now
  • Loading branch information
bbpennel committed Mar 31, 2021
1 parent 290dbc6 commit aedc31b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package edu.unc.lib.dl.services.camel.longleaf;

import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -28,6 +29,7 @@
import edu.unc.lib.dl.fedora.ServiceException;
import edu.unc.lib.dl.metrics.HistogramFactory;
import edu.unc.lib.dl.metrics.TimerFactory;
import edu.unc.lib.dl.persist.services.transfer.FileSystemTransferHelpers;
import io.dropwizard.metrics5.Histogram;
import io.dropwizard.metrics5.Timer;

Expand Down Expand Up @@ -62,16 +64,23 @@ public void process(Exchange exchange) throws Exception {

String deregList = messages.stream().map(m -> {
URI uri = URI.create(m);
Path filePath;
if ("file".equals(uri.getScheme())) {
return Paths.get(uri).toString();
filePath = Paths.get(uri);
} else if (uri.getScheme() == null && m.startsWith("/")) {
// No scheme, assume it is a file path
return Paths.get(m).normalize().toString();
filePath = Paths.get(m);
} else {
log.warn("Ignoring invalid content URI during deregistration: {}", m);
return null;
}
}).filter(m -> m !=null).collect(Collectors.joining("\n"));
// Translate the content URI into its base logical path
return FileSystemTransferHelpers.getBaseBinaryPath(filePath.normalize());
}).filter(m -> m != null).collect(Collectors.joining("\n"));
// No valid content URIs to deregister
if (deregList.length() == 0) {
return;
}

try (Timer.Context context = timer.time()) {
ExecuteResult result = executeCommand("deregister -l @-", deregList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import static org.slf4j.LoggerFactory.getLogger;

import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.slf4j.Logger;

import edu.unc.lib.dl.persist.services.transfer.FileSystemTransferHelpers;

/**
* @author bbpennel
*/
Expand Down Expand Up @@ -61,9 +64,15 @@ protected void assertSubmittedPaths(long timeout, String... contentUris) throws
protected void assertSubmittedPaths(String... contentUris) {
for (String contentUri : contentUris) {
URI uri = URI.create(contentUri);
String contentPath = uri.getScheme() == null ? contentUri : Paths.get(uri).toString();
Path contentPath;
if (uri.getScheme() == null) {
contentPath = Paths.get(contentUri);
} else {
contentPath = Paths.get(uri);
}
String basePath = FileSystemTransferHelpers.getBaseBinaryPath(contentPath);
assertTrue("Expected content uri to be submitted: " + contentPath,
output.stream().anyMatch(line -> line.contains(contentPath)));
output.stream().anyMatch(line -> line.contains(basePath)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public void deregisterCommandErrorSuccessExit() throws Exception {
}

private String generateContentUri() {
return "file:///path/to/file/" + UUID.randomUUID().toString();
return "file:///path/to/file/" + UUID.randomUUID().toString() + "." + System.nanoTime();
}

private String[] generateContentUris(int num) {
Expand Down

0 comments on commit aedc31b

Please sign in to comment.