88051: Support filtering non-latest relationships

This commit is contained in:
Bruno Roemers
2022-03-02 00:58:32 +01:00
parent d0aab90ffc
commit a5f0c03a27
5 changed files with 368 additions and 136 deletions

View File

@@ -293,10 +293,18 @@ public class RelationshipServiceImpl implements RelationshipService {
}
@Override
public List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset,
boolean excludeTilted) throws SQLException {
public List<Relationship> findByItem(
Context context, Item item, Integer limit, Integer offset, boolean excludeTilted
) throws SQLException {
return findByItem(context, item, limit, offset, excludeTilted, true);
}
List<Relationship> list = relationshipDAO.findByItem(context, item, limit, offset, excludeTilted);
@Override
public List<Relationship> findByItem(
Context context, Item item, Integer limit, Integer offset, boolean excludeTilted, boolean excludeNonLinked
) throws SQLException {
List<Relationship> list =
relationshipDAO.findByItem(context, item, limit, offset, excludeTilted, excludeNonLinked);
list.sort((o1, o2) -> {
int relationshipType = o1.getRelationshipType().getLeftwardType()
@@ -652,22 +660,38 @@ public class RelationshipServiceImpl implements RelationshipService {
public List<Relationship> findByItemAndRelationshipType(Context context, Item item,
RelationshipType relationshipType)
throws SQLException {
return relationshipDAO.findByItemAndRelationshipType(context, item, relationshipType, -1, -1);
return findByItemAndRelationshipType(context, item, relationshipType, -1, -1, true);
}
@Override
public List<Relationship> findByItemAndRelationshipType(Context context, Item item,
RelationshipType relationshipType, int limit, int offset)
throws SQLException {
return relationshipDAO.findByItemAndRelationshipType(context, item, relationshipType, limit, offset);
return findByItemAndRelationshipType(context, item, relationshipType, limit, offset, true);
}
@Override
public List<Relationship> findByItemAndRelationshipType(Context context, Item item,
RelationshipType relationshipType, boolean isLeft,
int limit, int offset)
throws SQLException {
return relationshipDAO.findByItemAndRelationshipType(context, item, relationshipType, isLeft, limit, offset);
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, int limit, int offset, boolean excludeNonLatest
) throws SQLException {
return relationshipDAO
.findByItemAndRelationshipType(context, item, relationshipType, limit, offset, excludeNonLatest);
}
@Override
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, int limit, int offset
) throws SQLException {
return findByItemAndRelationshipType(context, item, relationshipType, isLeft, limit, offset, true);
}
@Override
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, int limit, int offset,
boolean excludeNonLatest
) throws SQLException {
return relationshipDAO
.findByItemAndRelationshipType(context, item, relationshipType, isLeft, limit, offset, excludeNonLatest);
}
@Override
@@ -704,7 +728,12 @@ public class RelationshipServiceImpl implements RelationshipService {
@Override
public int countByItem(Context context, Item item) throws SQLException {
return relationshipDAO.countByItem(context, item);
return countByItem(context, item, true);
}
@Override
public int countByItem(Context context, Item item, boolean excludeNonLatest) throws SQLException {
return relationshipDAO.countByItem(context, item, excludeNonLatest);
}
@Override
@@ -713,9 +742,18 @@ public class RelationshipServiceImpl implements RelationshipService {
}
@Override
public int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType,
boolean isLeft) throws SQLException {
return relationshipDAO.countByItemAndRelationshipType(context, item, relationshipType, isLeft);
public int countByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft
) throws SQLException {
return countByItemAndRelationshipType(context, item, relationshipType, isLeft, true);
}
@Override
public int countByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, boolean excludeNonLatest
) throws SQLException {
return relationshipDAO
.countByItemAndRelationshipType(context, item, relationshipType, isLeft, excludeNonLatest);
}
@Override

View File

@@ -32,11 +32,15 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
* @param item The item that should be either a leftItem or a rightItem of all
* the Relationship objects in the returned list
* @param excludeTilted If true, excludes tilted relationships
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return The list of Relationship objects that contain either a left or a
* right item that is equal to the given item
* @throws SQLException If something goes wrong
*/
List<Relationship> findByItem(Context context, Item item, boolean excludeTilted) throws SQLException;
List<Relationship> findByItem(
Context context, Item item, boolean excludeTilted, boolean excludeNonLatest
) throws SQLException;
/**
* This method returns a list of Relationship objects that have the given Item object
@@ -47,12 +51,15 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
* @param limit paging limit
* @param offset paging offset
* @param excludeTilted If true, excludes tilted relationships
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return The list of Relationship objects that contain either a left or a
* right item that is equal to the given item
* @throws SQLException If something goes wrong
*/
List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset, boolean excludeTilted)
throws SQLException;
List<Relationship> findByItem(
Context context, Item item, Integer limit, Integer offset, boolean excludeTilted, boolean excludeNonLatest
) throws SQLException;
/**
* This method returns the next leftplace integer to use for a relationship with this item as the leftItem
@@ -108,34 +115,41 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
* It will construct a list of all Relationship objects that have the given RelationshipType object
* as the relationshipType property
* @param context The relevant DSpace context
* @param item item to filter by
* @param relationshipType The RelationshipType object to be checked on
* @param limit paging limit
* @param offset paging offset
* @param item item to filter by
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType,
Integer limit, Integer offset) throws SQLException;
List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, Integer limit, Integer offset,
boolean excludeNonLatest
) throws SQLException;
/**
* This method returns a list of Relationship objects for the given RelationshipType object.
* It will construct a list of all Relationship objects that have the given RelationshipType object
* as the relationshipType property
* @param context The relevant DSpace context
* @param item item to filter by
* @param relationshipType The RelationshipType object to be checked on
* @param isLeft Is item left or right
* @param limit paging limit
* @param offset paging offset
* @param item item to filter by
* @param isLeft Is item left or right
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType,
boolean isLeft, Integer limit, Integer offset)
throws SQLException;
List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, Integer limit, Integer offset,
boolean excludeNonLatest
) throws SQLException;
/**
* This method returns a list of Relationship objects for the given typeName
@@ -186,11 +200,13 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
* @param context The relevant DSpace context
* @param item The item that should be either a leftItem or a rightItem of all
* the Relationship objects in the returned list
* @param excludeNonLatest if true, exclude relationships for which the opposite item is not the latest version
* that is relevant
* @return The list of Relationship objects that contain either a left or a
* right item that is equal to the given item
* @throws SQLException If something goes wrong
*/
int countByItem(Context context, Item item) throws SQLException;
int countByItem(Context context, Item item, boolean excludeNonLatest) throws SQLException;
/**
* Count total number of relationships (rows in relationship table) by an item and a relationship type and a boolean
@@ -199,12 +215,15 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
* @param context context
* @param relationshipType relationship type to filter by
* @param item item to filter by
* @param isLeft Indicating whether the counted Relationships should have the given Item on the left side or not
* @param isLeft indicating whether the counted Relationships should have the given Item on the left side
* @param excludeNonLatest if true, exclude relationships for which the opposite item is not the latest version
* that is relevant
* @return total count
* @throws SQLException if database error
*/
int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft)
throws SQLException;
int countByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, boolean excludeNonLatest
) throws SQLException;
/**
* Count total number of relationships (rows in relationship table) given a typeName

View File

@@ -14,6 +14,7 @@ import java.util.UUID;
import javax.persistence.Query;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.dspace.content.Item;
@@ -30,60 +31,147 @@ import org.dspace.core.Context;
public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> implements RelationshipDAO {
@Override
public List<Relationship> findByItem(Context context, Item item, boolean excludeTilted) throws SQLException {
return findByItem(context, item, -1, -1, excludeTilted);
public List<Relationship> findByItem(
Context context, Item item, boolean excludeTilted, boolean excludeNonLatest
) throws SQLException {
return findByItem(context, item, -1, -1, excludeTilted, excludeNonLatest);
}
@Override
public List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset,
boolean excludeTilted) throws SQLException {
public List<Relationship> findByItem(
Context context, Item item, Integer limit, Integer offset, boolean excludeTilted, boolean excludeNonLatest
) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
CriteriaQuery<Relationship> criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.select(relationshipRoot);
if (excludeTilted) {
// If this item is the left item,
// return relationships for types which are not tilted right (tilted is either left nor null)
// If this item is the right item,
// return relationships for types which are not tilted left (tilted is either right nor null)
criteriaQuery
.where(criteriaBuilder.or(
criteriaBuilder.and(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item),
criteriaQuery.where(
criteriaBuilder.or(
criteriaBuilder.isNull(relationshipRoot.get(Relationship_.relationshipType)
.get(RelationshipType_.tilted)),
criteriaBuilder.notEqual(relationshipRoot
.get(Relationship_.relationshipType)
.get(RelationshipType_.tilted), RelationshipType.Tilted.RIGHT))),
criteriaBuilder.and(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item),
criteriaBuilder.or(
criteriaBuilder.isNull(relationshipRoot.get(Relationship_.relationshipType)
.get(RelationshipType_.tilted)),
criteriaBuilder.notEqual(relationshipRoot
.get(Relationship_.relationshipType)
.get(RelationshipType_.tilted), RelationshipType.Tilted.LEFT)))));
} else {
criteriaQuery
.where(criteriaBuilder.or(criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item)));
}
getLeftItemPredicate(criteriaBuilder, relationshipRoot, item, excludeTilted, excludeNonLatest),
getRightItemPredicate(criteriaBuilder, relationshipRoot, item, excludeTilted, excludeNonLatest)
)
);
return list(context, criteriaQuery, false, Relationship.class, limit, offset);
}
@Override
public int countByItem(Context context, Item item)
throws SQLException {
/**
* Get the predicate for a criteria query that selects relationships by their left item.
* @param criteriaBuilder the criteria builder.
* @param relationshipRoot the relationship root.
* @param item the item that is being searched for.
* @param excludeTilted if true, exclude tilted relationships.
* @param excludeNonLatest if true, exclude relationships for which the opposite item is not the latest version
* that is relevant.
* @return a predicate that satisfies the given restrictions.
*/
protected Predicate getLeftItemPredicate(
CriteriaBuilder criteriaBuilder, Root<Relationship> relationshipRoot, Item item,
boolean excludeTilted, boolean excludeNonLatest
) {
List<Predicate> predicates = new ArrayList<>();
// match relationships based on the left item
predicates.add(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item)
);
if (excludeTilted) {
// if this item is the left item,
// return relationships for types which are NOT tilted right (tilted is either left nor null)
predicates.add(
criteriaBuilder.or(
criteriaBuilder.isNull(
relationshipRoot.get(Relationship_.relationshipType).get(RelationshipType_.tilted)
),
criteriaBuilder.notEqual(
relationshipRoot.get(Relationship_.relationshipType).get(RelationshipType_.tilted),
RelationshipType.Tilted.RIGHT
)
)
);
}
if (excludeNonLatest) {
// if this item is the left item,
// return relationships for which the right item is the "latest" version that is relevant.
predicates.add(
criteriaBuilder.notEqual(
relationshipRoot.get(Relationship_.LATEST_VERSION_STATUS),
Relationship.LatestVersionStatus.LEFT_ONLY
)
);
}
return criteriaBuilder.and(predicates.toArray(new Predicate[]{}));
}
/**
* Get the predicate for a criteria query that selects relationships by their right item.
* @param criteriaBuilder the criteria builder.
* @param relationshipRoot the relationship root.
* @param item the item that is being searched for.
* @param excludeTilted if true, exclude tilted relationships.
* @param excludeNonLatest if true, exclude relationships for which the opposite item is not the latest version
* that is relevant.
* @return a predicate that satisfies the given restrictions.
*/
protected Predicate getRightItemPredicate(
CriteriaBuilder criteriaBuilder, Root<Relationship> relationshipRoot, Item item,
boolean excludeTilted, boolean excludeNonLatest
) {
List<Predicate> predicates = new ArrayList<>();
// match relationships based on the right item
predicates.add(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item)
);
if (excludeTilted) {
// if this item is the right item,
// return relationships for types which are NOT tilted left (tilted is either right nor null)
predicates.add(
criteriaBuilder.or(
criteriaBuilder.isNull(
relationshipRoot.get(Relationship_.relationshipType).get(RelationshipType_.tilted)
),
criteriaBuilder.notEqual(
relationshipRoot.get(Relationship_.relationshipType).get(RelationshipType_.tilted),
RelationshipType.Tilted.LEFT
)
)
);
}
if (excludeNonLatest) {
// if this item is the right item,
// return relationships for which the left item is the "latest" version that is relevant.
predicates.add(
criteriaBuilder.notEqual(
relationshipRoot.get(Relationship_.LATEST_VERSION_STATUS),
Relationship.LatestVersionStatus.RIGHT_ONLY
)
);
}
return criteriaBuilder.and(predicates.toArray(new Predicate[]{}));
}
@Override
public int countByItem(Context context, Item item, boolean excludeNonLatest) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.select(relationshipRoot);
criteriaQuery
.where(criteriaBuilder.or(criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item)));
criteriaQuery.where(
criteriaBuilder.or(
getLeftItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest),
getRightItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
)
);
return count(context, criteriaQuery, criteriaBuilder, relationshipRoot);
}
@@ -140,46 +228,50 @@ public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> impl
}
@Override
public List<Relationship> findByItemAndRelationshipType(Context context, Item item,
RelationshipType relationshipType, Integer limit,
Integer offset)
throws SQLException {
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, Integer limit, Integer offset,
boolean excludeNonLatest
) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.select(relationshipRoot);
criteriaQuery
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
relationshipType), criteriaBuilder.or
(criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item)));
criteriaQuery.where(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType), relationshipType),
criteriaBuilder.or(
getLeftItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest),
getRightItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
)
);
return list(context, criteriaQuery, true, Relationship.class, limit, offset);
}
@Override
public List<Relationship> findByItemAndRelationshipType(Context context, Item item,
RelationshipType relationshipType, boolean isLeft,
Integer limit, Integer offset)
throws SQLException {
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, Integer limit, Integer offset,
boolean excludeNonLatest
) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.select(relationshipRoot);
if (isLeft) {
criteriaQuery
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
relationshipType),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item));
criteriaQuery.where(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType), relationshipType),
getLeftItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
);
criteriaQuery.orderBy(criteriaBuilder.asc(relationshipRoot.get(Relationship_.leftPlace)));
} else {
criteriaQuery
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
relationshipType),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item));
criteriaQuery.where(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType), relationshipType),
getRightItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
);
criteriaQuery.orderBy(criteriaBuilder.asc(relationshipRoot.get(Relationship_.rightPlace)));
}
return list(context, criteriaQuery, true, Relationship.class, limit, offset);
}
@@ -228,24 +320,26 @@ public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> impl
}
@Override
public int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType,
boolean isLeft) throws SQLException {
public int countByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, boolean excludeNonLatest
) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.select(relationshipRoot);
if (isLeft) {
criteriaQuery
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
relationshipType),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.leftItem), item));
criteriaQuery.where(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType), relationshipType),
getLeftItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
);
} else {
criteriaQuery
.where(criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType),
relationshipType),
criteriaBuilder.equal(relationshipRoot.get(Relationship_.rightItem), item));
criteriaQuery.where(
criteriaBuilder.equal(relationshipRoot.get(Relationship_.relationshipType), relationshipType),
getRightItemPredicate(criteriaBuilder, relationshipRoot, item, false, excludeNonLatest)
);
}
return count(context, criteriaQuery, criteriaBuilder, relationshipRoot);
}

