DS-4224 Improve paging impl for Entities

This commit is contained in:
Andrew Wood
2019-10-14 09:25:49 -04:00
parent d82fb48878
commit a4c0b62b52
18 changed files with 314 additions and 111 deletions

View File

@@ -211,7 +211,7 @@ public class InitializeEntities {
rightCardinalityMaxInteger = null;
}
RelationshipType relationshipType = relationshipTypeService
.findbyTypesAndLabels(context, leftEntityType, rightEntityType, leftwardType, rightwardType);
.findbyTypesAndTypeName(context, leftEntityType, rightEntityType, leftwardType, rightwardType);
if (relationshipType == null) {
relationshipTypeService.create(context, leftEntityType, rightEntityType, leftwardType, rightwardType,
leftCardinalityMinInteger, leftCardinalityMaxInteger,

View File

@@ -86,25 +86,14 @@ public class EntityServiceImpl implements EntityService {
}
@Override
public List<Relationship> getRelationsByLabel(Context context, String label) throws SQLException {
return getRelationsByLabel(context, label, -1, -1);
public List<Relationship> getRelationsByTypeName(Context context, String typeName) throws SQLException {
return getRelationsByTypeName(context, typeName, -1, -1);
}
@Override
public List<Relationship> getRelationsByLabel(Context context, String label, Integer limit, Integer offset)
public List<Relationship> getRelationsByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException {
List<Relationship> listToReturn = new LinkedList<>();
List<Relationship> relationshipList = relationshipService.findAll(context, limit, offset);
for (Relationship relationship : relationshipList) {
RelationshipType relationshipType = relationship.getRelationshipType();
if (StringUtils.equals(relationshipType.getLeftwardType(),label) ||
StringUtils.equals(relationshipType.getRightwardType(),label)) {
listToReturn.add(relationship);
}
}
return listToReturn;
return relationshipService.findByTypeName(context, typeName, limit, offset);
}
@Override
@@ -116,77 +105,42 @@ public class EntityServiceImpl implements EntityService {
@Override
public List<RelationshipType> getAllRelationshipTypes(Context context, Entity entity, Integer limit, Integer offset)
throws SQLException {
EntityType entityType = this.getType(context, entity);
if (entityType == null) {
return Collections.emptyList();
}
List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context, limit, offset)) {
if (relationshipType.getLeftType().getID() == entityType.getID() ||
relationshipType.getRightType().getID() == entityType.getID()) {
listToReturn.add(relationshipType);
}
}
return listToReturn;
return relationshipTypeService.findByEntityType(context, this.getType(context, entity), limit, offset);
}
@Override
public List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity) throws SQLException {
return getLeftRelationshipTypes(context, entity, -1, -1);
return getLeftRelationshipTypes(context, entity, true, -1, -1);
}
@Override
public List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity,
public List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity, boolean isLeft,
Integer limit, Integer offset) throws SQLException {
EntityType entityType = this.getType(context, entity);
List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context, limit, offset)) {
if (relationshipType.getLeftType().getID() == entityType.getID()) {
listToReturn.add(relationshipType);
}
}
return listToReturn;
return relationshipTypeService.findByEntityType(context, this.getType(context, entity), isLeft, limit, offset);
}
@Override
public List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity) throws SQLException {
return getRightRelationshipTypes(context, entity, -1, -1);
return getRightRelationshipTypes(context, entity, false, -1, -1);
}
@Override
public List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity,
public List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity, boolean isLeft,
Integer limit, Integer offset) throws SQLException {
EntityType entityType = this.getType(context, entity);
List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context, limit, offset)) {
if (relationshipType.getRightType().getID() == entityType.getID()) {
listToReturn.add(relationshipType);
}
}
return listToReturn;
return relationshipTypeService.findByEntityType(context, this.getType(context, entity), isLeft, limit, offset);
}
@Override
public List<RelationshipType> getRelationshipTypesByTypeName(Context context, String type) throws SQLException {
return getRelationshipTypesByTypeName(context, type, -1, -1);
}
@Override
public List<RelationshipType> getRelationshipTypesByTypeName(Context context, String type,
public List<RelationshipType> getRelationshipTypesByTypeName(Context context, String typeName,
Integer limit, Integer offset) throws SQLException {
List<RelationshipType> listToReturn = new LinkedList<>();
for (RelationshipType relationshipType : relationshipTypeService.findAll(context, limit, offset)) {
if (StringUtils.equals(relationshipType.getLeftwardType(),type) ||
StringUtils.equals(relationshipType.getRightwardType(),type)) {
listToReturn.add(relationshipType);
}
}
return listToReturn;
return relationshipTypeService.findByLeftwardOrRightwardTypeName(context, typeName, limit, offset);
}
}

