mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-2701] oai Drop unused classes with DB code in them
This commit is contained in:
@@ -29,7 +29,6 @@ import org.dspace.xoai.services.api.solr.SolrServerResolver;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.dspace.xoai.services.api.xoai.IdentifyResolver;
|
||||
import org.dspace.xoai.services.api.xoai.ItemRepositoryResolver;
|
||||
import org.dspace.xoai.services.api.xoai.SetRepositoryResolver;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceEmptyCacheService;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceXOAICacheService;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceXOAIItemCacheService;
|
||||
@@ -43,7 +42,6 @@ import org.dspace.xoai.services.impl.solr.DSpaceSolrServerResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.BaseDSpaceFilterResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.DSpaceIdentifyResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.DSpaceItemRepositoryResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.DSpaceSetRepositoryResolver;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -117,10 +115,6 @@ public class BasicConfiguration {
|
||||
return new DSpaceItemRepositoryResolver();
|
||||
}
|
||||
@Bean
|
||||
public SetRepositoryResolver setRepositoryResolver () {
|
||||
return new DSpaceSetRepositoryResolver();
|
||||
}
|
||||
@Bean
|
||||
public IdentifyResolver identifyResolver () {
|
||||
return new DSpaceIdentifyResolver();
|
||||
}
|
||||
|
@@ -1,236 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ListSetsResult;
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.data.DSpaceSet;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CollectionService;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team <dspace@lyncode.com>
|
||||
*/
|
||||
public class DSpaceSetRepository implements SetRepository
|
||||
{
|
||||
private static final Logger log = LogManager.getLogger(DSpaceSetRepository.class);
|
||||
|
||||
private static final CommunityService communityService
|
||||
= ContentServiceFactory.getInstance().getCommunityService();
|
||||
|
||||
private static final CollectionService collectionService
|
||||
= ContentServiceFactory.getInstance().getCollectionService();
|
||||
|
||||
private static final HandleService handleService
|
||||
= HandleServiceFactory.getInstance().getHandleService();
|
||||
|
||||
private final Context _context;
|
||||
|
||||
public DSpaceSetRepository(Context context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
private int getCommunityCount()
|
||||
{
|
||||
String query = "SELECT COUNT(*) as count FROM community";
|
||||
try
|
||||
{
|
||||
TableRowIterator iterator = DatabaseManager.query(_context, query);
|
||||
if (iterator.hasNext())
|
||||
return (int) iterator.next().getLongColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getCollectionCount()
|
||||
{
|
||||
String query = "SELECT COUNT(*) as count FROM collection";
|
||||
try
|
||||
{
|
||||
TableRowIterator iterator = DatabaseManager.query(_context, query);
|
||||
if (iterator.hasNext())
|
||||
return (int) iterator.next().getLongColumn("count");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a list of DSpaceCommunitySet. The list is a segment of the full
|
||||
* list of Community ordered by ID.
|
||||
*
|
||||
* @param offset start this far down the list of Community.
|
||||
* @param length return up to this many Sets.
|
||||
* @return some Sets representing the Community list segment.
|
||||
*/
|
||||
private List<Set> community(int offset, int length)
|
||||
{
|
||||
List<Set> array = new ArrayList<>();
|
||||
StringBuffer query = new StringBuffer("SELECT community_id FROM community ORDER BY community_id");
|
||||
List<Serializable> params = new ArrayList<>();
|
||||
|
||||
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
||||
|
||||
try
|
||||
{
|
||||
TableRowIterator iterator = DatabaseManager.query(_context, query.toString(),
|
||||
params.toArray());
|
||||
int i = 0;
|
||||
while (iterator.hasNext() && i < length)
|
||||
{
|
||||
TableRow row = iterator.next();
|
||||
int communityID = row.getIntColumn("community_id");
|
||||
Community community = communityService.find(_context, communityID);
|
||||
array.add(DSpaceSet.newDSpaceCommunitySet(
|
||||
community.getHandle(), community.getName()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a list of DSpaceCollectionSet. The list is a segment of the full
|
||||
* list of Collection ordered by ID.
|
||||
*
|
||||
* @param offset start this far down the list of Collection.
|
||||
* @param length return up to this many Sets.
|
||||
* @return some Sets representing the Collection list segment.
|
||||
*/
|
||||
private List<Set> collection(int offset, int length)
|
||||
{
|
||||
List<Set> array = new ArrayList<>();
|
||||
StringBuffer query = new StringBuffer("SELECT collection_id FROM collection ORDER BY collection_id");
|
||||
List<Serializable> params = new ArrayList<>();
|
||||
|
||||
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
||||
|
||||
try
|
||||
{
|
||||
TableRowIterator iterator = DatabaseManager.query(_context, query.toString(),
|
||||
params.toArray());
|
||||
int i = 0;
|
||||
while (iterator.hasNext() && i < length)
|
||||
{
|
||||
TableRow row = iterator.next();
|
||||
int collectionID = row.getIntColumn("collection_id");
|
||||
Collection collection = collectionService.find(_context, collectionID);
|
||||
array.add(DSpaceSet.newDSpaceCollectionSet(
|
||||
collection.getHandle(),
|
||||
collection.getName()));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListSetsResult retrieveSets(int offset, int length)
|
||||
{
|
||||
// Only database sets (virtual sets are added by lyncode common library)
|
||||
log.debug("Querying sets. Offset: " + offset + " - Length: " + length);
|
||||
List<Set> array = new ArrayList<>();
|
||||
int communityCount = this.getCommunityCount();
|
||||
log.debug("Communities: " + communityCount);
|
||||
int collectionCount = this.getCollectionCount();
|
||||
log.debug("Collections: " + collectionCount);
|
||||
|
||||
if (offset < communityCount)
|
||||
{
|
||||
if (offset + length > communityCount)
|
||||
{
|
||||
// Add some collections
|
||||
List<Set> tmp = community(offset, length);
|
||||
array.addAll(tmp);
|
||||
array.addAll(collection(0, length - tmp.size()));
|
||||
}
|
||||
else
|
||||
array.addAll(community(offset, length));
|
||||
}
|
||||
else if (offset < communityCount + collectionCount)
|
||||
{
|
||||
array.addAll(collection(offset - communityCount, length));
|
||||
}
|
||||
log.debug("Has More Results: "
|
||||
+ ((offset + length < communityCount + collectionCount) ? "Yes"
|
||||
: "No"));
|
||||
return new ListSetsResult(offset + length < communityCount
|
||||
+ collectionCount, array, communityCount + collectionCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportSets()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String setSpec)
|
||||
{
|
||||
if (setSpec.startsWith("col_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||
setSpec.replace("col_", "").replace("_", "/"));
|
||||
return !(dso == null || !(dso instanceof Collection));
|
||||
}
|
||||
catch (IllegalStateException | SQLException ex)
|
||||
{
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
else if (setSpec.startsWith("com_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||
setSpec.replace("com_", "").replace("_", "/"));
|
||||
return !(dso == null || !(dso instanceof Community));
|
||||
}
|
||||
catch (IllegalStateException | SQLException ex)
|
||||
{
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.xoai.SetRepositoryResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class DSpaceSetRepositoryResolver implements SetRepositoryResolver {
|
||||
@Autowired
|
||||
private ContextService contextService;
|
||||
|
||||
@Override
|
||||
public SetRepository getSetRepository() throws ContextServiceException {
|
||||
return new DSpaceSetRepository(contextService.getContext());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user