mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 05:53:08 +00:00
[DS-2729] Ensure SiteService extends DSpaceObjectService
This commit is contained in:
@@ -268,6 +268,11 @@ public class BitstreamServiceImpl extends DSpaceObjectServiceImpl<Bitstream> imp
|
||||
update(context, bitstream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.BITSTREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream retrieve(Context context, Bitstream bitstream) throws IOException, SQLException, AuthorizeException {
|
||||
// Maybe should return AuthorizeException??
|
||||
|
@@ -439,6 +439,11 @@ public class BundleServiceImpl extends DSpaceObjectServiceImpl<Bundle> implement
|
||||
bundleDAO.delete(context, bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.BUNDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle findByIdOrLegacyId(Context context, String id) throws SQLException {
|
||||
if(StringUtils.isNumeric(id))
|
||||
|
@@ -729,6 +729,11 @@ public class CollectionServiceImpl extends DSpaceObjectServiceImpl<Collection> i
|
||||
collectionDAO.delete(context, collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.COLLECTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Collection> findAuthorized(Context context, Community community, int actionID) throws SQLException {
|
||||
List<Collection> myResults = new ArrayList<Collection>();
|
||||
|
@@ -466,6 +466,11 @@ public class CommunityServiceImpl extends DSpaceObjectServiceImpl<Community> imp
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.COMMUNITY;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal method to remove the community and all its children from the
|
||||
|
@@ -578,6 +578,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
|
||||
rawDelete(context, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.ITEM;
|
||||
}
|
||||
|
||||
protected void rawDelete(Context context, Item item) throws AuthorizeException, SQLException, IOException {
|
||||
authorizeService.authorizeAction(context, item, Constants.REMOVE);
|
||||
|
||||
|
@@ -7,14 +7,19 @@
|
||||
*/
|
||||
package org.dspace.content;
|
||||
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.dao.SiteDAO;
|
||||
import org.dspace.content.service.SiteService;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Service implementation for the Site object.
|
||||
@@ -23,7 +28,10 @@ import java.sql.SQLException;
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public class SiteServiceImpl implements SiteService {
|
||||
public class SiteServiceImpl extends DSpaceObjectServiceImpl<Site> implements SiteService {
|
||||
|
||||
@Autowired(required = true)
|
||||
protected AuthorizeService authorizeService;
|
||||
|
||||
@Autowired(required = true)
|
||||
protected HandleService handleService;
|
||||
@@ -50,4 +58,33 @@ public class SiteServiceImpl implements SiteService {
|
||||
public Site findSite(Context context) throws SQLException {
|
||||
return siteDAO.findSite(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Site find(Context context, UUID id) throws SQLException {
|
||||
return siteDAO.findByID(context, Site.class, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLastModified(Context context, Site dso) throws SQLException, AuthorizeException {
|
||||
//Not used at the moment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Context context, Site dso) throws SQLException, AuthorizeException {
|
||||
if(!authorizeService.isAdmin(context)){
|
||||
throw new AuthorizeException();
|
||||
}
|
||||
siteDAO.save(context, dso);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Context context, Site dso) throws SQLException, AuthorizeException, IOException {
|
||||
throw new AuthorizeException("Site object cannot be deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.SITE;
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ import java.sql.SQLException;
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public interface SiteDAO extends GenericDAO<Site> {
|
||||
public interface SiteDAO extends DSpaceObjectDAO<Site> {
|
||||
|
||||
public Site findSite(Context context) throws SQLException;
|
||||
}
|
||||
|
@@ -16,6 +16,8 @@ import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||
import org.dspace.utils.DSpace;
|
||||
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Abstract factory to get services for the content package, use ContentServiceFactory.getInstance() to retrieve an implementation
|
||||
*
|
||||
@@ -23,6 +25,10 @@ import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||
*/
|
||||
public abstract class ContentServiceFactory {
|
||||
|
||||
public abstract List<DSpaceObjectService<? extends DSpaceObject>> getDSpaceObjectServices();
|
||||
|
||||
public abstract List<DSpaceObjectLegacySupportService<? extends DSpaceObject>> getDSpaceObjectLegacySupportServices();
|
||||
|
||||
public abstract BitstreamFormatService getBitstreamFormatService();
|
||||
|
||||
public abstract BitstreamService getBitstreamService();
|
||||
@@ -71,48 +77,27 @@ public abstract class ContentServiceFactory {
|
||||
|
||||
public DSpaceObjectService getDSpaceObjectService(int type)
|
||||
{
|
||||
switch (type)
|
||||
for (int i = 0; i < getDSpaceObjectServices().size(); i++) {
|
||||
DSpaceObjectService objectService = getDSpaceObjectServices().get(i);
|
||||
if(objectService.getSupportsTypeConstant() == type)
|
||||
{
|
||||
case Constants.BITSTREAM:
|
||||
return getBitstreamService();
|
||||
case Constants.BUNDLE:
|
||||
return getBundleService();
|
||||
case Constants.ITEM:
|
||||
return getItemService();
|
||||
case Constants.COLLECTION:
|
||||
return getCollectionService();
|
||||
case Constants.COMMUNITY:
|
||||
return getCommunityService();
|
||||
case Constants.GROUP:
|
||||
return EPersonServiceFactory.getInstance().getGroupService();
|
||||
case Constants.EPERSON:
|
||||
return EPersonServiceFactory.getInstance().getEPersonService();
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
return objectService;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException("Unknown DSpace type: " + type);
|
||||
}
|
||||
|
||||
public DSpaceObjectLegacySupportService<? extends DSpaceObject> getDSpaceLegacyObjectService(int type)
|
||||
{
|
||||
switch (type)
|
||||
for (int i = 0; i < getDSpaceObjectLegacySupportServices().size(); i++) {
|
||||
DSpaceObjectLegacySupportService<? extends DSpaceObject> objectLegacySupportService = getDSpaceObjectLegacySupportServices().get(i);
|
||||
if(objectLegacySupportService.getSupportsTypeConstant() == type)
|
||||
{
|
||||
case Constants.BITSTREAM:
|
||||
return getBitstreamService();
|
||||
case Constants.BUNDLE:
|
||||
return getBundleService();
|
||||
case Constants.ITEM:
|
||||
return getItemService();
|
||||
case Constants.COLLECTION:
|
||||
return getCollectionService();
|
||||
case Constants.COMMUNITY:
|
||||
return getCommunityService();
|
||||
case Constants.GROUP:
|
||||
return EPersonServiceFactory.getInstance().getGroupService();
|
||||
case Constants.EPERSON:
|
||||
return EPersonServiceFactory.getInstance().getEPersonService();
|
||||
default:
|
||||
throw new UnsupportedOperationException();
|
||||
return objectLegacySupportService;
|
||||
}
|
||||
|
||||
}
|
||||
throw new UnsupportedOperationException("Unknown DSpace type: " + type);
|
||||
}
|
||||
|
||||
public static ContentServiceFactory getInstance(){
|
||||
|
@@ -7,9 +7,12 @@
|
||||
*/
|
||||
package org.dspace.content.factory;
|
||||
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Factory implementation to get services for the content package, use ContentServiceFactory.getInstance() to retrieve an implementation
|
||||
*
|
||||
@@ -17,6 +20,12 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
*/
|
||||
public class ContentServiceFactoryImpl extends ContentServiceFactory {
|
||||
|
||||
|
||||
@Autowired(required = true)
|
||||
private List<DSpaceObjectService<? extends DSpaceObject>> dSpaceObjectServices;
|
||||
@Autowired(required = true)
|
||||
private List<DSpaceObjectLegacySupportService<? extends DSpaceObject>> dSpaceObjectLegacySupportServices;
|
||||
|
||||
@Autowired(required = true)
|
||||
private BitstreamFormatService bitstreamFormatService;
|
||||
@Autowired(required = true)
|
||||
@@ -45,6 +54,16 @@ public class ContentServiceFactoryImpl extends ContentServiceFactory {
|
||||
private SiteService siteService;
|
||||
|
||||
|
||||
@Override
|
||||
public List<DSpaceObjectService<? extends DSpaceObject>> getDSpaceObjectServices() {
|
||||
return dSpaceObjectServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DSpaceObjectLegacySupportService<? extends DSpaceObject>> getDSpaceObjectLegacySupportServices() {
|
||||
return dSpaceObjectLegacySupportServices;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BitstreamFormatService getBitstreamFormatService()
|
||||
{
|
||||
|
@@ -33,4 +33,11 @@ public interface DSpaceObjectLegacySupportService<T extends DSpaceObject> {
|
||||
* @throws java.sql.SQLException only upon failure accessing the database.
|
||||
*/
|
||||
public T findByLegacyId(Context context, int id) throws SQLException;
|
||||
|
||||
/**
|
||||
* Returns the Constants which this service supports
|
||||
*
|
||||
* @return a org.dspace.core.Constants that represents a DSpaceObjct type
|
||||
*/
|
||||
public int getSupportsTypeConstant();
|
||||
}
|
||||
|
@@ -337,4 +337,13 @@ public interface DSpaceObjectService<T extends DSpaceObject> {
|
||||
public void update(Context context, T dso) throws SQLException, AuthorizeException;
|
||||
|
||||
public void delete(Context context, T dso) throws SQLException, AuthorizeException, IOException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Constants which this service supports
|
||||
*
|
||||
* @return a org.dspace.core.Constants that represents a DSpaceObjct type
|
||||
*/
|
||||
public int getSupportsTypeConstant();
|
||||
|
||||
}
|
||||
|
@@ -18,7 +18,8 @@ import java.sql.SQLException;
|
||||
*
|
||||
* @author kevinvandevelde at atmire.com
|
||||
*/
|
||||
public interface SiteService {
|
||||
public interface SiteService extends DSpaceObjectService<Site>
|
||||
{
|
||||
|
||||
public Site createSite(Context context) throws SQLException;
|
||||
|
||||
|
@@ -224,6 +224,11 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
||||
"eperson_id=" + ePerson.getID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.EPERSON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPassword(EPerson ePerson, String password) {
|
||||
PasswordHash hash = new PasswordHash(password);
|
||||
|
@@ -323,6 +323,11 @@ public class GroupServiceImpl extends DSpaceObjectServiceImpl<Group> implements
|
||||
+ group.getID()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSupportsTypeConstant() {
|
||||
return Constants.GROUP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if group has no direct or indirect members
|
||||
*/
|
||||
|
Reference in New Issue
Block a user