diff --git a/services-camel/src/main/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafProcessor.java b/services-camel/src/main/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafProcessor.java index ede2e7a38c..98fcf0aec6 100644 --- a/services-camel/src/main/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafProcessor.java +++ b/services-camel/src/main/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafProcessor.java @@ -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; @@ -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; @@ -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); diff --git a/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/AbstractLongleafRouteTest.java b/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/AbstractLongleafRouteTest.java index 5d4b717b02..e6ac3e59c7 100644 --- a/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/AbstractLongleafRouteTest.java +++ b/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/AbstractLongleafRouteTest.java @@ -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 */ @@ -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))); } } diff --git a/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafRouteTest.java b/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafRouteTest.java index 6ed01047b9..d2693ac1e8 100644 --- a/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafRouteTest.java +++ b/services-camel/src/test/java/edu/unc/lib/dl/services/camel/longleaf/DeregisterLongleafRouteTest.java @@ -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) {