Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
import org.dspace.content.service.RelationshipService;
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.content.service.clarin.ClarinItemService;
import org.dspace.content.service.clarin.ClarinLicenseResourceMappingService;
import org.dspace.content.service.clarin.ClarinLicenseService;
import org.dspace.core.Constants;
Expand Down Expand Up @@ -188,6 +189,8 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
protected ClarinLicenseService clarinLicenseService;
@Autowired(required = true)
protected ClarinLicenseResourceMappingService clarinLicenseResourceMappingService;
@Autowired(required = true)
protected ClarinItemService clarinItemService;

protected String tempWorkDir;

Expand Down Expand Up @@ -723,6 +726,8 @@ public void replaceItems(Context c, List<Collection> mycollections,
itemService.clearMetadata(c, newItem, "dc", "rights", "label", Item.ANY);
itemService.addMetadata(c, newItem, "dc", "rights", "label", Item.ANY,
license.getNonExtendedClarinLicenseLabel().getLabel());
clarinItemService.updateItemFilesMetadata(c, newItem);

itemService.update(c, newItem);
c.uncacheEntity(newItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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.content.service.clarin.ClarinLicenseService;
import org.dspace.core.Constants;
Expand Down Expand Up @@ -70,6 +71,8 @@ public class BundleServiceImpl extends DSpaceObjectServiceImpl<Bundle> implement
protected ClarinLicenseService clarinLicenseService;
@Autowired(required = true)
protected ClarinLicenseResourceMappingService clarinLicenseResourceMappingService;
@Autowired(required = true)
protected ClarinItemService clarinItemService;

protected BundleServiceImpl() {
super();
Expand Down Expand Up @@ -161,6 +164,7 @@ 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 @@ -236,6 +240,7 @@ 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);
}
Expand Down Expand Up @@ -451,6 +456,7 @@ 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

import org.apache.commons.collections4.CollectionUtils;
import org.apache.logging.log4j.Logger;
import org.dspace.content.Bitstream;
import org.dspace.content.Bundle;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
import org.dspace.content.MetadataField;
import org.dspace.content.dao.clarin.ClarinItemDAO;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.clarin.ClarinItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
Expand All @@ -41,6 +44,9 @@ public class ClarinItemServiceImpl implements ClarinItemService {
@Autowired
CollectionService collectionService;

@Autowired
ItemService itemService;

@Override
public List<Item> findByBitstreamUUID(Context context, UUID bitstreamUUID) throws SQLException {
return clarinItemDAO.findByBitstreamUUID(context, bitstreamUUID);
Expand Down Expand Up @@ -125,4 +131,48 @@ public Community getOwningCommunity(Context context, UUID owningCollectionId) th
}
return null;
}

@Override
public void updateItemFilesMetadata(Context context, Item item) throws SQLException {
List<Bundle> originalBundles = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
if (Objects.nonNull(originalBundles.get(0))) {
updateItemFilesMetadata(context, item, originalBundles.get(0));
} else {
log.error("Cannot update item files metadata because the ORIGINAL bundle is null.");
}
}

@Override
public void updateItemFilesMetadata(Context context, Item item, Bundle bundle) throws SQLException {
if (!Objects.equals(bundle.getName(), Constants.CONTENT_BUNDLE_NAME)) {
return;
}

int totalNumberOfFiles = 0;
long totalSizeofFiles = 0;

/* Add local.has.files metadata */
boolean hasFiles = false;
List<Bundle> origs = itemService.getBundles(item, Constants.CONTENT_BUNDLE_NAME);
for (Bundle orig : origs) {
if (CollectionUtils.isNotEmpty(orig.getBitstreams())) {
hasFiles = true;
}
for (Bitstream bit : orig.getBitstreams()) {
totalNumberOfFiles ++;
totalSizeofFiles += bit.getSizeBytes();
}
}

itemService.clearMetadata(context, item, "local", "has", "files", Item.ANY);
itemService.clearMetadata(context, item, "local", "files", "count", Item.ANY);
itemService.clearMetadata(context, item, "local", "files", "size", Item.ANY);
if ( hasFiles ) {
itemService.addMetadata(context, item, "local", "has", "files", Item.ANY, "yes");
} else {
itemService.addMetadata(context, item,"local", "has", "files", Item.ANY, "no");
}
itemService.addMetadata(context, item,"local", "files", "count", Item.ANY, "" + totalNumberOfFiles);
itemService.addMetadata(context, item,"local", "files", "size", Item.ANY, "" + totalSizeofFiles);
}
}
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.Bundle;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.Item;
Expand Down Expand Up @@ -59,4 +60,24 @@ public interface ClarinItemService {
* @throws SQLException
*/
Community getOwningCommunity(Context context, UUID owningCollectionId) throws SQLException;

/**
* Update item's metadata about its files (local.has.files, local.files.size, local.files.count).
* This method doesn't require Item's Bundle to be passed as a parameter. The ORIGINAL bundle is used by default.
* @param context DSpace context object
* @param item Update metadata for this Item
* @throws SQLException
*/
void updateItemFilesMetadata(Context context, Item item) throws SQLException;

/**
* Update item's metadata about its files (local.has.files, local.files.size, local.files.count).
* @param context DSpace context object
* @param item Update metadata for this Item
* @param bundle Bundle to be used for the metadata update - it if is not the ORIGINAL bundle
* the method will be skipped.
* @throws SQLException
*/
void updateItemFilesMetadata(Context context, Item item, Bundle bundle) throws SQLException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ public void init() {
Item item = wi.getItem();
ContentServiceFactory.getInstance().getInstallItemService().installItem(context, wi, null);
context.restoreAuthSystemState();
context.commit();
it = item;
bundleService = ContentServiceFactory.getInstance().getBundleService();
bitstreamFormatService = ContentServiceFactory.getInstance().getBitstreamFormatService();
Expand Down
Loading