Skip to content

Commit

Permalink
Bxc 4710 thumbnails cleanup (#1808)
Browse files Browse the repository at this point in the history
* BXC-4710 delete image router routes

* BXC-4710 trying to update tests

* BXC-4710 fix SetDatastreamFilter

* BXC-4710 deleting THUMBNAIL_SMALL datastream type

* BXC-4710 remove THUMBNAIL_LARGE datastream

* BXC-4710 working on destroy derivatives router test

* BXC-4710 fix destroy derivatives router without thumbnail datastreams

* BXC-4710 cleanup

* BXC-4710 remove nonbinary enhancement processor

* BXC-4710 updating enhancement router

* BXC-4710 fixing destroy derivatives and access copies services

* BXC-4710 update destroy derivatives test

* BXC-4710 adding jp2 datastreams

* BXC-4710 delete more thumbnail references
  • Loading branch information
sharonluong authored Oct 9, 2024
1 parent 3959c4c commit f6c1bfe
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 1,021 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public class DatastreamPermissionUtil {
DS_PERMISSION_MAP.put(DatastreamType.ORIGINAL_FILE, Permission.viewOriginal);
DS_PERMISSION_MAP.put(DatastreamType.TECHNICAL_METADATA, Permission.viewHidden);
DS_PERMISSION_MAP.put(DatastreamType.TECHNICAL_METADATA_HISTORY, Permission.viewHidden);
DS_PERMISSION_MAP.put(DatastreamType.THUMBNAIL_SMALL, Permission.viewAccessCopies);
DS_PERMISSION_MAP.put(DatastreamType.THUMBNAIL_LARGE, Permission.viewAccessCopies);
}

private DatastreamPermissionUtil() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class SetDatastreamFilter implements IndexDocumentFilter {
private DerivativeService derivativeService;
private TechnicalMetadataService technicalMetadataService;
private Jp2InfoService jp2InfoService;
private static final List<DatastreamType> THUMBNAIL_DS_TYPES = Arrays.asList(DatastreamType.THUMBNAIL_SMALL, DatastreamType.THUMBNAIL_LARGE);

// Check for hours, minutes, seconds. Plus a check for optional milliseconds separated from seconds
// by a "." or a ":" via a non-capturing block followed by a capture group for the milliseconds.
private final Pattern TIMING_REGEX = Pattern.compile("(\\d+):(\\d+):(\\d+)(?:[.:](\\d+))?");
Expand Down Expand Up @@ -87,7 +87,7 @@ public void filter(DocumentIndexingPackage dip) throws IndexingException {
}

if (contentObj instanceof WorkObject) {
addThumbnailDerivatives((WorkObject) contentObj, datastreams);
addThumbnailDerivative((WorkObject) contentObj, datastreams);
}

// Add in metadata datastreams
Expand Down Expand Up @@ -288,6 +288,20 @@ private boolean needsExtent(String name, String mimetype) {
|| mimetype.startsWith("audio"));
}

/**
* Used to selectively add the JP2 thumbnail datastream
*
* @param workObject the work object with the thumbnail relation
* @param datastreams work object's datastreams to add thumbnail streams to
*/
private void addThumbnailDerivative(WorkObject workObject, List<Datastream> datastreams) {
FileObject thumbnailObject = workObject.getThumbnailObject();

if (thumbnailObject != null) {
addDerivatives(datastreams, thumbnailObject.getPid(), true, List.of(JP2_ACCESS_COPY));
}
}

private String getFirstChecksum(Resource resc) {
Statement prop = resc.getProperty(Premis.hasMessageDigest);
if (prop == null) {
Expand Down Expand Up @@ -353,33 +367,6 @@ private void addDerivatives(List<Datastream> dsList, PID pid, boolean ownedByOth
});
}

/**
* Used to selectively add only thumbnail datastreams
*
* @param workObject the work object with the thumbnail relation
* @param datastreams work object's datastreams to add thumbnail streams to
*/
private void addThumbnailDerivatives(WorkObject workObject, List<Datastream> datastreams) {
FileObject thumbnailObject = workObject.getThumbnailObject();

if (thumbnailObject != null) {
var updatedDatastreams = clearPreviousThumbnailDatastreams(datastreams);
addDerivatives(updatedDatastreams, thumbnailObject.getPid(), true, THUMBNAIL_DS_TYPES);
}
}

/**
* There may be thumbnail streams from the primary object, so we'll clear those
* before adding the assigned thumbnail datastreams
*
* @param datastreams full list of datastreams to index for the work object
* @return modified list of datastreams without thumbnail datastreams
*/
private List<Datastream> clearPreviousThumbnailDatastreams(List<Datastream> datastreams) {
datastreams.removeIf(ds -> THUMBNAIL_DS_TYPES.contains(DatastreamType.getByIdentifier(ds.getName())));
return datastreams;
}

private DatastreamImpl createDatastream(DerivativeService.Derivative derivative, String owner, String extent) {
DatastreamType type = derivative.getType();
String name = type.getId();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public enum DatastreamType {
MD_EVENTS("event_log", "application/n-triples", "nt", METADATA_CONTAINER, INTERNAL),
ORIGINAL_FILE("original_file", null, null, DATA_FILE_FILESET, INTERNAL),
TECHNICAL_METADATA("techmd_fits", "text/xml", "xml", DATA_FILE_FILESET, INTERNAL),
TECHNICAL_METADATA_HISTORY("techmd_fits_history", "text/xml", "xml", DATA_FILE_FILESET, INTERNAL),
THUMBNAIL_SMALL("thumbnail_small", "image/png", "png", null, EXTERNAL),
THUMBNAIL_LARGE("thumbnail_large", "image/png", "png", null, EXTERNAL);
TECHNICAL_METADATA_HISTORY("techmd_fits_history", "text/xml", "xml", DATA_FILE_FILESET, INTERNAL);

private final String id;
private final String mimetype;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
package edu.unc.lib.boxc.model.fcrepo.services;

import static edu.unc.lib.boxc.model.api.DatastreamType.JP2_ACCESS_COPY;
import static edu.unc.lib.boxc.model.api.DatastreamType.ORIGINAL_FILE;
import static edu.unc.lib.boxc.model.api.DatastreamType.THUMBNAIL_SMALL;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import edu.unc.lib.boxc.model.api.DatastreamType;
import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.model.fcrepo.services.DerivativeService.Derivative;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import edu.unc.lib.boxc.model.api.DatastreamType;
import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import edu.unc.lib.boxc.model.fcrepo.services.DerivativeService;
import edu.unc.lib.boxc.model.fcrepo.services.DerivativeService.Derivative;
import static edu.unc.lib.boxc.model.api.DatastreamType.FULLTEXT_EXTRACTION;
import static edu.unc.lib.boxc.model.api.DatastreamType.JP2_ACCESS_COPY;
import static edu.unc.lib.boxc.model.api.DatastreamType.ORIGINAL_FILE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
*
Expand Down Expand Up @@ -56,48 +54,48 @@ public void init() throws Exception {

@Test
public void testGetDerivative() throws Exception {
File originalDerivFile = createDerivative(pid, THUMBNAIL_SMALL);
File originalDerivFile = createDerivative(pid, JP2_ACCESS_COPY);

Derivative deriv = derivativeService.getDerivative(pid, THUMBNAIL_SMALL);
Derivative deriv = derivativeService.getDerivative(pid, JP2_ACCESS_COPY);

assertEquals(originalDerivFile, deriv.getFile());
assertEquals(THUMBNAIL_SMALL, deriv.getType());
assertEquals(JP2_ACCESS_COPY, deriv.getType());
}

@Test
public void testGetDerivativeNotExist() throws Exception {
Derivative deriv = derivativeService.getDerivative(pid, THUMBNAIL_SMALL);
Derivative deriv = derivativeService.getDerivative(pid, JP2_ACCESS_COPY);

assertNull(deriv);
}

@Test
public void testGetDerivatives() throws Exception {
File originalDerivFile1 = createDerivative(pid, THUMBNAIL_SMALL);
File originalDerivFile1 = createDerivative(pid, FULLTEXT_EXTRACTION);
File originalDerivFil21 = createDerivative(pid, JP2_ACCESS_COPY);

List<Derivative> derivs = derivativeService.getDerivatives(pid);
assertEquals(2, derivs.size());

Derivative thumbDeriv = findDerivative(derivs, THUMBNAIL_SMALL);
Derivative textDeriv = findDerivative(derivs, FULLTEXT_EXTRACTION);
Derivative jp2Deriv = findDerivative(derivs, JP2_ACCESS_COPY);

assertNotNull(thumbDeriv);
assertNotNull(textDeriv);
assertNotNull(jp2Deriv);

assertEquals(originalDerivFile1, thumbDeriv.getFile());
assertEquals(originalDerivFile1, textDeriv.getFile());
assertEquals(originalDerivFil21, jp2Deriv.getFile());
}

@Test
public void testGetDerivativesIgnoreNonDerivatives() throws Exception {
File originalDerivFile1 = createDerivative(pid, THUMBNAIL_SMALL);
File originalDerivFile1 = createDerivative(pid, JP2_ACCESS_COPY);
createDerivative(pid, ORIGINAL_FILE);

List<Derivative> derivs = derivativeService.getDerivatives(pid);
assertEquals(1, derivs.size());

Derivative thumbDeriv = findDerivative(derivs, THUMBNAIL_SMALL);
Derivative thumbDeriv = findDerivative(derivs, JP2_ACCESS_COPY);
assertEquals(originalDerivFile1, thumbDeriv.getFile());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@

import java.util.HashSet;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;

/**
* @author lfarrell
*/
public class QueryFilterFactoryTest {
@Test
public void NamedDatastreamFilterTest() {
var filter = QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, DatastreamType.THUMBNAIL_LARGE);
assertTrue(filter instanceof NamedDatastreamFilter);
var filter = QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, DatastreamType.JP2_ACCESS_COPY);
assertInstanceOf(NamedDatastreamFilter.class, filter);
}

@Test
public void MultipleDirectlyOwnedDatastreamsFilterTest() {
var datastreamTypes = new HashSet<DatastreamType>();
datastreamTypes.add(DatastreamType.THUMBNAIL_LARGE);
datastreamTypes.add(DatastreamType.THUMBNAIL_SMALL);
datastreamTypes.add(DatastreamType.JP2_ACCESS_COPY);
datastreamTypes.add(DatastreamType.FULLTEXT_EXTRACTION);
var filter = QueryFilterFactory.createFilter(SearchFieldKey.DATASTREAM, datastreamTypes);
assertTrue(filter instanceof MultipleDirectlyOwnedDatastreamsFilter);
assertInstanceOf(MultipleDirectlyOwnedDatastreamsFilter.class, filter);
}

@Test
public void HasPopulatedFieldFilterTest() {
var filter = QueryFilterFactory.createFilter(SearchFieldKey.STREAMING_TYPE);
assertTrue(filter instanceof HasPopulatedFieldFilter);
assertInstanceOf(HasPopulatedFieldFilter.class, filter);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package edu.unc.lib.boxc.services.camel.destroyDerivatives;

import static edu.unc.lib.boxc.services.camel.util.CdrFcrepoHeaders.CdrObjectType;
import static org.slf4j.LoggerFactory.getLogger;

import edu.unc.lib.boxc.services.camel.fulltext.FulltextProcessor;
import edu.unc.lib.boxc.services.camel.images.ImageDerivativeProcessor;
import org.apache.camel.BeanInject;
import org.apache.camel.LoggingLevel;
import org.apache.camel.PropertyInject;
import org.apache.camel.builder.RouteBuilder;
import org.slf4j.Logger;

import edu.unc.lib.boxc.model.api.rdf.Cdr;
import edu.unc.lib.boxc.services.camel.fulltext.FulltextProcessor;
import edu.unc.lib.boxc.services.camel.images.ImageDerivativeProcessor;
import static org.slf4j.LoggerFactory.getLogger;

/**
* Router to process requests to destroy derivatives for an object
Expand All @@ -25,15 +22,6 @@ public class DestroyDerivativesRouter extends RouteBuilder {
@BeanInject(value = "destroyedMsgProcessor")
private DestroyedMsgProcessor destroyedMsgProcessor;

@BeanInject(value = "destroyCollectionSrcImgProcessor")
private DestroyDerivativesProcessor destroyCollectionSrcImgProcessor;

@BeanInject(value = "destroySmallThumbnailProcessor")
private DestroyDerivativesProcessor destroySmallThumbnailProcessor;

@BeanInject(value = "destroyLargeThumbnailProcessor")
private DestroyDerivativesProcessor destroyLargeThumbnailProcessor;

@BeanInject(value = "destroyAccessCopyProcessor")
private DestroyDerivativesProcessor destroyAccessCopyProcessor;

Expand Down Expand Up @@ -74,45 +62,14 @@ public void configure() throws Exception {
from("direct:image.derivatives.destroy")
.routeId("CdrDestroyImage")
.startupOrder(202)
.log(LoggingLevel.DEBUG, log, "Destroying derivative thumbnails")
.bean(destroySmallThumbnailProcessor)
.bean(destroyLargeThumbnailProcessor)
.choice()
.when(simple("${headers['" + CdrObjectType + "']} == '" + Cdr.FileObject.getURI() + "'"))
.to("direct:image.access.destroy")
.when(simple("${headers['CollectionThumb']} != null"))
.to("direct:image.collection.destroy")
.end();

from("direct:image.access.destroy")
.routeId("CdrDestroyAccessCopy")
.startupOrder(201)
.log(LoggingLevel.DEBUG, log, "Destroying access copy")
.log(LoggingLevel.DEBUG, log, "Destroying access copy derivatives")
.bean(destroyAccessCopyProcessor);

from("direct:image.collection.destroy")
.routeId("CdrDestroyCollectionUpload")
.startupOrder(200)
.log(LoggingLevel.DEBUG, log, "Destroying collection image upload")
.bean(destroyCollectionSrcImgProcessor);
}

public void setDestroyedMsgProcessor(DestroyedMsgProcessor destroyedMsgProcessor) {
this.destroyedMsgProcessor = destroyedMsgProcessor;
}

public void setDestroyCollectionSrcImgProcessor(DestroyDerivativesProcessor destroyCollectionSrcImgProcessor) {
this.destroyCollectionSrcImgProcessor = destroyCollectionSrcImgProcessor;
}

public void setDestroySmallThumbnailProcessor(DestroyDerivativesProcessor destroySmallThumbnailProcessor) {
this.destroySmallThumbnailProcessor = destroySmallThumbnailProcessor;
}

public void setDestroyLargeThumbnailProcessor(DestroyDerivativesProcessor destroyLargeThumbnailProcessor) {
this.destroyLargeThumbnailProcessor = destroyLargeThumbnailProcessor;
}

public void setDestroyAccessCopyProcessor(DestroyDerivativesProcessor destroyAccessCopyProcessor) {
this.destroyAccessCopyProcessor = destroyAccessCopyProcessor;
}
Expand Down
Loading

0 comments on commit f6c1bfe

Please sign in to comment.