View File

@@ -429,6 +429,19 @@ public class RelationshipServiceImpl implements RelationshipService {
return relationshipDAO.findByRelationshipType(context, relationshipType, limit, offset);
}
@Override
public List<Relationship> findByTypeName(Context context, String typeName)
throws SQLException {
return this.findByTypeName(context, typeName, -1, -1);
}
@Override
public List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException {
return relationshipDAO.findByTypeName(context, typeName, limit, offset);
}
@Override
public int countTotal(Context context) throws SQLException {
return relationshipDAO.countRows(context);
@@ -449,4 +462,10 @@ public class RelationshipServiceImpl implements RelationshipService {
throws SQLException {
return relationshipDAO.countByItemAndRelationshipType(context, item, relationshipType);
}
@Override
public int countByTypeName(Context context, String typeName)
throws SQLException {
return relationshipDAO.countByTypeName(context, typeName);
}
}

View File

@@ -47,9 +47,9 @@ public class RelationshipTypeServiceImpl implements RelationshipTypeService {
}
@Override
public RelationshipType findbyTypesAndLabels(Context context,EntityType leftType,EntityType rightType,
public RelationshipType findbyTypesAndTypeName(Context context,EntityType leftType,EntityType rightType,
String leftwardType,String rightwardType) throws SQLException {
return relationshipTypeDAO.findByTypesAndLabels(context, leftType, rightType, leftwardType, rightwardType);
return relationshipTypeDAO.findbyTypesAndTypeName(context, leftType, rightType, leftwardType, rightwardType);
}
@Override
@@ -64,15 +64,16 @@ public class RelationshipTypeServiceImpl implements RelationshipTypeService {
}
@Override
public List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String label) throws SQLException {
return findByLeftwardOrRightwardTypeName(context, label, -1, -1);
public List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String typeName)
throws SQLException {
return findByLeftwardOrRightwardTypeName(context, typeName, -1, -1);
}
@Override
public List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String label, Integer limit,
public List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String typeName, Integer limit,
Integer offset)
throws SQLException {
return relationshipTypeDAO.findByLeftwardOrRightwardTypeName(context, label, limit, offset);
return relationshipTypeDAO.findByLeftwardOrRightwardTypeName(context, typeName, limit, offset);
}
@Override
@@ -86,6 +87,18 @@ public class RelationshipTypeServiceImpl implements RelationshipTypeService {
return relationshipTypeDAO.findByEntityType(context, entityType, limit, offset);
}
@Override
public List<RelationshipType> findByEntityType(Context context, EntityType entityType, boolean isLeft)
throws SQLException {
return findByEntityType(context, entityType, isLeft, -1, -1);
}
@Override
public List<RelationshipType> findByEntityType(Context context, EntityType entityType, boolean isLeft,
Integer limit, Integer offset) throws SQLException {
return relationshipTypeDAO.findByEntityType(context, entityType, isLeft, limit, offset);
}
@Override
public RelationshipType create(Context context, EntityType leftEntityType, EntityType rightEntityType,
String leftwardType, String rightwardType, Integer leftCardinalityMinInteger,

View File

@@ -133,6 +133,31 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
boolean isLeft, Integer limit, Integer offset)
throws SQLException;
/**
* This method returns a list of Relationship objects for the given typeName
* @param context The relevant DSpace context
* @param typeName The leftward or rightward typeName of the relationship type
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByTypeName(Context context, String typeName)
throws SQLException;
/**
* This method returns a list of Relationship objects for the given typeName
* @param context The relevant DSpace context
* @param typeName The leftward or rightward typeName of the relationship type
* @param limit paging limit
* @param offset paging offset
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException;
/**
* Count total number of relationships (rows in relationship table)
*
@@ -175,4 +200,15 @@ public interface RelationshipDAO extends GenericDAO<Relationship> {
*/
int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType)
throws SQLException;
/**
* Count total number of relationships (rows in relationship table) given a typeName
*
* @param context context
* @param typeName the relationship typeName to filter by
* @return total count
* @throws SQLException if database error
*/
int countByTypeName(Context context, String typeName)
throws SQLException;
}