View File

@@ -50,6 +50,25 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset, boolean excludeTilted)
throws SQLException;
/**
* Retrieves the list of Relationships currently in the system for which the given Item is either
* a leftItem or a rightItem object
* @param context The relevant DSpace context
* @param item The Item that has to be the left or right item for the relationship to be
* included in the list
* @param limit paging limit
* @param offset paging offset
* @param excludeTilted If true, excludes tilted relationships
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return The list of relationships for which each relationship adheres to the above
* listed constraint
* @throws SQLException If something goes wrong
*/
List<Relationship> findByItem(
Context context, Item item, Integer limit, Integer offset, boolean excludeTilted, boolean excludeNonLatest
) throws SQLException;
/**
* Retrieves the full list of relationships currently in the system
* @param context The relevant DSpace context
@@ -129,6 +148,22 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
RelationshipType relationshipType, int limit, int offset)
throws SQLException;
/**
* This method returns a list of Relationships for which the leftItem or rightItem is equal to the given
* Item object and for which the RelationshipType object is equal to the relationshipType property
* @param context The relevant DSpace context
* @param item The Item object to be matched on the leftItem or rightItem for the relationship
* @param relationshipType The RelationshipType object that will be used to check the Relationship on
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return The list of Relationship objects that have the given Item object as leftItem or rightItem and
* for which the relationshipType property is equal to the given RelationshipType
* @throws SQLException If something goes wrong
*/
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, int limit, int offset, boolean excludeNonLatest
) throws SQLException;
/**
* This method returns a list of Relationships for which the leftItem or rightItem is equal to the given
* Item object and for which the RelationshipType object is equal to the relationshipType property
@@ -145,6 +180,24 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
int limit, int offset)
throws SQLException;
/**
* This method returns a list of Relationships for which the leftItem or rightItem is equal to the given
* Item object and for which the RelationshipType object is equal to the relationshipType property
* @param context The relevant DSpace context
* @param item The Item object to be matched on the leftItem or rightItem for the relationship
* @param relationshipType The RelationshipType object that will be used to check the Relationship on
* @param isLeft Is the item left or right
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return The list of Relationship objects that have the given Item object as leftItem or rightItem and
* for which the relationshipType property is equal to the given RelationshipType
* @throws SQLException If something goes wrong
*/
public List<Relationship> findByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, int limit, int offset,
boolean excludeNonLatest
) throws SQLException;
/**
* This method will update the place for the Relationship and all other relationships found by the items and
* relationship type of the given Relationship. It will give this Relationship the last place in both the
@@ -310,6 +363,20 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
*/
int countByItem(Context context, Item item) throws SQLException;
/**
* This method returns a count of Relationship objects that have the given Item object
* as a leftItem or a rightItem
* @param context The relevant DSpace context
* @param item The item that should be either a leftItem or a rightItem of all
* the Relationship objects in the returned list
* @param excludeNonLatest if true, exclude relationships for which the opposite item is not the latest version
* that is relevant
* @return The list of Relationship objects that contain either a left or a
* right item that is equal to the given item
* @throws SQLException If something goes wrong
*/
int countByItem(Context context, Item item, boolean excludeNonLatest) throws SQLException;
/**
* Count total number of relationships (rows in relationship table) by a relationship type and a boolean indicating
* whether the relationship should contain the item on the left side or not
@@ -323,6 +390,21 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft)
throws SQLException;
/**
* Count total number of relationships (rows in relationship table) by a relationship type and a boolean indicating
* whether the relationship should contain the item on the left side or not
* @param context context
* @param relationshipType relationship type to filter by
* @param isLeft Indicating whether the counted Relationships should have the given Item on the left side
* @param excludeNonLatest If true, excludes all relationships for which the other item has a more recent version
* that is relevant for this relationship
* @return total count with the given parameters
* @throws SQLException if database error
*/
int countByItemAndRelationshipType(
Context context, Item item, RelationshipType relationshipType, boolean isLeft, boolean excludeNonLatest
) throws SQLException;
/**
* Count total number of relationships (rows in relationship table)
* by a relationship leftward or rightward typeName

View File

@@ -155,12 +155,11 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
* @return A list of distinct results as depicted by the CriteriaQuery and parameters
* @throws SQLException
*/
public List<T> list(Context context, CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults,
int offset) throws SQLException {
public List<T> list(
Context context, CriteriaQuery<T> criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset
) throws SQLException {
criteriaQuery.distinct(true);
@SuppressWarnings("unchecked")
List<T> result = (List<T>) executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
return result;
return executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
}
/**
@@ -183,12 +182,12 @@ public abstract class AbstractHibernateDAO<T> implements GenericDAO<T> {
* @return A list of results determined by the CriteriaQuery and parameters
* @throws SQLException
*/
public List<T> list(Context context, CriteriaQuery criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults,
int offset, boolean distinct) throws SQLException {
public List<T> list(
Context context, CriteriaQuery<T> criteriaQuery, boolean cacheable, Class<T> clazz, int maxResults, int offset,
boolean distinct
) throws SQLException {
criteriaQuery.distinct(distinct);
@SuppressWarnings("unchecked")
List<T> result = (List<T>) executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
return result;
return executeCriteriaQuery(context, criteriaQuery, cacheable, maxResults, offset);
}
/**