mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-11 12:03:09 +00:00
[DS-2701] oai mostly finding oldest date in some metadata field
This commit is contained in:
@@ -102,4 +102,12 @@ public class MetadataValueServiceImpl implements MetadataValueService {
|
||||
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException {
|
||||
metadataValueDAO.deleteByMetadataField(context, metadataField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataValue getMinimum(Context context, int metadataFieldId)
|
||||
throws SQLException
|
||||
{
|
||||
return metadataValueDAO.getMinimum(context,
|
||||
metadataFieldId);
|
||||
}
|
||||
}
|
||||
|
@@ -29,4 +29,7 @@ public interface MetadataValueDAO extends GenericDAO<MetadataValue> {
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
|
||||
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException;
|
||||
|
||||
public MetadataValue getMinimum(Context context, int metadataFieldId)
|
||||
throws SQLException;
|
||||
}
|
||||
|
@@ -55,4 +55,15 @@ public class MetadataValueDAOImpl extends AbstractHibernateDAO<MetadataValue> im
|
||||
query.setParameter("metadataField", metadataField);
|
||||
query.executeUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MetadataValue getMinimum(Context context, int metadataFieldId)
|
||||
throws SQLException
|
||||
{
|
||||
String queryString = "SELECT m FROM metadatavalue WHERE metadata_field_id = :metadata_field_id ORDER BY value";
|
||||
Query query = createQuery(context, queryString);
|
||||
query.setParameter("metadata_field_id", metadataFieldId);
|
||||
query.setMaxResults(1);
|
||||
return (MetadataValue) query.uniqueResult();
|
||||
}
|
||||
}
|
||||
|
@@ -80,4 +80,15 @@ public interface MetadataValueService {
|
||||
public List<MetadataValue> findByValueLike(Context context, String value) throws SQLException;
|
||||
|
||||
public void deleteByMetadataField(Context context, MetadataField metadataField) throws SQLException;
|
||||
|
||||
/**
|
||||
* Get the minimum value of a given metadata field across all objects.
|
||||
*
|
||||
* @param context
|
||||
* @param metadataFieldId unique identifier of the interesting field.
|
||||
* @return
|
||||
* @throws SQLException
|
||||
*/
|
||||
public MetadataValue getMinimum(Context context, int metadataFieldId)
|
||||
throws SQLException;
|
||||
}
|
||||
|
@@ -255,7 +255,7 @@ public class XOAI {
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
XmlOutputContext xmlContext = XmlOutputContext.emptyContext(out, Second);
|
||||
retrieveMetadata(item).write(xmlContext);
|
||||
retrieveMetadata(context, item).write(xmlContext);
|
||||
xmlContext.getWriter().flush();
|
||||
xmlContext.getWriter().close();
|
||||
doc.addField("item.compile", out.toString());
|
||||
@@ -440,7 +440,7 @@ public class XOAI {
|
||||
while (iterator.hasNext()) {
|
||||
Item item = iterator.next();
|
||||
if (verbose) System.out.println("Compiling item with handle: " + item.getHandle());
|
||||
xoaiItemCacheService.put(item, retrieveMetadata(item));
|
||||
xoaiItemCacheService.put(item, retrieveMetadata(context, item));
|
||||
}
|
||||
|
||||
xoaiLastCompilationCacheService.put(new Date());
|
||||
|
@@ -10,7 +10,6 @@ package org.dspace.xoai.filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.DatabaseFilterResult;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
@@ -34,8 +33,6 @@ public class DSpaceWithdrawnFilter extends DSpaceFilter {
|
||||
List<Object> params = new ArrayList<>();
|
||||
|
||||
String filter = "i.withdrawn=TRUE";
|
||||
if(DatabaseManager.isOracle())
|
||||
filter = "i.withdrawn=1";
|
||||
|
||||
return new DatabaseFilterResult(filter, params);
|
||||
}
|
||||
|
@@ -15,7 +15,6 @@ import java.util.List;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
|
@@ -10,8 +10,6 @@ package org.dspace.xoai.services.impl.database;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.database.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.database.FieldResolver;
|
||||
@@ -20,6 +18,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.MetadataValueService;
|
||||
|
||||
public class DSpaceEarliestDateResolver implements EarliestDateResolver {
|
||||
private static final Logger log = LogManager.getLogger(DSpaceEarliestDateResolver.class);
|
||||
@@ -30,20 +31,13 @@ public class DSpaceEarliestDateResolver implements EarliestDateResolver {
|
||||
@Override
|
||||
public Date getEarliestDate(Context context) throws InvalidMetadataFieldException, SQLException {
|
||||
String query = "SELECT MIN(text_value) as value FROM metadatavalue WHERE metadata_field_id = ?";
|
||||
boolean postgres = ! DatabaseManager.isOracle();
|
||||
|
||||
if (!postgres) {
|
||||
query = "SELECT MIN(TO_CHAR(text_value)) as value FROM metadatavalue WHERE metadata_field_id = ?";
|
||||
}
|
||||
|
||||
TableRowIterator iterator = DatabaseManager
|
||||
.query(context,
|
||||
query,
|
||||
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
|
||||
MetadataValue minimum = metadataValueService.getMinimum(context,
|
||||
fieldResolver.getFieldID(context, "dc.date.available"));
|
||||
|
||||
if (iterator.hasNext())
|
||||
if (null != minimum)
|
||||
{
|
||||
String str = iterator.next().getStringColumn("value");
|
||||
String str = minimum.getValue();
|
||||
try
|
||||
{
|
||||
Date d = DateUtils.parse(str);
|
||||
|
@@ -8,8 +8,6 @@
|
||||
package org.dspace.xoai.services.impl.database;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.database.FieldResolver;
|
||||
|
||||
|
@@ -21,10 +21,6 @@ import org.apache.log4j.Logger;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.ItemIterator;
|
||||
import org.dspace.handle.HandleServiceImpl;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.xoai.data.DSpaceDatabaseItem;
|
||||
import org.dspace.xoai.data.DSpaceSet;
|
||||
import org.dspace.xoai.services.api.cache.XOAIItemCacheService;
|
||||
@@ -39,6 +35,7 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
|
||||
@@ -55,31 +52,39 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||
private static final HandleService handleService
|
||||
= HandleServiceFactory.getInstance().getHandleService();
|
||||
|
||||
private XOAIItemCacheService cacheService;
|
||||
private boolean useCache;
|
||||
private DatabaseQueryResolver queryResolver;
|
||||
private ContextService context;
|
||||
private CollectionsService collectionsService;
|
||||
private ConfigurationService configurationService;
|
||||
private final XOAIItemCacheService cacheService;
|
||||
private final boolean useCache;
|
||||
private final DatabaseQueryResolver queryResolver;
|
||||
private final ContextService contextService;
|
||||
private final CollectionsService collectionsService;
|
||||
private final ConfigurationService configurationService;
|
||||
private final Context context;
|
||||
|
||||
public DSpaceItemDatabaseRepository(ConfigurationService configurationService, CollectionsService collectionsService, HandleResolver handleResolver, XOAIItemCacheService cacheService, DatabaseQueryResolver queryResolver, ContextService context)
|
||||
public DSpaceItemDatabaseRepository(Context context,
|
||||
ConfigurationService configurationService,
|
||||
CollectionsService collectionsService,
|
||||
HandleResolver handleResolver,
|
||||
XOAIItemCacheService cacheService,
|
||||
DatabaseQueryResolver queryResolver,
|
||||
ContextService contextService)
|
||||
{
|
||||
super(collectionsService, handleResolver);
|
||||
this.context = context;
|
||||
this.configurationService = configurationService;
|
||||
this.collectionsService = collectionsService;
|
||||
this.cacheService = cacheService;
|
||||
this.queryResolver = queryResolver;
|
||||
this.context = context;
|
||||
this.contextService = contextService;
|
||||
this.useCache = configurationService.getBooleanProperty("oai", "cache.enabled", true);
|
||||
}
|
||||
|
||||
private Metadata getMetadata (org.dspace.content.Item item) throws IOException {
|
||||
private Metadata getMetadata (Context context, org.dspace.content.Item item) throws IOException {
|
||||
if (this.useCache) {
|
||||
if (!cacheService.hasCache(item))
|
||||
cacheService.put(item, ItemUtils.retrieveMetadata(item));
|
||||
cacheService.put(item, ItemUtils.retrieveMetadata(context, item));
|
||||
|
||||
return cacheService.get(item);
|
||||
} else return ItemUtils.retrieveMetadata(item);
|
||||
} else return ItemUtils.retrieveMetadata(context, item);
|
||||
}
|
||||
|
||||
private List<ReferenceSet> getSets(org.dspace.content.Item item)
|
||||
@@ -118,7 +123,7 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||
String parts[] = id.split(Pattern.quote(":"));
|
||||
if (parts.length == 3)
|
||||
{
|
||||
DSpaceObject obj = handleService.resolveToObject(context.getContext(),
|
||||
DSpaceObject obj = handleService.resolveToObject(contextService.getContext(),
|
||||
parts[2]);
|
||||
if (obj == null)
|
||||
throw new IdDoesNotExistException();
|
||||
@@ -126,7 +131,7 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||
throw new IdDoesNotExistException();
|
||||
|
||||
org.dspace.content.Item item = (org.dspace.content.Item) obj;
|
||||
return new DSpaceDatabaseItem(item, this.getMetadata(item), getSets(item));
|
||||
return new DSpaceDatabaseItem(item, this.getMetadata(context, item), getSets(item));
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
@@ -150,14 +155,14 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||
try
|
||||
{
|
||||
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
||||
TableRowIterator rowIterator = DatabaseManager.queryTable(context.getContext(), "item",
|
||||
TableRowIterator rowIterator = DatabaseManager.queryTable(contextService.getContext(), "item",
|
||||
databaseQuery.getQuery(), databaseQuery.getParameters().toArray());
|
||||
ItemIterator iterator = new ItemIterator(context.getContext(), rowIterator);
|
||||
ItemIterator iterator = new ItemIterator(contextService.getContext(), rowIterator);
|
||||
int i = 0;
|
||||
while (iterator.hasNext() && i < length)
|
||||
{
|
||||
org.dspace.content.Item it = iterator.next();
|
||||
list.add(new DSpaceDatabaseItem(it, this.getMetadata(it), getSets(it)));
|
||||
list.add(new DSpaceDatabaseItem(it, this.getMetadata(context, it), getSets(it)));
|
||||
i++;
|
||||
}
|
||||
return new ListItemsResults((databaseQuery.getTotal() > offset + length), list, databaseQuery.getTotal());
|
||||
@@ -184,14 +189,14 @@ public class DSpaceItemDatabaseRepository extends DSpaceItemRepository
|
||||
try
|
||||
{
|
||||
DatabaseQuery databaseQuery = queryResolver.buildQuery(filters, offset, length);
|
||||
TableRowIterator rowIterator = DatabaseManager.queryTable(context.getContext(), "item",
|
||||
TableRowIterator rowIterator = DatabaseManager.queryTable(contextService.getContext(), "item",
|
||||
databaseQuery.getQuery(), databaseQuery.getParameters().toArray());
|
||||
ItemIterator iterator = new ItemIterator(context.getContext(), rowIterator);
|
||||
ItemIterator iterator = new ItemIterator(contextService.getContext(), rowIterator);
|
||||
int i = 0;
|
||||
while (iterator.hasNext() && i < length)
|
||||
{
|
||||
org.dspace.content.Item it = iterator.next();
|
||||
list.add(new DSpaceDatabaseItem(it, this.getMetadata(it), getSets(it)));
|
||||
list.add(new DSpaceDatabaseItem(it, this.getMetadata(context, it), getSets(it)));
|
||||
i++;
|
||||
}
|
||||
return new ListItemIdentifiersResult((databaseQuery.getTotal() > offset + length), list, databaseQuery.getTotal());
|
||||
|
@@ -16,9 +16,6 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRow;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.xoai.data.DSpaceSet;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@@ -14,7 +14,6 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Metadatum;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.authority.Choices;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
@@ -31,7 +30,9 @@ 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.BitstreamService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -45,6 +46,9 @@ public class ItemUtils
|
||||
private static final ItemService itemService
|
||||
= ContentServiceFactory.getInstance().getItemService();
|
||||
|
||||
private static final BitstreamService bitstreamService
|
||||
= ContentServiceFactory.getInstance().getBitstreamService();
|
||||
|
||||
private static Element getElement(List<Element> list, String name)
|
||||
{
|
||||
for (Element e : list)
|
||||
@@ -68,7 +72,7 @@ public class ItemUtils
|
||||
e.setName(name);
|
||||
return e;
|
||||
}
|
||||
public static Metadata retrieveMetadata (Item item) {
|
||||
public static Metadata retrieveMetadata (Context context, Item item) {
|
||||
Metadata metadata;
|
||||
|
||||
//DSpaceDatabaseItem dspaceItem = new DSpaceDatabaseItem(item);
|
||||
@@ -188,9 +192,9 @@ public class ItemUtils
|
||||
}
|
||||
if (bsName == null)
|
||||
{
|
||||
String ext[] = bit.getBitstream().getFormat().getExtensions();
|
||||
List<String> ext = bit.getBitstream().getFormat(context).getExtensions();
|
||||
bsName = "bitstream_" + sid
|
||||
+ (ext.length > 0 ? ext[0] : "");
|
||||
+ (ext.isEmpty() ? "" : ext.get(0));
|
||||
}
|
||||
if (handle != null && baseUrl != null)
|
||||
{
|
||||
@@ -220,7 +224,7 @@ public class ItemUtils
|
||||
bitstream.getField().add(
|
||||
createValue("description", description));
|
||||
bitstream.getField().add(
|
||||
createValue("format", bit.getBitstream().getFormat()
|
||||
createValue("format", bit.getBitstream().getFormat(context)
|
||||
.getMIMEType()));
|
||||
bitstream.getField().add(
|
||||
createValue("size", "" + bit.getBitstream().getSize()));
|
||||
@@ -279,7 +283,7 @@ public class ItemUtils
|
||||
InputStream in;
|
||||
try
|
||||
{
|
||||
in = licBit.getBitstream().retrieve();
|
||||
in = bitstreamService.retrieve(context, licBit.getBitstream());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Utils.bufferedCopy(in, out);
|
||||
license.getField().add(
|
||||
|
Reference in New Issue
Block a user