Package org.dspace.versioning
Class VersioningConsumer
java.lang.Object
org.dspace.versioning.VersioningConsumer
- All Implemented Interfaces:
Consumer
When a new version of an item is published, unarchive the previous version and
update
Relationship.latestVersionStatus of the relevant relationships.- Author:
- Fabio Bolognesi (fabio at atmire dot com), Mark Diggory (markd at atmire dot com), Ben Bosman (ben at atmire dot com)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidConsume an event.protected booleandoEntityTypesMatch(Item latestItem, Item previousItem) Given two items, check if their entity types match.voidSignal that there are no more events queued in this event stream and event processing for the preceding consume calls should be finished up.voidFinish - free any allocated resources.protected List<Relationship>getAllRelationships(Context ctx, Item item, RelationshipType relationshipType) Get all relationships of the given type linked to the given item.protected EntityTypegetEntityType(Context ctx, Item item) Get the entity type (stored in metadata field dspace.entity.type) of any item.protected RelationshipgetMatchingRelationship(Item latestItem, boolean isLeft, Relationship previousItemRelationship, List<Relationship> relationships) From a list of relationships, find the relationship with the correct relationship type and items.protected RelationshipgetMatchingRelationship(Item expectedLeftItem, RelationshipType expectedRelationshipType, Item expectedRightItem, List<Relationship> relationships) Find the relationship with the given left item, relation type and right item, from a list of relationships.protected List<RelationshipType>getRelationshipTypes(Context ctx, EntityType entityType) Get all relationship types that have the given entity type on their left and/or right side.voidAllocate any resources required to operate.protected voidreindexRelationship(Context ctx, RelationshipVersioningUtils.LatestVersionStatusChangelog changelog, Relationship relationship) If theRelationship.latestVersionStatusof the relationship has changed, an "item modified" event should be fired for both the left and right item of the relationship.protected voidunarchiveItem(Context ctx, Item item) protected voidupdateRelationships(Context ctx, Item latestItem, Item previousItem) UpdateRelationship.latestVersionStatusof the relationships of both the old version and the new version of the item.
-
Constructor Details
-
VersioningConsumer
public VersioningConsumer()
-
-
Method Details
-
initialize
Description copied from interface:ConsumerAllocate any resources required to operate. This may include initializing any pooled JMS resources. Called ONCE when created by the dispatcher pool. This should be used to set up expensive resources that will remain for the lifetime of the consumer.- Specified by:
initializein interfaceConsumer- Throws:
Exception- if error
-
finish
Description copied from interface:ConsumerFinish - free any allocated resources. Called when consumer (via it's parent dispatcher) is going to be destroyed by the dispatcher pool. -
consume
Description copied from interface:ConsumerConsume an event. Events may be filtered by a dispatcher, hiding them from the consumer. This behavior is based on the dispatcher/consumer configuration. Should include logic to initialize any resources required for a batch of events.This method must not commit the context. Committing causes re-dispatch of the event queue, which can result in infinite recursion leading to memory exhaustion as seen in {@link https://github.com/DSpace/DSpace/pull/8756}.
-
unarchiveItem
-
updateRelationships
UpdateRelationship.latestVersionStatusof the relationships of both the old version and the new version of the item. This method will first locate all relationships that are eligible for an update, then it will try to match each of those relationships on the old version of given item with a relationship on the new version. One of the following scenarios will happen: - if a match is found, then the "latest" status on the side of given item is transferred from the old relationship to the new relationship. This implies that on the page of the third-party item, the old version of given item will NOT be shown anymore and the new version of given item will appear. Both versions of the given item still show the third-party item on their pages. - if a relationship only exists on the new version of given item, then this method does nothing. The status of those relationships should already have been set to "latest" on both sides during relationship creation. - if a relationship only exists on the old version of given item, then we assume that the relationship is no longer relevant to / has been removed from the new version of the item. The "latest" status is removed from the side of the given item. This implies that on the page of the third-party item, the relationship with given item will no longer be listed. The old version of given item still lists the third-party item and the new version doesn't.- Parameters:
ctx- the DSpace context.latestItem- the new version of the item.previousItem- the old version of the item.
-
reindexRelationship
protected void reindexRelationship(Context ctx, RelationshipVersioningUtils.LatestVersionStatusChangelog changelog, Relationship relationship) If theRelationship.latestVersionStatusof the relationship has changed, an "item modified" event should be fired for both the left and right item of the relationship. On one item the relation.* fields will change. On the other item the relation.*.latestForDiscovery will change. The event will cause the items to be re-indexed by theIndexEventConsumer.- Parameters:
ctx- the DSpace context.changelog- indicates which side of the relationship has changed.relationship- the relationship.
-
doEntityTypesMatch
Given two items, check if their entity types match. If one or both items don't have an entity type, comparing is pointless and this method will return false.- Parameters:
latestItem- the item that represents the most recent version.previousItem- the item that represents the second-most recent version.- Returns:
- true if the entity types of both items are non-null and equal, false otherwise.
-
getEntityType
Get the entity type (stored in metadata field dspace.entity.type) of any item.- Parameters:
item- the item.- Returns:
- the entity type.
-
getRelationshipTypes
Get all relationship types that have the given entity type on their left and/or right side.- Parameters:
ctx- the DSpace context.entityType- the entity type for which all relationship types should be found.- Returns:
- a list of relationship types (possibly empty), or null in case of error.
-
getAllRelationships
protected List<Relationship> getAllRelationships(Context ctx, Item item, RelationshipType relationshipType) Get all relationships of the given type linked to the given item.- Parameters:
ctx- the DSpace context.item- the item.relationshipType- the relationship type.- Returns:
- a list of relationships (possibly empty), or null in case of error.
-
getMatchingRelationship
protected Relationship getMatchingRelationship(Item latestItem, boolean isLeft, Relationship previousItemRelationship, List<Relationship> relationships) From a list of relationships, find the relationship with the correct relationship type and items. If isLeft is true, the provided item should be on the left side of the relationship. If isLeft is false, the provided item should be on the right side of the relationship. In both cases, the other item is taken from the given relationship.- Parameters:
latestItem- the item that should either be on the left or right side of the returned relationship (if any).isLeft- decide on which side of the relationship the provided item should be.previousItemRelationship- the relationship from which the type and the other item are read.relationships- the list of relationships that we'll search through.- Returns:
- the relationship that satisfies the requirements (can only be one or zero).
-
getMatchingRelationship
protected Relationship getMatchingRelationship(Item expectedLeftItem, RelationshipType expectedRelationshipType, Item expectedRightItem, List<Relationship> relationships) Find the relationship with the given left item, relation type and right item, from a list of relationships.- Parameters:
expectedLeftItem- the relationship that we're looking for has this item on the left side.expectedRelationshipType- the relationship that we're looking for has this relationship type.expectedRightItem- the relationship that we're looking for has this item on the right side.relationships- the list of relationships that we'll search through.- Returns:
- the relationship that satisfies the requirements (can only be one or zero).
-
end
Description copied from interface:ConsumerSignal that there are no more events queued in this event stream and event processing for the preceding consume calls should be finished up.
-