Skip to content

Commit

Permalink
BXC-4082 cleaning up set datastream filter class
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharon Luong committed Sep 25, 2023
1 parent 28151c5 commit 7ed8a91
Showing 1 changed file with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public void filter(DocumentIndexingPackage dip) throws IndexingException {
doc.setFilesizeSort(getFilesize(datastreams));

// Add list of derivatives associated from the representative file
addDerivatives(datastreams, fileObj.getPid(), ownedByOtherObject);
addDerivatives(datastreams, fileObj.getPid(), ownedByOtherObject, null);
} else {
// Add list of derivatives associated with the object
addDerivatives(datastreams, contentObj.getPid(), false);
addDerivatives(datastreams, contentObj.getPid(), false, null);
}

if (contentObj instanceof WorkObject) {
Expand Down Expand Up @@ -155,7 +155,7 @@ private String getExtent(List<BinaryObject> binList) {
* @param ownedByOtherObject
*/
private void addDatastreams(List<Datastream> dsList, List<BinaryObject> binList, boolean ownedByOtherObject) {
binList.stream().forEach(binary -> {
binList.forEach(binary -> {
Resource binaryResc = binary.getResource();

String name = binaryResc.getURI();
Expand Down Expand Up @@ -215,38 +215,31 @@ private long getFilesize(List<Datastream> datastreams) throws IndexingException
.filter(ds -> ORIGINAL_FILE.getId().equals(ds.getName()))
.findFirst();

if (!original.isPresent()) {
if (original.isEmpty()) {
throw new IndexingException("File object in invalid state, cannot find original file binary");
}

Long size = original.get().getFilesize();
return size != null ? size : 0l;
}

private void addDerivatives(List<Datastream> dsList, PID pid, boolean ownedByOtherObject) {
derivativeService.getDerivatives(pid)
.forEach(deriv -> {
String owner = (ownedByOtherObject ? pid.getId() : null);
private void addDerivatives(List<Datastream> dsList, PID pid, boolean ownedByOtherObject, List<DatastreamType> types) {
derivativeService.getDerivatives(pid).forEach(deriv -> {
DatastreamType type = deriv.getType();
// only add derivatives of types listed
if (!(types == null) && !types.contains(type)) return;

DatastreamType type = deriv.getType();
addToDatastreamList(type, owner, dsList, deriv.getFile());
});
}

private void addSelectedDerivatives(List<Datastream> dsList, PID pid, boolean ownedByOtherObject, List<DatastreamType> types) {
var derivatives = derivativeService.getDerivatives(pid);


derivatives.forEach(deriv -> {
DatastreamType type = deriv.getType();
// only add derivatives of types listed
if (!types.contains(type)) return;

String owner = (ownedByOtherObject ? pid.getId() : null);
addToDatastreamList(type, owner, dsList, deriv.getFile());
});
String owner = (ownedByOtherObject ? pid.getId() : null);
addToDatastreamList(type, owner, dsList, deriv.getFile());
});
}

/**
* Used to selectively add only thumbnail datastreams
*
* @param contentObject should be 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();
Expand All @@ -256,7 +249,7 @@ private void addThumbnailDerivatives(ContentObject contentObject, List<Datastrea
types.add(DatastreamType.THUMBNAIL_SMALL);
types.add(DatastreamType.THUMBNAIL_LARGE);

addSelectedDerivatives(datastreams, thumbnailObject.getPid(), true, types);
addDerivatives(datastreams, thumbnailObject.getPid(), true, types);
}
}

Expand Down

0 comments on commit 7ed8a91

Please sign in to comment.