Skip to content

Commit

Permalink
The bitstreams cannot be seen after the item is created (#657)
Browse files Browse the repository at this point in the history
* Update Item's metadata when the bitstream is updated.

* Update Item's metadata about files after deleting the bitstream.

* Update Item's metadata before the bundle is deleted or touched

* Check if the bundle is not null before using it.
  • Loading branch information
milanmajchrak committed Jun 19, 2024
1 parent 2e8c525 commit 3242faf
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.dspace.content.service.BitstreamService;
import org.dspace.content.service.BundleService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.clarin.ClarinItemService;
import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
Expand Down Expand Up @@ -66,6 +67,8 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
protected BitstreamStorageService bitstreamStorageService;
@Autowired(required = true)
protected ClarinLicenseResourceMappingService clarinLicenseResourceMappingService;
@Autowired(required = true)
protected ClarinItemService clarinItemService;

protected BitstreamServiceImpl() {
super();
Expand Down Expand Up @@ -275,6 +278,8 @@ public void delete(Context context, Bitstream bitstream) throws SQLException, Au
// Remove bitstream itself
bitstream.setDeleted(true);
update(context, bitstream);
// Update Item's metadata about bitstreams
clarinItemService.updateItemFilesMetadata(context, bitstream);

//Remove our bitstream from all our bundles
final List<Bundle> bundles = bitstream.getBundles();
Expand All @@ -286,7 +291,6 @@ public void delete(Context context, Bitstream bitstream) throws SQLException, Au
}
bundle.removeBitstream(bitstream);
}

//Remove all bundles from the bitstream object, clearing the connection in 2 ways
bundles.clear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ public void addBitstream(Context context, Bundle bundle, Bitstream bitstream)
// Ensure that the last modified from the item is triggered !
Item owningItem = (Item) getParentObject(context, bundle);
if (owningItem != null) {
clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
itemService.updateLastModified(context, owningItem);
itemService.update(context, owningItem);
}
Expand Down Expand Up @@ -219,6 +218,7 @@ public void addBitstream(Context context, Bundle bundle, Bitstream bitstream)
}
bitstreamService.update(context, bitstream);

clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
// Add clarin license to the bitstream and clarin license values to the item metadata
clarinLicenseService.addClarinLicenseToBitstream(context, owningItem, bundle, bitstream);
}
Expand All @@ -240,9 +240,9 @@ public void removeBitstream(Context context, Bundle bundle, Bitstream bitstream)
//Ensure that the last modified from the item is triggered !
Item owningItem = (Item) getParentObject(context, bundle);
if (owningItem != null) {
clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
itemService.updateLastModified(context, owningItem);
itemService.update(context, owningItem);
clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
}

// In the event that the bitstream to remove is actually
Expand Down Expand Up @@ -456,10 +456,9 @@ public void setOrder(Context context, Bundle bundle, UUID[] bitstreamIds) throws
//The order of the bitstreams has changed, ensure that we update the last modified of our item
Item owningItem = (Item) getParentObject(context, bundle);
if (owningItem != null) {
clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
itemService.updateLastModified(context, owningItem);
itemService.update(context, owningItem);

clarinItemService.updateItemFilesMetadata(context, owningItem, bundle);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,32 @@ public void updateItemFilesMetadata(Context context, Item item, Bundle bundle) t
itemService.addMetadata(context, item,"local", "files", "count", Item.ANY, "" + totalNumberOfFiles);
itemService.addMetadata(context, item,"local", "files", "size", Item.ANY, "" + totalSizeofFiles);
}

@Override
public void updateItemFilesMetadata(Context context, Bitstream bit) throws SQLException {
// Get the Item the bitstream is associated with
Item item = null;
Bundle bundle = null;
List<Bundle> origs = bit.getBundles();
for (Bundle orig : origs) {
if (!Constants.CONTENT_BUNDLE_NAME.equals(orig.getName())) {
continue;
}

List<Item> items = orig.getItems();
if (CollectionUtils.isEmpty(items)) {
continue;
}

item = items.get(0);
bundle = orig;
break;
}

// It could be null when the bundle name is e.g. `LICENSE`
if (Objects.isNull(item) || Objects.isNull(bundle)) {
return;
}
this.updateItemFilesMetadata(context, item, bundle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.UUID;

import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
Expand Down Expand Up @@ -80,4 +81,13 @@ public interface ClarinItemService {
*/
void updateItemFilesMetadata(Context context, Item item, Bundle bundle) throws SQLException;

/**
* Update item's metadata about its files (local.has.files, local.files.size, local.files.count).
* The Item and Bundle information is taken from the Bitstream object.
* @param context
* @param bit
* @throws SQLException
*/
void updateItemFilesMetadata(Context context, Bitstream bit) throws SQLException;

}

0 comments on commit 3242faf

Please sign in to comment.