View File

@@ -34,7 +34,7 @@ public interface RelationshipTypeDAO extends GenericDAO<RelationshipType> {
* @return The RelationshipType object that matches all the given parameters
* @throws SQLException If something goes wrong
*/
RelationshipType findByTypesAndLabels(Context context, EntityType leftType,EntityType rightType,
RelationshipType findbyTypesAndTypeName(Context context, EntityType leftType,EntityType rightType,
String leftwardType,
String rightwardType)
throws SQLException;
@@ -88,4 +88,36 @@ public interface RelationshipTypeDAO extends GenericDAO<RelationshipType> {
*/
List<RelationshipType> findByEntityType(Context context, EntityType entityType, Integer limit, Integer offset)
throws SQLException;
/**
* This method will return a list of RelationshipType objects for which the given EntityType object is equal
* to the leftType or rightType
* @param context The relevant DSpace context
* @param entityType The EntityType object that will be used to check on
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @return The list of RelationshipType objects that have the given EntityType object
* as either a leftType or rightType
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findByEntityType(Context context, EntityType entityType, Boolean isLeft)
throws SQLException;
/**
* This method will return a list of RelationshipType objects for which the given EntityType object is equal
* to the leftType or rightType
* @param context The relevant DSpace context
* @param entityType The EntityType object that will be used to check on
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @param limit paging limit
* @param offset paging offset
* @return The list of RelationshipType objects that have the given EntityType object
* as either a leftType or rightType
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findByEntityType(Context context, EntityType entityType, Boolean isLeft,
Integer limit, Integer offset)
throws SQLException;
}

View File

@@ -8,6 +8,7 @@
package org.dspace.content.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
@@ -18,6 +19,8 @@ import org.dspace.content.Relationship;
import org.dspace.content.RelationshipType;
import org.dspace.content.Relationship_;
import org.dspace.content.dao.RelationshipDAO;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.RelationshipTypeService;
import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context;
@@ -151,6 +154,29 @@ public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> impl
return list(context, criteriaQuery, true, Relationship.class, limit, offset);
}
@Override
public List<Relationship> findByTypeName(Context context, String typeName)
throws SQLException {
return this.findByTypeName(context, typeName, -1, -1);
}
@Override
public List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException {
RelationshipTypeService relationshipTypeService = ContentServiceFactory.getInstance()
.getRelationshipTypeService();
List<RelationshipType> relTypes = relationshipTypeService.findByLeftwardOrRightwardTypeName(context, typeName);
List<Integer> ids = new ArrayList<>();
for ( RelationshipType relationshipType : relTypes) {
ids.add(relationshipType.getID());
}
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.where(relationshipRoot.get(Relationship_.relationshipType).in(ids));
return list(context, criteriaQuery, true, Relationship.class, limit, offset);
}
@Override
public int countByRelationshipType(Context context, RelationshipType relationshipType) throws SQLException {
@@ -188,4 +214,21 @@ public class RelationshipDAOImpl extends AbstractHibernateDAO<Relationship> impl
return count(context, criteriaQuery, criteriaBuilder, relationshipRoot);
}
@Override
public int countByTypeName(Context context, String typeName)
throws SQLException {
RelationshipTypeService relationshipTypeService = ContentServiceFactory.getInstance()
.getRelationshipTypeService();
List<RelationshipType> relTypes = relationshipTypeService.findByLeftwardOrRightwardTypeName(context, typeName);
List<Integer> ids = new ArrayList<>();
for ( RelationshipType relationshipType : relTypes) {
ids.add(relationshipType.getID());
}
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, Relationship.class);
Root<Relationship> relationshipRoot = criteriaQuery.from(Relationship.class);
criteriaQuery.where(relationshipRoot.get(Relationship_.relationshipType).in(ids));
return count(context, criteriaQuery, criteriaBuilder, relationshipRoot);
}
}

View File

@@ -23,7 +23,7 @@ import org.dspace.core.Context;
public class RelationshipTypeDAOImpl extends AbstractHibernateDAO<RelationshipType> implements RelationshipTypeDAO {
@Override
public RelationshipType findByTypesAndLabels(Context context, EntityType leftType, EntityType rightType,
public RelationshipType findbyTypesAndTypeName(Context context, EntityType leftType, EntityType rightType,
String leftwardType, String rightwardType)
throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
@@ -86,4 +86,29 @@ public class RelationshipTypeDAOImpl extends AbstractHibernateDAO<RelationshipTy
return list(context, criteriaQuery, false, RelationshipType.class, limit, offset);
}
@Override
public List<RelationshipType> findByEntityType(Context context, EntityType entityType, Boolean isLeft)
throws SQLException {
return findByEntityType(context, entityType, isLeft, -1, -1);
}
@Override
public List<RelationshipType> findByEntityType(Context context, EntityType entityType, Boolean isLeft,
Integer limit, Integer offset) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, RelationshipType.class);
Root<RelationshipType> relationshipTypeRoot = criteriaQuery.from(RelationshipType.class);
criteriaQuery.select(relationshipTypeRoot);
if (isLeft) {
criteriaQuery.where(
criteriaBuilder.equal(relationshipTypeRoot.get(RelationshipType_.leftType), entityType)
);
} else {
criteriaQuery.where(
criteriaBuilder.equal(relationshipTypeRoot.get(RelationshipType_.rightType), entityType)
);
}
return list(context, criteriaQuery, false, RelationshipType.class, limit, offset);
}
}

View File

@@ -82,25 +82,25 @@ public interface EntityService {
* Retrieves the list of relationships for which their relationshiptype has a left or right label that is
* equal to the passed along label String
* @param context The relevant DSpace context
* @param label The label that needs to be in the relationshiptype of the relationship
* @param typeName The label that needs to be in the relationshiptype of the relationship
* @return The list of relationships that have a relationshiptype with a left or right label
* that is equal to the label param
* @throws SQLException If something goes wrong
*/
List<Relationship> getRelationsByLabel(Context context, String label) throws SQLException;
List<Relationship> getRelationsByTypeName(Context context, String typeName) throws SQLException;
/**
* Retrieves the list of relationships for which their relationshiptype has a left or right label that is
* equal to the passed along label String
* @param context The relevant DSpace context
* @param label The label that needs to be in the relationshiptype of the relationship
* @param typeName The label that needs to be in the relationshiptype of the relationship
* @param limit paging limit
* @param offset paging offset
* @return The list of relationships that have a relationshiptype with a left or right label
* that is equal to the label param
* @throws SQLException If something goes wrong
*/
List<Relationship> getRelationsByLabel(Context context, String label, Integer limit, Integer offset)
List<Relationship> getRelationsByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException;
/**
@@ -150,13 +150,15 @@ public interface EntityService {
* in the leftEntityType
* @param context The relevant DSpace context
* @param entity The Entity for which the EntityType should be checked for relationships
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @param limit paging limit
* @param offset paging offset
* @return The list of relationships that each contain a relationshiptype in which there is a left entity type that
* is equal to the entity type for the given entity
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity,
List<RelationshipType> getLeftRelationshipTypes(Context context, Entity entity, boolean isLeft,
Integer limit, Integer offset) throws SQLException;
/**
@@ -177,25 +179,27 @@ public interface EntityService {
* in the rightEntityType
* @param context The relevant DSpace context
* @param entity The Entity for which the EntityType should be checked for relationships
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @param limit paging limit
* @param offset paging offset
* @return The list of relationships that each contain a relationshiptype in which there is a right entity type that
* is equal to the entity type for the given entity
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity,
List<RelationshipType> getRightRelationshipTypes(Context context, Entity entity, boolean isLeft,
Integer limit, Integer offset) throws SQLException;
/**
* Retrieves a list of RelationshipType objects for which either their left or right label is equal to the
* label parameter that's being passed along
* @param context The relevant DSpace context
* @param type The label for which the relationshiptype's labels must be checked
* @param typeName The typeName for which the relationshiptype's labels must be checked
* @return The list of relationshiptypes that each contain a left or right label that is equal
* to the given label parameter
* @throws SQLException If something goes wrong
*/
List<RelationshipType> getRelationshipTypesByTypeName(Context context, String type) throws SQLException;
List<RelationshipType> getRelationshipTypesByTypeName(Context context, String typeName) throws SQLException;
/**
* Retrieves a list of RelationshipType objects for which either their left or right label is equal to the

View File

@@ -228,6 +228,30 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
int leftPlace, int rightPlace)
throws AuthorizeException, SQLException;
/**
* This method returns a list of Relationship objects for the given typeName
* @param context The relevant DSpace context
* @param typeName The leftward or rightward typeName of the relationship type
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByTypeName(Context context, String typeName) throws SQLException;
/**
* This method returns a list of Relationship objects for the given typeName
* @param context The relevant DSpace context
* @param typeName The leftward or rightward typeName of the relationship type
* @param limit paging limit
* @param offset paging offset
* @return A list of Relationship objects that have the given RelationshipType object as the
* relationshipType property
* @throws SQLException If something goes wrong
*/
List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset)
throws SQLException;
/**
* counts all relationships
*
@@ -269,4 +293,16 @@ public interface RelationshipService extends DSpaceCRUDService<Relationship> {
*/
int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType)
throws SQLException;
/**
* Count total number of relationships (rows in relationship table)
* by a relationship leftward or rightward typeName
*
* @param context context
* @param typeName typeName of relationship
* @return total count
* @throws SQLException if database error
*/
int countByTypeName(Context context, String typeName)
throws SQLException;
}

