Skip to content

Commit

Permalink
BXC-4082 addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Luong committed Sep 26, 2023
1 parent 7ed8a91 commit af92d89
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private List<String> determineContentStatus(DocumentIndexingPackage dip)
if (parentResc.hasProperty(Cdr.primaryObject, resc)) {
status.add(FacetConstants.IS_PRIMARY_OBJECT);
}
if (parentResc.hasProperty(Cdr.useAsThumbnail, resc)) {
status.add(FacetConstants.IS_ASSIGNED_THUMBNAIL);
}
}

return status;
Expand All @@ -70,5 +73,11 @@ private void addWorkObjectStatuses(List<String> status, Resource resource) {
} else {
status.add(FacetConstants.MEMBERS_ARE_UNORDERED);
}

if (resource.hasProperty(Cdr.useAsThumbnail)) {
status.add(FacetConstants.THUMBNAIL_ASSIGNED);
} else {
status.add(FacetConstants.NO_THUMBNAIL_ASSIGNED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class SetDatastreamFilter implements IndexDocumentFilter {

private DerivativeService derivativeService;
private TechnicalMetadataService technicalMetadataService;
private static final List<DatastreamType> THUMBNAIL_DS_TYPES = Arrays.asList(DatastreamType.THUMBNAIL_SMALL, DatastreamType.THUMBNAIL_LARGE);

@Override
public void filter(DocumentIndexingPackage dip) throws IndexingException {
Expand Down Expand Up @@ -76,7 +78,7 @@ public void filter(DocumentIndexingPackage dip) throws IndexingException {
}

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

// Add in metadata datastreams
Expand Down Expand Up @@ -227,41 +229,56 @@ private void addDerivatives(List<Datastream> dsList, PID pid, boolean ownedByOth
derivativeService.getDerivatives(pid).forEach(deriv -> {
DatastreamType type = deriv.getType();
// only add derivatives of types listed
if (!(types == null) && !types.contains(type)) return;
if ((types != null) && !types.contains(type)) {
return;
}

String owner = (ownedByOtherObject ? pid.getId() : null);
addToDatastreamList(type, owner, dsList, deriv.getFile());
String name = type.getId();
String mimetype = type.getMimetype();
String extension = type.getExtension();
File file = deriv.getFile();
Long filesize = file.length();
String filename = file.getName();
var derivative = new DatastreamImpl(owner, name, filesize, mimetype, filename, extension, null, null);
addDerivativeToList(dsList, derivative);
});
}

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

if (thumbnailObject != null) {
List<DatastreamType> types = new ArrayList<>();
types.add(DatastreamType.THUMBNAIL_SMALL);
types.add(DatastreamType.THUMBNAIL_LARGE);

addDerivatives(datastreams, thumbnailObject.getPid(), true, types);
var updatedDatastreams = clearPreviousThumbnailDatastreams(datastreams);
addDerivatives(updatedDatastreams, thumbnailObject.getPid(), true, THUMBNAIL_DS_TYPES);
}
}

private void addToDatastreamList(DatastreamType type, String owner, List<Datastream> dsList, File file) {
String name = type.getId();
String mimetype = type.getMimetype();
String extension = type.getExtension();

Long filesize = file.length();
String filename = file.getName();
/**
* 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) {
for (Datastream datastream : datastreams) {
var type = DatastreamType.getByIdentifier(datastream.getName());
if (THUMBNAIL_DS_TYPES.contains(type)) {
datastreams.remove(datastream);
}
}
return datastreams;
}

dsList.add(new DatastreamImpl(owner, name, filesize, mimetype, filename, extension, null, null));
private void addDerivativeToList(List<Datastream> dsList, DatastreamImpl derivative) {
dsList.add(derivative);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void setPrimaryObject(PID primaryPid) {
*/
@Override
public FileObject getPrimaryObject() {
return getObject(Cdr.primaryObject);
return getFileObjectByProperty(Cdr.primaryObject);
}

@Override
Expand Down Expand Up @@ -205,10 +205,10 @@ public List<PID> getMemberOrder() {

@Override
public FileObject getThumbnailObject() {
return getObject(Cdr.useAsThumbnail);
return getFileObjectByProperty(Cdr.useAsThumbnail);
}

private FileObject getObject(Property property) {
private FileObject getFileObjectByProperty(Property property) {
Resource resource = getResource();
// Find the object relation if it is present
Statement stmt = resource.getProperty(property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void clearPrimaryObjectTest() {
@Test
public void getPrimaryObjectTest() {
PID primaryPid = makePid();
Resource primaryResc = createResource(primaryPid.getURI());
Resource primaryResc = createResource(primaryPid.getRepositoryPath());

when(driver.getRepositoryObject(eq(primaryPid), eq(FileObject.class))).thenReturn(fileObj);

Expand Down Expand Up @@ -296,6 +296,28 @@ public void getMemberOrderWithMembers() {
assertEquals(members, work.getMemberOrder());
}

@Test
public void getThumbnailObjectTest() {
PID pid = makePid();
Resource resource = createResource(pid.getRepositoryPath());

when(driver.getRepositoryObject(eq(pid), eq(FileObject.class))).thenReturn(fileObj);

resc.addProperty(Cdr.useAsThumbnail, resource);

FileObject resultObj = work.getThumbnailObject();

assertEquals(resultObj, fileObj);
}

@Test
public void getNoThumbnailObjectTest() {
FileObject resultObj = work.getThumbnailObject();

assertNull(resultObj);
verify(driver, never()).getRepositoryObject(any(PID.class), eq(FileObject.class));
}

private PID makePid() {
return PIDs.get(UUID.randomUUID().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ public abstract class FacetConstants {
public static final String STAFF_ONLY_ACCESS = "Staff-Only Access";
public static final String MEMBERS_ARE_ORDERED = "Members Are Ordered";
public static final String MEMBERS_ARE_UNORDERED = "Members Are Unordered";
public static final String THUMBNAIL_ASSIGNED = "Has Assigned Thumbnail";
public static final String NO_THUMBNAIL_ASSIGNED = "No Assigned Thumbnail";
public static final String IS_ASSIGNED_THUMBNAIL = "Is Assigned Thumbnail";

}

0 comments on commit af92d89

Please sign in to comment.