Skip to content

Commit

Permalink
BXC-4710 update destroy derivatives test
Browse files Browse the repository at this point in the history
  • Loading branch information
sharonluong committed Oct 7, 2024
1 parent 3f9664b commit 380fb51
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.7'

services:
fedora:
image: fcrepo/fcrepo:5.1.1
image: fcrepo/fcrepo:5.1.1-multiplatform
ports:
- "48085:8080"
volumes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class DestroyedMsgProcessor implements Processor {
private static final Logger log = LoggerFactory.getLogger(DestroyedMsgProcessor.class);

private String jp2BasePath;

@Override
public void process(Exchange exchange) throws Exception {
Expand All @@ -52,6 +52,16 @@ public void process(Exchange exchange) throws Exception {
String pidId = content.getChildTextTrim("pidId", JDOMNamespaceUtil.CDR_MESSAGE_NS);
String binaryPath = content.getChildTextTrim("contentUri", JDOMNamespaceUtil.CDR_MESSAGE_NS);

if (!objType.equals(Cdr.FileObject.getURI())) {
String uuid = PIDs.get(pidId).getId();
String binarySubPath = idToPath(uuid, HASHED_PATH_DEPTH, HASHED_PATH_SIZE);
Path jp2Path = Paths.get(jp2BasePath, binarySubPath, uuid + ".jp2");

if (Files.exists(jp2Path)) {
mimeType = "image/jp2";
}
}

if (mimeType == null) {
mimeType = "";
if (objType.equals(Cdr.FileObject.getURI())) {
Expand All @@ -64,4 +74,8 @@ public void process(Exchange exchange) throws Exception {
in.setHeader(CdrBinaryPath, binaryPath);
in.setHeader(CdrObjectType, objType);
}

public void setJp2BasePath(String jp2BasePath) {
this.jp2BasePath = jp2BasePath;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package edu.unc.lib.boxc.services.camel.images;

import java.util.regex.Pattern;

import edu.unc.lib.boxc.services.camel.util.CdrFcrepoHeaders;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.unc.lib.boxc.services.camel.util.CdrFcrepoHeaders;
import java.util.regex.Pattern;

/**
* Processor which validates and prepares image objects for producing derivatives
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
</bean>

<bean id="destroyedMsgProcessor" class="edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyedMsgProcessor">
<property name="jp2BasePath" value="${cdr.enhancement.path.jp2}" />
</bean>

<bean id="destroyCollectionSrcImgProcessor" class="edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyDerivativesProcessor">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mock;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -90,6 +92,9 @@ public class DestroyDerivativesRouterIT extends CamelSpringTestSupport {
@Mock
private MemberOrderRequestSender memberOrderRequestSender;

@TempDir
public Path tmpFolder;

private DestroyedMsgProcessor destroyedMsgProcessor;

private DestroyDerivativesProcessor destroyAccessCopyProcessor;
Expand Down Expand Up @@ -156,6 +161,7 @@ public void init() {
.model);

collection = repoObjectFactory.createCollectionObject(null);
destroyedMsgProcessor.setJp2BasePath(tmpFolder.toString());

contentRoot.addMember(adminUnit);
adminUnit.addMember(collection);
Expand Down Expand Up @@ -197,15 +203,16 @@ public void destroyCollectionImageTest() throws Exception {

treeIndexer.indexAll(baseAddress);

// Create collection thumbnail
// Create collection thumbnail jp2
PID collPid = collectionWithImg.getPid();
String uuid = collPid.getId();
String binarySubPath = idToPath(uuid, HASHED_PATH_DEPTH, HASHED_PATH_SIZE);
Path existingFileDirs = Files.createDirectories(new File("target/" + binarySubPath).toPath());
File existingFile = new File(existingFileDirs.toString(), uuid);
FileUtils.writeStringToFile(existingFile, "thumbnail", "UTF-8");
var derivativeFinalDir = Files.createDirectories(tmpFolder.resolve( binarySubPath)).toFile();
var file = new File(derivativeFinalDir, uuid + ".jp2");
FileUtils.writeStringToFile(file, "fake jp2", StandardCharsets.UTF_8);

markForDeletion(collPid);
new MarkForDeletionJob(collPid, "", agent, repoObjLoader,
sparqlUpdateService, aclService, premisLoggerFactory).run();
initializeDestroyJob(Collections.singletonList(collPid));

destroyJob.run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ error.retryDelay=0
error.maxRedeliveries=2
error.backOffMultiplier=1

sourceImages.dir=target

cdr.stream=activemq:queue:repository.events
cdr.stream.camel=activemq://activemq:queue:repository.events

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
</bean>

<bean id="destroyedMsgProcessor" class="edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyedMsgProcessor">
<constructor-arg value="${sourceImages.dir}" />
</bean>

<bean id="destroyAccessCopyProcessor" class="org.mockito.Mockito" factory-method="mock">
Expand Down

0 comments on commit 380fb51

Please sign in to comment.