mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
[DS-2701] dspace-oai 'the simple bits'
This commit is contained in:
@@ -23,14 +23,11 @@ import org.apache.solr.client.solrj.SolrServer;
|
|||||||
import org.apache.solr.client.solrj.SolrServerException;
|
import org.apache.solr.client.solrj.SolrServerException;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.authorize.AuthorizeServiceImpl;
|
|
||||||
import org.dspace.content.*;
|
import org.dspace.content.*;
|
||||||
import org.dspace.core.ConfigurationManager;
|
import org.dspace.core.ConfigurationManager;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
|
||||||
import org.dspace.storage.rdbms.TableRowIterator;
|
|
||||||
import org.dspace.xoai.exceptions.CompilingException;
|
import org.dspace.xoai.exceptions.CompilingException;
|
||||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||||
import org.dspace.xoai.services.api.cache.XOAIItemCacheService;
|
import org.dspace.xoai.services.api.cache.XOAIItemCacheService;
|
||||||
@@ -55,10 +52,12 @@ import java.text.ParseException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import org.dspace.content.service.ItemService;
|
||||||
|
|
||||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||||
import static org.dspace.content.Item.find;
|
|
||||||
import static org.dspace.xoai.util.ItemUtils.retrieveMetadata;
|
import static org.dspace.xoai.util.ItemUtils.retrieveMetadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,9 +67,9 @@ import static org.dspace.xoai.util.ItemUtils.retrieveMetadata;
|
|||||||
public class XOAI {
|
public class XOAI {
|
||||||
private static Logger log = LogManager.getLogger(XOAI.class);
|
private static Logger log = LogManager.getLogger(XOAI.class);
|
||||||
|
|
||||||
private Context context;
|
private final Context context;
|
||||||
private boolean optimize;
|
private boolean optimize;
|
||||||
private boolean verbose;
|
private final boolean verbose;
|
||||||
private boolean clean;
|
private boolean clean;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -87,15 +86,19 @@ public class XOAI {
|
|||||||
private XOAIItemCacheService xoaiItemCacheService;
|
private XOAIItemCacheService xoaiItemCacheService;
|
||||||
@Autowired
|
@Autowired
|
||||||
private CollectionsService collectionsService;
|
private CollectionsService collectionsService;
|
||||||
|
@Inject
|
||||||
|
private AuthorizeService authorizeService;
|
||||||
|
@Inject
|
||||||
|
private ItemService itemService;
|
||||||
|
|
||||||
|
|
||||||
private static List<String> getFileFormats(Item item) {
|
private List<String> getFileFormats(Item item) {
|
||||||
List<String> formats = new ArrayList<String>();
|
List<String> formats = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
for (Bundle b : item.getBundles("ORIGINAL")) {
|
for (Bundle b : itemService.getBundles(item, "ORIGINAL")) {
|
||||||
for (Bitstream bs : b.getBitstreams()) {
|
for (BundleBitstream bs : b.getBitstreams()) {
|
||||||
if (!formats.contains(bs.getFormat().getMIMEType())) {
|
if (!formats.contains(bs.getBitstream().getFormat(context).getMIMEType())) {
|
||||||
formats.add(bs.getFormat().getMIMEType());
|
formats.add(bs.getBitstream().getFormat(context).getMIMEType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,11 +157,7 @@ public class XOAI {
|
|||||||
// Set last compilation date
|
// Set last compilation date
|
||||||
xoaiLastCompilationCacheService.put(new Date());
|
xoaiLastCompilationCacheService.put(new Date());
|
||||||
return result;
|
return result;
|
||||||
} catch (DSpaceSolrException ex) {
|
} catch (DSpaceSolrException | SolrServerException | IOException ex) {
|
||||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
|
||||||
} catch (SolrServerException ex) {
|
|
||||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,17 +256,20 @@ public class XOAI {
|
|||||||
doc.addField("item.communities",
|
doc.addField("item.communities",
|
||||||
"com_" + com.getHandle().replace("/", "_"));
|
"com_" + com.getHandle().replace("/", "_"));
|
||||||
|
|
||||||
Metadatum[] allData = item.getMetadata(Item.ANY, Item.ANY, Item.ANY,
|
List<MetadataValue> allData = itemService.getMetadata(item,
|
||||||
Item.ANY);
|
Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||||
for (Metadatum dc : allData) {
|
for (MetadataValue dc : allData) {
|
||||||
String key = "metadata." + dc.schema + "." + dc.element;
|
MetadataField field = dc.getMetadataField();
|
||||||
if (dc.qualifier != null) {
|
String key = "metadata."
|
||||||
key += "." + dc.qualifier;
|
+ field.getMetadataSchema().getName() + "."
|
||||||
|
+ field.getElement();
|
||||||
|
if (field.getQualifier() != null) {
|
||||||
|
key += "." + field.getQualifier();
|
||||||
}
|
}
|
||||||
doc.addField(key, dc.value);
|
doc.addField(key, dc.getValue());
|
||||||
if (dc.authority != null) {
|
if (dc.getAuthority() != null) {
|
||||||
doc.addField(key + ".authority", dc.authority);
|
doc.addField(key + ".authority", dc.getAuthority());
|
||||||
doc.addField(key + ".confidence", dc.confidence + "");
|
doc.addField(key + ".confidence", dc.getConfidence() + "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,10 +278,10 @@ public class XOAI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
XmlOutputContext context = XmlOutputContext.emptyContext(out, Second);
|
XmlOutputContext xmlContext = XmlOutputContext.emptyContext(out, Second);
|
||||||
retrieveMetadata(item).write(context);
|
retrieveMetadata(item).write(xmlContext);
|
||||||
context.getWriter().flush();
|
xmlContext.getWriter().flush();
|
||||||
context.getWriter().close();
|
xmlContext.getWriter().close();
|
||||||
doc.addField("item.compile", out.toString());
|
doc.addField("item.compile", out.toString());
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
@@ -294,7 +296,7 @@ public class XOAI {
|
|||||||
boolean pub = false;
|
boolean pub = false;
|
||||||
try {
|
try {
|
||||||
//Check if READ access allowed on this Item
|
//Check if READ access allowed on this Item
|
||||||
pub = AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ);
|
pub = authorizeService.authorizeActionBoolean(context, item, Constants.READ);
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
log.error(ex.getMessage());
|
log.error(ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -327,9 +329,7 @@ public class XOAI {
|
|||||||
solrServerResolver.getServer().deleteByQuery("*:*");
|
solrServerResolver.getServer().deleteByQuery("*:*");
|
||||||
solrServerResolver.getServer().commit();
|
solrServerResolver.getServer().commit();
|
||||||
System.out.println("Index cleared");
|
System.out.println("Index cleared");
|
||||||
} catch (SolrServerException ex) {
|
} catch (SolrServerException | IOException ex) {
|
||||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,13 +449,13 @@ public class XOAI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void compile() throws CompilingException {
|
private void compile() throws CompilingException {
|
||||||
ItemIterator iterator;
|
Iterator<Item> iterator;
|
||||||
try {
|
try {
|
||||||
Date last = xoaiLastCompilationCacheService.get();
|
Date last = xoaiLastCompilationCacheService.get();
|
||||||
|
|
||||||
if (last == null) {
|
if (last == null) {
|
||||||
System.out.println("Retrieving all items to be compiled");
|
System.out.println("Retrieving all items to be compiled");
|
||||||
iterator = Item.findAll(context);
|
iterator = itemService.findAll(context);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("Retrieving items modified after " + last + " to be compiled");
|
System.out.println("Retrieving items modified after " + last + " to be compiled");
|
||||||
String query = "SELECT * FROM item WHERE last_modified>?";
|
String query = "SELECT * FROM item WHERE last_modified>?";
|
||||||
@@ -466,13 +466,10 @@ public class XOAI {
|
|||||||
Item item = iterator.next();
|
Item item = iterator.next();
|
||||||
if (verbose) System.out.println("Compiling item with handle: " + item.getHandle());
|
if (verbose) System.out.println("Compiling item with handle: " + item.getHandle());
|
||||||
xoaiItemCacheService.put(item, retrieveMetadata(item));
|
xoaiItemCacheService.put(item, retrieveMetadata(item));
|
||||||
context.clearCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
xoaiLastCompilationCacheService.put(new Date());
|
xoaiLastCompilationCacheService.put(new Date());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | IOException e) {
|
||||||
throw new CompilingException(e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new CompilingException(e);
|
throw new CompilingException(e);
|
||||||
}
|
}
|
||||||
System.out.println("Items compiled");
|
System.out.println("Items compiled");
|
||||||
|
@@ -14,11 +14,13 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeManager;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
|
import org.dspace.authorize.service.AuthorizeService;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.handle.HandleServiceImpl;
|
import org.dspace.handle.factory.HandleServiceFactory;
|
||||||
|
import org.dspace.handle.service.HandleService;
|
||||||
import org.dspace.xoai.data.DSpaceItem;
|
import org.dspace.xoai.data.DSpaceItem;
|
||||||
import org.dspace.xoai.filter.results.DatabaseFilterResult;
|
import org.dspace.xoai.filter.results.DatabaseFilterResult;
|
||||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||||
@@ -29,12 +31,18 @@ import org.dspace.xoai.filter.results.SolrFilterResult;
|
|||||||
*/
|
*/
|
||||||
public class DSpaceAuthorizationFilter extends DSpaceFilter
|
public class DSpaceAuthorizationFilter extends DSpaceFilter
|
||||||
{
|
{
|
||||||
private static Logger log = LogManager.getLogger(DSpaceAuthorizationFilter.class);
|
private static final Logger log = LogManager.getLogger(DSpaceAuthorizationFilter.class);
|
||||||
|
|
||||||
|
private static final AuthorizeService authorizeService
|
||||||
|
= AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||||
|
|
||||||
|
private static final HandleService handleService
|
||||||
|
= HandleServiceFactory.getInstance().getHandleService();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseFilterResult buildDatabaseQuery(Context context)
|
public DatabaseFilterResult buildDatabaseQuery(Context context)
|
||||||
{
|
{
|
||||||
List<Object> params = new ArrayList<Object>();
|
List<Object> params = new ArrayList<>();
|
||||||
return new DatabaseFilterResult("EXISTS (SELECT p.action_id FROM "
|
return new DatabaseFilterResult("EXISTS (SELECT p.action_id FROM "
|
||||||
+ "resourcepolicy p, " + "bundle2bitstream b, " + "bundle bu, "
|
+ "resourcepolicy p, " + "bundle2bitstream b, " + "bundle bu, "
|
||||||
+ "item2bundle ib " + "WHERE " + "p.resource_type_id=0 AND "
|
+ "item2bundle ib " + "WHERE " + "p.resource_type_id=0 AND "
|
||||||
@@ -54,12 +62,12 @@ public class DSpaceAuthorizationFilter extends DSpaceFilter
|
|||||||
String handle = DSpaceItem.parseHandle(item.getIdentifier());
|
String handle = DSpaceItem.parseHandle(item.getIdentifier());
|
||||||
if (handle == null)
|
if (handle == null)
|
||||||
return false;
|
return false;
|
||||||
Item dspaceItem = (Item) HandleManager.resolveToObject(context, handle);
|
Item dspaceItem = (Item) handleService.resolveToObject(context, handle);
|
||||||
if (dspaceItem == null)
|
if (dspaceItem == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check if READ access allowed on Item
|
// Check if READ access allowed on Item
|
||||||
pub = AuthorizeManager.authorizeActionBoolean(context, dspaceItem, Constants.READ);
|
pub = authorizeService.authorizeActionBoolean(context, dspaceItem, Constants.READ);
|
||||||
}
|
}
|
||||||
catch (SQLException ex)
|
catch (SQLException ex)
|
||||||
{
|
{
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
package org.dspace.xoai.filter;
|
package org.dspace.xoai.filter;
|
||||||
|
|
||||||
import com.lyncode.xoai.dataprovider.core.ReferenceSet;
|
import com.lyncode.xoai.dataprovider.core.ReferenceSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@@ -21,6 +22,8 @@ import org.dspace.xoai.services.api.database.CollectionsService;
|
|||||||
import org.dspace.xoai.services.api.database.HandleResolver;
|
import org.dspace.xoai.services.api.database.HandleResolver;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.dspace.xoai.services.api.database.HandleResolverException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -28,11 +31,11 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class DSpaceSetSpecFilter extends DSpaceFilter
|
public class DSpaceSetSpecFilter extends DSpaceFilter
|
||||||
{
|
{
|
||||||
private static Logger log = LogManager.getLogger(DSpaceSetSpecFilter.class);
|
private static final Logger log = LogManager.getLogger(DSpaceSetSpecFilter.class);
|
||||||
|
|
||||||
private String setSpec;
|
private final String setSpec;
|
||||||
private HandleResolver handleResolver;
|
private final HandleResolver handleResolver;
|
||||||
private CollectionsService collectionsService;
|
private final CollectionsService collectionsService;
|
||||||
|
|
||||||
public DSpaceSetSpecFilter(CollectionsService collectionsService, HandleResolver handleResolver, String spec)
|
public DSpaceSetSpecFilter(CollectionsService collectionsService, HandleResolver handleResolver, String spec)
|
||||||
{
|
{
|
||||||
@@ -66,14 +69,14 @@ public class DSpaceSetSpecFilter extends DSpaceFilter
|
|||||||
{
|
{
|
||||||
DSpaceObject dso = handleResolver.resolve(setSpec.replace("com_", "").replace("_", "/"));
|
DSpaceObject dso = handleResolver.resolve(setSpec.replace("com_", "").replace("_", "/"));
|
||||||
if(dso != null){
|
if(dso != null){
|
||||||
List<Integer> list = collectionsService.getAllSubCollections(dso.getID());
|
List<UUID> list = collectionsService.getAllSubCollections(dso.getID());
|
||||||
String subCollections = StringUtils.join(list.iterator(), ",");
|
String subCollections = StringUtils.join(list.iterator(), ",");
|
||||||
return new DatabaseFilterResult(
|
return new DatabaseFilterResult(
|
||||||
"EXISTS (SELECT tmp.* FROM collection2item tmp WHERE tmp.resource_id=i.item_id AND collection_id IN ("
|
"EXISTS (SELECT tmp.* FROM collection2item tmp WHERE tmp.resource_id=i.item_id AND collection_id IN ("
|
||||||
+ subCollections + "))");
|
+ subCollections + "))");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (HandleResolverException | SQLException e)
|
||||||
{
|
{
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,7 @@ public class DSpaceWithdrawnFilter extends DSpaceFilter {
|
|||||||
@Override
|
@Override
|
||||||
public DatabaseFilterResult buildDatabaseQuery(Context context)
|
public DatabaseFilterResult buildDatabaseQuery(Context context)
|
||||||
{
|
{
|
||||||
List<Object> params = new ArrayList<Object>();
|
List<Object> params = new ArrayList<>();
|
||||||
|
|
||||||
String filter = "i.withdrawn=TRUE";
|
String filter = "i.withdrawn=TRUE";
|
||||||
if(DatabaseManager.isOracle())
|
if(DatabaseManager.isOracle())
|
||||||
@@ -48,10 +48,7 @@ public class DSpaceWithdrawnFilter extends DSpaceFilter {
|
|||||||
// we can properly respond with a "deleted" status via OAI-PMH.
|
// we can properly respond with a "deleted" status via OAI-PMH.
|
||||||
// Don't worry, this does NOT make the metadata public for withdrawn items,
|
// Don't worry, this does NOT make the metadata public for withdrawn items,
|
||||||
// it merely provides an item "tombstone" via OAI-PMH.
|
// it merely provides an item "tombstone" via OAI-PMH.
|
||||||
if (item.isDeleted())
|
return item.isDeleted();
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -13,9 +13,10 @@ import org.dspace.content.Item;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface CollectionsService {
|
public interface CollectionsService {
|
||||||
List<Integer> getAllSubCollections(int communityId) throws SQLException;
|
List<UUID> getAllSubCollections(UUID communityId) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Collection collection) throws SQLException;
|
List<Community> flatParentCommunities(Collection collection) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Community community) throws SQLException;
|
List<Community> flatParentCommunities(Community community) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Item item) throws SQLException;
|
List<Community> flatParentCommunities(Item item) throws SQLException;
|
||||||
|
@@ -16,11 +16,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DatabaseQuery {
|
public class DatabaseQuery {
|
||||||
private static Logger log = Logger.getLogger(DatabaseQuery.class);
|
private static final Logger log = Logger.getLogger(DatabaseQuery.class);
|
||||||
|
|
||||||
private String query;
|
private String query;
|
||||||
private List<Object> parameters;
|
private final List<Object> parameters;
|
||||||
private Context context;
|
private final Context context;
|
||||||
private Integer total;
|
private Integer total;
|
||||||
|
|
||||||
private String countQuery;
|
private String countQuery;
|
||||||
@@ -28,7 +28,7 @@ public class DatabaseQuery {
|
|||||||
|
|
||||||
public DatabaseQuery(Context context) {
|
public DatabaseQuery(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.parameters = new ArrayList<Object>();
|
this.parameters = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQuery() {
|
public String getQuery() {
|
||||||
|
@@ -14,7 +14,6 @@ import org.springframework.web.context.request.RequestContextHolder;
|
|||||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DSpaceContextService implements ContextService {
|
public class DSpaceContextService implements ContextService {
|
||||||
private static final String OAI_CONTEXT = "OAI_CONTEXT";
|
private static final String OAI_CONTEXT = "OAI_CONTEXT";
|
||||||
@@ -24,11 +23,7 @@ public class DSpaceContextService implements ContextService {
|
|||||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||||
Object value = request.getAttribute(OAI_CONTEXT);
|
Object value = request.getAttribute(OAI_CONTEXT);
|
||||||
if (value == null || !(value instanceof Context)) {
|
if (value == null || !(value instanceof Context)) {
|
||||||
try {
|
request.setAttribute(OAI_CONTEXT, new Context());
|
||||||
request.setAttribute(OAI_CONTEXT, new Context());
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new ContextServiceException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (Context) request.getAttribute(OAI_CONTEXT);
|
return (Context) request.getAttribute(OAI_CONTEXT);
|
||||||
}
|
}
|
||||||
|
@@ -19,18 +19,24 @@ import java.util.ArrayList;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.CommunityService;
|
||||||
|
|
||||||
public class DSpaceCollectionsService implements CollectionsService {
|
public class DSpaceCollectionsService implements CollectionsService {
|
||||||
|
|
||||||
private ContextService contextService;
|
private ContextService contextService;
|
||||||
|
private static final CommunityService communityService
|
||||||
|
= ContentServiceFactory.getInstance().getCommunityService();
|
||||||
|
|
||||||
public List<Integer> getAllSubCollections(int communityId)
|
@Override
|
||||||
|
public List<UUID> getAllSubCollections(UUID communityId)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
Queue<Community> comqueue = new LinkedList<Community>();
|
Queue<Community> comqueue = new LinkedList<>();
|
||||||
List<Integer> list = new ArrayList<Integer>();
|
List<UUID> list = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
comqueue.add(Community.find(contextService.getContext(), communityId));
|
comqueue.add(communityService.find(contextService.getContext(), communityId));
|
||||||
} catch (ContextServiceException e) {
|
} catch (ContextServiceException e) {
|
||||||
throw new SQLException(e);
|
throw new SQLException(e);
|
||||||
}
|
}
|
||||||
@@ -40,26 +46,27 @@ public class DSpaceCollectionsService implements CollectionsService {
|
|||||||
for (Community sub : c.getSubcommunities())
|
for (Community sub : c.getSubcommunities())
|
||||||
comqueue.add(sub);
|
comqueue.add(sub);
|
||||||
for (Collection col : c.getCollections())
|
for (Collection col : c.getCollections())
|
||||||
if (!list.contains(col))
|
if (!list.contains(col.getID()))
|
||||||
list.add(col.getID());
|
list.add(col.getID());
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<Community> flatParentCommunities(Collection c)
|
public List<Community> flatParentCommunities(Collection c)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
Queue<Community> queue = new LinkedList<Community>();
|
Queue<Community> queue = new LinkedList<>();
|
||||||
List<Community> result = new ArrayList<Community>();
|
List<Community> result = new ArrayList<>();
|
||||||
for (Community com : c.getCommunities())
|
for (Community com : c.getCommunities())
|
||||||
queue.add(com);
|
queue.add(com);
|
||||||
|
|
||||||
while (!queue.isEmpty())
|
while (!queue.isEmpty())
|
||||||
{
|
{
|
||||||
Community p = queue.poll();
|
Community p = queue.poll();
|
||||||
Community par = p.getParentCommunity();
|
List<Community> par = p.getParentCommunities();
|
||||||
if (par != null)
|
if (par != null)
|
||||||
queue.add(par);
|
queue.addAll(par);
|
||||||
if (!result.contains(p))
|
if (!result.contains(p))
|
||||||
result.add(p);
|
result.add(p);
|
||||||
}
|
}
|
||||||
@@ -67,20 +74,21 @@ public class DSpaceCollectionsService implements CollectionsService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<Community> flatParentCommunities(Community c)
|
public List<Community> flatParentCommunities(Community c)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
Queue<Community> queue = new LinkedList<Community>();
|
Queue<Community> queue = new LinkedList<>();
|
||||||
List<Community> result = new ArrayList<Community>();
|
List<Community> result = new ArrayList<>();
|
||||||
|
|
||||||
queue.add(c);
|
queue.add(c);
|
||||||
|
|
||||||
while (!queue.isEmpty())
|
while (!queue.isEmpty())
|
||||||
{
|
{
|
||||||
Community p = queue.poll();
|
Community p = queue.poll();
|
||||||
Community par = p.getParentCommunity();
|
List<Community> par = p.getParentCommunities();
|
||||||
if (par != null)
|
if (par != null)
|
||||||
queue.add(par);
|
queue.addAll(par);
|
||||||
if (!result.contains(p))
|
if (!result.contains(p))
|
||||||
result.add(p);
|
result.add(p);
|
||||||
}
|
}
|
||||||
@@ -88,21 +96,22 @@ public class DSpaceCollectionsService implements CollectionsService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<Community> flatParentCommunities(Item c)
|
public List<Community> flatParentCommunities(Item c)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
Queue<Community> queue = new LinkedList<Community>();
|
Queue<Community> queue = new LinkedList<>();
|
||||||
List<Community> result = new ArrayList<Community>();
|
List<Community> result = new ArrayList<>();
|
||||||
|
|
||||||
for (Community com : c.getCommunities())
|
for (Collection com : c.getCollections())
|
||||||
queue.add(com);
|
queue.addAll(com.getCommunities());
|
||||||
|
|
||||||
while (!queue.isEmpty())
|
while (!queue.isEmpty())
|
||||||
{
|
{
|
||||||
Community p = queue.poll();
|
Community p = queue.poll();
|
||||||
Community par = p.getParentCommunity();
|
List<Community> par = p.getParentCommunities();
|
||||||
if (par != null)
|
if (par != null)
|
||||||
queue.add(par);
|
queue.addAll(par);
|
||||||
if (!result.contains(p))
|
if (!result.contains(p))
|
||||||
result.add(p);
|
result.add(p);
|
||||||
}
|
}
|
||||||
|
@@ -39,8 +39,8 @@ public class DSpaceDatabaseQueryResolver implements DatabaseQueryResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseQuery buildQuery(List<ScopedFilter> filters, int offset, int length) throws DatabaseQueryException {
|
public DatabaseQuery buildQuery(List<ScopedFilter> filters, int offset, int length) throws DatabaseQueryException {
|
||||||
List<Object> parameters = new ArrayList<Object>();
|
List<Object> parameters = new ArrayList<>();
|
||||||
List<Object> countParameters = new ArrayList<Object>();
|
List<Object> countParameters = new ArrayList<>();
|
||||||
String query = "SELECT i.* FROM item i ";
|
String query = "SELECT i.* FROM item i ";
|
||||||
String countQuery = "SELECT COUNT(*) as count FROM item i";
|
String countQuery = "SELECT COUNT(*) as count FROM item i";
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ public class DSpaceDatabaseQueryResolver implements DatabaseQueryResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String buildCondition (List<ScopedFilter> filters, List<Object> parameters) throws ContextServiceException {
|
private String buildCondition (List<ScopedFilter> filters, List<Object> parameters) throws ContextServiceException {
|
||||||
List<String> whereCond = new ArrayList<String>();
|
List<String> whereCond = new ArrayList<>();
|
||||||
for (ScopedFilter filter : filters)
|
for (ScopedFilter filter : filters)
|
||||||
whereCond.add(this.buildQuery(filter.getCondition(), filter.getScope(), parameters));
|
whereCond.add(this.buildQuery(filter.getCondition(), filter.getScope(), parameters));
|
||||||
|
|
||||||
|
@@ -7,28 +7,27 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.xoai.services.impl.database;
|
package org.dspace.xoai.services.impl.database;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import javax.inject.Inject;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.handle.HandleServiceImpl;
|
import org.dspace.handle.service.HandleService;
|
||||||
import org.dspace.xoai.services.api.context.ContextService;
|
import org.dspace.xoai.services.api.context.ContextService;
|
||||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||||
import org.dspace.xoai.services.api.database.HandleResolver;
|
import org.dspace.xoai.services.api.database.HandleResolver;
|
||||||
import org.dspace.xoai.services.api.database.HandleResolverException;
|
import org.dspace.xoai.services.api.database.HandleResolverException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
public class DSpaceHandlerResolver implements HandleResolver {
|
public class DSpaceHandlerResolver implements HandleResolver {
|
||||||
@Autowired
|
@Inject
|
||||||
private ContextService contextService;
|
private ContextService contextService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private HandleService handleService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DSpaceObject resolve(String handle) throws HandleResolverException {
|
public DSpaceObject resolve(String handle) throws HandleResolverException {
|
||||||
try {
|
try {
|
||||||
return HandleServiceImpl.resolveToObject(contextService.getContext(), handle);
|
return handleService.resolveToObject(contextService.getContext(), handle);
|
||||||
} catch (ContextServiceException e) {
|
} catch (ContextServiceException | SQLException e) {
|
||||||
throw new HandleResolverException(e);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
throw new HandleResolverException(e);
|
throw new HandleResolverException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,10 +35,8 @@ public class DSpaceHandlerResolver implements HandleResolver {
|
|||||||
@Override
|
@Override
|
||||||
public String getHandle(DSpaceObject object) throws HandleResolverException {
|
public String getHandle(DSpaceObject object) throws HandleResolverException {
|
||||||
try {
|
try {
|
||||||
return HandleServiceImpl.findHandle(contextService.getContext(), object);
|
return handleService.findHandle(contextService.getContext(), object);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | ContextServiceException e) {
|
||||||
throw new HandleResolverException(e);
|
|
||||||
} catch (ContextServiceException e) {
|
|
||||||
throw new HandleResolverException(e);
|
throw new HandleResolverException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,6 +39,8 @@ import java.sql.SQLException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import org.dspace.handle.factory.HandleServiceFactory;
|
||||||
|
import org.dspace.handle.service.HandleService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -48,7 +50,10 @@ import java.util.regex.Pattern;
|
|||||||
public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
private static Logger log = LogManager.getLogger(DSpaceItemDatabaseRepository.class);
|
private static final Logger log = LogManager.getLogger(DSpaceItemDatabaseRepository.class);
|
||||||
|
|
||||||
|
private static final HandleService handleService
|
||||||
|
= HandleServiceFactory.getInstance().getHandleService();
|
||||||
|
|
||||||
private XOAIItemCacheService cacheService;
|
private XOAIItemCacheService cacheService;
|
||||||
private boolean useCache;
|
private boolean useCache;
|
||||||
@@ -79,11 +84,11 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
|||||||
|
|
||||||
private List<ReferenceSet> getSets(org.dspace.content.Item item)
|
private List<ReferenceSet> getSets(org.dspace.content.Item item)
|
||||||
{
|
{
|
||||||
List<ReferenceSet> sets = new ArrayList<ReferenceSet>();
|
List<ReferenceSet> sets = new ArrayList<>();
|
||||||
List<Community> coms = new ArrayList<Community>();
|
List<Community> coms = new ArrayList<>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Collection[] itemCollections = item.getCollections();
|
List<Collection> itemCollections = item.getCollections();
|
||||||
for (Collection col : itemCollections)
|
for (Collection col : itemCollections)
|
||||||
{
|
{
|
||||||
ReferenceSet s = new DSpaceSet(col);
|
ReferenceSet s = new DSpaceSet(col);
|
||||||
@@ -113,7 +118,7 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
|||||||
String parts[] = id.split(Pattern.quote(":"));
|
String parts[] = id.split(Pattern.quote(":"));
|
||||||
if (parts.length == 3)
|
if (parts.length == 3)
|
||||||
{
|
{
|
||||||
DSpaceObject obj = HandleServiceImpl.resolveToObject(context.getContext(),
|
DSpaceObject obj = handleService.resolveToObject(context.getContext(),
|
||||||
parts[2]);
|
parts[2]);
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
throw new IdDoesNotExistException();
|
throw new IdDoesNotExistException();
|
||||||
@@ -129,13 +134,9 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
|||||||
log.debug(e.getMessage(), e);
|
log.debug(e.getMessage(), e);
|
||||||
throw new IdDoesNotExistException();
|
throw new IdDoesNotExistException();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException | IOException | ContextServiceException e)
|
||||||
{
|
{
|
||||||
throw new OAIException(e);
|
throw new OAIException(e);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new OAIException(e);
|
|
||||||
} catch (ContextServiceException e) {
|
|
||||||
throw new OAIException(e);
|
|
||||||
}
|
}
|
||||||
throw new IdDoesNotExistException();
|
throw new IdDoesNotExistException();
|
||||||
}
|
}
|
||||||
@@ -145,7 +146,7 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
|||||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||||
int length) throws OAIException
|
int length) throws OAIException
|
||||||
{
|
{
|
||||||
List<Item> list = new ArrayList<Item>();
|
List<Item> list = new ArrayList<>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
||||||
@@ -179,7 +180,7 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
|||||||
List<ScopedFilter> filters, int offset, int length) throws OAIException
|
List<ScopedFilter> filters, int offset, int length) throws OAIException
|
||||||
{
|
{
|
||||||
|
|
||||||
List<ItemIdentifier> list = new ArrayList<ItemIdentifier>();
|
List<ItemIdentifier> list = new ArrayList<>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
||||||
|
@@ -16,7 +16,6 @@ import org.dspace.content.Collection;
|
|||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.handle.HandleServiceImpl;
|
|
||||||
import org.dspace.storage.rdbms.DatabaseManager;
|
import org.dspace.storage.rdbms.DatabaseManager;
|
||||||
import org.dspace.storage.rdbms.TableRow;
|
import org.dspace.storage.rdbms.TableRow;
|
||||||
import org.dspace.storage.rdbms.TableRowIterator;
|
import org.dspace.storage.rdbms.TableRowIterator;
|
||||||
@@ -26,6 +25,11 @@ import java.io.Serializable;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -35,6 +39,15 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
private static final Logger log = LogManager.getLogger(DSpaceSetRepository.class);
|
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;
|
private final Context _context;
|
||||||
|
|
||||||
public DSpaceSetRepository(Context context)
|
public DSpaceSetRepository(Context context)
|
||||||
@@ -84,9 +97,9 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
*/
|
*/
|
||||||
private List<Set> community(int offset, int length)
|
private List<Set> community(int offset, int length)
|
||||||
{
|
{
|
||||||
List<Set> array = new ArrayList<Set>();
|
List<Set> array = new ArrayList<>();
|
||||||
StringBuffer query = new StringBuffer("SELECT community_id FROM community ORDER BY community_id");
|
StringBuffer query = new StringBuffer("SELECT community_id FROM community ORDER BY community_id");
|
||||||
List<Serializable> params = new ArrayList<Serializable>();
|
List<Serializable> params = new ArrayList<>();
|
||||||
|
|
||||||
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
||||||
|
|
||||||
@@ -99,7 +112,7 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
TableRow row = iterator.next();
|
TableRow row = iterator.next();
|
||||||
int communityID = row.getIntColumn("community_id");
|
int communityID = row.getIntColumn("community_id");
|
||||||
Community community = Community.find(_context, communityID);
|
Community community = communityService.find(_context, communityID);
|
||||||
array.add(DSpaceSet.newDSpaceCommunitySet(
|
array.add(DSpaceSet.newDSpaceCommunitySet(
|
||||||
community.getHandle(), community.getName()));
|
community.getHandle(), community.getName()));
|
||||||
i++;
|
i++;
|
||||||
@@ -122,9 +135,9 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
*/
|
*/
|
||||||
private List<Set> collection(int offset, int length)
|
private List<Set> collection(int offset, int length)
|
||||||
{
|
{
|
||||||
List<Set> array = new ArrayList<Set>();
|
List<Set> array = new ArrayList<>();
|
||||||
StringBuffer query = new StringBuffer("SELECT collection_id FROM collection ORDER BY collection_id");
|
StringBuffer query = new StringBuffer("SELECT collection_id FROM collection ORDER BY collection_id");
|
||||||
List<Serializable> params = new ArrayList<Serializable>();
|
List<Serializable> params = new ArrayList<>();
|
||||||
|
|
||||||
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
DatabaseManager.applyOffsetAndLimit(query,params,offset,length);
|
||||||
|
|
||||||
@@ -137,7 +150,7 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
TableRow row = iterator.next();
|
TableRow row = iterator.next();
|
||||||
int collectionID = row.getIntColumn("collection_id");
|
int collectionID = row.getIntColumn("collection_id");
|
||||||
Collection collection = Collection.find(_context, collectionID);
|
Collection collection = collectionService.find(_context, collectionID);
|
||||||
array.add(DSpaceSet.newDSpaceCollectionSet(
|
array.add(DSpaceSet.newDSpaceCollectionSet(
|
||||||
collection.getHandle(),
|
collection.getHandle(),
|
||||||
collection.getName()));
|
collection.getName()));
|
||||||
@@ -156,7 +169,7 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
// Only database sets (virtual sets are added by lyncode common library)
|
// Only database sets (virtual sets are added by lyncode common library)
|
||||||
log.debug("Querying sets. Offset: " + offset + " - Length: " + length);
|
log.debug("Querying sets. Offset: " + offset + " - Length: " + length);
|
||||||
List<Set> array = new ArrayList<Set>();
|
List<Set> array = new ArrayList<>();
|
||||||
int communityCount = this.getCommunityCount();
|
int communityCount = this.getCommunityCount();
|
||||||
log.debug("Communities: " + communityCount);
|
log.debug("Communities: " + communityCount);
|
||||||
int collectionCount = this.getCollectionCount();
|
int collectionCount = this.getCollectionCount();
|
||||||
@@ -198,13 +211,11 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DSpaceObject dso = HandleServiceImpl.resolveToObject(_context,
|
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||||
setSpec.replace("col_", "").replace("_", "/"));
|
setSpec.replace("col_", "").replace("_", "/"));
|
||||||
if (dso == null || !(dso instanceof Collection))
|
return !(dso == null || !(dso instanceof Collection));
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (IllegalStateException | SQLException ex)
|
||||||
{
|
{
|
||||||
log.error(ex.getMessage(), ex);
|
log.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
@@ -213,13 +224,11 @@ public class DSpaceSetRepository implements SetRepository
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DSpaceObject dso = HandleServiceImpl.resolveToObject(_context,
|
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||||
setSpec.replace("com_", "").replace("_", "/"));
|
setSpec.replace("com_", "").replace("_", "/"));
|
||||||
if (dso == null || !(dso instanceof Community))
|
return !(dso == null || !(dso instanceof Community));
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (IllegalStateException | SQLException ex)
|
||||||
{
|
{
|
||||||
log.error(ex.getMessage(), ex);
|
log.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
|
@@ -13,7 +13,6 @@ import com.lyncode.xoai.util.Base64Utils;
|
|||||||
import org.apache.log4j.LogManager;
|
import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.Bitstream;
|
|
||||||
import org.dspace.content.Bundle;
|
import org.dspace.content.Bundle;
|
||||||
import org.dspace.content.Metadatum;
|
import org.dspace.content.Metadatum;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
@@ -28,6 +27,11 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.dspace.content.BundleBitstream;
|
||||||
|
import org.dspace.content.MetadataField;
|
||||||
|
import org.dspace.content.MetadataValue;
|
||||||
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
|
import org.dspace.content.service.ItemService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -36,8 +40,10 @@ import java.util.List;
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public class ItemUtils
|
public class ItemUtils
|
||||||
{
|
{
|
||||||
private static Logger log = LogManager
|
private static final Logger log = LogManager.getLogger(ItemUtils.class);
|
||||||
.getLogger(ItemUtils.class);
|
|
||||||
|
private static final ItemService itemService
|
||||||
|
= ContentServiceFactory.getInstance().getItemService();
|
||||||
|
|
||||||
private static Element getElement(List<Element> list, String name)
|
private static Element getElement(List<Element> list, String name)
|
||||||
{
|
{
|
||||||
@@ -69,38 +75,40 @@ public class ItemUtils
|
|||||||
|
|
||||||
// read all metadata into Metadata Object
|
// read all metadata into Metadata Object
|
||||||
metadata = new Metadata();
|
metadata = new Metadata();
|
||||||
Metadatum[] vals = item.getMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
List<MetadataValue> vals = itemService.getMetadata(item, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||||
for (Metadatum val : vals)
|
for (MetadataValue val : vals)
|
||||||
{
|
{
|
||||||
|
MetadataField field = val.getMetadataField();
|
||||||
|
|
||||||
Element valueElem = null;
|
Element valueElem = null;
|
||||||
Element schema = getElement(metadata.getElement(), val.schema);
|
Element schema = getElement(metadata.getElement(), field.getMetadataSchema().getName());
|
||||||
if (schema == null)
|
if (schema == null)
|
||||||
{
|
{
|
||||||
schema = create(val.schema);
|
schema = create(field.getMetadataSchema().getName());
|
||||||
metadata.getElement().add(schema);
|
metadata.getElement().add(schema);
|
||||||
}
|
}
|
||||||
valueElem = schema;
|
valueElem = schema;
|
||||||
|
|
||||||
// Has element.. with XOAI one could have only schema and value
|
// Has element.. with XOAI one could have only schema and value
|
||||||
if (val.element != null && !val.element.equals(""))
|
if (field.getElement() != null && !field.getElement().equals(""))
|
||||||
{
|
{
|
||||||
Element element = getElement(schema.getElement(),
|
Element element = getElement(schema.getElement(),
|
||||||
val.element);
|
field.getElement());
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
element = create(val.element);
|
element = create(field.getElement());
|
||||||
schema.getElement().add(element);
|
schema.getElement().add(element);
|
||||||
}
|
}
|
||||||
valueElem = element;
|
valueElem = element;
|
||||||
|
|
||||||
// Qualified element?
|
// Qualified element?
|
||||||
if (val.qualifier != null && !val.qualifier.equals(""))
|
if (field.getQualifier() != null && !field.getQualifier().equals(""))
|
||||||
{
|
{
|
||||||
Element qualifier = getElement(element.getElement(),
|
Element qualifier = getElement(element.getElement(),
|
||||||
val.qualifier);
|
field.getQualifier());
|
||||||
if (qualifier == null)
|
if (qualifier == null)
|
||||||
{
|
{
|
||||||
qualifier = create(val.qualifier);
|
qualifier = create(field.getQualifier());
|
||||||
element.getElement().add(qualifier);
|
element.getElement().add(qualifier);
|
||||||
}
|
}
|
||||||
valueElem = qualifier;
|
valueElem = qualifier;
|
||||||
@@ -108,13 +116,13 @@ public class ItemUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Language?
|
// Language?
|
||||||
if (val.language != null && !val.language.equals(""))
|
if (val.getLanguage() != null && !val.getLanguage().equals(""))
|
||||||
{
|
{
|
||||||
Element language = getElement(valueElem.getElement(),
|
Element language = getElement(valueElem.getElement(),
|
||||||
val.language);
|
val.getLanguage());
|
||||||
if (language == null)
|
if (language == null)
|
||||||
{
|
{
|
||||||
language = create(val.language);
|
language = create(val.getLanguage());
|
||||||
valueElem.getElement().add(language);
|
valueElem.getElement().add(language);
|
||||||
}
|
}
|
||||||
valueElem = language;
|
valueElem = language;
|
||||||
@@ -131,11 +139,11 @@ public class ItemUtils
|
|||||||
valueElem = language;
|
valueElem = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
valueElem.getField().add(createValue("value", val.value));
|
valueElem.getField().add(createValue("value", val.getValue()));
|
||||||
if (val.authority != null) {
|
if (val.getAuthority() != null) {
|
||||||
valueElem.getField().add(createValue("authority", val.authority));
|
valueElem.getField().add(createValue("authority", val.getAuthority()));
|
||||||
if (val.confidence != Choices.CF_NOVALUE)
|
if (val.getConfidence() != Choices.CF_NOVALUE)
|
||||||
valueElem.getField().add(createValue("confidence", val.confidence + ""));
|
valueElem.getField().add(createValue("confidence", val.getConfidence() + ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Done! Metadata has been read!
|
// Done! Metadata has been read!
|
||||||
@@ -143,7 +151,7 @@ public class ItemUtils
|
|||||||
Element bundles = create("bundles");
|
Element bundles = create("bundles");
|
||||||
metadata.getElement().add(bundles);
|
metadata.getElement().add(bundles);
|
||||||
|
|
||||||
Bundle[] bs;
|
List<Bundle> bs;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
bs = item.getBundles();
|
bs = item.getBundles();
|
||||||
@@ -156,31 +164,31 @@ public class ItemUtils
|
|||||||
|
|
||||||
Element bitstreams = create("bitstreams");
|
Element bitstreams = create("bitstreams");
|
||||||
bundle.getElement().add(bitstreams);
|
bundle.getElement().add(bitstreams);
|
||||||
Bitstream[] bits = b.getBitstreams();
|
List<BundleBitstream> bits = b.getBitstreams();
|
||||||
for (Bitstream bit : bits)
|
for (BundleBitstream bit : bits)
|
||||||
{
|
{
|
||||||
Element bitstream = create("bitstream");
|
Element bitstream = create("bitstream");
|
||||||
bitstreams.getElement().add(bitstream);
|
bitstreams.getElement().add(bitstream);
|
||||||
String url = "";
|
String url = "";
|
||||||
String bsName = bit.getName();
|
String bsName = bit.getBitstream().getName();
|
||||||
String sid = String.valueOf(bit.getSequenceID());
|
String sid = String.valueOf(bit.getBitstream().getSequenceID());
|
||||||
String baseUrl = ConfigurationManager.getProperty("oai",
|
String baseUrl = ConfigurationManager.getProperty("oai",
|
||||||
"bitstream.baseUrl");
|
"bitstream.baseUrl");
|
||||||
String handle = null;
|
String handle = null;
|
||||||
// get handle of parent Item of this bitstream, if there
|
// get handle of parent Item of this bitstream, if there
|
||||||
// is one:
|
// is one:
|
||||||
Bundle[] bn = bit.getBundles();
|
List<BundleBitstream> bn = bit.getBitstream().getBundles();
|
||||||
if (bn.length > 0)
|
if (!bn.isEmpty())
|
||||||
{
|
{
|
||||||
Item bi[] = bn[0].getItems();
|
List<Item> bi = bn.get(0).getBundle().getItems();
|
||||||
if (bi.length > 0)
|
if (!bi.isEmpty())
|
||||||
{
|
{
|
||||||
handle = bi[0].getHandle();
|
handle = bi.get(0).getHandle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bsName == null)
|
if (bsName == null)
|
||||||
{
|
{
|
||||||
String ext[] = bit.getFormat().getExtensions();
|
String ext[] = bit.getBitstream().getFormat().getExtensions();
|
||||||
bsName = "bitstream_" + sid
|
bsName = "bitstream_" + sid
|
||||||
+ (ext.length > 0 ? ext[0] : "");
|
+ (ext.length > 0 ? ext[0] : "");
|
||||||
}
|
}
|
||||||
@@ -196,11 +204,11 @@ public class ItemUtils
|
|||||||
url = URLUtils.encode(bsName);
|
url = URLUtils.encode(bsName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String cks = bit.getChecksum();
|
String cks = bit.getBitstream().getChecksum();
|
||||||
String cka = bit.getChecksumAlgorithm();
|
String cka = bit.getBitstream().getChecksumAlgorithm();
|
||||||
String oname = bit.getSource();
|
String oname = bit.getBitstream().getSource();
|
||||||
String name = bit.getName();
|
String name = bit.getBitstream().getName();
|
||||||
String description = bit.getDescription();
|
String description = bit.getBitstream().getDescription();
|
||||||
|
|
||||||
if (name != null)
|
if (name != null)
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
@@ -212,17 +220,17 @@ public class ItemUtils
|
|||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("description", description));
|
createValue("description", description));
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("format", bit.getFormat()
|
createValue("format", bit.getBitstream().getFormat()
|
||||||
.getMIMEType()));
|
.getMIMEType()));
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("size", "" + bit.getSize()));
|
createValue("size", "" + bit.getBitstream().getSize()));
|
||||||
bitstream.getField().add(createValue("url", url));
|
bitstream.getField().add(createValue("url", url));
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("checksum", cks));
|
createValue("checksum", cks));
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("checksumAlgorithm", cka));
|
createValue("checksumAlgorithm", cka));
|
||||||
bitstream.getField().add(
|
bitstream.getField().add(
|
||||||
createValue("sid", bit.getSequenceID()
|
createValue("sid", bit.getBitstream().getSequenceID()
|
||||||
+ ""));
|
+ ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,21 +265,21 @@ public class ItemUtils
|
|||||||
|
|
||||||
// Licensing info
|
// Licensing info
|
||||||
Element license = create("license");
|
Element license = create("license");
|
||||||
Bundle[] licBundles;
|
List<Bundle> licBundles;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
licBundles = item.getBundles(Constants.LICENSE_BUNDLE_NAME);
|
licBundles = itemService.getBundles(item, Constants.LICENSE_BUNDLE_NAME);
|
||||||
if (licBundles.length > 0)
|
if (!licBundles.isEmpty())
|
||||||
{
|
{
|
||||||
Bundle licBundle = licBundles[0];
|
Bundle licBundle = licBundles.get(0);
|
||||||
Bitstream[] licBits = licBundle.getBitstreams();
|
List<BundleBitstream> licBits = licBundle.getBitstreams();
|
||||||
if (licBits.length > 0)
|
if (!licBits.isEmpty())
|
||||||
{
|
{
|
||||||
Bitstream licBit = licBits[0];
|
BundleBitstream licBit = licBits.get(0);
|
||||||
InputStream in;
|
InputStream in;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
in = licBit.retrieve();
|
in = licBit.getBitstream().retrieve();
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
Utils.bufferedCopy(in, out);
|
Utils.bufferedCopy(in, out);
|
||||||
license.getField().add(
|
license.getField().add(
|
||||||
@@ -279,15 +287,7 @@ public class ItemUtils
|
|||||||
Base64Utils.encode(out.toString())));
|
Base64Utils.encode(out.toString())));
|
||||||
metadata.getElement().add(license);
|
metadata.getElement().add(license);
|
||||||
}
|
}
|
||||||
catch (AuthorizeException e)
|
catch (AuthorizeException | IOException | SQLException e)
|
||||||
{
|
|
||||||
log.warn(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
log.warn(e.getMessage(), e);
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
{
|
||||||
log.warn(e.getMessage(), e);
|
log.warn(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user