Merge pull request #2960 from atmire/duplicate-discovery-bugfix

Bugfix to avoid duplicates in discovery consumer
This commit is contained in:
Tim Donohue
2020-09-22 12:18:45 -05:00
committed by GitHub
6 changed files with 51 additions and 10 deletions

View File

@@ -0,0 +1,43 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.discovery.indexobject;
import java.io.Serializable;
import org.dspace.core.ReloadableEntity;
import org.dspace.discovery.IndexableObject;
/**
* This class exists in order to provide a default implementation for the equals and hashCode methods.
* Since IndexableObjects can be made multiple times for the same underlying object, we needed a more finetuned
* equals and hashcode methods. We're simply checking that the underlying objects are equal and generating the hashcode
* for the underlying object. This way, we'll always get a proper result when calling equals or hashcode on an
* IndexableObject because it'll depend on the underlying object
* @param <T> Refers to the underlying entity that is linked to this object
* @param <PK> The type of ID that this entity uses
*/
public abstract class AbstractIndexableObject<T extends ReloadableEntity<PK>, PK extends Serializable>
implements IndexableObject<T,PK> {
@Override
public boolean equals(Object obj) {
//Two IndexableObjects of the same DSpaceObject are considered equal
if (!(obj instanceof AbstractIndexableObject)) {
return false;
}
IndexableDSpaceObject other = (IndexableDSpaceObject) obj;
return other.getIndexedObject().equals(getIndexedObject());
}
@Override
public int hashCode() {
//Two IndexableObjects of the same DSpaceObject are considered equal
return getIndexedObject().hashCode();
}
}

View File

@@ -7,7 +7,6 @@
*/ */
package org.dspace.discovery.indexobject; package org.dspace.discovery.indexobject;
import org.dspace.discovery.IndexableObject;
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask; import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
/** /**
@@ -15,7 +14,7 @@ import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
* *
* @author Kevin Van de Velde (kevin at atmire dot com) * @author Kevin Van de Velde (kevin at atmire dot com)
*/ */
public class IndexableClaimedTask implements IndexableObject<ClaimedTask, Integer> { public class IndexableClaimedTask extends AbstractIndexableObject<ClaimedTask, Integer> {
private ClaimedTask claimedTask; private ClaimedTask claimedTask;
public static final String TYPE = ClaimedTask.class.getSimpleName(); public static final String TYPE = ClaimedTask.class.getSimpleName();

View File

@@ -10,7 +10,6 @@ package org.dspace.discovery.indexobject;
import java.util.UUID; import java.util.UUID;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
import org.dspace.discovery.IndexableObject;
/** /**
* DSpaceObject implementation for the IndexableObject, contains methods used by all DSpaceObject methods * DSpaceObject implementation for the IndexableObject, contains methods used by all DSpaceObject methods
@@ -18,7 +17,7 @@ import org.dspace.discovery.IndexableObject;
* *
* @author Kevin Van de Velde (kevin at atmire dot com) * @author Kevin Van de Velde (kevin at atmire dot com)
*/ */
public abstract class IndexableDSpaceObject<T extends DSpaceObject> implements IndexableObject<T, UUID> { public abstract class IndexableDSpaceObject<T extends DSpaceObject> extends AbstractIndexableObject<T, UUID> {
private T dso; private T dso;
@@ -40,4 +39,6 @@ public abstract class IndexableDSpaceObject<T extends DSpaceObject> implements I
public UUID getID() { public UUID getID() {
return dso.getID(); return dso.getID();
} }
}
}

View File

@@ -8,14 +8,13 @@
package org.dspace.discovery.indexobject; package org.dspace.discovery.indexobject;
import org.dspace.content.InProgressSubmission; import org.dspace.content.InProgressSubmission;
import org.dspace.discovery.IndexableObject;
/** /**
* InProgressSubmission implementation for the IndexableObject * InProgressSubmission implementation for the IndexableObject
* @author Kevin Van de Velde (kevin at atmire dot com) * @author Kevin Van de Velde (kevin at atmire dot com)
*/ */
public abstract class IndexableInProgressSubmission<T extends InProgressSubmission> public abstract class IndexableInProgressSubmission<T extends InProgressSubmission>
implements IndexableObject<T, Integer> { extends AbstractIndexableObject<T, Integer> {
protected T inProgressSubmission; protected T inProgressSubmission;

View File

@@ -15,7 +15,7 @@ import org.dspace.discovery.IndexableObject;
* *
* @author Maria Verdonck (Atmire) on 14/07/2020 * @author Maria Verdonck (Atmire) on 14/07/2020
*/ */
public class IndexableMetadataField implements IndexableObject<MetadataField, Integer> { public class IndexableMetadataField extends AbstractIndexableObject<MetadataField, Integer> {
private MetadataField metadataField; private MetadataField metadataField;
public static final String TYPE = MetadataField.class.getSimpleName(); public static final String TYPE = MetadataField.class.getSimpleName();

View File

@@ -7,14 +7,13 @@
*/ */
package org.dspace.discovery.indexobject; package org.dspace.discovery.indexobject;
import org.dspace.discovery.IndexableObject;
import org.dspace.xmlworkflow.storedcomponents.PoolTask; import org.dspace.xmlworkflow.storedcomponents.PoolTask;
/** /**
* PoolTask implementation for the IndexableObject * PoolTask implementation for the IndexableObject
* @author Kevin Van de Velde (kevin at atmire dot com) * @author Kevin Van de Velde (kevin at atmire dot com)
*/ */
public class IndexablePoolTask implements IndexableObject<PoolTask, Integer> { public class IndexablePoolTask extends AbstractIndexableObject<PoolTask, Integer> {
public static final String TYPE = PoolTask.class.getSimpleName(); public static final String TYPE = PoolTask.class.getSimpleName();