View File

@@ -41,7 +41,7 @@ public interface RelationshipTypeService extends DSpaceCRUDService<RelationshipT
* @return
* @throws SQLException If something goes wrong
*/
RelationshipType findbyTypesAndLabels(Context context, EntityType leftType, EntityType rightType,
RelationshipType findbyTypesAndTypeName(Context context, EntityType leftType, EntityType rightType,
String leftwardType, String rightwardType)
throws SQLException;
@@ -67,12 +67,12 @@ public interface RelationshipTypeService extends DSpaceCRUDService<RelationshipT
* Retrieves all RelationshipType objects that have a left or right type that is
* equal to the given String
* @param context The relevant DSpace context
* @param label The label that has to match
* @param typeName The label that has to match
* @return The list of all RelationshipType objects that have a left or right label
* that is equal to the given label param
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String label) throws SQLException;
List<RelationshipType> findByLeftwardOrRightwardTypeName(Context context, String typeName) throws SQLException;
/**
* Retrieves all RelationshipType objects that have a left or right label that is
@@ -103,6 +103,38 @@ public interface RelationshipTypeService extends DSpaceCRUDService<RelationshipT
List<RelationshipType> findByEntityType(Context context, EntityType entityType, Integer limit, Integer offset)
throws SQLException;
/**
* This method will return a list of RelationshipType objects for which the given EntityType object is equal
* to the leftType or rightType
* @param context The relevant DSpace context
* @param entityType The EntityType object that will be used to check on
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @return The list of RelationshipType objects that have the given EntityType object
* as either a leftType or rightType
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findByEntityType(Context context, EntityType entityType, boolean isLeft)
throws SQLException;
/**
* This method will return a list of RelationshipType objects for which the given EntityType object is equal
* to the leftType or rightType
* @param context The relevant DSpace context
* @param entityType The EntityType object that will be used to check on
* @param isLeft Boolean value used to filter by left_type or right_type. If true left_type results only
* else right_type results.
* @param limit paging limit
* @param offset paging offset
* @return The list of RelationshipType objects that have the given EntityType object
* as either a leftType or rightType
* @throws SQLException If something goes wrong
*/
List<RelationshipType> findByEntityType(Context context, EntityType entityType, boolean isLeft,
Integer limit, Integer offset)
throws SQLException;
/**
* This method will support the creation of a RelationshipType object with the given parameters
* @param context The relevant DSpace context

View File

@@ -135,7 +135,7 @@ public class EntityServiceImplTest {
}
@Test
public void testGetRelationsByLabel() throws Exception {
public void testGetRelationsByTypeName() throws Exception {
// Declare objects utilized in unit test
Relationship relationship = mock(Relationship.class);
RelationshipType relationshipType = mock(RelationshipType.class);
@@ -150,10 +150,11 @@ public class EntityServiceImplTest {
when(relationship.getRelationshipType()).thenReturn(relationshipType);
when(relationshipType.getLeftwardType()).thenReturn("leftwardType");
when(relationshipType.getRightwardType()).thenReturn("rightwardType");
when(relationshipService.findByTypeName(context, "leftwardType", -1, -1)).thenReturn(relationshipList);
// The relation(s) reported from our defined type should match our relationshipList
assertEquals("TestGetRelationsByLabel 0", relationshipList,
entityService.getRelationsByLabel(context, "leftwardType"));
entityService.getRelationsByTypeName(context, "leftwardType"));
}
@Test
@@ -186,6 +187,8 @@ public class EntityServiceImplTest {
when(leftType.getID()).thenReturn(0);
when(rightType.getID()).thenReturn(1);
when(entityService.getType(context, entity)).thenReturn(leftType); // Mock
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), -1, -1))
.thenReturn(relationshipTypeList);
// The relation(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetAllRelationshipTypes 0", relationshipTypeList,
@@ -216,6 +219,8 @@ public class EntityServiceImplTest {
when(relationshipType.getLeftType()).thenReturn(entityType);
when(entityService.getType(context, entity)).thenReturn(entityType);
when(entityTypeService.findByEntityType(any(), any())).thenReturn(entityType);
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), true, -1, -1))
.thenReturn(relationshipTypeList);
// The left relationshipType(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetLeftRelationshipTypes 0", relationshipTypeList,
@@ -246,6 +251,8 @@ public class EntityServiceImplTest {
when(relationshipType.getRightType()).thenReturn(entityType);
when(entityService.getType(context, entity)).thenReturn(entityType);
when(entityTypeService.findByEntityType(any(), any())).thenReturn(entityType);
when(relationshipTypeService.findByEntityType(context, entityService.getType(context, entity), false, -1, -1))
.thenReturn(relationshipTypeList);
// The right relationshipType(s) reported from our mocked Entity should match our relationshipList
assertEquals("TestGetRightRelationshipTypes 0", relationshipTypeList,
@@ -254,7 +261,7 @@ public class EntityServiceImplTest {
@Test
public void testGetRelationshipTypesByLabel() throws Exception {
public void testGetRelationshipTypesByTypeName() throws Exception {
// Declare objects utilized in unit test
List<RelationshipType> list = new LinkedList<>();
RelationshipType relationshipType = mock(RelationshipType.class);
@@ -265,6 +272,8 @@ public class EntityServiceImplTest {
when(relationshipTypeService.findAll(context, -1, -1)).thenReturn(list);
when(relationshipType.getLeftwardType()).thenReturn("leftwardType");
when(relationshipType.getRightwardType()).thenReturn("rightwardType");
when(relationshipTypeService.findByLeftwardOrRightwardTypeName(context, "leftwardType", -1, -1))
.thenReturn(list);
// The RelationshipType(s) reported from our mocked Entity should match our list
assertEquals("TestGetRelationshipTypesByLabel 0", list,

View File

@@ -87,11 +87,11 @@ public class RelationshipTypeTest {
@Test
public void testRelationshipTypeFindByTypesAndLabels() throws Exception {
// Mock DAO to return our firstRelationshipType
when(relationshipTypeDAO.findByTypesAndLabels(any(), any(), any(), any(), any()))
when(relationshipTypeDAO.findbyTypesAndTypeName(any(), any(), any(), any(), any()))
.thenReturn(firstRelationshipType);
// Declare objects utilized for this test
RelationshipType found = relationshipTypeService.findbyTypesAndLabels(context, mock(EntityType.class),
RelationshipType found = relationshipTypeService.findbyTypesAndTypeName(context, mock(EntityType.class),
mock(EntityType.class),
"mock", "mock");

View File

@@ -132,7 +132,7 @@ public class RelationshipTypeDAOImplTest extends AbstractIntegrationTest {
@Test
public void testFindByTypesAndLabels() throws Exception {
assertEquals("TestFindbyTypesAndLabels 0", relationshipType, relationshipTypeService
.findbyTypesAndLabels(context, entityTypeTwo, entityTypeOne, "isAuthorOfPublication",
.findbyTypesAndTypeName(context, entityTypeTwo, entityTypeOne, "isAuthorOfPublication",
"isPublicationOfAuthor"));
}

View File

@@ -162,12 +162,12 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.build();
isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
isOrgUnitOfPersonRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Person"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Person"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfPerson", "isPersonOfOrgUnit");
@@ -188,15 +188,15 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isOrgUnitOfPersonRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Person"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Person"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfPerson", "isPersonOfOrgUnit");
RelationshipType isOrgUnitOfProjectRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Project"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Project"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfProject", "isProjectOfOrgUnit");
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -656,7 +656,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
.build();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -2130,15 +2130,15 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isOrgUnitOfPersonRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Person"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Person"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfPerson", "isPersonOfOrgUnit");
RelationshipType isOrgUnitOfProjectRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Project"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Project"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfProject", "isProjectOfOrgUnit");
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -2261,7 +2261,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -2298,7 +2298,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -2338,7 +2338,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");
@@ -2393,7 +2393,7 @@ public class RelationshipRestRepositoryIT extends AbstractEntityIntegrationTest
context.turnOffAuthorisationSystem();
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");

View File

@@ -72,19 +72,19 @@ public class RelationshipTypeRestControllerIT extends AbstractEntityIntegrationT
EntityType journalIssueEntityType = entityTypeService.findByEntityType(context, "journalIssue");
RelationshipType relationshipType1 = relationshipTypeService
.findbyTypesAndLabels(context, publicationEntityType, personEntityType, "isAuthorOfPublication",
.findbyTypesAndTypeName(context, publicationEntityType, personEntityType, "isAuthorOfPublication",
"isPublicationOfAuthor");
RelationshipType relationshipType2 = relationshipTypeService
.findbyTypesAndLabels(context, publicationEntityType, projectEntityType, "isProjectOfPublication",
.findbyTypesAndTypeName(context, publicationEntityType, projectEntityType, "isProjectOfPublication",
"isPublicationOfProject");
RelationshipType relationshipType3 = relationshipTypeService
.findbyTypesAndLabels(context, publicationEntityType, orgunitEntityType, "isOrgUnitOfPublication",
.findbyTypesAndTypeName(context, publicationEntityType, orgunitEntityType, "isOrgUnitOfPublication",
"isPublicationOfOrgUnit");
RelationshipType relationshipType4 = relationshipTypeService
.findbyTypesAndLabels(context, journalIssueEntityType, publicationEntityType, "isPublicationOfJournalIssue",
"isJournalIssueOfPublication");
.findbyTypesAndTypeName(context, journalIssueEntityType, publicationEntityType,
"isPublicationOfJournalIssue", "isJournalIssueOfPublication");
RelationshipType relationshipType5 = relationshipTypeService
.findbyTypesAndLabels(context, publicationEntityType, orgunitEntityType, "isAuthorOfPublication",
.findbyTypesAndTypeName(context, publicationEntityType, orgunitEntityType, "isAuthorOfPublication",
"isPublicationOfAuthor");
getClient().perform(get("/api/core/entitytypes/" + publicationEntityType.getID() + "/relationshiptypes"))
.andExpect(status().isOk())
@@ -162,15 +162,15 @@ public class RelationshipTypeRestControllerIT extends AbstractEntityIntegrationT
.build();
RelationshipType isOrgUnitOfPersonRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Person"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Person"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfPerson", "isPersonOfOrgUnit");
RelationshipType isOrgUnitOfProjectRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Project"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Project"),
entityTypeService.findByEntityType(context, "OrgUnit"),
"isOrgUnitOfProject", "isProjectOfOrgUnit");
RelationshipType isAuthorOfPublicationRelationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"),
"isAuthorOfPublication", "isPublicationOfAuthor");

View File

@@ -120,7 +120,7 @@ public class RelationshipTypeRestRepositoryIT extends AbstractEntityIntegrationT
private void checkRelationshipType(String leftType, String rightType, String leftwardType, String rightwardType)
throws SQLException {
RelationshipType relationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, leftType),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, leftType),
entityTypeService.findByEntityType(context, rightType),
leftwardType, rightwardType);
assertNotNull(relationshipType);
@@ -189,7 +189,7 @@ public class RelationshipTypeRestRepositoryIT extends AbstractEntityIntegrationT
@Test
public void cardinalityOnAuthorPublicationRelationshipTypesTest() throws Exception {
RelationshipType relationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"), "isAuthorOfPublication",
"isPublicationOfAuthor");
assertEquals(((Integer) 0), relationshipType.getLeftMinCardinality());
@@ -234,7 +234,7 @@ public class RelationshipTypeRestRepositoryIT extends AbstractEntityIntegrationT
@Test
public void cardinalityOnIssueJournalJournalVolumeRelationshipTypesTest() throws Exception {
RelationshipType relationshipType = relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "JournalVolume"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "JournalVolume"),
entityTypeService.findByEntityType(context, "JournalIssue"), "isIssueOfJournalVolume",
"isJournalVolumeOfIssue");
assertEquals(((Integer) 0), relationshipType.getLeftMinCardinality());

View File

@@ -131,7 +131,7 @@ public class CsvImportIT extends AbstractEntityIntegrationTest {
private void assertArticleRelationships(Item article, Item itemB, Item itemC, Item itemF) throws SQLException {
List<Relationship> relationshipsForArticle = relationshipService
.findByItemAndRelationshipType(context, article, relationshipTypeService
.findbyTypesAndLabels(context, entityTypeService.findByEntityType(context, "Publication"),
.findbyTypesAndTypeName(context, entityTypeService.findByEntityType(context, "Publication"),
entityTypeService.findByEntityType(context, "Person"), "isAuthorOfPublication",
"isPublicationOfAuthor"));
assertThat(relationshipsForArticle.size(), is(3));