Package org.dspace.content
Class RelationshipServiceImpl
- java.lang.Object
-
- org.dspace.content.RelationshipServiceImpl
-
- All Implemented Interfaces:
RelationshipService,DSpaceCRUDService<Relationship>
public class RelationshipServiceImpl extends Object implements RelationshipService
-
-
Field Summary
Fields Modifier and Type Field Description protected AuthorizeServiceauthorizeServiceprotected ItemServiceitemServiceprotected RelationshipDAOrelationshipDAOprotected RelationshipTypeServicerelationshipTypeService
-
Constructor Summary
Constructors Constructor Description RelationshipServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcountByItem(Context context, Item item)This method returns a count of Relationship objects that have the given Item object as a leftItem or a rightItemintcountByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft)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 notintcountByItemRelationshipTypeAndRelatedList(Context context, UUID focusUUID, RelationshipType relationshipType, List<UUID> items, boolean isLeft)Count total number of relationships that match focusItem on the one hand and matches list of related items elsewhere.intcountByRelationshipType(Context context, RelationshipType relationshipType)Count total number of relationships (rows in relationship table) by a relationship typeintcountByTypeName(Context context, String typeName)Count total number of relationships (rows in relationship table) by a relationship leftward or rightward typeNameintcountTotal(Context context)counts all relationshipsRelationshipcreate(Context context)Relationshipcreate(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType, int leftPlace, int rightPlace)This method is used to construct a Relationship object with all it's variables, except the leftward and rightward labelsRelationshipcreate(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType, int leftPlace, int rightPlace, String leftwardValue, String rightwardValue)This method is used to construct a Relationship object with all it's variablesRelationshipcreate(Context context, Relationship relationship)This method creates a relationship object in the database equal to the given relationship param if this is a valid relationshipvoiddelete(Context context, Relationship relationship)voiddelete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem)This method is used to delete a Relationship whilst given the possibility to copy the Virtual Metadata created by this relationship to the left and/or right itemRelationshipfind(Context context, int id)List<Relationship>findAll(Context context)Retrieves the full list of relationships currently in the systemList<Relationship>findAll(Context context, Integer limit, Integer offset)Retrieves the full list of relationships currently in the systemList<Relationship>findByItem(Context context, Item item)Retrieves the list of Relationships currently in the system for which the given Item is either a leftItem or a rightItem objectList<Relationship>findByItem(Context context, Item item, Integer limit, Integer offset, boolean excludeTilted)Retrieves the list of Relationships currently in the system for which the given Item is either a leftItem or a rightItem objectList<Relationship>findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType)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 propertyList<Relationship>findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft)List<Relationship>findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft, int limit, int offset)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 propertyList<Relationship>findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, int limit, int offset)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 propertyList<Relationship>findByItemRelationshipTypeAndRelatedList(Context context, UUID focusUUID, RelationshipType relationshipType, List<UUID> items, boolean isLeft, int offset, int limit)This method is used to retrieve relationships that match focusItem on the one hand and matches list of related items elsewhere.List<Relationship>findByRelationshipType(Context context, RelationshipType relationshipType)This method returns a list of Relationship objects for which the relationshipType property is equal to the given RelationshipType objectList<Relationship>findByRelationshipType(Context context, RelationshipType relationshipType, Integer limit, Integer offset)This method returns a list of Relationship objets for which the relationshipType property is equal to the given RelationshipType objectList<Relationship>findByTypeName(Context context, String typeName)This method returns a list of Relationship objects for the given typeNameList<Relationship>findByTypeName(Context context, String typeName, Integer limit, Integer offset)This method returns a list of Relationship objects for the given typeNameintfindNextLeftPlaceByLeftItem(Context context, Item item)This method returns the next leftplace integer to use for a relationship with this item as the leftItemintfindNextRightPlaceByRightItem(Context context, Item item)This method returns the next rightplace integer to use for a relationship with this item as the rightItemvoidforceDelete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem)This method is used to delete a Relationship whilst given the possibility to copy the Virtual Metadata created by this relationship to the left and/or right item.voidupdate(Context context, List<Relationship> relationships)Persist a collection of model objects.voidupdate(Context context, Relationship relationship)Persist a model object.voidupdateItem(Context context, Item relatedItem)This method will update the given item's metadata order.voidupdatePlaceInRelationship(Context context, Relationship relationship)This method will update the place for the Relationship and all other relationships found by the items and relationship type of the given Relationship.
-
-
-
Field Detail
-
relationshipDAO
@Autowired(required=true) protected RelationshipDAO relationshipDAO
-
authorizeService
@Autowired(required=true) protected AuthorizeService authorizeService
-
itemService
@Autowired(required=true) protected ItemService itemService
-
relationshipTypeService
@Autowired(required=true) protected RelationshipTypeService relationshipTypeService
-
-
Method Detail
-
create
public Relationship create(Context context) throws SQLException, AuthorizeException
- Specified by:
createin interfaceDSpaceCRUDService<Relationship>- Throws:
SQLExceptionAuthorizeException
-
create
public Relationship create(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType, int leftPlace, int rightPlace) throws AuthorizeException, SQLException
Description copied from interface:RelationshipServiceThis method is used to construct a Relationship object with all it's variables, except the leftward and rightward labels- Specified by:
createin interfaceRelationshipService- Parameters:
c- The relevant DSpace contextleftItem- The leftItem Item object for the relationshiprightItem- The rightItem Item object for the relationshiprelationshipType- The RelationshipType object for the relationshipleftPlace- The leftPlace integer for the relationshiprightPlace- The rightPlace integer for the relationship- Returns:
- The created Relationship object with the given properties
- Throws:
AuthorizeException- If something goes wrongSQLException- If something goes wrong
-
create
public Relationship create(Context c, Item leftItem, Item rightItem, RelationshipType relationshipType, int leftPlace, int rightPlace, String leftwardValue, String rightwardValue) throws AuthorizeException, SQLException
Description copied from interface:RelationshipServiceThis method is used to construct a Relationship object with all it's variables- Specified by:
createin interfaceRelationshipService- Parameters:
c- The relevant DSpace contextleftItem- The leftItem Item object for the relationshiprightItem- The rightItem Item object for the relationshiprelationshipType- The RelationshipType object for the relationshipleftPlace- The leftPlace integer for the relationshiprightPlace- The rightPlace integer for the relationshipleftwardValue- The leftwardValue string for the relationshiprightwardValue- The rightwardValue string for the relationship- Returns:
- The created Relationship object with the given properties
- Throws:
AuthorizeException- If something goes wrongSQLException- If something goes wrong
-
create
public Relationship create(Context context, Relationship relationship) throws SQLException, AuthorizeException
Description copied from interface:RelationshipServiceThis method creates a relationship object in the database equal to the given relationship param if this is a valid relationship- Specified by:
createin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationship- The relationship that will be created in the database if it is valid- Returns:
- The created relationship with updated place variables
- Throws:
SQLException- If something goes wrongAuthorizeException- If something goes wrong with authorizations
-
updatePlaceInRelationship
public void updatePlaceInRelationship(Context context, Relationship relationship) throws SQLException, AuthorizeException
Description copied from interface:RelationshipServiceThis 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 left and right place determined by querying for the list of leftRelationships and rightRelationships by the leftItem, rightItem and relationshipType of the given Relationship.- Specified by:
updatePlaceInRelationshipin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationship- The Relationship object that will have it's place updated and that will be used to retrieve the other relationships whose place might need to be updated- Throws:
SQLException- If something goes wrongAuthorizeException
-
updateItem
public void updateItem(Context context, Item relatedItem) throws SQLException, AuthorizeException
Description copied from interface:RelationshipServiceThis method will update the given item's metadata order. If the relationships for the item have been modified and will calculate the place based on a metadata field, this function will ensure the place is calculated.- Specified by:
updateItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelatedItem- The Item for which the list of Relationship location is calculated based on a metadata field- Throws:
SQLException- If something goes wrongAuthorizeException- If the user is not authorized to update the item
-
findNextLeftPlaceByLeftItem
public int findNextLeftPlaceByLeftItem(Context context, Item item) throws SQLException
Description copied from interface:RelationshipServiceThis method returns the next leftplace integer to use for a relationship with this item as the leftItem- Specified by:
findNextLeftPlaceByLeftItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The item that has to be the leftItem of a relationship for it to qualify- Returns:
- The next integer to be used for the leftplace of a relationship with the given item as a left item
- Throws:
SQLException- If something goes wrong
-
findNextRightPlaceByRightItem
public int findNextRightPlaceByRightItem(Context context, Item item) throws SQLException
Description copied from interface:RelationshipServiceThis method returns the next rightplace integer to use for a relationship with this item as the rightItem- Specified by:
findNextRightPlaceByRightItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The item that has to be the rightitem of a relationship for it to qualify- Returns:
- The next integer to be used for the rightplace of a relationship with the given item as a right item
- Throws:
SQLException- If something goes wrong
-
find
public Relationship find(Context context, int id) throws SQLException
- Specified by:
findin interfaceDSpaceCRUDService<Relationship>- Throws:
SQLException
-
findByItem
public List<Relationship> findByItem(Context context, Item item) throws SQLException
Description copied from interface:RelationshipServiceRetrieves the list of Relationships currently in the system for which the given Item is either a leftItem or a rightItem object- Specified by:
findByItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The Item that has to be the left or right item for the relationship to be included in the list- Returns:
- The list of relationships for which each relationship adheres to the above listed constraint
- Throws:
SQLException- If something goes wrong
-
findByItem
public List<Relationship> findByItem(Context context, Item item, Integer limit, Integer offset, boolean excludeTilted) throws SQLException
Description copied from interface:RelationshipServiceRetrieves the list of Relationships currently in the system for which the given Item is either a leftItem or a rightItem object- Specified by:
findByItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The Item that has to be the left or right item for the relationship to be included in the listlimit- paging limitoffset- paging offsetexcludeTilted- If true, excludes tilted relationships- Returns:
- The list of relationships for which each relationship adheres to the above listed constraint
- Throws:
SQLException- If something goes wrong
-
findAll
public List<Relationship> findAll(Context context) throws SQLException
Description copied from interface:RelationshipServiceRetrieves the full list of relationships currently in the system- Specified by:
findAllin interfaceRelationshipService- Parameters:
context- The relevant DSpace context- Returns:
- The list of all relationships currently in the system
- Throws:
SQLException- If something goes wrong
-
findAll
public List<Relationship> findAll(Context context, Integer limit, Integer offset) throws SQLException
Description copied from interface:RelationshipServiceRetrieves the full list of relationships currently in the system- Specified by:
findAllin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextlimit- paging limitoffset- paging offset- Returns:
- The list of all relationships currently in the system
- Throws:
SQLException- If something goes wrong
-
update
public void update(Context context, Relationship relationship) throws SQLException, AuthorizeException
Description copied from interface:DSpaceCRUDServicePersist a model object.- Specified by:
updatein interfaceDSpaceCRUDService<Relationship>relationship- object to be persisted.- Throws:
SQLException- passed through.AuthorizeException- passed through.
-
update
public void update(Context context, List<Relationship> relationships) throws SQLException, AuthorizeException
Description copied from interface:DSpaceCRUDServicePersist a collection of model objects.- Specified by:
updatein interfaceDSpaceCRUDService<Relationship>relationships- object to be persisted.- Throws:
SQLException- passed through.AuthorizeException- passed through.
-
delete
public void delete(Context context, Relationship relationship) throws SQLException, AuthorizeException
- Specified by:
deletein interfaceDSpaceCRUDService<Relationship>- Throws:
SQLExceptionAuthorizeException
-
delete
public void delete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem) throws SQLException, AuthorizeException
Description copied from interface:RelationshipServiceThis method is used to delete a Relationship whilst given the possibility to copy the Virtual Metadata created by this relationship to the left and/or right item- Specified by:
deletein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationship- The relationship to be deletedcopyToLeftItem- A boolean indicating whether we should copy metadata to the left item or notcopyToRightItem- A boolean indicating whether we should copy metadata to the right item or not- Throws:
SQLExceptionAuthorizeException
-
forceDelete
public void forceDelete(Context context, Relationship relationship, boolean copyToLeftItem, boolean copyToRightItem) throws SQLException, AuthorizeException
Description copied from interface:RelationshipServiceThis method is used to delete a Relationship whilst given the possibility to copy the Virtual Metadata created by this relationship to the left and/or right item. This method will bypass the cardinality checks on theRelationshipTypefor the givenRelationshipThis should only be used during the deletion of items so that the min cardinality check can't disallow items to be deleted- Specified by:
forceDeletein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationship- The relationship to be deletedcopyToLeftItem- A boolean indicating whether we should copy metadata to the left item or notcopyToRightItem- A boolean indicating whether we should copy metadata to the right item or not- Throws:
SQLExceptionAuthorizeException
-
findByItemAndRelationshipType
public List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft) throws SQLException
- Throws:
SQLException
-
findByItemAndRelationshipType
public List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType) throws SQLException
Description copied from interface:RelationshipServiceThis 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- Specified by:
findByItemAndRelationshipTypein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The Item object to be matched on the leftItem or rightItem for the relationshiprelationshipType- The RelationshipType object that will be used to check the Relationship on- Returns:
- 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
-
findByItemAndRelationshipType
public List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, int limit, int offset) throws SQLException
Description copied from interface:RelationshipServiceThis 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- Specified by:
findByItemAndRelationshipTypein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The Item object to be matched on the leftItem or rightItem for the relationshiprelationshipType- The RelationshipType object that will be used to check the Relationship on- Returns:
- 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
-
findByItemAndRelationshipType
public List<Relationship> findByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft, int limit, int offset) throws SQLException
Description copied from interface:RelationshipServiceThis 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- Specified by:
findByItemAndRelationshipTypein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The Item object to be matched on the leftItem or rightItem for the relationshiprelationshipType- The RelationshipType object that will be used to check the Relationship onisLeft- Is the item left or right- Returns:
- 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
-
findByRelationshipType
public List<Relationship> findByRelationshipType(Context context, RelationshipType relationshipType) throws SQLException
Description copied from interface:RelationshipServiceThis method returns a list of Relationship objects for which the relationshipType property is equal to the given RelationshipType object- Specified by:
findByRelationshipTypein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationshipType- The RelationshipType object that will be used to check the Relationship on- Returns:
- The list of Relationship objects for which the given RelationshipType object is equal to the relationshipType property
- Throws:
SQLException- If something goes wrong
-
findByRelationshipType
public List<Relationship> findByRelationshipType(Context context, RelationshipType relationshipType, Integer limit, Integer offset) throws SQLException
Description copied from interface:RelationshipServiceThis method returns a list of Relationship objets for which the relationshipType property is equal to the given RelationshipType object- Specified by:
findByRelationshipTypein interfaceRelationshipService- Parameters:
context- The relevant DSpace contextrelationshipType- The RelationshipType object that will be used to check the Relationship onlimit- paging limitoffset- paging offset- Returns:
- The list of Relationship objects for which the given RelationshipType object is equal to the relationshipType property
- Throws:
SQLException- If something goes wrong
-
findByTypeName
public List<Relationship> findByTypeName(Context context, String typeName) throws SQLException
Description copied from interface:RelationshipServiceThis method returns a list of Relationship objects for the given typeName- Specified by:
findByTypeNamein interfaceRelationshipService- Parameters:
context- The relevant DSpace contexttypeName- The leftward or rightward typeName of the relationship type- Returns:
- A list of Relationship objects that have the given RelationshipType object as the relationshipType property
- Throws:
SQLException- If something goes wrong
-
findByTypeName
public List<Relationship> findByTypeName(Context context, String typeName, Integer limit, Integer offset) throws SQLException
Description copied from interface:RelationshipServiceThis method returns a list of Relationship objects for the given typeName- Specified by:
findByTypeNamein interfaceRelationshipService- Parameters:
context- The relevant DSpace contexttypeName- The leftward or rightward typeName of the relationship typelimit- paging limitoffset- paging offset- Returns:
- A list of Relationship objects that have the given RelationshipType object as the relationshipType property
- Throws:
SQLException- If something goes wrong
-
countTotal
public int countTotal(Context context) throws SQLException
Description copied from interface:RelationshipServicecounts all relationships- Specified by:
countTotalin interfaceRelationshipService- Parameters:
context- DSpace context object- Returns:
- total relationships
- Throws:
SQLException- if database error
-
countByItem
public int countByItem(Context context, Item item) throws SQLException
Description copied from interface:RelationshipServiceThis method returns a count of Relationship objects that have the given Item object as a leftItem or a rightItem- Specified by:
countByItemin interfaceRelationshipService- Parameters:
context- The relevant DSpace contextitem- The item that should be either a leftItem or a rightItem of all the Relationship objects in the returned list- Returns:
- 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
-
countByRelationshipType
public int countByRelationshipType(Context context, RelationshipType relationshipType) throws SQLException
Description copied from interface:RelationshipServiceCount total number of relationships (rows in relationship table) by a relationship type- Specified by:
countByRelationshipTypein interfaceRelationshipService- Parameters:
context- contextrelationshipType- relationship type to filter by- Returns:
- total count
- Throws:
SQLException- if database error
-
countByItemAndRelationshipType
public int countByItemAndRelationshipType(Context context, Item item, RelationshipType relationshipType, boolean isLeft) throws SQLException
Description copied from interface:RelationshipServiceCount 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- Specified by:
countByItemAndRelationshipTypein interfaceRelationshipService- Parameters:
context- contextrelationshipType- relationship type to filter byisLeft- Indicating whether the counted Relationships should have the given Item on the left side or not- Returns:
- total count with the given parameters
- Throws:
SQLException- if database error
-
countByTypeName
public int countByTypeName(Context context, String typeName) throws SQLException
Description copied from interface:RelationshipServiceCount total number of relationships (rows in relationship table) by a relationship leftward or rightward typeName- Specified by:
countByTypeNamein interfaceRelationshipService- Parameters:
context- contexttypeName- typeName of relationship- Returns:
- total count
- Throws:
SQLException- if database error
-
findByItemRelationshipTypeAndRelatedList
public List<Relationship> findByItemRelationshipTypeAndRelatedList(Context context, UUID focusUUID, RelationshipType relationshipType, List<UUID> items, boolean isLeft, int offset, int limit) throws SQLException
Description copied from interface:RelationshipServiceThis method is used to retrieve relationships that match focusItem on the one hand and matches list of related items elsewhere.- Specified by:
findByItemRelationshipTypeAndRelatedListin interfaceRelationshipService- Parameters:
context- DSpace context objectfocusUUID- UUID of Item that will match left side if the param isLeft is true otherwise right siderelationshipType- Relationship type to filter byitems- List of UUID that will use to filter other side respect the focusUUIDisLeft- Indicating whether the counted Relationships should have the given Item on the left side or notoffset- paging offsetlimit- paging limit- Returns:
- Throws:
SQLException- If database error
-
countByItemRelationshipTypeAndRelatedList
public int countByItemRelationshipTypeAndRelatedList(Context context, UUID focusUUID, RelationshipType relationshipType, List<UUID> items, boolean isLeft) throws SQLException
Description copied from interface:RelationshipServiceCount total number of relationships that match focusItem on the one hand and matches list of related items elsewhere.- Specified by:
countByItemRelationshipTypeAndRelatedListin interfaceRelationshipService- Parameters:
context- DSpace context objectfocusUUID- UUID of Item that will match left side if the param isLeft is true otherwise right siderelationshipType- Relationship type to filter byitems- List of UUID that will use to filter other side respect the focusUUIDisLeft- Indicating whether the counted Relationships should have the given Item on the left side or not- Returns:
- Throws:
SQLException- If database error
-
-