Package org.dspace.content
Class CommunityServiceImpl
- java.lang.Object
-
- org.dspace.content.DSpaceObjectServiceImpl<Community>
-
- org.dspace.content.CommunityServiceImpl
-
- All Implemented Interfaces:
CommunityService,DSpaceObjectLegacySupportService<Community>,DSpaceObjectService<Community>
public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> implements CommunityService
Service implementation for the Community object. This class is responsible for all business logic calls for the Community object and is autowired by spring. This class should never be accessed directly.- Author:
- kevinvandevelde at atmire.com
-
-
Field Summary
Fields Modifier and Type Field Description protected AuthorizeServiceauthorizeServiceprotected BitstreamServicebitstreamServiceprotected CollectionServicecollectionServiceprotected CommunityDAOcommunityDAOprotected GroupServicegroupServiceprotected IdentifierServiceidentifierServiceprotected ItemServiceitemServiceprotected SiteServicesiteServiceprotected SubscribeServicesubscribeService-
Fields inherited from class org.dspace.content.DSpaceObjectServiceImpl
choiceAuthorityService, handleService, metadataAuthorityService, metadataFieldService, metadataValueService, relationshipService
-
Fields inherited from interface org.dspace.content.service.DSpaceObjectService
MD_COPYRIGHT_TEXT, MD_INTRODUCTORY_TEXT, MD_LICENSE, MD_NAME, MD_PROVENANCE_DESCRIPTION, MD_SHORT_DESCRIPTION, MD_SIDEBAR_TEXT, MD_SOURCE, MD_USER_FORMAT_DESCRIPTION
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedCommunityServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCollection(Context context, Community community, Collection collection)Add an exisiting collection to the communityprotected voidaddCollectionList(Community community, List<Collection> collectionList)Internal method to process subcommunities recursivelyvoidaddSubcommunity(Context context, Community parentCommunity, Community childCommunity)Add an existing community as a subcommunity to the communityvoidcanEdit(Context context, Community community)booleancanEditBoolean(Context context, Community community)return TRUE if context's user can edit community, false otherwiseintcountArchivedItems(Community community)Returns total community archived itemsintcountTotal(Context context)Communitycreate(Community parent, Context context)Create a new top-level community, with a new ID.Communitycreate(Community parent, Context context, String handle)Create a new top-level community, with a new ID.Communitycreate(Community parent, Context context, String handle, UUID uuid)Create a new top-level community, with a new ID.GroupcreateAdministrators(Context context, Community community)Create a default administrators group if one does not already exist.CommunitycreateSubcommunity(Context context, Community parentCommunity)Create a new sub-community within this community.CommunitycreateSubcommunity(Context context, Community parentCommunity, String handle)Create a new sub-community within this community.CommunitycreateSubcommunity(Context context, Community parentCommunity, String handle, UUID uuid)Create a new sub-community within this community.voiddelete(Context context, Community community)Communityfind(Context context, UUID id)Generic find for when the precise type of an Entity is not knownList<Community>findAll(Context context)Get a list of all communities in the system.List<Community>findAll(Context context, Integer limit, Integer offset)Get all communities in the system.List<Community>findAllTop(Context context)Get a list of all top-level communities in the system.List<Community>findAuthorized(Context context, List<Integer> actions)List<Community>findAuthorizedGroupMapped(Context context, List<Integer> actions)CommunityfindByAdminGroup(Context context, Group group)CommunityfindByIdOrLegacyId(Context context, String id)CommunityfindByLegacyId(Context context, int id)Generic find for when the precise type of a DSO is not known, just the a pair of type number and database ID.DSpaceObjectgetAdminObject(Context context, Community community, int action)Return the dspace object where an ADMIN action right is sufficient to grant the initial authorize check.List<Collection>getAllCollections(Context context, Community community)Return an array of collections of this community and its subcommunitiesList<Community>getAllParents(Context context, Collection collection)Return an array of parent communities of this collection.List<Community>getAllParents(Context context, Community community)Return an array of parent communities of this community, in ascending order.DSpaceObjectgetParentObject(Context context, Community community)Return the dspace object that "own" the current object in the hierarchy.intgetSupportsTypeConstant()Returns the Constants which this service supportsprotected voidrawDelete(Context context, Community community)Internal method to remove the community and all its children from the database, and perform any pre/post-cleanupvoidremoveAdministrators(Context context, Community community)Remove the administrators group, if no group has already been created then return without error.voidremoveCollection(Context context, Community community, Collection collection)Remove a collection.voidremoveSubcommunity(Context context, Community parentCommunity, Community childCommunity)Remove a subcommunity.BitstreamsetLogo(Context context, Community community, InputStream is)Give the community a logo.voidsetMetadataSingleValue(Context context, Community community, MetadataFieldName field, String language, String value)Set first metadata field valuevoidupdate(Context context, Community community)voidupdateLastModified(Context context, Community community)-
Methods inherited from class org.dspace.content.DSpaceObjectServiceImpl
addAndShiftRightMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, clearMetadata, getAuthoritiesAndConfidences, getElements, getElementsFilled, getIdentifiers, getMDValueByField, getMDValueByLegacyField, getMetadata, getMetadata, getMetadata, getMetadata, getMetadataByMetadataString, getMetadataFirstValue, getMetadataFirstValue, getMetadataValuePlace, getName, getTypeText, match, moveMetadata, moveSingleMetadataValue, removeMetadataValues, replaceMetadata, setMetadataModified, setMetadataSingleValue
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.dspace.content.service.DSpaceObjectService
addAndShiftRightMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, addMetadata, clearMetadata, getIdentifiers, getMetadata, getMetadata, getMetadata, getMetadata, getMetadataByMetadataString, getMetadataFirstValue, getMetadataFirstValue, getName, getTypeText, moveMetadata, removeMetadataValues, replaceMetadata, setMetadataModified, setMetadataSingleValue
-
-
-
-
Field Detail
-
communityDAO
@Autowired(required=true) protected CommunityDAO communityDAO
-
collectionService
@Autowired(required=true) protected CollectionService collectionService
-
groupService
@Autowired(required=true) protected GroupService groupService
-
authorizeService
@Autowired(required=true) protected AuthorizeService authorizeService
-
itemService
@Autowired(required=true) protected ItemService itemService
-
bitstreamService
@Autowired(required=true) protected BitstreamService bitstreamService
-
siteService
@Autowired(required=true) protected SiteService siteService
-
identifierService
@Autowired(required=true) protected IdentifierService identifierService
-
subscribeService
@Autowired(required=true) protected SubscribeService subscribeService
-
-
Method Detail
-
create
public Community create(Community parent, Context context) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new top-level community, with a new ID.- Specified by:
createin interfaceCommunityService- Parameters:
parent- parent communitycontext- DSpace context object- Returns:
- the newly created community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
create
public Community create(Community parent, Context context, String handle) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new top-level community, with a new ID.- Specified by:
createin interfaceCommunityService- Parameters:
parent- parent communitycontext- DSpace context objecthandle- the pre-determined Handle to assign to the new community- Returns:
- the newly created community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
create
public Community create(Community parent, Context context, String handle, UUID uuid) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new top-level community, with a new ID.- Specified by:
createin interfaceCommunityService- Parameters:
parent- parent communitycontext- DSpace context objecthandle- the pre-determined Handle to assign to the new communityuuid- the pre-determined uuid to assign to the new community- Returns:
- the newly created community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
find
public Community find(Context context, UUID id) throws SQLException
Description copied from interface:DSpaceObjectServiceGeneric find for when the precise type of an Entity is not known- Specified by:
findin interfaceDSpaceObjectService<Community>- Parameters:
context- - the contextid- - uuid within table of typed dspace objects- Returns:
- the dspace object found, or null if it does not exist.
- Throws:
SQLException- only upon failure accessing the database.
-
findAll
public List<Community> findAll(Context context) throws SQLException
Description copied from interface:CommunityServiceGet a list of all communities in the system. These are alphabetically sorted by community name.- Specified by:
findAllin interfaceCommunityService- Parameters:
context- DSpace context object- Returns:
- the communities in the system
- Throws:
SQLException- if database error
-
findAll
public List<Community> findAll(Context context, Integer limit, Integer offset) throws SQLException
Description copied from interface:CommunityServiceGet all communities in the system. Adds support for limit and offset.- Specified by:
findAllin interfaceCommunityService- Parameters:
context- contextlimit- limitoffset- offset- Returns:
- list of communities
- Throws:
SQLException- if database error
-
findAllTop
public List<Community> findAllTop(Context context) throws SQLException
Description copied from interface:CommunityServiceGet a list of all top-level communities in the system. These are alphabetically sorted by community name. A top-level community is one without a parent community.- Specified by:
findAllTopin interfaceCommunityService- Parameters:
context- DSpace context object- Returns:
- the top-level communities in the system
- Throws:
SQLException- if database error
-
setMetadataSingleValue
public void setMetadataSingleValue(Context context, Community community, MetadataFieldName field, String language, String value) throws MissingResourceException, SQLException
Description copied from interface:DSpaceObjectServiceSet first metadata field value- Specified by:
setMetadataSingleValuein interfaceDSpaceObjectService<Community>- Overrides:
setMetadataSingleValuein classDSpaceObjectServiceImpl<Community>- Parameters:
context- DSpace contextcommunity- DSpaceObjectfield- {schema, element, qualifier} for the desired field.language- the ISO639 language code, optionally followed by an underscore and the ISO3166 country code.nullmeans only values with no language are removed, andItem.ANYmeans values with any country code or no country code are removed.value- metadata value- Throws:
SQLException- if database errorMissingResourceException
-
setLogo
public Bitstream setLogo(Context context, Community community, InputStream is) throws AuthorizeException, IOException, SQLException
Description copied from interface:CommunityServiceGive the community a logo. Passing innullremoves any existing logo. You will need to set the format of the new logo bitstream before it will work, for example to "JPEG". Note thatupdatewill need to be called for the change to take effect. Setting a logo and not callingupdatelater may result in a previous logo lying around as an "orphaned" bitstream.- Specified by:
setLogoin interfaceCommunityService- Parameters:
context- contextcommunity- communityis- the stream to use as the new logo- Returns:
- the new logo bitstream, or
nullif there is no logo (nullwas passed in) - Throws:
AuthorizeException- if authorization errorIOException- if IO errorSQLException- if database error
-
update
public void update(Context context, Community community) throws SQLException, AuthorizeException
- Specified by:
updatein interfaceDSpaceObjectService<Community>- Overrides:
updatein classDSpaceObjectServiceImpl<Community>- Throws:
SQLExceptionAuthorizeException
-
createAdministrators
public Group createAdministrators(Context context, Community community) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a default administrators group if one does not already exist. Returns either the newly created group or the previously existing one. Note that other groups may also be administrators.- Specified by:
createAdministratorsin interfaceCommunityService- Parameters:
context- contextcommunity- community- Returns:
- the default group of editors associated with this community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
removeAdministrators
public void removeAdministrators(Context context, Community community) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceRemove the administrators group, if no group has already been created then return without error. This will merely dereference the current administrators group from the community so that it may be deleted without violating database constraints.- Specified by:
removeAdministratorsin interfaceCommunityService- Parameters:
context- contextcommunity- community- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
getAllParents
public List<Community> getAllParents(Context context, Community community) throws SQLException
Description copied from interface:CommunityServiceReturn an array of parent communities of this community, in ascending order. If community is top-level, return an empty array.- Specified by:
getAllParentsin interfaceCommunityService- Parameters:
context- contextcommunity- community- Returns:
- an array of parent communities, empty if top-level
- Throws:
SQLException- if database error
-
getAllParents
public List<Community> getAllParents(Context context, Collection collection) throws SQLException
Description copied from interface:CommunityServiceReturn an array of parent communities of this collection.- Specified by:
getAllParentsin interfaceCommunityService- Parameters:
context- The relevant DSpace Context.collection- collection to check- Returns:
- an array of parent communities
- Throws:
SQLException- if database error
-
getAllCollections
public List<Collection> getAllCollections(Context context, Community community) throws SQLException
Description copied from interface:CommunityServiceReturn an array of collections of this community and its subcommunities- Specified by:
getAllCollectionsin interfaceCommunityService- Parameters:
context- contextcommunity- community- Returns:
- an array of collections
- Throws:
SQLException- if database error
-
addCollectionList
protected void addCollectionList(Community community, List<Collection> collectionList) throws SQLException
Internal method to process subcommunities recursively- Parameters:
community- communitycollectionList- list of collections- Throws:
SQLException- if database error
-
addCollection
public void addCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceAdd an exisiting collection to the community- Specified by:
addCollectionin interfaceCommunityService- Parameters:
context- contextcommunity- communitycollection- collection to add- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
createSubcommunity
public Community createSubcommunity(Context context, Community parentCommunity) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new sub-community within this community.- Specified by:
createSubcommunityin interfaceCommunityService- Parameters:
context- contextparentCommunity- parent community- Returns:
- the new community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
createSubcommunity
public Community createSubcommunity(Context context, Community parentCommunity, String handle) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new sub-community within this community.- Specified by:
createSubcommunityin interfaceCommunityService- Parameters:
context- contextparentCommunity- parent communityhandle- the pre-determined Handle to assign to the new community- Returns:
- the new community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
createSubcommunity
public Community createSubcommunity(Context context, Community parentCommunity, String handle, UUID uuid) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceCreate a new sub-community within this community.- Specified by:
createSubcommunityin interfaceCommunityService- Parameters:
context- contextparentCommunity- parent communityhandle- the pre-determined Handle to assign to the new communityuuid- the pre-determined UUID to assign to the new community- Returns:
- the new community
- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
addSubcommunity
public void addSubcommunity(Context context, Community parentCommunity, Community childCommunity) throws SQLException, AuthorizeException
Description copied from interface:CommunityServiceAdd an existing community as a subcommunity to the community- Specified by:
addSubcommunityin interfaceCommunityService- Parameters:
context- contextparentCommunity- parent community to add our subcommunity tochildCommunity- subcommunity to add- Throws:
SQLException- if database errorAuthorizeException- if authorization error
-
removeCollection
public void removeCollection(Context context, Community community, Collection collection) throws SQLException, AuthorizeException, IOException
Description copied from interface:CommunityServiceRemove a collection. If it only belongs to one parent community, then it is permanently deleted. If it has more than one parent community, it is simply unmapped from the current community.- Specified by:
removeCollectionin interfaceCommunityService- Parameters:
context- contextcommunity- communitycollection- collection to remove- Throws:
SQLException- if database errorAuthorizeException- if authorization errorIOException- if IO error
-
removeSubcommunity
public void removeSubcommunity(Context context, Community parentCommunity, Community childCommunity) throws SQLException, AuthorizeException, IOException
Description copied from interface:CommunityServiceRemove a subcommunity. If it only belongs to one parent community, then it is permanently deleted. If it has more than one parent community, it is simply unmapped from the current community.- Specified by:
removeSubcommunityin interfaceCommunityService- Parameters:
context- contextparentCommunity- parent communitychildCommunity- subcommunity to remove- Throws:
SQLException- if database errorAuthorizeException- if authorization errorIOException- if IO error
-
delete
public void delete(Context context, Community community) throws SQLException, AuthorizeException, IOException
- Specified by:
deletein interfaceDSpaceObjectService<Community>- Throws:
SQLExceptionAuthorizeExceptionIOException
-
getSupportsTypeConstant
public int getSupportsTypeConstant()
Description copied from interface:DSpaceObjectServiceReturns the Constants which this service supports- Specified by:
getSupportsTypeConstantin interfaceDSpaceObjectLegacySupportService<Community>- Specified by:
getSupportsTypeConstantin interfaceDSpaceObjectService<Community>- Returns:
- a org.dspace.core.Constants that represents a IndexableObject type
-
rawDelete
protected void rawDelete(Context context, Community community) throws SQLException, AuthorizeException, IOException
Internal method to remove the community and all its children from the database, and perform any pre/post-cleanup- Parameters:
context- contextcommunity- community- Throws:
SQLException- if database errorAuthorizeException- if authorization errorIOException- if IO error
-
canEditBoolean
public boolean canEditBoolean(Context context, Community community) throws SQLException
Description copied from interface:CommunityServicereturn TRUE if context's user can edit community, false otherwise- Specified by:
canEditBooleanin interfaceCommunityService- Parameters:
context- contextcommunity- community- Returns:
- boolean true = current user can edit community
- Throws:
SQLException- if database error
-
canEdit
public void canEdit(Context context, Community community) throws AuthorizeException, SQLException
- Specified by:
canEditin interfaceCommunityService- Throws:
AuthorizeExceptionSQLException
-
findByAdminGroup
public Community findByAdminGroup(Context context, Group group) throws SQLException
- Specified by:
findByAdminGroupin interfaceCommunityService- Throws:
SQLException
-
findAuthorized
public List<Community> findAuthorized(Context context, List<Integer> actions) throws SQLException
- Specified by:
findAuthorizedin interfaceCommunityService- Throws:
SQLException
-
findAuthorizedGroupMapped
public List<Community> findAuthorizedGroupMapped(Context context, List<Integer> actions) throws SQLException
- Specified by:
findAuthorizedGroupMappedin interfaceCommunityService- Throws:
SQLException
-
getAdminObject
public DSpaceObject getAdminObject(Context context, Community community, int action) throws SQLException
Description copied from interface:DSpaceObjectServiceReturn the dspace object where an ADMIN action right is sufficient to grant the initial authorize check.Default behaviour is ADMIN right on the object grant right on all other action on the object itself. Subclass should override this method as needed.
- Specified by:
getAdminObjectin interfaceDSpaceObjectService<Community>- Overrides:
getAdminObjectin classDSpaceObjectServiceImpl<Community>- Parameters:
context- DSpace contextcommunity- DSpaceObjectaction- ID of action being attempted, fromorg.dspace.core.Constants. The ADMIN action is not a valid parameter for this method, an IllegalArgumentException should be thrown- Returns:
- the dspace object, if any, where an ADMIN action is sufficient to grant the original action
- Throws:
SQLException- if database error
-
getParentObject
public DSpaceObject getParentObject(Context context, Community community) throws SQLException
Description copied from interface:DSpaceObjectServiceReturn the dspace object that "own" the current object in the hierarchy. Note that this method has a meaning slightly different from the getAdminObject because it is independent of the action but it is in a way related to it. It defines the "first" dspace object OTHER then the current one, where allowed ADMIN actions imply allowed ADMIN actions on the object self.- Specified by:
getParentObjectin interfaceDSpaceObjectService<Community>- Overrides:
getParentObjectin classDSpaceObjectServiceImpl<Community>- Parameters:
context- DSpace contextcommunity- DSpaceObject- Returns:
- the dspace object that "own" the current object in the hierarchy
- Throws:
SQLException- if database error
-
updateLastModified
public void updateLastModified(Context context, Community community)
- Specified by:
updateLastModifiedin interfaceDSpaceObjectService<Community>
-
findByIdOrLegacyId
public Community findByIdOrLegacyId(Context context, String id) throws SQLException
- Specified by:
findByIdOrLegacyIdin interfaceDSpaceObjectLegacySupportService<Community>- Throws:
SQLException
-
findByLegacyId
public Community findByLegacyId(Context context, int id) throws SQLException
Description copied from interface:DSpaceObjectLegacySupportServiceGeneric find for when the precise type of a DSO is not known, just the a pair of type number and database ID.- Specified by:
findByLegacyIdin interfaceDSpaceObjectLegacySupportService<Community>- Parameters:
context- - the contextid- - the legacy id within table of type'd objects- Returns:
- the object found, or null if it does not exist.
- Throws:
SQLException- only upon failure accessing the database.
-
countTotal
public int countTotal(Context context) throws SQLException
- Specified by:
countTotalin interfaceCommunityService- Throws:
SQLException
-
countArchivedItems
public int countArchivedItems(Community community) throws ItemCountException
Returns total community archived items- Specified by:
countArchivedItemsin interfaceCommunityService- Parameters:
community- Community- Returns:
- total community archived items
- Throws:
ItemCountException
-
-