mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
Fix dspace-oai module per new code style
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>dspace-oai</artifactId>
|
||||
<packaging>war</packaging>
|
||||
@@ -104,8 +105,8 @@
|
||||
<artifactId>xml-apis</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
@@ -156,8 +157,8 @@
|
||||
<artifactId>javassist</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
@@ -16,17 +16,13 @@ import org.dspace.app.util.AbstractDSpaceWebapp;
|
||||
* @author Christian Scheible (christian.scheible at uni-konstanz dot de)
|
||||
*/
|
||||
public class DSpaceWebapp
|
||||
extends AbstractDSpaceWebapp
|
||||
{
|
||||
public DSpaceWebapp()
|
||||
{
|
||||
extends AbstractDSpaceWebapp {
|
||||
public DSpaceWebapp() {
|
||||
super("OAI");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUI()
|
||||
{
|
||||
public boolean isUI() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -7,16 +7,12 @@
|
||||
*/
|
||||
package org.dspace.xoai.app;
|
||||
|
||||
import org.dspace.xoai.services.impl.DSpaceFieldResolver;
|
||||
import org.dspace.xoai.services.impl.DSpaceHandleResolver;
|
||||
import org.dspace.xoai.services.impl.DSpaceEarliestDateResolver;
|
||||
import org.dspace.xoai.services.impl.DSpaceCollectionsService;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||
import org.dspace.xoai.services.api.cache.XOAIItemCacheService;
|
||||
import org.dspace.xoai.services.api.cache.XOAILastCompilationCacheService;
|
||||
@@ -30,6 +26,10 @@ 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.DSpaceCollectionsService;
|
||||
import org.dspace.xoai.services.impl.DSpaceEarliestDateResolver;
|
||||
import org.dspace.xoai.services.impl.DSpaceFieldResolver;
|
||||
import org.dspace.xoai.services.impl.DSpaceHandleResolver;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceEmptyCacheService;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceXOAICacheService;
|
||||
import org.dspace.xoai.services.impl.cache.DSpaceXOAIItemCacheService;
|
||||
@@ -63,7 +63,7 @@ public class BasicConfiguration {
|
||||
|
||||
|
||||
@Bean
|
||||
public SolrServerResolver solrServerResolver () {
|
||||
public SolrServerResolver solrServerResolver() {
|
||||
return new DSpaceSolrServerResolver();
|
||||
}
|
||||
|
||||
@@ -82,17 +82,18 @@ public class BasicConfiguration {
|
||||
log.error("Not able to start XOAI normal cache service.", e);
|
||||
return new DSpaceEmptyCacheService();
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
return new DSpaceEmptyCacheService();
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public XOAILastCompilationCacheService xoaiLastCompilationCacheService () {
|
||||
public XOAILastCompilationCacheService xoaiLastCompilationCacheService() {
|
||||
return new DSpaceXOAILastCompilationCacheService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public XOAIItemCacheService xoaiItemCacheService () {
|
||||
public XOAIItemCacheService xoaiItemCacheService() {
|
||||
return new DSpaceXOAIItemCacheService();
|
||||
}
|
||||
|
||||
@@ -103,47 +104,47 @@ public class BasicConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FieldResolver databaseService () {
|
||||
public FieldResolver databaseService() {
|
||||
return new DSpaceFieldResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EarliestDateResolver earliestDateResolver () {
|
||||
public EarliestDateResolver earliestDateResolver() {
|
||||
return new DSpaceEarliestDateResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemRepositoryResolver itemRepositoryResolver () {
|
||||
public ItemRepositoryResolver itemRepositoryResolver() {
|
||||
return new DSpaceItemRepositoryResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SetRepositoryResolver setRepositoryResolver () {
|
||||
public SetRepositoryResolver setRepositoryResolver() {
|
||||
return new DSpaceSetRepositoryResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdentifyResolver identifyResolver () {
|
||||
public IdentifyResolver identifyResolver() {
|
||||
return new DSpaceIdentifyResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DSpaceFilterResolver dSpaceFilterResolver () {
|
||||
public DSpaceFilterResolver dSpaceFilterResolver() {
|
||||
return new BaseDSpaceFilterResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public HandleResolver handleResolver () {
|
||||
public HandleResolver handleResolver() {
|
||||
return new DSpaceHandleResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CollectionsService collectionsService () {
|
||||
public CollectionsService collectionsService() {
|
||||
return new DSpaceCollectionsService();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SolrQueryResolver solrQueryResolver () {
|
||||
public SolrQueryResolver solrQueryResolver() {
|
||||
return new DSpaceSolrQueryResolver();
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.app;
|
||||
|
||||
import static java.lang.Integer.MAX_VALUE;
|
||||
|
||||
import com.lyncode.jtwig.mvc.JtwigViewResolver;
|
||||
import org.dspace.xoai.services.api.xoai.ItemRepositoryResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.DSpaceItemRepositoryResolver;
|
||||
@@ -20,10 +22,8 @@ import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
import static java.lang.Integer.MAX_VALUE;
|
||||
|
||||
@Import({
|
||||
BasicConfiguration.class
|
||||
@Import( {
|
||||
BasicConfiguration.class
|
||||
})
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@@ -53,6 +53,7 @@ public class DSpaceWebappConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
return viewResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemRepositoryResolver xoaiItemRepositoryResolver() {
|
||||
return new DSpaceItemRepositoryResolver();
|
||||
|
@@ -7,6 +7,21 @@
|
||||
*/
|
||||
package org.dspace.xoai.app;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.dspace.xoai.util.ItemUtils.retrieveMetadata;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.exceptions.ConfigurationException;
|
||||
import com.lyncode.xoai.dataprovider.exceptions.MetadataBindException;
|
||||
import com.lyncode.xoai.dataprovider.exceptions.WritingXmlException;
|
||||
@@ -25,15 +40,18 @@ import org.apache.solr.common.SolrDocumentList;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||
import org.dspace.authorize.service.AuthorizeService;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.Utils;
|
||||
import org.dspace.handle.Handle;
|
||||
import org.dspace.xoai.exceptions.CompilingException;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||
@@ -47,17 +65,6 @@ import org.dspace.xoai.solr.exceptions.DSpaceSolrIndexerException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.ConnectException;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.dspace.xoai.util.ItemUtils.retrieveMetadata;
|
||||
|
||||
/**
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@@ -133,15 +140,16 @@ public class XOAI {
|
||||
result = this.indexAll();
|
||||
} else {
|
||||
SolrQuery solrParams = new SolrQuery("*:*")
|
||||
.addField("item.lastmodified")
|
||||
.addSortField("item.lastmodified", ORDER.desc).setRows(1);
|
||||
.addField("item.lastmodified")
|
||||
.addSortField("item.lastmodified", ORDER.desc).setRows(1);
|
||||
|
||||
SolrDocumentList results = DSpaceSolrSearch.query(solrServerResolver.getServer(), solrParams);
|
||||
if (results.getNumFound() == 0) {
|
||||
System.out.println("There are no indexed documents, using full import.");
|
||||
result = this.indexAll();
|
||||
} else
|
||||
} else {
|
||||
result = this.index((Date) results.get(0).getFieldValue("item.lastmodified"));
|
||||
}
|
||||
|
||||
}
|
||||
solrServerResolver.getServer().commit();
|
||||
@@ -163,13 +171,13 @@ public class XOAI {
|
||||
|
||||
private int index(Date last) throws DSpaceSolrIndexerException {
|
||||
System.out
|
||||
.println("Incremental import. Searching for documents modified after: "
|
||||
+ last.toString());
|
||||
.println("Incremental import. Searching for documents modified after: "
|
||||
+ last.toString());
|
||||
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
|
||||
// (in order to notify external OAI harvesters of their new status)
|
||||
try {
|
||||
Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
|
||||
context, last);
|
||||
context, last);
|
||||
return this.index(iterator);
|
||||
} catch (SQLException ex) {
|
||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
||||
@@ -182,7 +190,7 @@ public class XOAI {
|
||||
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
|
||||
// (in order to notify external OAI harvesters of their new status)
|
||||
Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
|
||||
context, null);
|
||||
context, null);
|
||||
return this.index(iterator);
|
||||
} catch (SQLException ex) {
|
||||
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
|
||||
@@ -190,7 +198,7 @@ public class XOAI {
|
||||
}
|
||||
|
||||
private int index(Iterator<Item> iterator)
|
||||
throws DSpaceSolrIndexerException {
|
||||
throws DSpaceSolrIndexerException {
|
||||
try {
|
||||
int i = 0;
|
||||
SolrServer server = solrServerResolver.getServer();
|
||||
@@ -203,11 +211,13 @@ public class XOAI {
|
||||
context.uncacheEntity(item);
|
||||
|
||||
} catch (SQLException | MetadataBindException | ParseException
|
||||
| XMLStreamException | WritingXmlException ex) {
|
||||
| XMLStreamException | WritingXmlException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
i++;
|
||||
if (i % 100 == 0) System.out.println(i + " items imported so far...");
|
||||
if (i % 100 == 0) {
|
||||
System.out.println(i + " items imported so far...");
|
||||
}
|
||||
}
|
||||
System.out.println("Total: " + i + " items");
|
||||
server.commit();
|
||||
@@ -217,7 +227,8 @@ public class XOAI {
|
||||
}
|
||||
}
|
||||
|
||||
private SolrInputDocument index(Item item) throws SQLException, MetadataBindException, ParseException, XMLStreamException, WritingXmlException {
|
||||
private SolrInputDocument index(Item item)
|
||||
throws SQLException, MetadataBindException, ParseException, XMLStreamException, WritingXmlException {
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
doc.addField("item.id", item.getID());
|
||||
boolean pub = this.isPublic(item);
|
||||
@@ -229,20 +240,22 @@ public class XOAI {
|
||||
doc.addField("item.submitter", item.getSubmitter().getEmail());
|
||||
}
|
||||
doc.addField("item.deleted", item.isWithdrawn() ? "true" : "false");
|
||||
for (Collection col : item.getCollections())
|
||||
for (Collection col : item.getCollections()) {
|
||||
doc.addField("item.collections",
|
||||
"col_" + col.getHandle().replace("/", "_"));
|
||||
for (Community com : collectionsService.flatParentCommunities(context, item))
|
||||
"col_" + col.getHandle().replace("/", "_"));
|
||||
}
|
||||
for (Community com : collectionsService.flatParentCommunities(context, item)) {
|
||||
doc.addField("item.communities",
|
||||
"com_" + com.getHandle().replace("/", "_"));
|
||||
"com_" + com.getHandle().replace("/", "_"));
|
||||
}
|
||||
|
||||
List<MetadataValue> allData = itemService.getMetadata(item,
|
||||
Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||
Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||
for (MetadataValue dc : allData) {
|
||||
MetadataField field = dc.getMetadataField();
|
||||
String key = "metadata."
|
||||
+ field.getMetadataSchema().getName() + "."
|
||||
+ field.getElement();
|
||||
+ field.getMetadataSchema().getName() + "."
|
||||
+ field.getElement();
|
||||
if (field.getQualifier() != null) {
|
||||
key += "." + field.getQualifier();
|
||||
}
|
||||
@@ -286,8 +299,8 @@ public class XOAI {
|
||||
private static boolean getKnownExplanation(Throwable t) {
|
||||
if (t instanceof ConnectException) {
|
||||
System.err.println("Solr server ("
|
||||
+ ConfigurationManager.getProperty("oai", "solr.url")
|
||||
+ ") is down, turn it on.");
|
||||
+ ConfigurationManager.getProperty("oai", "solr.url")
|
||||
+ ") is down, turn it on.");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -295,10 +308,12 @@ public class XOAI {
|
||||
}
|
||||
|
||||
private static boolean searchForReason(Throwable t) {
|
||||
if (getKnownExplanation(t))
|
||||
if (getKnownExplanation(t)) {
|
||||
return true;
|
||||
if (t.getCause() != null)
|
||||
}
|
||||
if (t.getCause() != null) {
|
||||
return searchForReason(t.getCause());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -313,7 +328,8 @@ public class XOAI {
|
||||
}
|
||||
}
|
||||
|
||||
private static void cleanCache(XOAIItemCacheService xoaiItemCacheService, XOAICacheService xoaiCacheService) throws IOException {
|
||||
private static void cleanCache(XOAIItemCacheService xoaiItemCacheService, XOAICacheService xoaiCacheService)
|
||||
throws IOException {
|
||||
System.out.println("Purging cached OAI responses.");
|
||||
xoaiItemCacheService.deleteAll();
|
||||
xoaiCacheService.deleteAll();
|
||||
@@ -327,8 +343,8 @@ public class XOAI {
|
||||
public static void main(String[] argv) throws IOException, ConfigurationException {
|
||||
|
||||
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(new Class[]{
|
||||
BasicConfiguration.class
|
||||
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(new Class[] {
|
||||
BasicConfiguration.class
|
||||
});
|
||||
|
||||
ConfigurationService configurationService = applicationContext.getBean(ConfigurationService.class);
|
||||
@@ -342,7 +358,7 @@ public class XOAI {
|
||||
Options options = new Options();
|
||||
options.addOption("c", "clear", false, "Clear index before indexing");
|
||||
options.addOption("o", "optimize", false,
|
||||
"Optimize index at the end");
|
||||
"Optimize index at the end");
|
||||
options.addOption("v", "verbose", false, "Verbose output");
|
||||
options.addOption("h", "help", false, "Shows some help");
|
||||
options.addOption("n", "number", true, "FOR DEVELOPMENT MUST DELETE");
|
||||
@@ -378,14 +394,16 @@ public class XOAI {
|
||||
if (COMMAND_IMPORT.equals(command)) {
|
||||
ctx = new Context(Context.Mode.READ_ONLY);
|
||||
XOAI indexer = new XOAI(ctx,
|
||||
line.hasOption('o'),
|
||||
line.hasOption('c'),
|
||||
line.hasOption('v'));
|
||||
line.hasOption('o'),
|
||||
line.hasOption('c'),
|
||||
line.hasOption('v'));
|
||||
|
||||
applicationContext.getAutowireCapableBeanFactory().autowireBean(indexer);
|
||||
|
||||
int imported = indexer.index();
|
||||
if (imported > 0) cleanCache(itemCacheService, cacheService);
|
||||
if (imported > 0) {
|
||||
cleanCache(itemCacheService, cacheService);
|
||||
}
|
||||
} else if (COMMAND_CLEAN_CACHE.equals(command)) {
|
||||
cleanCache(itemCacheService, cacheService);
|
||||
} else if (COMMAND_COMPILE_ITEMS.equals(command)) {
|
||||
@@ -403,8 +421,8 @@ public class XOAI {
|
||||
}
|
||||
|
||||
System.out.println("OAI 2.0 manager action ended. It took "
|
||||
+ ((System.currentTimeMillis() - start) / 1000)
|
||||
+ " seconds.");
|
||||
+ ((System.currentTimeMillis() - start) / 1000)
|
||||
+ " seconds.");
|
||||
} else {
|
||||
usage();
|
||||
}
|
||||
@@ -413,12 +431,11 @@ public class XOAI {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
} finally {
|
||||
// Abort our context, if still open
|
||||
if(ctx!=null && ctx.isValid())
|
||||
if (ctx != null && ctx.isValid()) {
|
||||
ctx.abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -442,7 +459,9 @@ public class XOAI {
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
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(context, item));
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,21 @@
|
||||
*/
|
||||
package org.dspace.xoai.controller;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.OAIDataProvider;
|
||||
import com.lyncode.xoai.dataprovider.OAIRequestParameters;
|
||||
import com.lyncode.xoai.dataprovider.core.XOAIManager;
|
||||
@@ -30,41 +45,30 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
|
||||
import static org.apache.log4j.Logger.getLogger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@Controller
|
||||
public class DSpaceOAIDataProvider
|
||||
{
|
||||
public class DSpaceOAIDataProvider {
|
||||
private static final Logger log = getLogger(DSpaceOAIDataProvider.class);
|
||||
|
||||
@Autowired XOAICacheService cacheService;
|
||||
@Autowired ContextService contextService;
|
||||
@Autowired XOAIManagerResolver xoaiManagerResolver;
|
||||
@Autowired ItemRepositoryResolver itemRepositoryResolver;
|
||||
@Autowired IdentifyResolver identifyResolver;
|
||||
@Autowired SetRepositoryResolver setRepositoryResolver;
|
||||
@Autowired
|
||||
XOAICacheService cacheService;
|
||||
@Autowired
|
||||
ContextService contextService;
|
||||
@Autowired
|
||||
XOAIManagerResolver xoaiManagerResolver;
|
||||
@Autowired
|
||||
ItemRepositoryResolver itemRepositoryResolver;
|
||||
@Autowired
|
||||
IdentifyResolver identifyResolver;
|
||||
@Autowired
|
||||
SetRepositoryResolver setRepositoryResolver;
|
||||
|
||||
private DSpaceResumptionTokenFormatter resumptionTokenFormat = new DSpaceResumptionTokenFormatter();
|
||||
|
||||
@RequestMapping("/")
|
||||
public String indexAction (HttpServletResponse response, Model model) throws ServletException {
|
||||
public String indexAction(HttpServletResponse response, Model model) throws ServletException {
|
||||
try {
|
||||
XOAIManager manager = xoaiManagerResolver.getManager();
|
||||
model.addAttribute("contexts", manager.getContextManager().getContexts());
|
||||
@@ -77,7 +81,8 @@ public class DSpaceOAIDataProvider
|
||||
}
|
||||
|
||||
@RequestMapping("/{context}")
|
||||
public String contextAction (Model model, HttpServletRequest request, HttpServletResponse response, @PathVariable("context") String xoaiContext) throws IOException, ServletException {
|
||||
public String contextAction(Model model, HttpServletRequest request, HttpServletResponse response,
|
||||
@PathVariable("context") String xoaiContext) throws IOException, ServletException {
|
||||
Context context = null;
|
||||
try {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
@@ -86,10 +91,10 @@ public class DSpaceOAIDataProvider
|
||||
XOAIManager manager = xoaiManagerResolver.getManager();
|
||||
|
||||
OAIDataProvider dataProvider = new OAIDataProvider(manager, xoaiContext,
|
||||
identifyResolver.getIdentify(),
|
||||
setRepositoryResolver.getSetRepository(),
|
||||
itemRepositoryResolver.getItemRepository(),
|
||||
resumptionTokenFormat);
|
||||
identifyResolver.getIdentify(),
|
||||
setRepositoryResolver.getSetRepository(),
|
||||
itemRepositoryResolver.getItemRepository(),
|
||||
resumptionTokenFormat);
|
||||
|
||||
OutputStream out = response.getOutputStream();
|
||||
OAIRequestParameters parameters = new OAIRequestParameters(buildParametersMap(request));
|
||||
@@ -100,11 +105,14 @@ public class DSpaceOAIDataProvider
|
||||
String identification = xoaiContext + parameters.requestID();
|
||||
|
||||
if (cacheService.isActive()) {
|
||||
if (!cacheService.hasCache(identification))
|
||||
if (!cacheService.hasCache(identification)) {
|
||||
cacheService.store(identification, dataProvider.handle(parameters));
|
||||
}
|
||||
|
||||
cacheService.handle(identification, out);
|
||||
} else dataProvider.handle(parameters, out);
|
||||
} else {
|
||||
dataProvider.handle(parameters, out);
|
||||
}
|
||||
|
||||
|
||||
out.flush();
|
||||
@@ -119,24 +127,25 @@ public class DSpaceOAIDataProvider
|
||||
log.error(e.getMessage(), e);
|
||||
closeContext(context);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
} catch (XOAIManagerResolverException e) {
|
||||
throw new ServletException("OAI 2.0 wasn't correctly initialized, please check the log for previous errors", e);
|
||||
throw new ServletException("OAI 2.0 wasn't correctly initialized, please check the log for previous errors",
|
||||
e);
|
||||
} catch (OAIException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
closeContext(context);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"Unexpected error. For more information visit the log files.");
|
||||
"Unexpected error. For more information visit the log files.");
|
||||
} catch (WritingXmlException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
closeContext(context);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
} catch (XMLStreamException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
closeContext(context);
|
||||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
"Unexpected error while writing the output. For more information visit the log files.");
|
||||
} finally {
|
||||
closeContext(context);
|
||||
}
|
||||
@@ -145,20 +154,21 @@ public class DSpaceOAIDataProvider
|
||||
}
|
||||
|
||||
private void closeContext(Context context) {
|
||||
if (context != null && context.isValid())
|
||||
if (context != null && context.isValid()) {
|
||||
context.abort();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<String>> buildParametersMap(
|
||||
HttpServletRequest request) {
|
||||
Map<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
Enumeration names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String) names.nextElement();
|
||||
String[] values = request.getParameterValues(name);
|
||||
map.put(name, asList(values));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
private Map<String, List<String>> buildParametersMap(
|
||||
HttpServletRequest request) {
|
||||
Map<String, List<String>> map = new HashMap<String, List<String>>();
|
||||
Enumeration names = request.getParameterNames();
|
||||
while (names.hasMoreElements()) {
|
||||
String name = (String) names.nextElement();
|
||||
String[] values = request.getParameterValues(name);
|
||||
map.put(name, asList(values));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.xoai.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -16,101 +20,108 @@ import com.lyncode.xoai.dataprovider.xml.xoai.Element;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Element.Field;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public abstract class DSpaceItem implements Item
|
||||
{
|
||||
private static List<Element> filter (List<Element> input, String name) {
|
||||
return Lists.newArrayList(Collections2.filter(input, new MetadataNamePredicate(name)));
|
||||
}
|
||||
|
||||
private static List<Element> flat (List<Element> input) {
|
||||
List<Element> elems = new ArrayList<Element>();
|
||||
for (Element e : input) {
|
||||
if (e.getElement() != null) {
|
||||
elems.addAll(e.getElement());
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
private static List<String> values (List<Element> input) {
|
||||
List<String> elems = new ArrayList<String>();
|
||||
for (Element e : input)
|
||||
if (e.getElement() != null && !e.getElement().isEmpty() && e.getElement().get(0).getField() != null)
|
||||
for (Field f : e.getElement().get(0).getField())
|
||||
if (f.getName() != null && f.getName().equals("value"))
|
||||
elems.add(f.getValue());
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
private List<String> getMetadata (String schema, String element) {
|
||||
List<Element> metadata = this.getMetadata().getMetadata().getElement();
|
||||
return values(filter(flat(filter(metadata, schema)), element));
|
||||
}
|
||||
|
||||
private List<String> getMetadata (String schema, String element, String qualifier) {
|
||||
List<Element> metadata = this.getMetadata().getMetadata().getElement();
|
||||
return values(filter(flat(filter(flat(filter(metadata, schema)), element)), qualifier));
|
||||
public abstract class DSpaceItem implements Item {
|
||||
private static List<Element> filter(List<Element> input, String name) {
|
||||
return Lists.newArrayList(Collections2.filter(input, new MetadataNamePredicate(name)));
|
||||
}
|
||||
|
||||
|
||||
private static List<Element> flat(List<Element> input) {
|
||||
List<Element> elems = new ArrayList<Element>();
|
||||
for (Element e : input) {
|
||||
if (e.getElement() != null) {
|
||||
elems.addAll(e.getElement());
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
private static List<String> values(List<Element> input) {
|
||||
List<String> elems = new ArrayList<String>();
|
||||
for (Element e : input) {
|
||||
if (e.getElement() != null && !e.getElement().isEmpty() && e.getElement().get(0).getField() != null) {
|
||||
for (Field f : e.getElement().get(0).getField()) {
|
||||
if (f.getName() != null && f.getName().equals("value")) {
|
||||
elems.add(f.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return elems;
|
||||
}
|
||||
|
||||
|
||||
private List<String> getMetadata(String schema, String element) {
|
||||
List<Element> metadata = this.getMetadata().getMetadata().getElement();
|
||||
return values(filter(flat(filter(metadata, schema)), element));
|
||||
}
|
||||
|
||||
private List<String> getMetadata(String schema, String element, String qualifier) {
|
||||
List<Element> metadata = this.getMetadata().getMetadata().getElement();
|
||||
return values(filter(flat(filter(flat(filter(metadata, schema)), element)), qualifier));
|
||||
}
|
||||
|
||||
|
||||
private static String _prefix = null;
|
||||
public static String buildIdentifier (String handle) {
|
||||
if (_prefix == null)
|
||||
{
|
||||
|
||||
public static String buildIdentifier(String handle) {
|
||||
if (_prefix == null) {
|
||||
_prefix = ConfigurationManager.getProperty("oai",
|
||||
"identifier.prefix");
|
||||
"identifier.prefix");
|
||||
}
|
||||
return "oai:" + _prefix + ":" + handle;
|
||||
}
|
||||
public static String parseHandle (String oaiIdentifier) {
|
||||
String[] parts = oaiIdentifier.split(Pattern.quote(":"));
|
||||
if (parts.length > 0) return parts[parts.length - 1];
|
||||
else return null; // Contract
|
||||
|
||||
public static String parseHandle(String oaiIdentifier) {
|
||||
String[] parts = oaiIdentifier.split(Pattern.quote(":"));
|
||||
if (parts.length > 0) {
|
||||
return parts[parts.length - 1];
|
||||
} else {
|
||||
return null; // Contract
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getMetadata(String field)
|
||||
{
|
||||
|
||||
public List<String> getMetadata(String field) {
|
||||
String[] parts = field.split(Pattern.quote("."));
|
||||
if (parts.length == 2) return this.getMetadata(parts[0], parts[1]);
|
||||
else if (parts.length == 3) return this.getMetadata(parts[0], parts[1], parts[2]);
|
||||
else return new ArrayList<String>();
|
||||
if (parts.length == 2) {
|
||||
return this.getMetadata(parts[0], parts[1]);
|
||||
} else if (parts.length == 3) {
|
||||
return this.getMetadata(parts[0], parts[1], parts[2]);
|
||||
} else {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<About> getAbout()
|
||||
{
|
||||
return new ArrayList<About>();
|
||||
}
|
||||
|
||||
protected abstract String getHandle ();
|
||||
|
||||
@Override
|
||||
public String getIdentifier()
|
||||
{
|
||||
return buildIdentifier(getHandle());
|
||||
public List<About> getAbout() {
|
||||
return new ArrayList<About>();
|
||||
}
|
||||
|
||||
protected abstract String getHandle();
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return buildIdentifier(getHandle());
|
||||
}
|
||||
|
||||
private static class MetadataNamePredicate implements Predicate<Element> {
|
||||
private String name;
|
||||
|
||||
public MetadataNamePredicate (String n) {
|
||||
public MetadataNamePredicate(String n) {
|
||||
name = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Element arg0) {
|
||||
if (name == null) return false;
|
||||
else if (name.equals(org.dspace.content.Item.ANY)) return true;
|
||||
else return (name.toLowerCase().equals(arg0.getName().toLowerCase()));
|
||||
if (name == null) {
|
||||
return false;
|
||||
} else if (name.equals(org.dspace.content.Item.ANY)) {
|
||||
return true;
|
||||
} else {
|
||||
return (name.toLowerCase().equals(arg0.getName().toLowerCase()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,38 +7,37 @@
|
||||
*/
|
||||
package org.dspace.xoai.data;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSet extends Set {
|
||||
private static final String DefaultName = "undefined";
|
||||
private static final String DefaultName = "undefined";
|
||||
|
||||
public static String checkName(String name) {
|
||||
if (name != null && !name.trim().equals(""))
|
||||
return name;
|
||||
return DefaultName;
|
||||
}
|
||||
public static String checkName(String name) {
|
||||
if (name != null && !name.trim().equals("")) {
|
||||
return name;
|
||||
}
|
||||
return DefaultName;
|
||||
}
|
||||
|
||||
public static Set newDSpaceCommunitySet(String handle, String name) {
|
||||
public static Set newDSpaceCommunitySet(String handle, String name) {
|
||||
|
||||
return new Set("com_" + handle.replace('/', '_'), checkName(name));
|
||||
}
|
||||
return new Set("com_" + handle.replace('/', '_'), checkName(name));
|
||||
}
|
||||
|
||||
public static Set newDSpaceCollectionSet(String handle, String name) {
|
||||
return new Set("col_" + handle.replace('/', '_'), checkName(name));
|
||||
}
|
||||
public static Set newDSpaceCollectionSet(String handle, String name) {
|
||||
return new Set("col_" + handle.replace('/', '_'), checkName(name));
|
||||
}
|
||||
|
||||
public DSpaceSet(Community c) {
|
||||
super("com_" + c.getHandle().replace('/', '_'), checkName(c.getName()));
|
||||
}
|
||||
public DSpaceSet(Community c) {
|
||||
super("com_" + c.getHandle().replace('/', '_'), checkName(c.getName()));
|
||||
}
|
||||
|
||||
public DSpaceSet(Collection c) {
|
||||
super("col_" + c.getHandle().replace('/', '_'), checkName(c.getName()));
|
||||
}
|
||||
public DSpaceSet(Collection c) {
|
||||
super("col_" + c.getHandle().replace('/', '_'), checkName(c.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -8,26 +8,23 @@
|
||||
package org.dspace.xoai.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ItemMetadata;
|
||||
import com.lyncode.xoai.dataprovider.core.ReferenceSet;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.solr.common.SolrDocument;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ItemMetadata;
|
||||
import com.lyncode.xoai.dataprovider.core.ReferenceSet;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSolrItem extends DSpaceItem
|
||||
{
|
||||
public class DSpaceSolrItem extends DSpaceItem {
|
||||
private static final Logger log = LogManager
|
||||
.getLogger(DSpaceSolrItem.class);
|
||||
|
||||
.getLogger(DSpaceSolrItem.class);
|
||||
|
||||
private final String unparsedMD;
|
||||
private ItemMetadata metadata;
|
||||
private final String handle;
|
||||
@@ -35,8 +32,8 @@ public class DSpaceSolrItem extends DSpaceItem
|
||||
private final List<ReferenceSet> sets;
|
||||
private final boolean deleted;
|
||||
|
||||
public DSpaceSolrItem (SolrDocument doc) {
|
||||
log.debug("Creating OAI Item from Solr source");
|
||||
public DSpaceSolrItem(SolrDocument doc) {
|
||||
log.debug("Creating OAI Item from Solr source");
|
||||
unparsedMD = (String) doc.getFieldValue("item.compile");
|
||||
handle = (String) doc.getFieldValue("item.handle");
|
||||
lastMod = (Date) doc.getFieldValue("item.lastmodified");
|
||||
@@ -45,21 +42,24 @@ public class DSpaceSolrItem extends DSpaceItem
|
||||
Collection<Object> fieldValues;
|
||||
|
||||
fieldValues = doc.getFieldValues("item.communities");
|
||||
if (null != fieldValues)
|
||||
for (Object obj : fieldValues)
|
||||
if (null != fieldValues) {
|
||||
for (Object obj : fieldValues) {
|
||||
sets.add(new ReferenceSet((String) obj));
|
||||
}
|
||||
}
|
||||
|
||||
fieldValues = doc.getFieldValues("item.collections");
|
||||
if (null != fieldValues)
|
||||
for (Object obj : fieldValues)
|
||||
if (null != fieldValues) {
|
||||
for (Object obj : fieldValues) {
|
||||
sets.add(new ReferenceSet((String) obj));
|
||||
}
|
||||
}
|
||||
|
||||
deleted = (Boolean) doc.getFieldValue("item.deleted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMetadata getMetadata()
|
||||
{
|
||||
public ItemMetadata getMetadata() {
|
||||
if (metadata == null) {
|
||||
metadata = new ItemMetadata(unparsedMD);
|
||||
}
|
||||
@@ -67,26 +67,22 @@ public class DSpaceSolrItem extends DSpaceItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getDatestamp()
|
||||
{
|
||||
public Date getDatestamp() {
|
||||
return lastMod;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ReferenceSet> getSets()
|
||||
{
|
||||
public List<ReferenceSet> getSets() {
|
||||
return sets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeleted()
|
||||
{
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getHandle()
|
||||
{
|
||||
protected String getHandle() {
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@@ -9,29 +9,23 @@ package org.dspace.xoai.exceptions;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class CompilingException extends Exception
|
||||
{
|
||||
public class CompilingException extends Exception {
|
||||
|
||||
public CompilingException()
|
||||
{
|
||||
public CompilingException() {
|
||||
}
|
||||
|
||||
public CompilingException(String arg0)
|
||||
{
|
||||
public CompilingException(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public CompilingException(Throwable arg0)
|
||||
{
|
||||
public CompilingException(Throwable arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public CompilingException(String arg0, Throwable arg1)
|
||||
{
|
||||
public CompilingException(String arg0, Throwable arg1) {
|
||||
super(arg0, arg1);
|
||||
}
|
||||
|
||||
|
@@ -8,11 +8,9 @@
|
||||
package org.dspace.xoai.exceptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class InvalidMetadataFieldException extends Exception
|
||||
{
|
||||
public class InvalidMetadataFieldException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5187555092904394914L;
|
||||
|
||||
|
@@ -22,7 +22,8 @@ public class AndFilter extends DSpaceFilter {
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
return new SolrFilterResult("("+left.buildSolrQuery().getQuery()+") AND ("+right.buildSolrQuery().getQuery()+")");
|
||||
return new SolrFilterResult(
|
||||
"(" + left.buildSolrQuery().getQuery() + ") AND (" + right.buildSolrQuery().getQuery() + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -11,6 +11,11 @@ package org.dspace.xoai.filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.lyncode.builder.ListBuilder;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterList;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterValue;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.SimpleType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -19,12 +24,6 @@ import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.data.DSpaceMetadataFilterOperator;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.lyncode.builder.ListBuilder;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterList;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterValue;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.SimpleType;
|
||||
|
||||
/**
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@@ -45,72 +44,87 @@ public class DSpaceAtLeastOneMetadataFilter extends DSpaceFilter {
|
||||
private List<String> getValues() {
|
||||
if (values == null) {
|
||||
ParameterValue parameterValue = getConfiguration().get("value");
|
||||
if (parameterValue == null) parameterValue = getConfiguration().get("values");
|
||||
if (parameterValue == null) {
|
||||
parameterValue = getConfiguration().get("values");
|
||||
}
|
||||
|
||||
if (parameterValue instanceof SimpleType) {
|
||||
values = new ArrayList<>();
|
||||
values.add(((SimpleType) parameterValue).asString());
|
||||
} else if (parameterValue instanceof ParameterList) {
|
||||
values = new ListBuilder<ParameterValue>()
|
||||
.add(parameterValue.asParameterList().getValues())
|
||||
.build(new Function<ParameterValue, String>() {
|
||||
@Override
|
||||
public String apply(ParameterValue elem) {
|
||||
return elem.asSimpleType().asString();
|
||||
}
|
||||
});
|
||||
} else values = new ArrayList<>();
|
||||
.add(parameterValue.asParameterList().getValues())
|
||||
.build(new Function<ParameterValue, String>() {
|
||||
@Override
|
||||
public String apply(ParameterValue elem) {
|
||||
return elem.asSimpleType().asString();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
values = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
private DSpaceMetadataFilterOperator getOperator() {
|
||||
if (operator == DSpaceMetadataFilterOperator.UNDEF)
|
||||
if (operator == DSpaceMetadataFilterOperator.UNDEF) {
|
||||
operator = DSpaceMetadataFilterOperator.valueOf(getConfiguration()
|
||||
.get("operator").asSimpleType().asString().toUpperCase());
|
||||
.get("operator").asSimpleType().asString()
|
||||
.toUpperCase());
|
||||
}
|
||||
return operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
if (this.getField() == null)
|
||||
if (this.getField() == null) {
|
||||
return true;
|
||||
}
|
||||
List<String> values = item.getMetadata(this.getField());
|
||||
for (String praticalValue : values) {
|
||||
for (String theoreticValue : this.getValues()) {
|
||||
switch (this.getOperator()) {
|
||||
case STARTS_WITH:
|
||||
if (praticalValue.startsWith(theoreticValue))
|
||||
if (praticalValue.startsWith(theoreticValue)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case ENDS_WITH:
|
||||
if (praticalValue.endsWith(theoreticValue))
|
||||
if (praticalValue.endsWith(theoreticValue)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case EQUAL:
|
||||
if (praticalValue.equals(theoreticValue))
|
||||
if (praticalValue.equals(theoreticValue)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GREATER:
|
||||
if (praticalValue.compareTo(theoreticValue) > 0)
|
||||
if (praticalValue.compareTo(theoreticValue) > 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case GREATER_OR_EQUAL:
|
||||
if (praticalValue.compareTo(theoreticValue) >= 0)
|
||||
if (praticalValue.compareTo(theoreticValue) >= 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LOWER:
|
||||
if (praticalValue.compareTo(theoreticValue) < 0)
|
||||
if (praticalValue.compareTo(theoreticValue) < 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case LOWER_OR_EQUAL:
|
||||
if (praticalValue.compareTo(theoreticValue) <= 0)
|
||||
if (praticalValue.compareTo(theoreticValue) <= 0) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case CONTAINS:
|
||||
default:
|
||||
if (praticalValue.contains(theoreticValue))
|
||||
if (praticalValue.contains(theoreticValue)) {
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -123,12 +137,13 @@ public class DSpaceAtLeastOneMetadataFilter extends DSpaceFilter {
|
||||
String field = this.getField();
|
||||
List<String> parts = new ArrayList<>();
|
||||
if (this.getField() != null) {
|
||||
for (String v : this.getValues())
|
||||
for (String v : this.getValues()) {
|
||||
this.buildQuery("metadata." + field,
|
||||
ClientUtils.escapeQueryChars(v), parts);
|
||||
ClientUtils.escapeQueryChars(v), parts);
|
||||
}
|
||||
if (parts.size() > 0) {
|
||||
return new SolrFilterResult(StringUtils.join(parts.iterator(),
|
||||
" OR "));
|
||||
" OR "));
|
||||
}
|
||||
}
|
||||
return new SolrFilterResult();
|
||||
|
@@ -22,46 +22,41 @@ import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceAuthorizationFilter extends DSpaceFilter
|
||||
{
|
||||
public class DSpaceAuthorizationFilter extends DSpaceFilter {
|
||||
private static final Logger log = LogManager.getLogger(DSpaceAuthorizationFilter.class);
|
||||
|
||||
private static final AuthorizeService authorizeService
|
||||
= AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
= AuthorizeServiceFactory.getInstance().getAuthorizeService();
|
||||
|
||||
private static final HandleService handleService
|
||||
= HandleServiceFactory.getInstance().getHandleService();
|
||||
= HandleServiceFactory.getInstance().getHandleService();
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item)
|
||||
{
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
boolean pub = false;
|
||||
try
|
||||
{
|
||||
try {
|
||||
// If Handle or Item are not found, return false
|
||||
String handle = DSpaceItem.parseHandle(item.getIdentifier());
|
||||
if (handle == null)
|
||||
if (handle == null) {
|
||||
return false;
|
||||
}
|
||||
Item dspaceItem = (Item) handleService.resolveToObject(context, handle);
|
||||
if (dspaceItem == null)
|
||||
if (dspaceItem == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if READ access allowed on Item
|
||||
pub = authorizeService.authorizeActionBoolean(context, dspaceItem, Constants.READ);
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
} catch (SQLException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
return pub;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery()
|
||||
{
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
return new SolrFilterResult("item.public:true");
|
||||
}
|
||||
|
||||
|
@@ -10,35 +10,37 @@ package org.dspace.xoai.filter;
|
||||
import com.lyncode.xoai.dataprovider.data.Filter;
|
||||
import com.lyncode.xoai.dataprovider.data.ItemIdentifier;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterMap;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public abstract class DSpaceFilter implements Filter
|
||||
{
|
||||
/** The configuration from xoai.xml file */
|
||||
public abstract class DSpaceFilter implements Filter {
|
||||
/**
|
||||
* The configuration from xoai.xml file
|
||||
*/
|
||||
protected ParameterMap configuration;
|
||||
|
||||
/** The configuration from xoai.xml file */
|
||||
/**
|
||||
* The configuration from xoai.xml file
|
||||
*/
|
||||
protected FieldResolver fieldResolver;
|
||||
|
||||
/** The oai context */
|
||||
/**
|
||||
* The oai context
|
||||
*/
|
||||
protected Context context;
|
||||
|
||||
public abstract SolrFilterResult buildSolrQuery();
|
||||
|
||||
public abstract boolean isShown(DSpaceItem item);
|
||||
|
||||
@Override
|
||||
public boolean isItemShown(ItemIdentifier item)
|
||||
{
|
||||
if (item instanceof DSpaceItem)
|
||||
{
|
||||
public boolean isItemShown(ItemIdentifier item) {
|
||||
if (item instanceof DSpaceItem) {
|
||||
return isShown((DSpaceItem) item);
|
||||
}
|
||||
return false;
|
||||
@@ -47,51 +49,42 @@ public abstract class DSpaceFilter implements Filter
|
||||
/**
|
||||
* @return the configuration map if defined in xoai.xml, otherwise null.
|
||||
*/
|
||||
public ParameterMap getConfiguration()
|
||||
{
|
||||
public ParameterMap getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param configuration
|
||||
* the configuration map to set
|
||||
* @param configuration the configuration map to set
|
||||
*/
|
||||
public void setConfiguration(ParameterMap configuration)
|
||||
{
|
||||
public void setConfiguration(ParameterMap configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the fieldResolver
|
||||
*/
|
||||
public FieldResolver getFieldResolver()
|
||||
{
|
||||
public FieldResolver getFieldResolver() {
|
||||
return fieldResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fieldResolver
|
||||
* the fieldResolver to set
|
||||
* @param fieldResolver the fieldResolver to set
|
||||
*/
|
||||
public void setFieldResolver(FieldResolver fieldResolver)
|
||||
{
|
||||
public void setFieldResolver(FieldResolver fieldResolver) {
|
||||
this.fieldResolver = fieldResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the context
|
||||
*/
|
||||
public Context getContext()
|
||||
{
|
||||
public Context getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param context
|
||||
* the context to set
|
||||
* @param context the context to set
|
||||
*/
|
||||
public void setContext(Context context)
|
||||
{
|
||||
public void setContext(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
|
@@ -10,14 +10,13 @@ package org.dspace.xoai.filter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterValue;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.SimpleType;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterValue;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.SimpleType;
|
||||
|
||||
/**
|
||||
* This filter allows one to retrieve (from the data source) those items
|
||||
* which contains at least one metadata field value defined, it allows
|
||||
@@ -30,22 +29,25 @@ import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.SimpleType;
|
||||
*/
|
||||
public class DSpaceMetadataExistsFilter extends DSpaceFilter {
|
||||
private static final Logger log = LogManager
|
||||
.getLogger(DSpaceMetadataExistsFilter.class);
|
||||
.getLogger(DSpaceMetadataExistsFilter.class);
|
||||
|
||||
private List<String> fields;
|
||||
|
||||
private List<String> getFields() {
|
||||
if (this.fields == null) {
|
||||
ParameterValue fields = getConfiguration().get("fields");
|
||||
if (fields == null) fields = getConfiguration().get("field");
|
||||
if (fields == null) {
|
||||
fields = getConfiguration().get("field");
|
||||
}
|
||||
|
||||
if (fields instanceof SimpleType) {
|
||||
this.fields = new ArrayList<String>();
|
||||
this.fields.add(((SimpleType) fields).asString());
|
||||
} else {
|
||||
this.fields = new ArrayList<String>();
|
||||
for (ParameterValue val : fields.asParameterList().getValues())
|
||||
for (ParameterValue val : fields.asParameterList().getValues()) {
|
||||
this.fields.add(val.asSimpleType().asString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,8 +58,9 @@ public class DSpaceMetadataExistsFilter extends DSpaceFilter {
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
for (String field : this.getFields()) {
|
||||
//do we have a match? if yes, our job is done
|
||||
if (item.getMetadata(field).size() > 0)
|
||||
if (item.getMetadata(field).size() > 0) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -68,8 +71,9 @@ public class DSpaceMetadataExistsFilter extends DSpaceFilter {
|
||||
List<String> fields = this.getFields();
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
cond.append("metadata.").append(fields.get(i)).append(":[* TO *]");
|
||||
if (i < fields.size() - 1)
|
||||
if (i < fields.size() - 1) {
|
||||
cond.append(" OR ");
|
||||
}
|
||||
}
|
||||
cond.append(")");
|
||||
|
||||
|
@@ -18,57 +18,45 @@ import org.dspace.xoai.services.api.HandleResolver;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSetSpecFilter extends DSpaceFilter
|
||||
{
|
||||
public class DSpaceSetSpecFilter extends DSpaceFilter {
|
||||
private static final Logger log = LogManager.getLogger(DSpaceSetSpecFilter.class);
|
||||
|
||||
private final String setSpec;
|
||||
private final HandleResolver handleResolver;
|
||||
private final CollectionsService collectionsService;
|
||||
|
||||
public DSpaceSetSpecFilter(CollectionsService collectionsService, HandleResolver handleResolver, String spec)
|
||||
{
|
||||
public DSpaceSetSpecFilter(CollectionsService collectionsService, HandleResolver handleResolver, String spec) {
|
||||
this.collectionsService = collectionsService;
|
||||
this.handleResolver = handleResolver;
|
||||
this.setSpec = spec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item)
|
||||
{
|
||||
for (ReferenceSet s : item.getSets())
|
||||
if (s.getSetSpec().equals(setSpec))
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
for (ReferenceSet s : item.getSets()) {
|
||||
if (s.getSetSpec().equals(setSpec)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery()
|
||||
{
|
||||
if (setSpec.startsWith("col_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
if (setSpec.startsWith("col_")) {
|
||||
try {
|
||||
return new SolrFilterResult("item.collections:"
|
||||
+ ClientUtils.escapeQueryChars(setSpec));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
+ ClientUtils.escapeQueryChars(setSpec));
|
||||
} catch (Exception ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
else if (setSpec.startsWith("com_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
} else if (setSpec.startsWith("com_")) {
|
||||
try {
|
||||
return new SolrFilterResult("item.communities:"
|
||||
+ ClientUtils.escapeQueryChars(setSpec));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
+ ClientUtils.escapeQueryChars(setSpec));
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@@ -18,14 +18,13 @@ import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
* http://www.openarchives.org/OAI/openarchivesprotocol.html#deletion
|
||||
* <P>
|
||||
* (Don't worry, a tombstone doesn't display the withdrawn item's metadata or files.)
|
||||
*
|
||||
*
|
||||
* @author Tim Donohue
|
||||
*/
|
||||
public class DSpaceWithdrawnFilter extends DSpaceFilter {
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item)
|
||||
{
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
// For DSpace, if an Item is withdrawn, "isDeleted()" will be true.
|
||||
// In this scenario, we want a withdrawn item to be *shown* so that
|
||||
// we can properly respond with a "deleted" status via OAI-PMH.
|
||||
@@ -35,8 +34,7 @@ public class DSpaceWithdrawnFilter extends DSpaceFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery()
|
||||
{
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
// In Solr, we store withdrawn items as "deleted".
|
||||
// See org.dspace.xoai.app.XOAI, index(Item) method.
|
||||
return new SolrFilterResult("item.deleted:true");
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.filter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.lyncode.builder.DateBuilder;
|
||||
import com.lyncode.xoai.dataprovider.services.api.DateProvider;
|
||||
import com.lyncode.xoai.dataprovider.services.impl.BaseDateProvider;
|
||||
@@ -14,36 +16,31 @@ import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DateFromFilter extends DSpaceFilter {
|
||||
private static final DateProvider dateProvider = new BaseDateProvider();
|
||||
private final Date date;
|
||||
|
||||
public DateFromFilter(Date date)
|
||||
{
|
||||
public DateFromFilter(Date date) {
|
||||
this.date = new DateBuilder(date).setMinMilliseconds().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item)
|
||||
{
|
||||
if (item.getDatestamp().compareTo(date) >= 0)
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
if (item.getDatestamp().compareTo(date) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery()
|
||||
{
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
String format = dateProvider.format(date).replace("Z", ".000Z"); // Tweak to set the milliseconds
|
||||
return new SolrFilterResult("item.lastmodified:["
|
||||
+ ClientUtils.escapeQueryChars(format)
|
||||
+ " TO *]");
|
||||
+ ClientUtils.escapeQueryChars(format)
|
||||
+ " TO *]");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.filter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.lyncode.builder.DateBuilder;
|
||||
import com.lyncode.xoai.dataprovider.services.api.DateProvider;
|
||||
import com.lyncode.xoai.dataprovider.services.impl.BaseDateProvider;
|
||||
@@ -14,41 +16,34 @@ import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DateUntilFilter extends DSpaceFilter
|
||||
{
|
||||
public class DateUntilFilter extends DSpaceFilter {
|
||||
private static final DateProvider dateProvider = new BaseDateProvider();
|
||||
private final Date date;
|
||||
|
||||
public DateUntilFilter(Date date)
|
||||
{
|
||||
public DateUntilFilter(Date date) {
|
||||
this.date = new DateBuilder(date).setMaxMilliseconds().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShown(DSpaceItem item)
|
||||
{
|
||||
if (item.getDatestamp().compareTo(date) <= 0)
|
||||
public boolean isShown(DSpaceItem item) {
|
||||
if (item.getDatestamp().compareTo(date) <= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery()
|
||||
{
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
String format = dateProvider.format(date).replace("Z", ".999Z"); // Tweak to set the milliseconds
|
||||
// if date has timestamp of 00:00:00, switch it to refer to end of day
|
||||
if (format.substring(11, 19).equals("00:00:00"))
|
||||
{
|
||||
if (format.substring(11, 19).equals("00:00:00")) {
|
||||
format = format.substring(0, 11) + "23:59:59" + format.substring(19);
|
||||
}
|
||||
return new SolrFilterResult("item.lastmodified:[* TO "
|
||||
+ ClientUtils.escapeQueryChars(format) + "]");
|
||||
+ ClientUtils.escapeQueryChars(format) + "]");
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -22,7 +22,8 @@ public class OrFilter extends DSpaceFilter {
|
||||
|
||||
@Override
|
||||
public SolrFilterResult buildSolrQuery() {
|
||||
return new SolrFilterResult("("+left.buildSolrQuery().getQuery()+") OR ("+right.buildSolrQuery().getQuery()+")");
|
||||
return new SolrFilterResult(
|
||||
"(" + left.buildSolrQuery().getQuery() + ") OR (" + right.buildSolrQuery().getQuery() + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -11,35 +11,29 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class SolrFilterResult
|
||||
{
|
||||
private static Logger log = LogManager.getLogger(SolrFilterResult.class);
|
||||
public class SolrFilterResult {
|
||||
private static Logger log = LogManager.getLogger(SolrFilterResult.class);
|
||||
private String _where;
|
||||
|
||||
private boolean _nothing;
|
||||
|
||||
public SolrFilterResult()
|
||||
{
|
||||
public SolrFilterResult() {
|
||||
_nothing = true;
|
||||
}
|
||||
|
||||
public SolrFilterResult(String query)
|
||||
{
|
||||
log.debug("XOAI SolrQuery: "+ query);
|
||||
public SolrFilterResult(String query) {
|
||||
log.debug("XOAI SolrQuery: " + query);
|
||||
_nothing = false;
|
||||
_where = query;
|
||||
}
|
||||
|
||||
public boolean hasResult()
|
||||
{
|
||||
public boolean hasResult() {
|
||||
return !_nothing;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
public String getQuery() {
|
||||
return _where;
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,6 @@
|
||||
package org.dspace.xoai.filter.data;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public enum DSpaceMetadataFilterOperator {
|
||||
|
@@ -11,35 +11,29 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class SolrFilterResult
|
||||
{
|
||||
private static Logger log = LogManager.getLogger(SolrFilterResult.class);
|
||||
public class SolrFilterResult {
|
||||
private static Logger log = LogManager.getLogger(SolrFilterResult.class);
|
||||
private String _where;
|
||||
|
||||
private boolean _nothing;
|
||||
|
||||
public SolrFilterResult()
|
||||
{
|
||||
public SolrFilterResult() {
|
||||
_nothing = true;
|
||||
}
|
||||
|
||||
public SolrFilterResult(String query)
|
||||
{
|
||||
log.debug("XOAI SolrQuery: "+ query);
|
||||
public SolrFilterResult(String query) {
|
||||
log.debug("XOAI SolrQuery: " + query);
|
||||
_nothing = false;
|
||||
_where = query;
|
||||
}
|
||||
|
||||
public boolean hasResult()
|
||||
{
|
||||
public boolean hasResult() {
|
||||
return !_nothing;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
public String getQuery() {
|
||||
return _where;
|
||||
}
|
||||
}
|
||||
|
@@ -7,19 +7,22 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface CollectionsService {
|
||||
List<UUID> getAllSubCollections(ContextService contextService, UUID communityId) throws SQLException;
|
||||
|
||||
List<Community> flatParentCommunities(Collection collection) throws SQLException;
|
||||
|
||||
List<Community> flatParentCommunities(Community community) throws SQLException;
|
||||
|
||||
List<Community> flatParentCommunities(Context context, Item item) throws SQLException;
|
||||
}
|
||||
|
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
|
||||
public interface EarliestDateResolver {
|
||||
public Date getEarliestDate (Context context) throws InvalidMetadataFieldException, SQLException;
|
||||
public Date getEarliestDate(Context context) throws InvalidMetadataFieldException, SQLException;
|
||||
}
|
||||
|
@@ -7,11 +7,11 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public interface FieldResolver {
|
||||
int getFieldID(Context context, String field) throws InvalidMetadataFieldException, SQLException;
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ package org.dspace.xoai.services.api;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
|
||||
public interface HandleResolver {
|
||||
DSpaceObject resolve (String handle) throws HandleResolverException;
|
||||
String getHandle (DSpaceObject object) throws HandleResolverException;
|
||||
DSpaceObject resolve(String handle) throws HandleResolverException;
|
||||
|
||||
String getHandle(DSpaceObject object) throws HandleResolverException;
|
||||
}
|
||||
|
@@ -8,5 +8,5 @@
|
||||
package org.dspace.xoai.services.api;
|
||||
|
||||
public interface ServiceResolver {
|
||||
<T> T getService (Class<T> type);
|
||||
<T> T getService(Class<T> type);
|
||||
}
|
||||
|
@@ -7,17 +7,22 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api.cache;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.oaipmh.OAIPMH;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.oaipmh.OAIPMH;
|
||||
|
||||
|
||||
public interface XOAICacheService {
|
||||
boolean isActive ();
|
||||
boolean hasCache (String requestID);
|
||||
void handle (String requestID, OutputStream out) throws IOException;
|
||||
void store (String requestID, OAIPMH response) throws IOException;
|
||||
void delete (String requestID);
|
||||
void deleteAll () throws IOException;
|
||||
boolean isActive();
|
||||
|
||||
boolean hasCache(String requestID);
|
||||
|
||||
void handle(String requestID, OutputStream out) throws IOException;
|
||||
|
||||
void store(String requestID, OAIPMH response) throws IOException;
|
||||
|
||||
void delete(String requestID);
|
||||
|
||||
void deleteAll() throws IOException;
|
||||
}
|
||||
|
@@ -7,16 +7,20 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api.cache;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Metadata;
|
||||
import org.dspace.content.Item;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public interface XOAIItemCacheService {
|
||||
boolean hasCache (Item item);
|
||||
Metadata get (Item item) throws IOException;
|
||||
void put (Item item, Metadata metadata) throws IOException;
|
||||
void delete (Item item);
|
||||
boolean hasCache(Item item);
|
||||
|
||||
Metadata get(Item item) throws IOException;
|
||||
|
||||
void put(Item item, Metadata metadata) throws IOException;
|
||||
|
||||
void delete(Item item);
|
||||
|
||||
void deleteAll() throws IOException;
|
||||
}
|
||||
|
@@ -12,7 +12,9 @@ import java.util.Date;
|
||||
|
||||
|
||||
public interface XOAILastCompilationCacheService {
|
||||
boolean hasCache ();
|
||||
void put (Date date) throws IOException;
|
||||
Date get () throws IOException;
|
||||
boolean hasCache();
|
||||
|
||||
void put(Date date) throws IOException;
|
||||
|
||||
Date get() throws IOException;
|
||||
}
|
||||
|
@@ -8,7 +8,9 @@
|
||||
package org.dspace.xoai.services.api.config;
|
||||
|
||||
public interface ConfigurationService {
|
||||
String getProperty (String key);
|
||||
String getProperty (String module, String key);
|
||||
String getProperty(String key);
|
||||
|
||||
String getProperty(String module, String key);
|
||||
|
||||
boolean getBooleanProperty(String module, String key, boolean defaultValue);
|
||||
}
|
||||
|
@@ -10,5 +10,5 @@ package org.dspace.xoai.services.api.config;
|
||||
import com.lyncode.xoai.dataprovider.core.XOAIManager;
|
||||
|
||||
public interface XOAIManagerResolver {
|
||||
XOAIManager getManager () throws XOAIManagerResolverException;
|
||||
XOAIManager getManager() throws XOAIManagerResolverException;
|
||||
}
|
||||
|
@@ -8,7 +8,8 @@
|
||||
package org.dspace.xoai.services.api.config;
|
||||
|
||||
public class XOAIManagerResolverException extends Exception {
|
||||
public XOAIManagerResolverException() {}
|
||||
public XOAIManagerResolverException() {
|
||||
}
|
||||
|
||||
public XOAIManagerResolverException(String message) {
|
||||
super(message);
|
||||
|
@@ -14,7 +14,9 @@ import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.xoai.exceptions.InvalidSetSpecException;
|
||||
|
||||
public interface SetSpecResolver {
|
||||
String toSetSpec (Community community) throws InvalidSetSpecException;
|
||||
String toSetSpec (Collection collection) throws InvalidSetSpecException;
|
||||
DSpaceObject fromSetSpec (String setSpec) throws InvalidSetSpecException;
|
||||
String toSetSpec(Community community) throws InvalidSetSpecException;
|
||||
|
||||
String toSetSpec(Collection collection) throws InvalidSetSpecException;
|
||||
|
||||
DSpaceObject fromSetSpec(String setSpec) throws InvalidSetSpecException;
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api.solr;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
|
||||
|
||||
public interface SolrQueryResolver {
|
||||
String buildQuery (List<ScopedFilter> filters);
|
||||
String buildQuery(List<ScopedFilter> filters);
|
||||
}
|
||||
|
@@ -11,5 +11,5 @@ import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
|
||||
public interface SolrServerResolver {
|
||||
SolrServer getServer () throws SolrServerException;
|
||||
SolrServer getServer() throws SolrServerException;
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.api.xoai;
|
||||
|
||||
|
||||
import com.lyncode.xoai.dataprovider.filter.Scope;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.Condition;
|
||||
import com.lyncode.xoai.dataprovider.services.api.FilterResolver;
|
||||
|
@@ -11,5 +11,5 @@ import com.lyncode.xoai.dataprovider.services.api.ItemRepository;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
|
||||
public interface ItemRepositoryResolver {
|
||||
ItemRepository getItemRepository () throws ContextServiceException;
|
||||
ItemRepository getItemRepository() throws ContextServiceException;
|
||||
}
|
||||
|
@@ -11,5 +11,5 @@ import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
|
||||
public interface SetRepositoryResolver {
|
||||
SetRepository getSetRepository () throws ContextServiceException;
|
||||
SetRepository getSetRepository() throws ContextServiceException;
|
||||
}
|
||||
|
@@ -7,32 +7,31 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.CommunityService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
|
||||
public class DSpaceCollectionsService implements CollectionsService {
|
||||
|
||||
private static final CommunityService communityService
|
||||
= ContentServiceFactory.getInstance().getCommunityService();
|
||||
= ContentServiceFactory.getInstance().getCommunityService();
|
||||
|
||||
@Override
|
||||
public List<UUID> getAllSubCollections(ContextService contextService, UUID communityId)
|
||||
throws SQLException
|
||||
{
|
||||
throws SQLException {
|
||||
Queue<Community> comqueue = new LinkedList<>();
|
||||
List<UUID> list = new ArrayList<>();
|
||||
try {
|
||||
@@ -40,35 +39,38 @@ public class DSpaceCollectionsService implements CollectionsService {
|
||||
} catch (ContextServiceException e) {
|
||||
throw new SQLException(e);
|
||||
}
|
||||
while (!comqueue.isEmpty())
|
||||
{
|
||||
while (!comqueue.isEmpty()) {
|
||||
Community c = comqueue.poll();
|
||||
for (Community sub : c.getSubcommunities())
|
||||
for (Community sub : c.getSubcommunities()) {
|
||||
comqueue.add(sub);
|
||||
for (Collection col : c.getCollections())
|
||||
if (!list.contains(col.getID()))
|
||||
}
|
||||
for (Collection col : c.getCollections()) {
|
||||
if (!list.contains(col.getID())) {
|
||||
list.add(col.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Community> flatParentCommunities(Collection c)
|
||||
throws SQLException
|
||||
{
|
||||
throws SQLException {
|
||||
Queue<Community> queue = new LinkedList<>();
|
||||
List<Community> result = new ArrayList<>();
|
||||
for (Community com : c.getCommunities())
|
||||
for (Community com : c.getCommunities()) {
|
||||
queue.add(com);
|
||||
}
|
||||
|
||||
while (!queue.isEmpty())
|
||||
{
|
||||
while (!queue.isEmpty()) {
|
||||
Community p = queue.poll();
|
||||
List<Community> par = p.getParentCommunities();
|
||||
if (par != null)
|
||||
if (par != null) {
|
||||
queue.addAll(par);
|
||||
if (!result.contains(p))
|
||||
}
|
||||
if (!result.contains(p)) {
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -76,21 +78,21 @@ public class DSpaceCollectionsService implements CollectionsService {
|
||||
|
||||
@Override
|
||||
public List<Community> flatParentCommunities(Community c)
|
||||
throws SQLException
|
||||
{
|
||||
throws SQLException {
|
||||
Queue<Community> queue = new LinkedList<>();
|
||||
List<Community> result = new ArrayList<>();
|
||||
|
||||
queue.add(c);
|
||||
|
||||
while (!queue.isEmpty())
|
||||
{
|
||||
while (!queue.isEmpty()) {
|
||||
Community p = queue.poll();
|
||||
List<Community> par = p.getParentCommunities();
|
||||
if (par != null)
|
||||
if (par != null) {
|
||||
queue.addAll(par);
|
||||
if (!result.contains(p))
|
||||
}
|
||||
if (!result.contains(p)) {
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -98,22 +100,23 @@ public class DSpaceCollectionsService implements CollectionsService {
|
||||
|
||||
@Override
|
||||
public List<Community> flatParentCommunities(Context context, Item c)
|
||||
throws SQLException
|
||||
{
|
||||
throws SQLException {
|
||||
Queue<Community> queue = new LinkedList<>();
|
||||
List<Community> result = new ArrayList<>();
|
||||
|
||||
for (Collection collection : c.getCollections())
|
||||
for (Collection collection : c.getCollections()) {
|
||||
queue.addAll(communityService.getAllParents(context, collection));
|
||||
}
|
||||
|
||||
while (!queue.isEmpty())
|
||||
{
|
||||
while (!queue.isEmpty()) {
|
||||
Community p = queue.poll();
|
||||
List<Community> par = p.getParentCommunities();
|
||||
if (par != null)
|
||||
if (par != null) {
|
||||
queue.addAll(par);
|
||||
if (!result.contains(p))
|
||||
}
|
||||
if (!result.contains(p)) {
|
||||
result.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -7,8 +7,14 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.MetadataValueService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
@@ -16,12 +22,6 @@ import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.util.DateUtils;
|
||||
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);
|
||||
|
||||
@@ -34,17 +34,15 @@ public class DSpaceEarliestDateResolver implements EarliestDateResolver {
|
||||
|
||||
MetadataValueService metadataValueService = ContentServiceFactory.getInstance().getMetadataValueService();
|
||||
MetadataValue minimum = metadataValueService.getMinimum(context,
|
||||
fieldResolver.getFieldID(context, "dc.date.available"));
|
||||
if (null != minimum)
|
||||
{
|
||||
fieldResolver.getFieldID(context, "dc.date.available"));
|
||||
if (null != minimum) {
|
||||
String str = minimum.getValue();
|
||||
try
|
||||
{
|
||||
try {
|
||||
Date d = DateUtils.parse(str);
|
||||
if (d != null) return d;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (d != null) {
|
||||
return d;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.MetadataFieldService;
|
||||
@@ -14,41 +17,37 @@ import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DSpaceFieldResolver implements FieldResolver {
|
||||
private MetadataFieldCache metadataFieldCache = null;
|
||||
|
||||
private static final MetadataFieldService metadataFieldService
|
||||
= ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||
= ContentServiceFactory.getInstance().getMetadataFieldService();
|
||||
|
||||
@Override
|
||||
public int getFieldID(Context context, String field) throws InvalidMetadataFieldException, SQLException {
|
||||
if (metadataFieldCache == null)
|
||||
if (metadataFieldCache == null) {
|
||||
metadataFieldCache = new MetadataFieldCache();
|
||||
if (!metadataFieldCache.hasField(field))
|
||||
{
|
||||
}
|
||||
if (!metadataFieldCache.hasField(field)) {
|
||||
String[] pieces = field.split(Pattern.quote("."));
|
||||
if (pieces.length > 1)
|
||||
{
|
||||
if (pieces.length > 1) {
|
||||
String schema = pieces[0];
|
||||
String element = pieces[1];
|
||||
String qualifier = null;
|
||||
if (pieces.length > 2)
|
||||
if (pieces.length > 2) {
|
||||
qualifier = pieces[2];
|
||||
}
|
||||
|
||||
MetadataField metadataField = metadataFieldService.findByElement(context, schema, element, qualifier);
|
||||
if (null != metadataField)
|
||||
{
|
||||
if (null != metadataField) {
|
||||
metadataFieldCache.add(field, metadataField.getID());
|
||||
}
|
||||
else
|
||||
} else {
|
||||
throw new InvalidMetadataFieldException();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
} else {
|
||||
throw new InvalidMetadataFieldException();
|
||||
}
|
||||
}
|
||||
return metadataFieldCache.getField(field);
|
||||
}
|
||||
|
@@ -9,13 +9,14 @@ package org.dspace.xoai.services.impl;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.HandleResolverException;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
|
||||
public class DSpaceHandleResolver implements HandleResolver {
|
||||
@Inject
|
||||
@@ -23,8 +24,7 @@ public class DSpaceHandleResolver implements HandleResolver {
|
||||
|
||||
private final HandleService handleService;
|
||||
|
||||
public DSpaceHandleResolver()
|
||||
{
|
||||
public DSpaceHandleResolver() {
|
||||
handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.lyncode.builder.MapBuilder;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import org.dspace.xoai.services.api.ServiceResolver;
|
||||
@@ -14,13 +16,11 @@ import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.impl.config.DSpaceConfigurationService;
|
||||
import org.dspace.xoai.services.impl.resources.DSpaceResourceResolver;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class DSpaceServiceResolver implements ServiceResolver {
|
||||
private Map<String, Object> services = new MapBuilder<String, Object>()
|
||||
.withPair(ConfigurationService.class.getName(), new DSpaceConfigurationService())
|
||||
.withPair(ResourceResolver.class.getName(), new DSpaceResourceResolver())
|
||||
.build();
|
||||
.withPair(ConfigurationService.class.getName(), new DSpaceConfigurationService())
|
||||
.withPair(ResourceResolver.class.getName(), new DSpaceResourceResolver())
|
||||
.build();
|
||||
|
||||
@Override
|
||||
public <T> T getService(Class<T> type) {
|
||||
|
@@ -7,40 +7,34 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class MetadataFieldCache
|
||||
{
|
||||
public class MetadataFieldCache {
|
||||
private static Logger log = LogManager
|
||||
.getLogger(MetadataFieldCache.class);
|
||||
.getLogger(MetadataFieldCache.class);
|
||||
|
||||
private Map<String, Integer> fields;
|
||||
|
||||
public MetadataFieldCache()
|
||||
{
|
||||
public MetadataFieldCache() {
|
||||
fields = new HashMap<String, Integer>();
|
||||
}
|
||||
|
||||
public boolean hasField(String field)
|
||||
{
|
||||
public boolean hasField(String field) {
|
||||
return fields.containsKey(field);
|
||||
}
|
||||
|
||||
public int getField(String field)
|
||||
{
|
||||
public int getField(String field) {
|
||||
return fields.get(field).intValue();
|
||||
}
|
||||
|
||||
public void add(String field, int id)
|
||||
{
|
||||
public void add(String field, int id) {
|
||||
fields.put(field, new Integer(id));
|
||||
}
|
||||
}
|
||||
|
@@ -7,12 +7,12 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.cache;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.oaipmh.OAIPMH;
|
||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.oaipmh.OAIPMH;
|
||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||
|
||||
public class DSpaceEmptyCacheService implements XOAICacheService {
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
|
@@ -7,6 +7,20 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.cache;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.apache.commons.io.FileUtils.deleteDirectory;
|
||||
import static org.apache.commons.io.IOUtils.copy;
|
||||
import static org.apache.commons.io.IOUtils.write;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.XOAIManager;
|
||||
import com.lyncode.xoai.dataprovider.exceptions.WritingXmlException;
|
||||
import com.lyncode.xoai.dataprovider.xml.XmlOutputContext;
|
||||
@@ -19,15 +33,6 @@ import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.util.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.apache.commons.io.FileUtils.deleteDirectory;
|
||||
import static org.apache.commons.io.IOUtils.copy;
|
||||
import static org.apache.commons.io.IOUtils.write;
|
||||
|
||||
|
||||
public class DSpaceXOAICacheService implements XOAICacheService {
|
||||
private static final String REQUEST_DIR = File.separator + "requests";
|
||||
@@ -43,12 +48,15 @@ public class DSpaceXOAICacheService implements XOAICacheService {
|
||||
}
|
||||
|
||||
private static String getStaticHead(XOAIManager manager, Date date) {
|
||||
if (staticHead == null)
|
||||
if (staticHead == null) {
|
||||
staticHead = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
|
||||
+ ((manager.hasStyleSheet()) ? ("<?xml-stylesheet type=\"text/xsl\" href=\""
|
||||
+ manager.getStyleSheet() + "\"?>") : "")
|
||||
+ "<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
|
||||
+ "xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">";
|
||||
+ ((manager.hasStyleSheet()) ? ("<?xml-stylesheet type=\"text/xsl\" href=\""
|
||||
+ manager.getStyleSheet() + "\"?>") : "")
|
||||
+ "<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www" +
|
||||
".w3.org/2001/XMLSchema-instance\" "
|
||||
+ "xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives" +
|
||||
".org/OAI/2.0/OAI-PMH.xsd\">";
|
||||
}
|
||||
|
||||
return staticHead + "<responseDate>" + DateUtils.format(date) + "</responseDate>";
|
||||
}
|
||||
@@ -64,8 +72,9 @@ public class DSpaceXOAICacheService implements XOAICacheService {
|
||||
|
||||
private File getCacheFile(String id) {
|
||||
File dir = new File(getBaseDir());
|
||||
if (!dir.exists())
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String name = File.separator + Base64Utils.encode(id);
|
||||
return new File(getBaseDir() + name);
|
||||
@@ -103,8 +112,9 @@ public class DSpaceXOAICacheService implements XOAICacheService {
|
||||
// Cutting the header (to allow one to change the response time)
|
||||
String end = "</responseDate>";
|
||||
int pos = xoaiResponse.indexOf(end);
|
||||
if (pos > 0)
|
||||
if (pos > 0) {
|
||||
xoaiResponse = xoaiResponse.substring(pos + (end.length()));
|
||||
}
|
||||
|
||||
FileUtils.write(this.getCacheFile(requestID), xoaiResponse);
|
||||
} catch (XMLStreamException e) {
|
||||
|
@@ -7,6 +7,15 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.cache;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.apache.commons.io.FileUtils.deleteDirectory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.exceptions.WritingXmlException;
|
||||
import com.lyncode.xoai.dataprovider.xml.XmlOutputContext;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Metadata;
|
||||
@@ -17,15 +26,6 @@ import org.dspace.xoai.services.api.cache.XOAIItemCacheService;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
import static org.apache.commons.io.FileUtils.deleteDirectory;
|
||||
|
||||
|
||||
public class DSpaceXOAIItemCacheService implements XOAIItemCacheService {
|
||||
private static final String ITEMDIR = File.separator + "items";
|
||||
@@ -35,36 +35,31 @@ public class DSpaceXOAIItemCacheService implements XOAIItemCacheService {
|
||||
|
||||
private String baseDir;
|
||||
|
||||
private String getBaseDir()
|
||||
{
|
||||
if (baseDir == null)
|
||||
private String getBaseDir() {
|
||||
if (baseDir == null) {
|
||||
baseDir = configurationService.getProperty("oai", "cache.dir") + ITEMDIR;
|
||||
}
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
|
||||
private File getMetadataCache(Item item)
|
||||
{
|
||||
private File getMetadataCache(Item item) {
|
||||
File dir = new File(getBaseDir());
|
||||
if (!dir.exists())
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String name = File.separator + item.getHandle().replace('/', '_');
|
||||
return new File(getBaseDir() + name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasCache(Item item) {
|
||||
return getMetadataCache(item).exists();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Metadata get(Item item) throws IOException {
|
||||
System.out.println(FileUtils.readFileToString(getMetadataCache(item)));
|
||||
@@ -76,14 +71,11 @@ public class DSpaceXOAIItemCacheService implements XOAIItemCacheService {
|
||||
throw new IOException(e);
|
||||
}
|
||||
input.close();
|
||||
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void put(Item item, Metadata metadata) throws IOException {
|
||||
FileOutputStream output = new FileOutputStream(getMetadataCache(item));
|
||||
@@ -92,7 +84,7 @@ public class DSpaceXOAIItemCacheService implements XOAIItemCacheService {
|
||||
metadata.write(context);
|
||||
context.getWriter().flush();
|
||||
context.getWriter().close();
|
||||
|
||||
|
||||
output.close();
|
||||
} catch (XMLStreamException e) {
|
||||
throw new IOException(e);
|
||||
|
@@ -7,10 +7,6 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.cache;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.xoai.services.api.cache.XOAILastCompilationCacheService;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
@@ -18,23 +14,25 @@ import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.xoai.services.api.cache.XOAILastCompilationCacheService;
|
||||
|
||||
|
||||
public class DSpaceXOAILastCompilationCacheService implements XOAILastCompilationCacheService {
|
||||
|
||||
private static final ThreadLocal<DateFormat> format = new ThreadLocal<DateFormat>(){
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat();
|
||||
}
|
||||
};
|
||||
private static final ThreadLocal<DateFormat> format = new ThreadLocal<DateFormat>() {
|
||||
@Override
|
||||
protected DateFormat initialValue() {
|
||||
return new SimpleDateFormat();
|
||||
}
|
||||
};
|
||||
private static final String DATEFILE = File.separator + "date.file";
|
||||
|
||||
private static File file = null;
|
||||
|
||||
private static File getFile()
|
||||
{
|
||||
if (file == null)
|
||||
{
|
||||
private static File getFile() {
|
||||
if (file == null) {
|
||||
String dir = ConfigurationManager.getProperty("oai", "cache.dir") + DATEFILE;
|
||||
file = new File(dir);
|
||||
}
|
||||
@@ -48,18 +46,12 @@ public class DSpaceXOAILastCompilationCacheService implements XOAILastCompilatio
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void put(Date date) throws IOException {
|
||||
FileUtils.write(getFile(), format.get().format(date));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Date get() throws IOException {
|
||||
try {
|
||||
|
@@ -17,7 +17,7 @@ public class DSpaceConfigurationService implements ConfigurationService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String module, String key) {
|
||||
public String getProperty(String module, String key) {
|
||||
return ConfigurationManager.getProperty(module, key);
|
||||
}
|
||||
|
||||
|
@@ -7,20 +7,21 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.context;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public class DSpaceContextService implements ContextService {
|
||||
private static final String OAI_CONTEXT = "OAI_CONTEXT";
|
||||
|
||||
@Override
|
||||
public Context getContext() throws ContextServiceException {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
|
||||
.getRequest();
|
||||
Object value = request.getAttribute(OAI_CONTEXT);
|
||||
if (value == null || !(value instanceof Context)) {
|
||||
request.setAttribute(OAI_CONTEXT, new Context());
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.context;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.xml.xoaiconfig.Configuration.readConfiguration;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.XOAIManager;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import org.dspace.xoai.services.api.config.XOAIManagerResolver;
|
||||
@@ -14,12 +16,12 @@ import org.dspace.xoai.services.api.config.XOAIManagerResolverException;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.xml.xoaiconfig.Configuration.readConfiguration;
|
||||
|
||||
public class DSpaceXOAIManagerResolver implements XOAIManagerResolver {
|
||||
public static final String XOAI_CONFIGURATION_FILE = "xoai.xml";
|
||||
@Autowired ResourceResolver resourceResolver;
|
||||
@Autowired DSpaceFilterResolver filterResolver;
|
||||
@Autowired
|
||||
ResourceResolver resourceResolver;
|
||||
@Autowired
|
||||
DSpaceFilterResolver filterResolver;
|
||||
|
||||
private XOAIManager manager;
|
||||
|
||||
@@ -27,7 +29,8 @@ public class DSpaceXOAIManagerResolver implements XOAIManagerResolver {
|
||||
public XOAIManager getManager() throws XOAIManagerResolverException {
|
||||
if (manager == null) {
|
||||
try {
|
||||
manager = new XOAIManager(filterResolver, resourceResolver, readConfiguration(resourceResolver.getResource(XOAI_CONFIGURATION_FILE)));
|
||||
manager = new XOAIManager(filterResolver, resourceResolver,
|
||||
readConfiguration(resourceResolver.getResource(XOAI_CONFIGURATION_FILE)));
|
||||
} catch (Exception e) {
|
||||
throw new XOAIManagerResolverException(e);
|
||||
}
|
||||
|
@@ -11,35 +11,30 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
|
||||
public class DSpaceResourceResolver implements ResourceResolver
|
||||
{
|
||||
public class DSpaceResourceResolver implements ResourceResolver {
|
||||
private static final TransformerFactory transformerFactory = TransformerFactory
|
||||
.newInstance();
|
||||
.newInstance();
|
||||
|
||||
private final String basePath = ConfigurationManager.getProperty("oai",
|
||||
"config.dir");
|
||||
"config.dir");
|
||||
|
||||
@Override
|
||||
public InputStream getResource(String path) throws IOException
|
||||
{
|
||||
public InputStream getResource(String path) throws IOException {
|
||||
return new FileInputStream(new File(basePath, path));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transformer getTransformer(String path) throws IOException,
|
||||
TransformerConfigurationException
|
||||
{
|
||||
TransformerConfigurationException {
|
||||
// construct a Source that reads from an InputStream
|
||||
Source mySrc = new StreamSource(getResource(path));
|
||||
// specify a system ID (the path to the XSLT-file on the filesystem)
|
||||
|
@@ -8,20 +8,20 @@
|
||||
|
||||
package org.dspace.xoai.services.impl.set;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.xoai.exceptions.InvalidSetSpecException;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.HandleResolverException;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.set.SetSpecResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class DSpaceSetSpecResolver implements SetSpecResolver {
|
||||
private static final String HANDLE_PREFIX = "{handle-prefix}";
|
||||
private static final String LOCAL_ID = "{local-id}";
|
||||
@@ -40,7 +40,9 @@ public class DSpaceSetSpecResolver implements SetSpecResolver {
|
||||
public String toSetSpec(Community community) throws InvalidSetSpecException {
|
||||
String handle = community.getHandle();
|
||||
String[] split = handle.split("/");
|
||||
if (split.length != 2) throw new InvalidSetSpecException("Invalid handle "+handle);
|
||||
if (split.length != 2) {
|
||||
throw new InvalidSetSpecException("Invalid handle " + handle);
|
||||
}
|
||||
|
||||
return format(getSetSpecFormat(Community.class), split[0], split[1]);
|
||||
}
|
||||
@@ -49,7 +51,9 @@ public class DSpaceSetSpecResolver implements SetSpecResolver {
|
||||
public String toSetSpec(Collection collection) throws InvalidSetSpecException {
|
||||
String handle = collection.getHandle();
|
||||
String[] split = handle.split("/");
|
||||
if (split.length != 2) throw new InvalidSetSpecException("Invalid handle "+handle);
|
||||
if (split.length != 2) {
|
||||
throw new InvalidSetSpecException("Invalid handle " + handle);
|
||||
}
|
||||
|
||||
return String.format(getSetSpecFormat(Community.class), split[0], split[1]);
|
||||
}
|
||||
@@ -59,12 +63,13 @@ public class DSpaceSetSpecResolver implements SetSpecResolver {
|
||||
String communityPattern = getPattern(Community.class);
|
||||
String collectionPattern = getPattern(Collection.class);
|
||||
String pattern;
|
||||
if (setSpec.matches(communityPattern))
|
||||
if (setSpec.matches(communityPattern)) {
|
||||
pattern = communityPattern;
|
||||
else if (setSpec.matches(collectionPattern))
|
||||
} else if (setSpec.matches(collectionPattern)) {
|
||||
pattern = collectionPattern;
|
||||
else
|
||||
} else {
|
||||
throw new InvalidSetSpecException("Unknown set spec");
|
||||
}
|
||||
|
||||
|
||||
Matcher matcher = Pattern.compile(pattern).matcher(setSpec);
|
||||
@@ -83,11 +88,12 @@ public class DSpaceSetSpecResolver implements SetSpecResolver {
|
||||
}
|
||||
|
||||
private String getPattern(Class<?> clazz) {
|
||||
return "^"+getSetSpecFormat(clazz).replace(HANDLE_PREFIX, "([0-9]+)").replace(LOCAL_ID, "([0-9]+)")+"$";
|
||||
return "^" + getSetSpecFormat(clazz).replace(HANDLE_PREFIX, "([0-9]+)").replace(LOCAL_ID, "([0-9]+)") + "$";
|
||||
}
|
||||
|
||||
private String getSetSpecFormat(Class<?> clazz) {
|
||||
String property = configurationService.getProperty("oai", clazz.getSimpleName().toLowerCase() + ".setSpecFormat");
|
||||
String property = configurationService
|
||||
.getProperty("oai", clazz.getSimpleName().toLowerCase() + ".setSpecFormat");
|
||||
return property == null ? DEFAULT_FORMAT : property;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.solr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.filter.Scope;
|
||||
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.Condition;
|
||||
@@ -15,9 +18,6 @@ import org.dspace.xoai.services.api.solr.SolrQueryResolver;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class DSpaceSolrQueryResolver implements SolrQueryResolver {
|
||||
@Autowired
|
||||
DSpaceFilterResolver filterResolver;
|
||||
@@ -25,18 +25,20 @@ public class DSpaceSolrQueryResolver implements SolrQueryResolver {
|
||||
@Override
|
||||
public String buildQuery(List<ScopedFilter> filters) {
|
||||
List<String> whereCond = new ArrayList<String>();
|
||||
for (ScopedFilter filter : filters)
|
||||
for (ScopedFilter filter : filters) {
|
||||
whereCond.add(buildQuery(filter.getScope(), filter.getCondition()));
|
||||
}
|
||||
|
||||
if (whereCond.isEmpty())
|
||||
if (whereCond.isEmpty()) {
|
||||
whereCond.add("*:*");
|
||||
}
|
||||
String where = "(" + StringUtils.join(whereCond.iterator(), ") AND (") + ")";
|
||||
|
||||
return where;
|
||||
}
|
||||
|
||||
|
||||
private String buildQuery (Scope scope, Condition condition) {
|
||||
private String buildQuery(Scope scope, Condition condition) {
|
||||
return filterResolver.buildSolrQuery(scope, condition);
|
||||
}
|
||||
}
|
||||
|
@@ -24,17 +24,12 @@ public class DSpaceSolrServerResolver implements SolrServerResolver {
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
@Override
|
||||
public SolrServer getServer() throws SolrServerException
|
||||
{
|
||||
if (server == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
public SolrServer getServer() throws SolrServerException {
|
||||
if (server == null) {
|
||||
try {
|
||||
server = new HttpSolrServer(configurationService.getProperty("oai", "solr.url"));
|
||||
log.debug("Solr Server Initialized");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@@ -7,21 +7,28 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.filter.Scope.MetadataFormat;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.data.Filter;
|
||||
import com.lyncode.xoai.dataprovider.filter.Scope;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.*;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.AndCondition;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.Condition;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.CustomCondition;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.NotCondition;
|
||||
import com.lyncode.xoai.dataprovider.filter.conditions.OrCondition;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.parameters.ParameterMap;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.xoai.filter.*;
|
||||
import org.dspace.xoai.filter.AndFilter;
|
||||
import org.dspace.xoai.filter.DSpaceFilter;
|
||||
import org.dspace.xoai.filter.NotFilter;
|
||||
import org.dspace.xoai.filter.OrFilter;
|
||||
import org.dspace.xoai.filter.results.SolrFilterResult;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.filter.Scope.MetadataFormat;
|
||||
|
||||
public class BaseDSpaceFilterResolver implements DSpaceFilterResolver {
|
||||
private static final Logger LOGGER = Logger.getLogger(BaseDSpaceFilterResolver.class);
|
||||
|
||||
@@ -31,11 +38,14 @@ public class BaseDSpaceFilterResolver implements DSpaceFilterResolver {
|
||||
@Autowired
|
||||
ContextService contextService;
|
||||
|
||||
public DSpaceFilter getFilter (Condition condition) {
|
||||
if (condition instanceof AndCondition) return (DSpaceFilter) getFilter((AndCondition) condition);
|
||||
else if (condition instanceof OrCondition) return (DSpaceFilter) getFilter((OrCondition) condition);
|
||||
else if (condition instanceof NotCondition) return (DSpaceFilter) getFilter((NotCondition) condition);
|
||||
else if (condition instanceof CustomCondition) {
|
||||
public DSpaceFilter getFilter(Condition condition) {
|
||||
if (condition instanceof AndCondition) {
|
||||
return (DSpaceFilter) getFilter((AndCondition) condition);
|
||||
} else if (condition instanceof OrCondition) {
|
||||
return (DSpaceFilter) getFilter((OrCondition) condition);
|
||||
} else if (condition instanceof NotCondition) {
|
||||
return (DSpaceFilter) getFilter((NotCondition) condition);
|
||||
} else if (condition instanceof CustomCondition) {
|
||||
CustomCondition customCondition = (CustomCondition) condition;
|
||||
return (DSpaceFilter) customCondition.getFilter();
|
||||
} else {
|
||||
@@ -47,13 +57,13 @@ public class BaseDSpaceFilterResolver implements DSpaceFilterResolver {
|
||||
public String buildSolrQuery(Scope scope, Condition condition) {
|
||||
DSpaceFilter filter = getFilter(condition);
|
||||
SolrFilterResult result = filter.buildSolrQuery();
|
||||
if (result.hasResult())
|
||||
{
|
||||
if (scope == MetadataFormat)
|
||||
if (result.hasResult()) {
|
||||
if (scope == MetadataFormat) {
|
||||
return "(item.deleted:true OR ("
|
||||
+ result.getQuery() + "))";
|
||||
else
|
||||
+ result.getQuery() + "))";
|
||||
} else {
|
||||
return "(" + result.getQuery() + ")";
|
||||
}
|
||||
}
|
||||
return "true";
|
||||
}
|
||||
@@ -61,22 +71,18 @@ public class BaseDSpaceFilterResolver implements DSpaceFilterResolver {
|
||||
@Override
|
||||
public Filter getFilter(Class<? extends Filter> filterClass, ParameterMap configuration) {
|
||||
Filter result = null;
|
||||
try
|
||||
{
|
||||
try {
|
||||
result = filterClass.newInstance();
|
||||
if (result instanceof DSpaceFilter)
|
||||
{
|
||||
if (result instanceof DSpaceFilter) {
|
||||
// add the DSpace filter specific objects
|
||||
((DSpaceFilter) result).setConfiguration(configuration);
|
||||
((DSpaceFilter) result).setContext(contextService.getContext());
|
||||
((DSpaceFilter) result).setFieldResolver(fieldResolver);
|
||||
}
|
||||
}
|
||||
catch (InstantiationException | IllegalAccessException
|
||||
| ContextServiceException e)
|
||||
{
|
||||
} catch (InstantiationException | IllegalAccessException
|
||||
| ContextServiceException e) {
|
||||
LOGGER.error("Filter " + filterClass.getName()
|
||||
+ " could not be instantiated", e);
|
||||
+ " could not be instantiated", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@@ -8,10 +8,10 @@
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.RepositoryConfiguration;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.xoai.IdentifyResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -25,6 +25,7 @@ public class DSpaceIdentifyResolver implements IdentifyResolver {
|
||||
|
||||
@Override
|
||||
public RepositoryConfiguration getIdentify() throws ContextServiceException {
|
||||
return new DSpaceRepositoryConfiguration(earliestDateResolver, configurationService, contextService.getContext());
|
||||
return new DSpaceRepositoryConfiguration(earliestDateResolver, configurationService,
|
||||
contextService.getContext());
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ListItemIdentifiersResult;
|
||||
import com.lyncode.xoai.dataprovider.core.ListItemsResults;
|
||||
import com.lyncode.xoai.dataprovider.data.Filter;
|
||||
@@ -21,15 +24,10 @@ import org.dspace.xoai.filter.DateUntilFilter;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public abstract class DSpaceItemRepository implements ItemRepository
|
||||
{
|
||||
public abstract class DSpaceItemRepository implements ItemRepository {
|
||||
private CollectionsService collectionsService;
|
||||
private HandleResolver handleResolver;
|
||||
|
||||
@@ -40,24 +38,21 @@ public abstract class DSpaceItemRepository implements ItemRepository
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, Date from) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, Date from) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec), Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, Date from, Date until) throws OAIException
|
||||
{
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, Date from, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
@@ -65,67 +60,60 @@ public abstract class DSpaceItemRepository implements ItemRepository
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date from) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date from) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date from, Date until) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date from, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiersUntil(
|
||||
List<ScopedFilter> filters, int offset, int length, Date until) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiersUntil(
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date until) throws OAIException
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length, String setSpec,
|
||||
Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItemIdentifiers(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length, Date from) throws OAIException
|
||||
{
|
||||
int length, Date from) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length, String setSpec) throws OAIException
|
||||
{
|
||||
int length, String setSpec) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length, Date from, Date until) throws OAIException
|
||||
{
|
||||
int length, Date from, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
@@ -133,40 +121,36 @@ public abstract class DSpaceItemRepository implements ItemRepository
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length, String setSpec, Date from) throws OAIException
|
||||
{
|
||||
int length, String setSpec, Date from) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length, String setSpec, Date from, Date until) throws OAIException
|
||||
{
|
||||
int length, String setSpec, Date from, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateFromCondition(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItemsUntil(List<ScopedFilter> filters, int offset,
|
||||
int length, Date until) throws OAIException
|
||||
{
|
||||
int length, Date until) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(until), Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItemsUntil(List<ScopedFilter> filters, int offset,
|
||||
int length, String setSpec, Date from) throws OAIException
|
||||
{
|
||||
int length, String setSpec, Date from) throws OAIException {
|
||||
filters.add(new ScopedFilter(getDateUntilFilter(from), Scope.Query));
|
||||
filters.add(new ScopedFilter(getDSpaceSetSpecFilter(setSpec),
|
||||
Scope.Query));
|
||||
Scope.Query));
|
||||
return this.getItems(filters, offset, length);
|
||||
}
|
||||
|
||||
|
@@ -9,11 +9,11 @@ package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.ItemRepository;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.CollectionsService;
|
||||
import org.dspace.xoai.services.api.HandleResolver;
|
||||
import org.dspace.xoai.services.api.solr.SolrQueryResolver;
|
||||
import org.dspace.xoai.services.api.solr.SolrServerResolver;
|
||||
import org.dspace.xoai.services.api.xoai.ItemRepositoryResolver;
|
||||
@@ -41,10 +41,10 @@ public class DSpaceItemRepositoryResolver implements ItemRepositoryResolver {
|
||||
if (itemRepository == null) {
|
||||
try {
|
||||
itemRepository = new DSpaceItemSolrRepository(
|
||||
solrServerResolver.getServer(),
|
||||
collectionsService,
|
||||
handleResolver,
|
||||
solrQueryResolver);
|
||||
solrServerResolver.getServer(),
|
||||
collectionsService,
|
||||
handleResolver,
|
||||
solrQueryResolver);
|
||||
} catch (SolrServerException e) {
|
||||
throw new ContextServiceException(e.getMessage(), e);
|
||||
}
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.lyncode.builder.ListBuilder;
|
||||
import com.lyncode.xoai.dataprovider.core.ListItemIdentifiersResult;
|
||||
@@ -29,22 +33,16 @@ import org.dspace.xoai.solr.DSpaceSolrSearch;
|
||||
import org.dspace.xoai.solr.exceptions.DSpaceSolrException;
|
||||
import org.dspace.xoai.solr.exceptions.SolrSearchEmptyException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceItemSolrRepository extends DSpaceItemRepository
|
||||
{
|
||||
public class DSpaceItemSolrRepository extends DSpaceItemRepository {
|
||||
private static Logger log = LogManager.getLogger(DSpaceItemSolrRepository.class);
|
||||
private SolrServer server;
|
||||
private SolrQueryResolver solrQueryResolver;
|
||||
|
||||
public DSpaceItemSolrRepository(SolrServer server, CollectionsService collectionsService, HandleResolver handleResolver, SolrQueryResolver solrQueryResolver)
|
||||
{
|
||||
public DSpaceItemSolrRepository(SolrServer server, CollectionsService collectionsService,
|
||||
HandleResolver handleResolver, SolrQueryResolver solrQueryResolver) {
|
||||
super(collectionsService, handleResolver);
|
||||
this.server = server;
|
||||
this.solrQueryResolver = solrQueryResolver;
|
||||
@@ -52,17 +50,15 @@ public class DSpaceItemSolrRepository extends DSpaceItemRepository
|
||||
|
||||
@Override
|
||||
public Item getItem(String identifier) throws IdDoesNotExistException {
|
||||
if (identifier == null) throw new IdDoesNotExistException();
|
||||
if (identifier == null) {
|
||||
throw new IdDoesNotExistException();
|
||||
}
|
||||
String parts[] = identifier.split(Pattern.quote(":"));
|
||||
if (parts.length == 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (parts.length == 3) {
|
||||
try {
|
||||
SolrQuery params = new SolrQuery("item.handle:" + parts[2]);
|
||||
return new DSpaceSolrItem(DSpaceSolrSearch.querySingle(server, params));
|
||||
}
|
||||
catch (SolrSearchEmptyException ex)
|
||||
{
|
||||
} catch (SolrSearchEmptyException ex) {
|
||||
throw new IdDoesNotExistException(ex);
|
||||
}
|
||||
}
|
||||
@@ -71,23 +67,19 @@ public class DSpaceItemSolrRepository extends DSpaceItemRepository
|
||||
|
||||
@Override
|
||||
public ListItemIdentifiersResult getItemIdentifiers(
|
||||
List<ScopedFilter> filters, int offset, int length)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ScopedFilter> filters, int offset, int length) {
|
||||
try {
|
||||
QueryResult queryResult = retrieveItems(filters, offset, length);
|
||||
List<ItemIdentifier> identifierList = new ListBuilder<Item>()
|
||||
.add(queryResult.getResults())
|
||||
.build(new Function<Item, ItemIdentifier>() {
|
||||
@Override
|
||||
public ItemIdentifier apply(Item elem) {
|
||||
return elem;
|
||||
}
|
||||
});
|
||||
.add(queryResult.getResults())
|
||||
.build(new Function<Item, ItemIdentifier>() {
|
||||
@Override
|
||||
public ItemIdentifier apply(Item elem) {
|
||||
return elem;
|
||||
}
|
||||
});
|
||||
return new ListItemIdentifiersResult(queryResult.hasMore(), identifierList, queryResult.getTotal());
|
||||
}
|
||||
catch (DSpaceSolrException ex)
|
||||
{
|
||||
} catch (DSpaceSolrException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
return new ListItemIdentifiersResult(false, new ArrayList<ItemIdentifier>());
|
||||
}
|
||||
@@ -95,29 +87,27 @@ public class DSpaceItemSolrRepository extends DSpaceItemRepository
|
||||
|
||||
@Override
|
||||
public ListItemsResults getItems(List<ScopedFilter> filters, int offset,
|
||||
int length)
|
||||
{
|
||||
try
|
||||
{
|
||||
int length) {
|
||||
try {
|
||||
QueryResult queryResult = retrieveItems(filters, offset, length);
|
||||
return new ListItemsResults(queryResult.hasMore(), queryResult.getResults(), queryResult.getTotal());
|
||||
}
|
||||
catch (DSpaceSolrException ex)
|
||||
{
|
||||
} catch (DSpaceSolrException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
return new ListItemsResults(false, new ArrayList<Item>());
|
||||
}
|
||||
}
|
||||
|
||||
private QueryResult retrieveItems (List<ScopedFilter> filters, int offset, int length) throws DSpaceSolrException {
|
||||
private QueryResult retrieveItems(List<ScopedFilter> filters, int offset, int length) throws DSpaceSolrException {
|
||||
List<Item> list = new ArrayList<Item>();
|
||||
SolrQuery params = new SolrQuery(solrQueryResolver.buildQuery(filters))
|
||||
.setRows(length)
|
||||
.setStart(offset);
|
||||
.setRows(length)
|
||||
.setStart(offset);
|
||||
SolrDocumentList solrDocuments = DSpaceSolrSearch.query(server, params);
|
||||
for (SolrDocument doc : solrDocuments)
|
||||
for (SolrDocument doc : solrDocuments) {
|
||||
list.add(new DSpaceSolrItem(doc));
|
||||
return new QueryResult(list, (solrDocuments.getNumFound() > offset + length), (int) solrDocuments.getNumFound());
|
||||
}
|
||||
return new QueryResult(list, (solrDocuments.getNumFound() > offset + length),
|
||||
(int) solrDocuments.getNumFound());
|
||||
}
|
||||
|
||||
private class QueryResult {
|
||||
|
@@ -7,6 +7,14 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.DeleteMethod;
|
||||
import com.lyncode.xoai.dataprovider.core.Granularity;
|
||||
import com.lyncode.xoai.dataprovider.services.api.RepositoryConfiguration;
|
||||
@@ -15,26 +23,16 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
* @author Domingo Iglesias (diglesias at ub dot edu)
|
||||
*/
|
||||
public class DSpaceRepositoryConfiguration implements RepositoryConfiguration
|
||||
{
|
||||
public class DSpaceRepositoryConfiguration implements RepositoryConfiguration {
|
||||
private static Logger log = LogManager.getLogger(DSpaceRepositoryConfiguration.class);
|
||||
|
||||
private List<String> emails = null;
|
||||
@@ -44,126 +42,120 @@ public class DSpaceRepositoryConfiguration implements RepositoryConfiguration
|
||||
private EarliestDateResolver dateResolver;
|
||||
private ConfigurationService configurationService;
|
||||
|
||||
public DSpaceRepositoryConfiguration(EarliestDateResolver dateResolver, ConfigurationService configurationService, Context context)
|
||||
{
|
||||
public DSpaceRepositoryConfiguration(EarliestDateResolver dateResolver, ConfigurationService configurationService,
|
||||
Context context) {
|
||||
this.dateResolver = dateResolver;
|
||||
this.configurationService = configurationService;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAdminEmails()
|
||||
{
|
||||
if (emails == null)
|
||||
{
|
||||
public List<String> getAdminEmails() {
|
||||
if (emails == null) {
|
||||
emails = new ArrayList<String>();
|
||||
String result = configurationService.getProperty("mail.admin");
|
||||
if (result == null)
|
||||
{
|
||||
log.warn("{ OAI 2.0 :: DSpace } Not able to retrieve the mail.admin property from the configuration file");
|
||||
}
|
||||
else
|
||||
if (result == null) {
|
||||
log.warn(
|
||||
"{ OAI 2.0 :: DSpace } Not able to retrieve the mail.admin property from the configuration file");
|
||||
} else {
|
||||
emails.add(result);
|
||||
}
|
||||
}
|
||||
return emails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseUrl()
|
||||
{
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
|
||||
if (baseUrl == null)
|
||||
{
|
||||
public String getBaseUrl() {
|
||||
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
|
||||
.getRequest();
|
||||
if (baseUrl == null) {
|
||||
baseUrl = configurationService.getProperty("oai.url");
|
||||
if (baseUrl == null) {
|
||||
log.warn("{ OAI 2.0 :: DSpace } Not able to retrieve the oai.url property from oai.cfg. Falling back to request address");
|
||||
log.warn(
|
||||
"{ OAI 2.0 :: DSpace } Not able to retrieve the oai.url property from oai.cfg. Falling back to " +
|
||||
"request address");
|
||||
baseUrl = request.getRequestURL().toString()
|
||||
.replace(request.getPathInfo(), "");
|
||||
.replace(request.getPathInfo(), "");
|
||||
}
|
||||
}
|
||||
return baseUrl + request.getPathInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteMethod getDeleteMethod()
|
||||
{
|
||||
public DeleteMethod getDeleteMethod() {
|
||||
return DeleteMethod.TRANSIENT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getEarliestDate()
|
||||
{
|
||||
public Date getEarliestDate() {
|
||||
// Look at the database!
|
||||
try
|
||||
{
|
||||
try {
|
||||
return dateResolver.getEarliestDate(context);
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
catch (InvalidMetadataFieldException e)
|
||||
{
|
||||
} catch (InvalidMetadataFieldException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return new Date();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Granularity getGranularity()
|
||||
{
|
||||
public Granularity getGranularity() {
|
||||
return Granularity.Second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRepositoryName()
|
||||
{
|
||||
if (name == null)
|
||||
{
|
||||
public String getRepositoryName() {
|
||||
if (name == null) {
|
||||
name = configurationService.getProperty("dspace.name");
|
||||
if (name == null)
|
||||
{
|
||||
log.warn("{ OAI 2.0 :: DSpace } Not able to retrieve the dspace.name property from the configuration file");
|
||||
if (name == null) {
|
||||
log.warn(
|
||||
"{ OAI 2.0 :: DSpace } Not able to retrieve the dspace.name property from the configuration file");
|
||||
name = "OAI Repository";
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
List<String> result = new ArrayList<String>();
|
||||
String descriptionFile = configurationService.getProperty("oai", "description.file");
|
||||
if (descriptionFile == null) {
|
||||
// Try indexed
|
||||
boolean stop = false;
|
||||
List<String> descriptionFiles = new ArrayList<String>();
|
||||
for (int i=0;!stop;i++) {
|
||||
String tmp = configurationService.getProperty("oai", "description.file."+i);
|
||||
if (tmp == null) stop = true;
|
||||
else descriptionFiles.add(tmp);
|
||||
}
|
||||
|
||||
for (String path : descriptionFiles) {
|
||||
try {
|
||||
File f = new File(path);
|
||||
if (f.exists())
|
||||
result.add(FileUtils.readFileToString(f));
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
File f = new File(descriptionFile);
|
||||
if (f.exists())
|
||||
result.add(FileUtils.readFileToString(f));
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public List<String> getDescription() {
|
||||
List<String> result = new ArrayList<String>();
|
||||
String descriptionFile = configurationService.getProperty("oai", "description.file");
|
||||
if (descriptionFile == null) {
|
||||
// Try indexed
|
||||
boolean stop = false;
|
||||
List<String> descriptionFiles = new ArrayList<String>();
|
||||
for (int i = 0; !stop; i++) {
|
||||
String tmp = configurationService.getProperty("oai", "description.file." + i);
|
||||
if (tmp == null) {
|
||||
stop = true;
|
||||
} else {
|
||||
descriptionFiles.add(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
for (String path : descriptionFiles) {
|
||||
try {
|
||||
File f = new File(path);
|
||||
if (f.exists()) {
|
||||
result.add(FileUtils.readFileToString(f));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
try {
|
||||
File f = new File(descriptionFile);
|
||||
if (f.exists()) {
|
||||
result.add(FileUtils.readFileToString(f));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -7,6 +7,8 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ResumptionToken;
|
||||
import com.lyncode.xoai.dataprovider.exceptions.BadResumptionToken;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResumptionTokenFormatter;
|
||||
@@ -14,12 +16,10 @@ import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.xoai.util.DateUtils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class DSpaceResumptionTokenFormatter implements ResumptionTokenFormatter {
|
||||
private static Logger log = LogManager
|
||||
.getLogger(DSpaceResumptionTokenFormatter.class);
|
||||
.getLogger(DSpaceResumptionTokenFormatter.class);
|
||||
|
||||
public DSpaceResumptionTokenFormatter() {
|
||||
// TODO Auto-generated constructor stub
|
||||
@@ -27,10 +27,13 @@ public class DSpaceResumptionTokenFormatter implements ResumptionTokenFormatter
|
||||
|
||||
@Override
|
||||
public ResumptionToken parse(String resumptionToken) throws BadResumptionToken {
|
||||
if (resumptionToken == null) return new ResumptionToken();
|
||||
if (resumptionToken == null) {
|
||||
return new ResumptionToken();
|
||||
}
|
||||
String[] res = resumptionToken.split("/", -1);
|
||||
if (res.length != 5) throw new BadResumptionToken();
|
||||
else {
|
||||
if (res.length != 5) {
|
||||
throw new BadResumptionToken();
|
||||
} else {
|
||||
try {
|
||||
int offset = Integer.parseInt(res[4]);
|
||||
String prefix = (res[0].equals("")) ? null : res[0];
|
||||
@@ -49,17 +52,21 @@ public class DSpaceResumptionTokenFormatter implements ResumptionTokenFormatter
|
||||
@Override
|
||||
public String format(ResumptionToken resumptionToken) {
|
||||
String result = "";
|
||||
if (resumptionToken.hasMetadataPrefix())
|
||||
if (resumptionToken.hasMetadataPrefix()) {
|
||||
result += resumptionToken.getMetadataPrefix();
|
||||
}
|
||||
result += "/";
|
||||
if (resumptionToken.hasFrom())
|
||||
if (resumptionToken.hasFrom()) {
|
||||
result += DateUtils.format(resumptionToken.getFrom());
|
||||
}
|
||||
result += "/";
|
||||
if (resumptionToken.hasUntil())
|
||||
if (resumptionToken.hasUntil()) {
|
||||
result += DateUtils.format(resumptionToken.getUntil());
|
||||
}
|
||||
result += "/";
|
||||
if (resumptionToken.hasSet())
|
||||
if (resumptionToken.hasSet()) {
|
||||
result += resumptionToken.getSet();
|
||||
}
|
||||
result += "/";
|
||||
result += resumptionToken.getOffset();
|
||||
return result;
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.xoai.services.impl.xoai;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ListSetsResult;
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
@@ -15,24 +19,18 @@ 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.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.core.Context;
|
||||
import org.dspace.handle.factory.HandleServiceFactory;
|
||||
import org.dspace.handle.service.HandleService;
|
||||
import org.dspace.xoai.data.DSpaceSet;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSetRepository implements SetRepository
|
||||
{
|
||||
public class DSpaceSetRepository implements SetRepository {
|
||||
private static final Logger log = LogManager.getLogger(DSpaceSetRepository.class);
|
||||
|
||||
private final Context _context;
|
||||
@@ -41,39 +39,30 @@ public class DSpaceSetRepository implements SetRepository
|
||||
private final CommunityService communityService;
|
||||
private final CollectionService collectionService;
|
||||
|
||||
public DSpaceSetRepository(Context context)
|
||||
{
|
||||
public DSpaceSetRepository(Context context) {
|
||||
_context = context;
|
||||
handleService = HandleServiceFactory.getInstance().getHandleService();
|
||||
communityService = ContentServiceFactory.getInstance().getCommunityService();
|
||||
collectionService = ContentServiceFactory.getInstance().getCollectionService();
|
||||
}
|
||||
|
||||
private int getCommunityCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
private int getCommunityCount() {
|
||||
try {
|
||||
List<Community> communityList = communityService.findAll(_context);
|
||||
|
||||
return communityList.size();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int getCollectionCount()
|
||||
{
|
||||
try
|
||||
{
|
||||
private int getCollectionCount() {
|
||||
try {
|
||||
List<Collection> collectionList = collectionService.findAll(_context);
|
||||
|
||||
return collectionList.size();
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return 0;
|
||||
@@ -87,23 +76,18 @@ public class DSpaceSetRepository implements SetRepository
|
||||
* @param length return up to this many Sets.
|
||||
* @return some Sets representing the Community list segment.
|
||||
*/
|
||||
private List<Set> community(int offset, int length)
|
||||
{
|
||||
private List<Set> community(int offset, int length) {
|
||||
List<Set> array = new ArrayList<Set>();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
List<Community> communityList = communityService.findAll(_context, length, offset);
|
||||
|
||||
for(Community community : communityList)
|
||||
{
|
||||
for (Community community : communityList) {
|
||||
array.add(DSpaceSet.newDSpaceCommunitySet(
|
||||
community.getHandle(),
|
||||
community.getName()));
|
||||
community.getHandle(),
|
||||
community.getName()));
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return array;
|
||||
@@ -117,31 +101,25 @@ public class DSpaceSetRepository implements SetRepository
|
||||
* @param length return up to this many Sets.
|
||||
* @return some Sets representing the Collection list segment.
|
||||
*/
|
||||
private List<Set> collection(int offset, int length)
|
||||
{
|
||||
private List<Set> collection(int offset, int length) {
|
||||
List<Set> array = new ArrayList<Set>();
|
||||
|
||||
try
|
||||
{
|
||||
try {
|
||||
List<Collection> collectionList = collectionService.findAll(_context, length, offset);
|
||||
|
||||
for(Collection collection : collectionList)
|
||||
{
|
||||
for (Collection collection : collectionList) {
|
||||
array.add(DSpaceSet.newDSpaceCollectionSet(
|
||||
collection.getHandle(),
|
||||
collection.getName()));
|
||||
collection.getHandle(),
|
||||
collection.getName()));
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
} catch (SQLException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListSetsResult retrieveSets(int offset, int length)
|
||||
{
|
||||
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<Set>();
|
||||
@@ -150,66 +128,53 @@ public class DSpaceSetRepository implements SetRepository
|
||||
int collectionCount = this.getCollectionCount();
|
||||
log.debug("Collections: " + collectionCount);
|
||||
|
||||
if (offset < communityCount)
|
||||
{
|
||||
if (offset + length > communityCount)
|
||||
{
|
||||
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
|
||||
} else {
|
||||
array.addAll(community(offset, length));
|
||||
}
|
||||
else if (offset < communityCount + collectionCount)
|
||||
{
|
||||
}
|
||||
} else if (offset < communityCount + collectionCount) {
|
||||
array.addAll(collection(offset - communityCount, length));
|
||||
}
|
||||
log.debug("Has More Results: "
|
||||
+ ((offset + length < communityCount + collectionCount) ? "Yes"
|
||||
: "No"));
|
||||
+ ((offset + length < communityCount + collectionCount) ? "Yes"
|
||||
: "No"));
|
||||
return new ListSetsResult(offset + length < communityCount
|
||||
+ collectionCount, array, communityCount + collectionCount);
|
||||
+ collectionCount, array, communityCount + collectionCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportSets()
|
||||
{
|
||||
public boolean supportSets() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String setSpec)
|
||||
{
|
||||
if (setSpec.startsWith("col_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
public boolean exists(String setSpec) {
|
||||
if (setSpec.startsWith("col_")) {
|
||||
try {
|
||||
|
||||
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||
setSpec.replace("col_", "").replace("_", "/"));
|
||||
if (dso == null || !(dso instanceof Collection))
|
||||
setSpec.replace("col_", "").replace("_", "/"));
|
||||
if (dso == null || !(dso instanceof Collection)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
} catch (SQLException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
else if (setSpec.startsWith("com_"))
|
||||
{
|
||||
try
|
||||
{
|
||||
} else if (setSpec.startsWith("com_")) {
|
||||
try {
|
||||
DSpaceObject dso = handleService.resolveToObject(_context,
|
||||
setSpec.replace("com_", "").replace("_", "/"));
|
||||
if (dso == null || !(dso instanceof Community))
|
||||
setSpec.replace("com_", "").replace("_", "/"));
|
||||
if (dso == null || !(dso instanceof Community)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (SQLException ex)
|
||||
{
|
||||
} catch (SQLException ex) {
|
||||
log.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
@@ -19,40 +19,37 @@ import org.dspace.xoai.solr.exceptions.DSpaceSolrException;
|
||||
import org.dspace.xoai.solr.exceptions.SolrSearchEmptyException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSolrSearch
|
||||
{
|
||||
public class DSpaceSolrSearch {
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private DSpaceSolrSearch() { }
|
||||
|
||||
public static SolrDocumentList query(SolrServer server, SolrQuery solrParams)
|
||||
throws DSpaceSolrException
|
||||
{
|
||||
try
|
||||
{
|
||||
throws DSpaceSolrException {
|
||||
try {
|
||||
solrParams.addSortField("item.id", ORDER.asc);
|
||||
QueryResponse response = server.query(solrParams);
|
||||
return response.getResults();
|
||||
}
|
||||
catch (SolrServerException ex)
|
||||
{
|
||||
} catch (SolrServerException ex) {
|
||||
throw new DSpaceSolrException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static SolrDocument querySingle(SolrServer server, SolrQuery solrParams)
|
||||
throws SolrSearchEmptyException
|
||||
{
|
||||
try
|
||||
{
|
||||
throws SolrSearchEmptyException {
|
||||
try {
|
||||
solrParams.addSortField("item.id", ORDER.asc);
|
||||
QueryResponse response = server.query(solrParams);
|
||||
if (response.getResults().getNumFound() > 0)
|
||||
if (response.getResults().getNumFound() > 0) {
|
||||
return response.getResults().get(0);
|
||||
else
|
||||
} else {
|
||||
throw new SolrSearchEmptyException();
|
||||
}
|
||||
catch (SolrServerException ex)
|
||||
{
|
||||
}
|
||||
} catch (SolrServerException ex) {
|
||||
throw new SolrSearchEmptyException(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
@@ -16,27 +16,25 @@ import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DSpaceSolrServer
|
||||
{
|
||||
public class DSpaceSolrServer {
|
||||
private static Logger log = LogManager.getLogger(DSpaceSolrServer.class);
|
||||
|
||||
private static SolrServer _server = null;
|
||||
|
||||
public static SolrServer getServer() throws SolrServerException
|
||||
{
|
||||
if (_server == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private DSpaceSolrServer() { }
|
||||
|
||||
public static SolrServer getServer() throws SolrServerException {
|
||||
if (_server == null) {
|
||||
try {
|
||||
_server = new HttpSolrServer(
|
||||
ConfigurationManager.getProperty("oai", "solr.url"));
|
||||
ConfigurationManager.getProperty("oai", "solr.url"));
|
||||
log.debug("Solr Server Initialized");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@@ -8,35 +8,29 @@
|
||||
package org.dspace.xoai.solr.exceptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DSpaceSolrException extends Exception
|
||||
{
|
||||
public class DSpaceSolrException extends Exception {
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>DSpaceSolrException</code> without detail
|
||||
* message.
|
||||
*/
|
||||
public DSpaceSolrException()
|
||||
{
|
||||
public DSpaceSolrException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>DSpaceSolrException</code> with the
|
||||
* specified detail message.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public DSpaceSolrException(String msg)
|
||||
{
|
||||
public DSpaceSolrException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DSpaceSolrException(String msg, Throwable t)
|
||||
{
|
||||
public DSpaceSolrException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@@ -9,34 +9,28 @@
|
||||
package org.dspace.xoai.solr.exceptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DSpaceSolrIndexerException extends Exception
|
||||
{
|
||||
public class DSpaceSolrIndexerException extends Exception {
|
||||
/**
|
||||
* Creates a new instance of <code>DSpaceSolrException</code> without detail
|
||||
* message.
|
||||
*/
|
||||
public DSpaceSolrIndexerException()
|
||||
{
|
||||
public DSpaceSolrIndexerException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>DSpaceSolrException</code> with the
|
||||
* specified detail message.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public DSpaceSolrIndexerException(String msg)
|
||||
{
|
||||
public DSpaceSolrIndexerException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public DSpaceSolrIndexerException(String msg, Throwable t)
|
||||
{
|
||||
public DSpaceSolrIndexerException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@@ -9,35 +9,29 @@
|
||||
package org.dspace.xoai.solr.exceptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class SolrSearchEmptyException extends Exception
|
||||
{
|
||||
public class SolrSearchEmptyException extends Exception {
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>SolrSearchEmptyException</code> without
|
||||
* detail message.
|
||||
*/
|
||||
public SolrSearchEmptyException()
|
||||
{
|
||||
public SolrSearchEmptyException() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>SolrSearchEmptyException</code> with the
|
||||
* specified detail message.
|
||||
*
|
||||
* @param msg
|
||||
* the detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public SolrSearchEmptyException(String msg)
|
||||
{
|
||||
public SolrSearchEmptyException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SolrSearchEmptyException(String msg, Throwable t)
|
||||
{
|
||||
public SolrSearchEmptyException(String msg, Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@@ -7,24 +7,26 @@
|
||||
*/
|
||||
package org.dspace.xoai.util;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class DateUtils
|
||||
{
|
||||
public class DateUtils {
|
||||
|
||||
private static Logger log = LogManager.getLogger(DateUtils.class);
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private DateUtils() { }
|
||||
|
||||
/**
|
||||
* Format a Date object as a valid UTC Date String, per OAI-PMH guidelines
|
||||
@@ -33,13 +35,12 @@ public class DateUtils
|
||||
* @param date Date object
|
||||
* @return UTC date string
|
||||
*/
|
||||
public static String format(Date date)
|
||||
{
|
||||
public static String format(Date date) {
|
||||
// NOTE: OAI-PMH REQUIRES that all dates be expressed in UTC format
|
||||
// as YYYY-MM-DDThh:mm:ssZ For more details, see
|
||||
// http://www.openarchives.org/OAI/openarchivesprotocol.html#DatestampsResponses
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
// We indicate that the returned date is in UTC so we have
|
||||
// to set the time zone of sdf correctly
|
||||
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
@@ -49,57 +50,42 @@ public class DateUtils
|
||||
|
||||
/**
|
||||
* Parse a string into a Date object
|
||||
*
|
||||
* @param date string to parse
|
||||
* @return Date
|
||||
*/
|
||||
public static Date parse(String date)
|
||||
{
|
||||
public static Date parse(String date) {
|
||||
// First try to parse as a full UTC date/time, e.g. 2008-01-01T00:00:00Z
|
||||
SimpleDateFormat format = new SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date ret;
|
||||
try
|
||||
{
|
||||
try {
|
||||
ret = format.parse(date);
|
||||
return ret;
|
||||
}
|
||||
catch (ParseException ex)
|
||||
{
|
||||
} catch (ParseException ex) {
|
||||
// If a parse exception, try other logical date/time formats
|
||||
// based on the local timezone
|
||||
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
|
||||
Locale.getDefault());
|
||||
try
|
||||
{
|
||||
Locale.getDefault());
|
||||
try {
|
||||
return format.parse(date);
|
||||
}
|
||||
catch (ParseException e1)
|
||||
{
|
||||
} catch (ParseException e1) {
|
||||
format = new SimpleDateFormat("yyyy-MM-dd",
|
||||
Locale.getDefault());
|
||||
try
|
||||
{
|
||||
Locale.getDefault());
|
||||
try {
|
||||
return format.parse(date);
|
||||
}
|
||||
catch (ParseException e2)
|
||||
{
|
||||
} catch (ParseException e2) {
|
||||
format = new SimpleDateFormat("yyyy-MM",
|
||||
Locale.getDefault());
|
||||
try
|
||||
{
|
||||
Locale.getDefault());
|
||||
try {
|
||||
return format.parse(date);
|
||||
}
|
||||
catch (ParseException e3)
|
||||
{
|
||||
} catch (ParseException e3) {
|
||||
format = new SimpleDateFormat("yyyy",
|
||||
Locale.getDefault());
|
||||
try
|
||||
{
|
||||
Locale.getDefault());
|
||||
try {
|
||||
return format.parse(date);
|
||||
}
|
||||
catch (ParseException e4)
|
||||
{
|
||||
} catch (ParseException e4) {
|
||||
log.error(e4.getMessage(), e4);
|
||||
}
|
||||
}
|
||||
@@ -109,19 +95,15 @@ public class DateUtils
|
||||
return new Date();
|
||||
}
|
||||
|
||||
public static Date parseFromSolrDate(String date)
|
||||
{
|
||||
public static Date parseFromSolrDate(String date) {
|
||||
SimpleDateFormat format = new SimpleDateFormat(
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
"yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
Date ret;
|
||||
try
|
||||
{
|
||||
try {
|
||||
ret = format.parse(date);
|
||||
return ret;
|
||||
}
|
||||
catch (ParseException e)
|
||||
{
|
||||
} catch (ParseException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return new Date();
|
||||
|
@@ -7,123 +7,124 @@
|
||||
*/
|
||||
package org.dspace.xoai.util;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Element;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Metadata;
|
||||
import com.lyncode.xoai.util.Base64Utils;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.content.authority.Choices;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Utils;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Element;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoai.Metadata;
|
||||
import com.lyncode.xoai.util.Base64Utils;
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.factory.UtilServiceFactory;
|
||||
import org.dspace.app.util.service.MetadataExposureService;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataField;
|
||||
import org.dspace.content.MetadataValue;
|
||||
import org.dspace.content.authority.Choices;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.BitstreamService;
|
||||
import org.dspace.content.service.ItemService;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Constants;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.Utils;
|
||||
import org.dspace.xoai.data.DSpaceItem;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ItemUtils
|
||||
{
|
||||
public class ItemUtils {
|
||||
private static final Logger log = LogManager.getLogger(ItemUtils.class);
|
||||
|
||||
|
||||
private static final MetadataExposureService metadataExposureService
|
||||
= UtilServiceFactory.getInstance().getMetadataExposureService();
|
||||
= UtilServiceFactory.getInstance().getMetadataExposureService();
|
||||
|
||||
private static final ItemService itemService
|
||||
= ContentServiceFactory.getInstance().getItemService();
|
||||
= ContentServiceFactory.getInstance().getItemService();
|
||||
|
||||
private static final BitstreamService bitstreamService
|
||||
= ContentServiceFactory.getInstance().getBitstreamService();
|
||||
= ContentServiceFactory.getInstance().getBitstreamService();
|
||||
|
||||
private static Element getElement(List<Element> list, String name)
|
||||
{
|
||||
for (Element e : list)
|
||||
if (name.equals(e.getName()))
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private ItemUtils() { }
|
||||
|
||||
private static Element getElement(List<Element> list, String name) {
|
||||
for (Element e : list) {
|
||||
if (name.equals(e.getName())) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
private static Element create(String name)
|
||||
{
|
||||
|
||||
private static Element create(String name) {
|
||||
Element e = new Element();
|
||||
e.setName(name);
|
||||
return e;
|
||||
}
|
||||
|
||||
private static Element.Field createValue(
|
||||
String name, String value)
|
||||
{
|
||||
String name, String value) {
|
||||
Element.Field e = new Element.Field();
|
||||
e.setValue(value);
|
||||
e.setName(name);
|
||||
return e;
|
||||
}
|
||||
public static Metadata retrieveMetadata (Context context, Item item) {
|
||||
|
||||
public static Metadata retrieveMetadata(Context context, Item item) {
|
||||
Metadata metadata;
|
||||
|
||||
// read all metadata into Metadata Object
|
||||
metadata = new Metadata();
|
||||
List<MetadataValue> vals = itemService.getMetadata(item, Item.ANY, Item.ANY, Item.ANY, Item.ANY);
|
||||
for (MetadataValue val : vals)
|
||||
{
|
||||
for (MetadataValue val : vals) {
|
||||
MetadataField field = val.getMetadataField();
|
||||
|
||||
|
||||
// Don't expose fields that are hidden by configuration
|
||||
try {
|
||||
if (metadataExposureService.isHidden(context,
|
||||
field.getMetadataSchema().getName(),
|
||||
field.getElement(),
|
||||
field.getQualifier()))
|
||||
{
|
||||
field.getMetadataSchema().getName(),
|
||||
field.getElement(),
|
||||
field.getQualifier())) {
|
||||
continue;
|
||||
}
|
||||
} catch(SQLException se) {
|
||||
} catch (SQLException se) {
|
||||
throw new RuntimeException(se);
|
||||
}
|
||||
|
||||
Element valueElem = null;
|
||||
Element schema = getElement(metadata.getElement(), field.getMetadataSchema().getName());
|
||||
if (schema == null)
|
||||
{
|
||||
if (schema == null) {
|
||||
schema = create(field.getMetadataSchema().getName());
|
||||
metadata.getElement().add(schema);
|
||||
}
|
||||
valueElem = schema;
|
||||
|
||||
// Has element.. with XOAI one could have only schema and value
|
||||
if (field.getElement() != null && !field.getElement().equals(""))
|
||||
{
|
||||
if (field.getElement() != null && !field.getElement().equals("")) {
|
||||
Element element = getElement(schema.getElement(),
|
||||
field.getElement());
|
||||
if (element == null)
|
||||
{
|
||||
field.getElement());
|
||||
if (element == null) {
|
||||
element = create(field.getElement());
|
||||
schema.getElement().add(element);
|
||||
}
|
||||
valueElem = element;
|
||||
|
||||
// Qualified element?
|
||||
if (field.getQualifier() != null && !field.getQualifier().equals(""))
|
||||
{
|
||||
if (field.getQualifier() != null && !field.getQualifier().equals("")) {
|
||||
Element qualifier = getElement(element.getElement(),
|
||||
field.getQualifier());
|
||||
if (qualifier == null)
|
||||
{
|
||||
field.getQualifier());
|
||||
if (qualifier == null) {
|
||||
qualifier = create(field.getQualifier());
|
||||
element.getElement().add(qualifier);
|
||||
}
|
||||
@@ -132,23 +133,18 @@ public class ItemUtils
|
||||
}
|
||||
|
||||
// Language?
|
||||
if (val.getLanguage() != null && !val.getLanguage().equals(""))
|
||||
{
|
||||
if (val.getLanguage() != null && !val.getLanguage().equals("")) {
|
||||
Element language = getElement(valueElem.getElement(),
|
||||
val.getLanguage());
|
||||
if (language == null)
|
||||
{
|
||||
val.getLanguage());
|
||||
if (language == null) {
|
||||
language = create(val.getLanguage());
|
||||
valueElem.getElement().add(language);
|
||||
}
|
||||
valueElem = language;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Element language = getElement(valueElem.getElement(),
|
||||
"none");
|
||||
if (language == null)
|
||||
{
|
||||
"none");
|
||||
if (language == null) {
|
||||
language = create("none");
|
||||
valueElem.getElement().add(language);
|
||||
}
|
||||
@@ -158,8 +154,9 @@ public class ItemUtils
|
||||
valueElem.getField().add(createValue("value", val.getValue()));
|
||||
if (val.getAuthority() != null) {
|
||||
valueElem.getField().add(createValue("authority", val.getAuthority()));
|
||||
if (val.getConfidence() != Choices.CF_NOVALUE)
|
||||
if (val.getConfidence() != Choices.CF_NOVALUE) {
|
||||
valueElem.getField().add(createValue("confidence", val.getConfidence() + ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Done! Metadata has been read!
|
||||
@@ -168,55 +165,46 @@ public class ItemUtils
|
||||
metadata.getElement().add(bundles);
|
||||
|
||||
List<Bundle> bs;
|
||||
try
|
||||
{
|
||||
try {
|
||||
bs = item.getBundles();
|
||||
for (Bundle b : bs)
|
||||
{
|
||||
for (Bundle b : bs) {
|
||||
Element bundle = create("bundle");
|
||||
bundles.getElement().add(bundle);
|
||||
bundle.getField()
|
||||
.add(createValue("name", b.getName()));
|
||||
.add(createValue("name", b.getName()));
|
||||
|
||||
Element bitstreams = create("bitstreams");
|
||||
bundle.getElement().add(bitstreams);
|
||||
List<Bitstream> bits = b.getBitstreams();
|
||||
for (Bitstream bit : bits)
|
||||
{
|
||||
for (Bitstream bit : bits) {
|
||||
Element bitstream = create("bitstream");
|
||||
bitstreams.getElement().add(bitstream);
|
||||
String url = "";
|
||||
String bsName = bit.getName();
|
||||
String sid = String.valueOf(bit.getSequenceID());
|
||||
String baseUrl = ConfigurationManager.getProperty("oai",
|
||||
"bitstream.baseUrl");
|
||||
"bitstream.baseUrl");
|
||||
String handle = null;
|
||||
// get handle of parent Item of this bitstream, if there
|
||||
// is one:
|
||||
List<Bundle> bn = bit.getBundles();
|
||||
if (!bn.isEmpty())
|
||||
{
|
||||
if (!bn.isEmpty()) {
|
||||
List<Item> bi = bn.get(0).getItems();
|
||||
if (!bi.isEmpty())
|
||||
{
|
||||
if (!bi.isEmpty()) {
|
||||
handle = bi.get(0).getHandle();
|
||||
}
|
||||
}
|
||||
if (bsName == null)
|
||||
{
|
||||
if (bsName == null) {
|
||||
List<String> ext = bit.getFormat(context).getExtensions();
|
||||
bsName = "bitstream_" + sid
|
||||
+ (ext.isEmpty() ? "" : ext.get(0));
|
||||
+ (ext.isEmpty() ? "" : ext.get(0));
|
||||
}
|
||||
if (handle != null && baseUrl != null)
|
||||
{
|
||||
if (handle != null && baseUrl != null) {
|
||||
url = baseUrl + "/bitstream/"
|
||||
+ handle + "/"
|
||||
+ sid + "/"
|
||||
+ URLUtils.encode(bsName);
|
||||
}
|
||||
else
|
||||
{
|
||||
+ handle + "/"
|
||||
+ sid + "/"
|
||||
+ URLUtils.encode(bsName);
|
||||
} else {
|
||||
url = URLUtils.encode(bsName);
|
||||
}
|
||||
|
||||
@@ -226,96 +214,89 @@ public class ItemUtils
|
||||
String name = bit.getName();
|
||||
String description = bit.getDescription();
|
||||
|
||||
if (name != null)
|
||||
if (name != null) {
|
||||
bitstream.getField().add(
|
||||
createValue("name", name));
|
||||
if (oname != null)
|
||||
createValue("name", name));
|
||||
}
|
||||
if (oname != null) {
|
||||
bitstream.getField().add(
|
||||
createValue("originalName", name));
|
||||
if (description != null)
|
||||
createValue("originalName", name));
|
||||
}
|
||||
if (description != null) {
|
||||
bitstream.getField().add(
|
||||
createValue("description", description));
|
||||
createValue("description", description));
|
||||
}
|
||||
bitstream.getField().add(
|
||||
createValue("format", bit.getFormat(context)
|
||||
.getMIMEType()));
|
||||
createValue("format", bit.getFormat(context)
|
||||
.getMIMEType()));
|
||||
bitstream.getField().add(
|
||||
createValue("size", "" + bit.getSize()));
|
||||
createValue("size", "" + bit.getSize()));
|
||||
bitstream.getField().add(createValue("url", url));
|
||||
bitstream.getField().add(
|
||||
createValue("checksum", cks));
|
||||
createValue("checksum", cks));
|
||||
bitstream.getField().add(
|
||||
createValue("checksumAlgorithm", cka));
|
||||
createValue("checksumAlgorithm", cka));
|
||||
bitstream.getField().add(
|
||||
createValue("sid", bit.getSequenceID()
|
||||
+ ""));
|
||||
createValue("sid", bit.getSequenceID()
|
||||
+ ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
} catch (SQLException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Other info
|
||||
Element other = create("others");
|
||||
|
||||
other.getField().add(
|
||||
createValue("handle", item.getHandle()));
|
||||
createValue("handle", item.getHandle()));
|
||||
other.getField().add(
|
||||
createValue("identifier", DSpaceItem.buildIdentifier(item.getHandle())));
|
||||
createValue("identifier", DSpaceItem.buildIdentifier(item.getHandle())));
|
||||
other.getField().add(
|
||||
createValue("lastModifyDate", item
|
||||
.getLastModified().toString()));
|
||||
createValue("lastModifyDate", item
|
||||
.getLastModified().toString()));
|
||||
metadata.getElement().add(other);
|
||||
|
||||
// Repository Info
|
||||
Element repository = create("repository");
|
||||
repository.getField().add(
|
||||
createValue("name",
|
||||
createValue("name",
|
||||
ConfigurationManager.getProperty("dspace.name")));
|
||||
repository.getField().add(
|
||||
createValue("mail",
|
||||
createValue("mail",
|
||||
ConfigurationManager.getProperty("mail.admin")));
|
||||
metadata.getElement().add(repository);
|
||||
|
||||
// Licensing info
|
||||
Element license = create("license");
|
||||
List<Bundle> licBundles;
|
||||
try
|
||||
{
|
||||
try {
|
||||
licBundles = itemService.getBundles(item, Constants.LICENSE_BUNDLE_NAME);
|
||||
if (!licBundles.isEmpty())
|
||||
{
|
||||
if (!licBundles.isEmpty()) {
|
||||
Bundle licBundle = licBundles.get(0);
|
||||
List<Bitstream> licBits = licBundle.getBitstreams();
|
||||
if (!licBits.isEmpty())
|
||||
{
|
||||
if (!licBits.isEmpty()) {
|
||||
Bitstream licBit = licBits.get(0);
|
||||
InputStream in;
|
||||
try
|
||||
{
|
||||
try {
|
||||
in = bitstreamService.retrieve(context, licBit);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
Utils.bufferedCopy(in, out);
|
||||
license.getField().add(
|
||||
createValue("bin",
|
||||
createValue("bin",
|
||||
Base64Utils.encode(out.toString())));
|
||||
metadata.getElement().add(license);
|
||||
}
|
||||
catch (AuthorizeException | IOException | SQLException e)
|
||||
{
|
||||
} catch (AuthorizeException | IOException | SQLException e) {
|
||||
log.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e1)
|
||||
{
|
||||
} catch (SQLException e1) {
|
||||
log.warn(e1.getMessage(), e1);
|
||||
}
|
||||
|
||||
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
|
@@ -7,28 +7,29 @@
|
||||
*/
|
||||
package org.dspace.xoai.util;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.log4j.LogManager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.util.Util;
|
||||
import org.dspace.core.Constants;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Lyncode Development Team (dspace at lyncode dot com)
|
||||
*/
|
||||
public class URLUtils
|
||||
{
|
||||
public class URLUtils {
|
||||
private static Logger log = LogManager.getLogger(URLUtils.class);
|
||||
|
||||
public static String encode (String value) {
|
||||
try
|
||||
{
|
||||
return Util.encodeBitstreamName(value, Constants.DEFAULT_ENCODING);
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
private URLUtils() { }
|
||||
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
public static String encode(String value) {
|
||||
try {
|
||||
return Util.encodeBitstreamName(value, Constants.DEFAULT_ENCODING);
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.warn(e.getMessage(), e);
|
||||
return value;
|
||||
}
|
||||
|
@@ -8,36 +8,34 @@
|
||||
http://www.dspace.org/license/
|
||||
|
||||
-->
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.3.xsd">
|
||||
<beans
|
||||
xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
|
||||
|
||||
<!-- Acquires the DSpace Utility Class with initialized Service Manager -->
|
||||
<bean id="dspace" class="org.dspace.utils.DSpace"/>
|
||||
|
||||
<!-- Acquires reference to EventService -->
|
||||
|
||||
<!-- Acquires reference to EventService -->
|
||||
<bean id="dspace.eventService" factory-bean="dspace" factory-method="getEventService"/>
|
||||
|
||||
<!-- Inject the Default LoggerUsageEventListener into the EventService -->
|
||||
<bean class="org.dspace.usage.LoggerUsageEventListener">
|
||||
<property name="eventService" >
|
||||
<ref bean="dspace.eventService"/>
|
||||
</property>
|
||||
<property name="eventService">
|
||||
<ref bean="dspace.eventService"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
|
||||
<!-- Inject the SolrLoggerUsageEventListener into the EventService -->
|
||||
<bean class="org.dspace.statistics.SolrLoggerUsageEventListener">
|
||||
<property name="eventService" >
|
||||
<property name="eventService">
|
||||
<ref bean="dspace.eventService"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<!-- Google Analytics recording -->
|
||||
<bean class="org.dspace.google.GoogleRecorderEventListener">
|
||||
<property name="eventService" >
|
||||
<property name="eventService">
|
||||
<ref bean="dspace.eventService"/>
|
||||
</property>
|
||||
</bean>
|
||||
|
@@ -9,16 +9,16 @@
|
||||
|
||||
-->
|
||||
<web-app id="XOAILynCode" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
|
||||
<display-name>XOAI Data Provider</display-name>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
|
||||
<context-param>
|
||||
<description>The location of the DSpace home directory</description>
|
||||
<param-name>dspace.dir</param-name>
|
||||
<param-value>${dspace.dir}</param-value>
|
||||
</context-param>
|
||||
<display-name>XOAI Data Provider</display-name>
|
||||
|
||||
<context-param>
|
||||
<description>The location of the DSpace home directory</description>
|
||||
<param-name>dspace.dir</param-name>
|
||||
<param-value>${dspace.dir}</param-value>
|
||||
</context-param>
|
||||
|
||||
|
||||
<!-- Location of root application context configs (to be loaded by ContextLoaderListener below) -->
|
||||
@@ -36,7 +36,7 @@
|
||||
<!-- Initializes the DSpace Kernel -->
|
||||
<listener>
|
||||
<listener-class>
|
||||
org.dspace.servicemanager.servlet.DSpaceKernelServletContextListener
|
||||
org.dspace.servicemanager.servlet.DSpaceKernelServletContextListener
|
||||
</listener-class>
|
||||
</listener>
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<servlet>
|
||||
<servlet>
|
||||
<servlet-name>oai</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<!-- Configure DispatcherServlet to use AnnotationConfigWebApplicationContext
|
||||
|
@@ -7,9 +7,11 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.dspace.xoai.services.impl.xoai.BaseDSpaceFilterResolver;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedConfigurationService;
|
||||
@@ -17,15 +19,13 @@ import org.dspace.xoai.tests.helpers.stubs.StubbedFieldResolver;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@Configuration
|
||||
public class DSpaceBasicTestConfiguration {
|
||||
|
||||
private final StubbedFieldResolver stubbedFieldResolver = new StubbedFieldResolver();
|
||||
|
||||
@Bean
|
||||
public DSpaceFilterResolver dSpaceFilterResolver () {
|
||||
public DSpaceFilterResolver dSpaceFilterResolver() {
|
||||
return new BaseDSpaceFilterResolver();
|
||||
}
|
||||
|
||||
@@ -38,12 +38,12 @@ public class DSpaceBasicTestConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ContextService contextService () {
|
||||
public ContextService contextService() {
|
||||
return mock(ContextService.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FieldResolver databaseService () {
|
||||
public FieldResolver databaseService() {
|
||||
return stubbedFieldResolver;
|
||||
}
|
||||
}
|
||||
|
@@ -11,11 +11,11 @@ import com.lyncode.xoai.dataprovider.services.api.ItemRepository;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.cache.XOAICacheService;
|
||||
import org.dspace.xoai.services.api.config.XOAIManagerResolver;
|
||||
import org.dspace.xoai.services.api.context.ContextService;
|
||||
import org.dspace.xoai.services.api.context.ContextServiceException;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.xoai.IdentifyResolver;
|
||||
import org.dspace.xoai.services.api.xoai.ItemRepositoryResolver;
|
||||
import org.dspace.xoai.services.api.xoai.SetRepositoryResolver;
|
||||
@@ -82,7 +82,8 @@ public class DSpaceTestConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
private StubbedSetRepository setRepository = new StubbedSetRepository();
|
||||
|
||||
@Bean StubbedSetRepository setRepository () {
|
||||
@Bean
|
||||
StubbedSetRepository setRepository() {
|
||||
return setRepository;
|
||||
}
|
||||
|
||||
@@ -99,8 +100,9 @@ public class DSpaceTestConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SetRepositoryResolver setRepositoryResolver () {
|
||||
public SetRepositoryResolver setRepositoryResolver() {
|
||||
return new SetRepositoryResolver() {
|
||||
@Override
|
||||
public SetRepository getSetRepository() throws ContextServiceException {
|
||||
@@ -108,13 +110,14 @@ public class DSpaceTestConfiguration extends WebMvcConfigurerAdapter {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdentifyResolver identifyResolver () {
|
||||
public IdentifyResolver identifyResolver() {
|
||||
return new DSpaceIdentifyResolver();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EarliestDateResolver earliestDateResolver () {
|
||||
public EarliestDateResolver earliestDateResolver() {
|
||||
return new StubbedEarliestDateResolver();
|
||||
}
|
||||
}
|
||||
|
@@ -7,16 +7,16 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
|
||||
public class HttpRequestBuilder {
|
||||
private MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
|
||||
public HttpRequestBuilder withUrl (String url) {
|
||||
public HttpRequestBuilder withUrl(String url) {
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
@@ -25,12 +25,12 @@ public class HttpRequestBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpRequestBuilder usingGetMethod () {
|
||||
public HttpRequestBuilder usingGetMethod() {
|
||||
request.setMethod("GET");
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpServletRequest build () {
|
||||
public HttpServletRequest build() {
|
||||
|
||||
return request;
|
||||
}
|
||||
|
@@ -8,13 +8,15 @@
|
||||
package org.dspace.xoai.tests.helpers;
|
||||
|
||||
public class SyntacticSugar {
|
||||
public static <T> T given (T elem) {
|
||||
public static <T> T given(T elem) {
|
||||
return elem;
|
||||
}
|
||||
public static <T> T the (T elem) {
|
||||
|
||||
public static <T> T the(T elem) {
|
||||
return elem;
|
||||
}
|
||||
public static <T> T and (T elem) {
|
||||
|
||||
public static <T> T and(T elem) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,16 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import com.lyncode.xoai.builders.dataprovider.ElementBuilder;
|
||||
import com.lyncode.xoai.builders.dataprovider.MetadataBuilder;
|
||||
import com.lyncode.xoai.dataprovider.exceptions.MetadataBindException;
|
||||
@@ -16,16 +26,6 @@ import com.lyncode.xoai.dataprovider.xml.xoai.Metadata;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.sql.SQLException;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.lyncode.xoai.dataprovider.core.Granularity.Second;
|
||||
|
||||
public class ItemRepositoryBuilder {
|
||||
private SolrServer solrServer;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ItemRepositoryBuilder {
|
||||
this.solrServer = solrServer;
|
||||
}
|
||||
|
||||
public ItemRepositoryBuilder withItem (DSpaceItemBuilder builder) {
|
||||
public ItemRepositoryBuilder withItem(DSpaceItemBuilder builder) {
|
||||
try {
|
||||
solrServer.add(index(builder));
|
||||
solrServer.commit();
|
||||
@@ -44,7 +44,8 @@ public class ItemRepositoryBuilder {
|
||||
}
|
||||
|
||||
|
||||
private SolrInputDocument index(DSpaceItemBuilder item) throws SQLException, MetadataBindException, ParseException, XMLStreamException, WritingXmlException {
|
||||
private SolrInputDocument index(DSpaceItemBuilder item)
|
||||
throws SQLException, MetadataBindException, ParseException, XMLStreamException, WritingXmlException {
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
|
||||
doc.addField("item.id", item.getId());
|
||||
@@ -54,11 +55,13 @@ public class ItemRepositoryBuilder {
|
||||
doc.addField("item.handle", item.getHandle());
|
||||
doc.addField("item.deleted", item.isDeleted());
|
||||
|
||||
for (String col : item.getCollections())
|
||||
for (String col : item.getCollections()) {
|
||||
doc.addField("item.collections", col);
|
||||
}
|
||||
|
||||
for (String col : item.getCommunities())
|
||||
for (String col : item.getCommunities()) {
|
||||
doc.addField("item.communities", col);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
XmlOutputContext context = XmlOutputContext.emptyContext(out, Second);
|
||||
@@ -82,38 +85,42 @@ public class ItemRepositoryBuilder {
|
||||
private boolean aPublic = true;
|
||||
|
||||
|
||||
public DSpaceItemBuilder withLastModifiedDate (Date lastModifiedDate) {
|
||||
public DSpaceItemBuilder withLastModifiedDate(Date lastModifiedDate) {
|
||||
this.lastModifiedDate = lastModifiedDate;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder withCollection (String colName) {
|
||||
public DSpaceItemBuilder withCollection(String colName) {
|
||||
collections.add(colName);
|
||||
return this;
|
||||
}
|
||||
public DSpaceItemBuilder withCommunity (String comName) {
|
||||
|
||||
public DSpaceItemBuilder withCommunity(String comName) {
|
||||
communities.add(comName);
|
||||
return this;
|
||||
}
|
||||
public DSpaceItemBuilder whichSsPublic () {
|
||||
|
||||
public DSpaceItemBuilder whichSsPublic() {
|
||||
aPublic = true;
|
||||
return this;
|
||||
}
|
||||
public DSpaceItemBuilder whichSsPrivate () {
|
||||
|
||||
public DSpaceItemBuilder whichSsPrivate() {
|
||||
aPublic = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder whichIsDeleted () {
|
||||
public DSpaceItemBuilder whichIsDeleted() {
|
||||
this.deleted = true;
|
||||
return this;
|
||||
}
|
||||
public DSpaceItemBuilder whichIsNotDeleted () {
|
||||
|
||||
public DSpaceItemBuilder whichIsNotDeleted() {
|
||||
this.deleted = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder withMetadata (String schema, String element, String value) {
|
||||
public DSpaceItemBuilder withMetadata(String schema, String element, String value) {
|
||||
metadataBuilder.withElement(new ElementBuilder().withName(schema).withField(element, value).build());
|
||||
return this;
|
||||
}
|
||||
@@ -122,17 +129,17 @@ public class ItemRepositoryBuilder {
|
||||
return handle;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder withHandle (String handle) {
|
||||
public DSpaceItemBuilder withHandle(String handle) {
|
||||
this.handle = handle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder withSubmitter (String submitter) {
|
||||
public DSpaceItemBuilder withSubmitter(String submitter) {
|
||||
this.submitter = submitter;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DSpaceItemBuilder withId (int id) {
|
||||
public DSpaceItemBuilder withId(int id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
@@ -7,36 +7,36 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
|
||||
public class StubbedConfigurationService implements ConfigurationService {
|
||||
private Map<String, Object> values = new HashMap<String, Object>();
|
||||
|
||||
|
||||
public StubbedConfigurationService hasBooleanProperty (String key, boolean value) {
|
||||
public StubbedConfigurationService hasBooleanProperty(String key, boolean value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedConfigurationService hasBooleanProperty (String module, String key, boolean value) {
|
||||
public StubbedConfigurationService hasBooleanProperty(String module, String key, boolean value) {
|
||||
values.put(module + "." + key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedConfigurationService hasProperty (String key, String value) {
|
||||
public StubbedConfigurationService hasProperty(String key, String value) {
|
||||
values.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedConfigurationService withoutProperty (String key) {
|
||||
public StubbedConfigurationService withoutProperty(String key) {
|
||||
values.remove(key);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedConfigurationService hasProperty (String module, String key, String value) {
|
||||
public StubbedConfigurationService hasProperty(String module, String key, String value) {
|
||||
values.put(module + "." + key, value);
|
||||
return this;
|
||||
}
|
||||
@@ -54,7 +54,10 @@ public class StubbedConfigurationService implements ConfigurationService {
|
||||
@Override
|
||||
public boolean getBooleanProperty(String module, String key, boolean defaultValue) {
|
||||
Boolean value = (Boolean) values.get(module + "." + key);
|
||||
if (value == null) return defaultValue;
|
||||
else return value;
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,17 +7,17 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
|
||||
public class StubbedEarliestDateResolver implements EarliestDateResolver {
|
||||
private Date date = new Date();
|
||||
|
||||
public StubbedEarliestDateResolver is (Date date) {
|
||||
public StubbedEarliestDateResolver is(Date date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
|
@@ -7,21 +7,23 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.xoai.exceptions.InvalidMetadataFieldException;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
|
||||
public class StubbedFieldResolver implements FieldResolver {
|
||||
private Map<String, Integer> fieldsMap = new HashMap<String, Integer>();
|
||||
|
||||
@Override
|
||||
public int getFieldID(Context context, String field) throws InvalidMetadataFieldException, SQLException {
|
||||
Integer integer = fieldsMap.get(field);
|
||||
if (integer == null) return -1;
|
||||
if (integer == null) {
|
||||
return -1;
|
||||
}
|
||||
return integer;
|
||||
}
|
||||
|
||||
|
@@ -7,15 +7,15 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
|
||||
public class StubbedResourceResolver implements ResourceResolver {
|
||||
private static TransformerFactory factory = TransformerFactory.newInstance();
|
||||
|
@@ -8,15 +8,15 @@
|
||||
package org.dspace.xoai.tests.helpers.stubs;
|
||||
|
||||
|
||||
import com.lyncode.xoai.dataprovider.core.ListSetsResult;
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
import static java.lang.Math.min;
|
||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static java.lang.Math.min;
|
||||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
|
||||
import com.lyncode.xoai.dataprovider.core.ListSetsResult;
|
||||
import com.lyncode.xoai.dataprovider.core.Set;
|
||||
import com.lyncode.xoai.dataprovider.services.api.SetRepository;
|
||||
|
||||
public class StubbedSetRepository implements SetRepository {
|
||||
private List<Set> sets = new ArrayList<Set>();
|
||||
@@ -29,15 +29,20 @@ public class StubbedSetRepository implements SetRepository {
|
||||
|
||||
@Override
|
||||
public ListSetsResult retrieveSets(int offset, int length) {
|
||||
if (offset > sets.size()) return new ListSetsResult(false, new ArrayList<Set>(), sets.size());
|
||||
return new ListSetsResult(offset+length < sets.size(), sets.subList(offset, min(offset + length, sets.size())), sets.size());
|
||||
if (offset > sets.size()) {
|
||||
return new ListSetsResult(false, new ArrayList<Set>(), sets.size());
|
||||
}
|
||||
return new ListSetsResult(offset + length < sets.size(),
|
||||
sets.subList(offset, min(offset + length, sets.size())), sets.size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(String setSpec) {
|
||||
for (Set set : sets)
|
||||
if (set.getSetSpec().equals(setSpec))
|
||||
for (Set set : sets) {
|
||||
if (set.getSetSpec().equals(setSpec)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -46,18 +51,21 @@ public class StubbedSetRepository implements SetRepository {
|
||||
this.supports = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedSetRepository doesNotSupportSets() {
|
||||
this.supports = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedSetRepository withSet(String name, String spec) {
|
||||
this.sets.add(new Set(spec, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public StubbedSetRepository withRandomlyGeneratedSets(int number) {
|
||||
for (int i=0;i<number;i++)
|
||||
for (int i = 0; i < number; i++) {
|
||||
this.sets.add(new Set(randomAlphabetic(10), randomAlphabetic(10)));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@@ -17,13 +17,14 @@ import org.dspace.xoai.services.api.xoai.DSpaceFilterResolver;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class StubbedXOAIManagerResolver implements XOAIManagerResolver {
|
||||
@Autowired ResourceResolver resourceResolver;
|
||||
@Autowired
|
||||
ResourceResolver resourceResolver;
|
||||
@Autowired
|
||||
DSpaceFilterResolver filterResolver;
|
||||
|
||||
private Configuration builder = new Configuration();
|
||||
|
||||
public Configuration configuration () {
|
||||
public Configuration configuration() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,13 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.integration.xoai;
|
||||
|
||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
|
||||
import com.lyncode.builder.MapBuilder;
|
||||
import com.lyncode.xoai.dataprovider.services.api.ResourceResolver;
|
||||
import com.lyncode.xoai.dataprovider.services.impl.BaseDateProvider;
|
||||
@@ -14,12 +21,18 @@ import com.lyncode.xoai.dataprovider.xml.xoaiconfig.Configuration;
|
||||
import com.lyncode.xoai.dataprovider.xml.xoaiconfig.FormatConfiguration;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.dspace.xoai.controller.DSpaceOAIDataProvider;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.config.XOAIManagerResolver;
|
||||
import org.dspace.xoai.services.api.EarliestDateResolver;
|
||||
import org.dspace.xoai.services.api.FieldResolver;
|
||||
import org.dspace.xoai.services.api.config.ConfigurationService;
|
||||
import org.dspace.xoai.services.api.config.XOAIManagerResolver;
|
||||
import org.dspace.xoai.tests.DSpaceTestConfiguration;
|
||||
import org.dspace.xoai.tests.helpers.stubs.*;
|
||||
import org.dspace.xoai.tests.helpers.stubs.ItemRepositoryBuilder;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedConfigurationService;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedEarliestDateResolver;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedFieldResolver;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedResourceResolver;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedSetRepository;
|
||||
import org.dspace.xoai.tests.helpers.stubs.StubbedXOAIManagerResolver;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,20 +46,14 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import org.springframework.test.web.servlet.result.XpathResultMatchers;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import java.util.Date;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes = { DSpaceTestConfiguration.class, DSpaceOAIDataProvider.class })
|
||||
@ContextConfiguration(classes = {DSpaceTestConfiguration.class, DSpaceOAIDataProvider.class})
|
||||
public abstract class AbstractDSpaceTest {
|
||||
private static BaseDateProvider baseDateProvider = new BaseDateProvider();
|
||||
@Autowired WebApplicationContext wac;
|
||||
@Autowired
|
||||
WebApplicationContext wac;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
private StubbedXOAIManagerResolver xoaiManagerResolver;
|
||||
@@ -69,7 +76,7 @@ public abstract class AbstractDSpaceTest {
|
||||
resourceResolver = (StubbedResourceResolver) this.wac.getBean(ResourceResolver.class);
|
||||
xoaiManagerResolver.configuration();
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
// Nullify all resources so that JUnit will clean them up
|
||||
@@ -84,30 +91,32 @@ public abstract class AbstractDSpaceTest {
|
||||
}
|
||||
|
||||
protected MockMvc againstTheDataProvider() {
|
||||
if (this.mockMvc == null) this.mockMvc = webAppContextSetup(this.wac).build();
|
||||
if (this.mockMvc == null) {
|
||||
this.mockMvc = webAppContextSetup(this.wac).build();
|
||||
}
|
||||
return this.mockMvc;
|
||||
}
|
||||
|
||||
protected Configuration theConfiguration () {
|
||||
protected Configuration theConfiguration() {
|
||||
return xoaiManagerResolver.configuration();
|
||||
}
|
||||
|
||||
protected StubbedConfigurationService theDSpaceConfiguration () {
|
||||
protected StubbedConfigurationService theDSpaceConfiguration() {
|
||||
return configurationService;
|
||||
}
|
||||
|
||||
protected StubbedFieldResolver theDatabase () {
|
||||
protected StubbedFieldResolver theDatabase() {
|
||||
return databaseService;
|
||||
}
|
||||
|
||||
protected StubbedEarliestDateResolver theEarlistEarliestDate () {
|
||||
protected StubbedEarliestDateResolver theEarlistEarliestDate() {
|
||||
return earliestDateResolver;
|
||||
}
|
||||
|
||||
protected XpathResultMatchers oaiXPath(String xpath) throws XPathExpressionException {
|
||||
return MockMvcResultMatchers.xpath(this.replaceXpath(xpath), new MapBuilder<String, String>()
|
||||
.withPair("o", "http://www.openarchives.org/OAI/2.0/")
|
||||
.build());
|
||||
.withPair("o", "http://www.openarchives.org/OAI/2.0/")
|
||||
.build());
|
||||
}
|
||||
|
||||
private String replaceXpath(String xpath) {
|
||||
@@ -116,22 +125,25 @@ public abstract class AbstractDSpaceTest {
|
||||
Pattern pattern = Pattern.compile("/[^/]+");
|
||||
Matcher matcher = pattern.matcher(xpath);
|
||||
while (matcher.find()) {
|
||||
if (matcher.start() > offset) newXpath += xpath.substring(offset, matcher.start());
|
||||
if (!matcher.group().contains(":") && !matcher.group().startsWith("/@"))
|
||||
if (matcher.start() > offset) {
|
||||
newXpath += xpath.substring(offset, matcher.start());
|
||||
}
|
||||
if (!matcher.group().contains(":") && !matcher.group().startsWith("/@")) {
|
||||
newXpath += "/o:" + matcher.group().substring(1);
|
||||
else
|
||||
} else {
|
||||
newXpath += matcher.group();
|
||||
}
|
||||
offset = matcher.end() + 1;
|
||||
}
|
||||
|
||||
return newXpath;
|
||||
}
|
||||
|
||||
protected String representationOfDate (Date date) {
|
||||
protected String representationOfDate(Date date) {
|
||||
return baseDateProvider.format(date);
|
||||
}
|
||||
|
||||
protected StubbedSetRepository theSetRepository () {
|
||||
protected StubbedSetRepository theSetRepository() {
|
||||
return setRepository;
|
||||
}
|
||||
|
||||
@@ -166,8 +178,9 @@ public abstract class AbstractDSpaceTest {
|
||||
private ItemRepositoryBuilder itemRepositoryBuilder;
|
||||
|
||||
public ItemRepositoryBuilder theItemRepository() {
|
||||
if (itemRepositoryBuilder == null)
|
||||
if (itemRepositoryBuilder == null) {
|
||||
itemRepositoryBuilder = new ItemRepositoryBuilder(solrServer);
|
||||
}
|
||||
return itemRepositoryBuilder;
|
||||
}
|
||||
}
|
@@ -7,16 +7,16 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.integration.xoai;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.dspace.xoai.tests.helpers.SyntacticSugar.and;
|
||||
import static org.dspace.xoai.tests.helpers.SyntacticSugar.given;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class IdentifyTest extends AbstractDSpaceTest {
|
||||
|
||||
public static final Date EARLIEST_DATE = new Date();
|
||||
@@ -24,26 +24,27 @@ public class IdentifyTest extends AbstractDSpaceTest {
|
||||
@Test
|
||||
public void requestForIdentifyWithoutRequiredConfigurationAdminEmailSetShouldFail() throws Exception {
|
||||
given(theDSpaceConfiguration()
|
||||
.withoutProperty("mail.admin"));
|
||||
.withoutProperty("mail.admin"));
|
||||
and(given(theConfiguration().withContextConfigurations(aContext("request"))));
|
||||
|
||||
againstTheDataProvider().perform(get("/request?verb=Identify"))
|
||||
.andExpect(status().isInternalServerError());
|
||||
.andExpect(status().isInternalServerError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestForIdentifyShouldReturnTheConfiguredValues() throws Exception {
|
||||
given(theDSpaceConfiguration()
|
||||
.hasProperty("dspace.name", "Test")
|
||||
.hasProperty("mail.admin", "test@test.com"));
|
||||
.hasProperty("dspace.name", "Test")
|
||||
.hasProperty("mail.admin", "test@test.com"));
|
||||
|
||||
and(given(theEarlistEarliestDate().is(EARLIEST_DATE)));
|
||||
and(given(theConfiguration().withContextConfigurations(aContext("request"))));
|
||||
|
||||
againstTheDataProvider().perform(get("/request?verb=Identify"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(oaiXPath("//repositoryName").string("Test"))
|
||||
.andExpect(oaiXPath("//adminEmail").string("test@test.com"))
|
||||
.andExpect(oaiXPath("//earliestDatestamp").string(is(representationOfDate(EARLIEST_DATE))));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(oaiXPath("//repositoryName").string("Test"))
|
||||
.andExpect(oaiXPath("//adminEmail").string("test@test.com"))
|
||||
.andExpect(
|
||||
oaiXPath("//earliestDatestamp").string(is(representationOfDate(EARLIEST_DATE))));
|
||||
}
|
||||
}
|
||||
|
@@ -7,8 +7,6 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.integration.xoai;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.dspace.xoai.tests.helpers.SyntacticSugar.and;
|
||||
import static org.dspace.xoai.tests.helpers.SyntacticSugar.given;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
@@ -16,50 +14,52 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ListSetsTest extends AbstractDSpaceTest {
|
||||
@Test
|
||||
public void listSetsWithLessSetsThenMaxSetsPerPage () throws Exception {
|
||||
public void listSetsWithLessSetsThenMaxSetsPerPage() throws Exception {
|
||||
given(theConfiguration()
|
||||
.withMaxListSetsSize(100)
|
||||
.withContextConfigurations(aContext("request")));
|
||||
.withMaxListSetsSize(100)
|
||||
.withContextConfigurations(aContext("request")));
|
||||
and(given(theSetRepository()
|
||||
.doesSupportSets()
|
||||
.withSet("name", "spec")));
|
||||
.doesSupportSets()
|
||||
.withSet("name", "spec")));
|
||||
|
||||
againstTheDataProvider().perform(get("/request?verb=ListSets"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(1))
|
||||
.andExpect(oaiXPath("//set/setSpec").string("spec"))
|
||||
.andExpect(oaiXPath("//set/setName").string("name"))
|
||||
.andExpect(resumptionToken().doesNotExist());
|
||||
.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(1))
|
||||
.andExpect(oaiXPath("//set/setSpec").string("spec"))
|
||||
.andExpect(oaiXPath("//set/setName").string("name"))
|
||||
.andExpect(resumptionToken().doesNotExist());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listSetsWithMoreSetsThenMaxSetsPerPage () throws Exception {
|
||||
public void listSetsWithMoreSetsThenMaxSetsPerPage() throws Exception {
|
||||
given(theConfiguration()
|
||||
.withMaxListSetsSize(10)
|
||||
.withContextConfigurations(aContext("request")));
|
||||
.withMaxListSetsSize(10)
|
||||
.withContextConfigurations(aContext("request")));
|
||||
|
||||
and(given(theSetRepository()
|
||||
.doesSupportSets()
|
||||
.withRandomlyGeneratedSets(20)));
|
||||
.doesSupportSets()
|
||||
.withRandomlyGeneratedSets(20)));
|
||||
|
||||
againstTheDataProvider().perform(get("/request?verb=ListSets"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(10))
|
||||
.andExpect(resumptionToken().string("////10"))
|
||||
.andExpect(oaiXPath("//resumptionToken/@completeListSize").number(Double.valueOf(20)));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(10))
|
||||
.andExpect(resumptionToken().string("////10"))
|
||||
.andExpect(oaiXPath("//resumptionToken/@completeListSize").number(Double.valueOf(20)));
|
||||
|
||||
and(againstTheDataProvider().perform(get("/request?verb=ListSets&resumptionToken=////10"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(10))
|
||||
.andExpect(resumptionToken().string("")));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(responseDate().exists())
|
||||
.andExpect(verb(is("ListSets")))
|
||||
.andExpect(oaiXPath("//set").nodeCount(10))
|
||||
.andExpect(resumptionToken().string("")));
|
||||
}
|
||||
}
|
||||
|
@@ -7,29 +7,29 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.integration.xoai;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class OAIContextTest extends AbstractDSpaceTest {
|
||||
public static final String ROOT_URL = "/";
|
||||
|
||||
@Test
|
||||
public void requestToRootShouldGiveListOfContextsWithBadRequestError() throws Exception {
|
||||
againstTheDataProvider().perform(get(ROOT_URL))
|
||||
.andDo(print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(model().attributeExists("contexts"));
|
||||
.andDo(print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(model().attributeExists("contexts"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestForUnknownContextShouldGiveListOfContextsWithBadRequestError() throws Exception {
|
||||
againstTheDataProvider().perform(get("/unexistentContext"))
|
||||
.andDo(print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(model().attributeExists("contexts"));
|
||||
.andDo(print())
|
||||
.andExpect(status().isBadRequest())
|
||||
.andExpect(model().attributeExists("contexts"));
|
||||
}
|
||||
}
|
||||
|
@@ -8,31 +8,31 @@
|
||||
|
||||
package org.dspace.xoai.tests.integration.xoai;
|
||||
|
||||
import com.lyncode.xoai.util.XSLPipeline;
|
||||
import org.junit.Test;
|
||||
import org.parboiled.common.FileUtils;
|
||||
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static com.lyncode.test.matchers.xml.XPathMatchers.xPath;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import com.lyncode.xoai.util.XSLPipeline;
|
||||
import org.junit.Test;
|
||||
import org.parboiled.common.FileUtils;
|
||||
|
||||
public class PipelineTest {
|
||||
private static TransformerFactory factory = TransformerFactory.newInstance();
|
||||
|
||||
@Test
|
||||
public void pipelineTest () throws Exception {
|
||||
public void pipelineTest() throws Exception {
|
||||
InputStream input = PipelineTest.class.getClassLoader().getResourceAsStream("item.xml");
|
||||
InputStream xslt = PipelineTest.class.getClassLoader().getResourceAsStream("oai_dc.xsl");
|
||||
String output = FileUtils.readAllText(new XSLPipeline(input, true)
|
||||
.apply(factory.newTransformer(new StreamSource(xslt)))
|
||||
.getTransformed());
|
||||
.apply(factory.newTransformer(new StreamSource(xslt)))
|
||||
.getTransformed());
|
||||
|
||||
assertThat(output, xPath("/oai_dc:dc/dc:title", equalTo("Teste")));
|
||||
|
||||
|
||||
input.close();
|
||||
input = null;
|
||||
xslt.close();
|
||||
|
@@ -7,25 +7,25 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.stylesheets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
public abstract class AbstractXSLTest {
|
||||
private static final TransformerFactory factory = TransformerFactory.newInstance();
|
||||
|
||||
protected TransformBuilder apply (String xslLocation) throws Exception {
|
||||
protected TransformBuilder apply(String xslLocation) throws Exception {
|
||||
return new TransformBuilder(xslLocation);
|
||||
}
|
||||
|
||||
protected InputStream resource (String location) throws Exception {
|
||||
protected InputStream resource(String location) throws Exception {
|
||||
return print(this.getClass().getClassLoader().getResourceAsStream(location));
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ public abstract class AbstractXSLTest {
|
||||
private final Transformer transformer;
|
||||
|
||||
public TransformBuilder(String xslLocation) throws Exception {
|
||||
this.transformer = factory.newTransformer(new StreamSource(new File("../dspace/config/crosswalks/oai/metadataFormats", xslLocation)));
|
||||
this.transformer = factory.newTransformer(
|
||||
new StreamSource(new File("../dspace/config/crosswalks/oai/metadataFormats", xslLocation)));
|
||||
}
|
||||
|
||||
public String to(InputStream input) throws Exception {
|
||||
|
@@ -7,14 +7,14 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.stylesheets;
|
||||
|
||||
import org.dspace.xoai.tests.support.XmlMatcherBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.dspace.xoai.tests.support.XmlMatcherBuilder.xml;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
import org.dspace.xoai.tests.support.XmlMatcherBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
public class QDCXslTest extends AbstractXSLTest {
|
||||
|
||||
@Test
|
||||
@@ -24,11 +24,11 @@ public class QDCXslTest extends AbstractXSLTest {
|
||||
assertThat(result, is(qdc().withXPath("//dc:title", equalTo("Test Webpage"))));
|
||||
}
|
||||
|
||||
private XmlMatcherBuilder qdc () {
|
||||
private XmlMatcherBuilder qdc() {
|
||||
return xml()
|
||||
.withNamespace("dqc", "http://dspace.org/qualifieddc/")
|
||||
.withNamespace("dcterms", "http://purl.org/dc/terms/")
|
||||
.withNamespace("dc", "http://purl.org/dc/elements/1.1/")
|
||||
;
|
||||
.withNamespace("dqc", "http://dspace.org/qualifieddc/")
|
||||
.withNamespace("dcterms", "http://purl.org/dc/terms/")
|
||||
.withNamespace("dc", "http://purl.org/dc/elements/1.1/")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@@ -7,14 +7,14 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.AllOf;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class MatcherBuilder<M extends MatcherBuilder, T> extends BaseMatcher<T> {
|
||||
private final Collection<Matcher<? super T>> matchers = new ArrayList<>();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class MatcherBuilder<M extends MatcherBuilder, T> extends BaseMatcher<T>
|
||||
description.appendDescriptionOf(matcher());
|
||||
}
|
||||
|
||||
protected M with (Matcher<? super T> matcher) {
|
||||
protected M with(Matcher<? super T> matcher) {
|
||||
matchers.add(matcher);
|
||||
return (M) this;
|
||||
}
|
||||
|
@@ -7,18 +7,22 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.xmlmatchers.XmlMatchers;
|
||||
import org.xmlmatchers.transform.StringSource;
|
||||
|
||||
import javax.xml.namespace.NamespaceContext;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class XmlMatcherBuilder extends MatcherBuilder<XmlMatcherBuilder, String> {
|
||||
public static XmlMatcherBuilder xml () {
|
||||
public static XmlMatcherBuilder xml() {
|
||||
return new XmlMatcherBuilder();
|
||||
}
|
||||
|
||||
@@ -63,8 +67,8 @@ public class XmlMatcherBuilder extends MatcherBuilder<XmlMatcherBuilder, String>
|
||||
@Override
|
||||
protected boolean matchesSafely(String item) {
|
||||
return XmlMatchers
|
||||
.hasXPath(xPath, namespaces, subMatcher)
|
||||
.matches(StringSource.toSource(item));
|
||||
.hasXPath(xPath, namespaces, subMatcher)
|
||||
.matches(StringSource.toSource(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,7 +78,7 @@ public class XmlMatcherBuilder extends MatcherBuilder<XmlMatcherBuilder, String>
|
||||
});
|
||||
}
|
||||
|
||||
public XmlMatcherBuilder withNamespace (String prefix, String uri) {
|
||||
public XmlMatcherBuilder withNamespace(String prefix, String uri) {
|
||||
namespaces.with(prefix, uri);
|
||||
return this;
|
||||
}
|
||||
@@ -91,16 +95,20 @@ public class XmlMatcherBuilder extends MatcherBuilder<XmlMatcherBuilder, String>
|
||||
public String getPrefix(String namespaceURI) {
|
||||
Iterator<String> prefixes = getPrefixes(namespaceURI);
|
||||
|
||||
if (!prefixes.hasNext()) return null;
|
||||
else return prefixes.next();
|
||||
if (!prefixes.hasNext()) {
|
||||
return null;
|
||||
} else {
|
||||
return prefixes.next();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator getPrefixes(String namespaceURI) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Map.Entry<String, String> stringStringEntry : namespace.entrySet()) {
|
||||
if (stringStringEntry.getValue().equals(namespaceURI))
|
||||
if (stringStringEntry.getValue().equals(namespaceURI)) {
|
||||
list.add(stringStringEntry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
return list.iterator();
|
||||
|
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.unit.services.impl;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.lyncode.builder.DateBuilder;
|
||||
import com.lyncode.xoai.dataprovider.services.impl.BaseDateProvider;
|
||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||
@@ -21,10 +25,6 @@ import org.junit.Before;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
public abstract class AbstractQueryResolverTest {
|
||||
private final BaseDateProvider baseDateProvider = new BaseDateProvider();
|
||||
protected HandleResolver handleResolver = mock(HandleResolver.class);
|
||||
@@ -32,10 +32,10 @@ public abstract class AbstractQueryResolverTest {
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Before
|
||||
public void setUp () {
|
||||
public void setUp() {
|
||||
applicationContext = new AnnotationConfigApplicationContext(DSpaceBasicTestConfiguration.class);
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
//Nullify all resoruces so that JUnit cleans them up
|
||||
@@ -53,15 +53,17 @@ public abstract class AbstractQueryResolverTest {
|
||||
return applicationContext.getBean(DSpaceFilterResolver.class);
|
||||
}
|
||||
|
||||
protected StubbedFieldResolver theFieldResolver () {
|
||||
protected StubbedFieldResolver theFieldResolver() {
|
||||
return (StubbedFieldResolver) applicationContext.getBean(FieldResolver.class);
|
||||
}
|
||||
|
||||
protected String escapedFromDate(Date date) {
|
||||
return ClientUtils.escapeQueryChars(baseDateProvider.format(new DateBuilder(date).setMinMilliseconds().build()).replace("Z", ".000Z"));
|
||||
return ClientUtils.escapeQueryChars(
|
||||
baseDateProvider.format(new DateBuilder(date).setMinMilliseconds().build()).replace("Z", ".000Z"));
|
||||
}
|
||||
|
||||
protected String escapedUntilDate(Date date) {
|
||||
return ClientUtils.escapeQueryChars(baseDateProvider.format(new DateBuilder(date).setMaxMilliseconds().build()).replace("Z", ".999Z"));
|
||||
return ClientUtils.escapeQueryChars(
|
||||
baseDateProvider.format(new DateBuilder(date).setMaxMilliseconds().build()).replace("Z", ".999Z"));
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,13 @@
|
||||
*/
|
||||
package org.dspace.xoai.tests.unit.services.impl.solr;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.lyncode.xoai.dataprovider.data.Filter;
|
||||
import com.lyncode.xoai.dataprovider.filter.Scope;
|
||||
import com.lyncode.xoai.dataprovider.filter.ScopedFilter;
|
||||
@@ -26,23 +33,17 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class DSpaceSolrQueryResolverTest extends AbstractQueryResolverTest {
|
||||
private static final Date DATE = new Date();
|
||||
private static final String SET = "col_testSet";
|
||||
private static final String FIELD_1 = "dc.title";
|
||||
private static final String FIELD_2 = "dc.type";
|
||||
|
||||
private DSpaceSolrQueryResolver underTest = new DSpaceSolrQueryResolver();;
|
||||
private DSpaceSolrQueryResolver underTest = new DSpaceSolrQueryResolver();
|
||||
;
|
||||
|
||||
@Before
|
||||
public void autowire () {
|
||||
public void autowire() {
|
||||
autowire(underTest);
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ public class DSpaceSolrQueryResolverTest extends AbstractQueryResolverTest {
|
||||
public void cleanup() {
|
||||
underTest = null;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fromFilterQuery() throws Exception {
|
||||
List<ScopedFilter> scopedFilters = new ArrayList<ScopedFilter>();
|
||||
@@ -82,48 +83,49 @@ public class DSpaceSolrQueryResolverTest extends AbstractQueryResolverTest {
|
||||
}
|
||||
};
|
||||
scopedFilters.add(new ScopedFilter(new AndCondition(getFilterResolver(),
|
||||
fromCondition, untilCondition), Scope.Query));
|
||||
fromCondition, untilCondition), Scope.Query));
|
||||
|
||||
String result = underTest.buildQuery(scopedFilters);
|
||||
|
||||
assertThat(result, is("(((item.lastmodified:["+escapedFromDate(DATE)+" TO *]) AND (item.lastmodified:[* TO "+escapedUntilDate(DATE)+"])))"));
|
||||
assertThat(result, is("(((item.lastmodified:[" + escapedFromDate(
|
||||
DATE) + " TO *]) AND (item.lastmodified:[* TO " + escapedUntilDate(DATE) + "])))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customConditionForMetadataExistsFilterWithOneSingleValue() throws Exception {
|
||||
List<ScopedFilter> scopedFilters = new ArrayList<ScopedFilter>();
|
||||
ParameterMap filterConfiguration = new ParameterMap().withValues(new StringValue()
|
||||
.withValue(FIELD_1)
|
||||
.withName("fields"));
|
||||
.withValue(FIELD_1)
|
||||
.withName("fields"));
|
||||
|
||||
scopedFilters.add(new ScopedFilter(new CustomCondition(getFilterResolver(),
|
||||
DSpaceMetadataExistsFilter.class,
|
||||
filterConfiguration),
|
||||
Scope.Query));
|
||||
DSpaceMetadataExistsFilter.class,
|
||||
filterConfiguration),
|
||||
Scope.Query));
|
||||
|
||||
String result = underTest.buildQuery(scopedFilters);
|
||||
|
||||
assertThat(result, is("(((metadata."+FIELD_1+":[* TO *])))"));
|
||||
assertThat(result, is("(((metadata." + FIELD_1 + ":[* TO *])))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customConditionForMetadataExistsFilterWithMultipleValues() throws Exception {
|
||||
List<ScopedFilter> scopedFilters = new ArrayList<ScopedFilter>();
|
||||
ParameterMap filterConfiguration = new ParameterMap().withValues(new ParameterList()
|
||||
.withValues(
|
||||
new StringValue().withValue(FIELD_1),
|
||||
new StringValue().withValue(FIELD_2)
|
||||
)
|
||||
.withName("fields"));
|
||||
.withValues(
|
||||
new StringValue().withValue(FIELD_1),
|
||||
new StringValue().withValue(FIELD_2)
|
||||
)
|
||||
.withName("fields"));
|
||||
|
||||
scopedFilters.add(new ScopedFilter(new CustomCondition(getFilterResolver(),
|
||||
DSpaceMetadataExistsFilter.class,
|
||||
filterConfiguration),
|
||||
Scope.Query));
|
||||
DSpaceMetadataExistsFilter.class,
|
||||
filterConfiguration),
|
||||
Scope.Query));
|
||||
|
||||
String result = underTest.buildQuery(scopedFilters);
|
||||
|
||||
assertThat(result, is("(((metadata."+FIELD_1+":[* TO *] OR metadata."+FIELD_2+":[* TO *])))"));
|
||||
assertThat(result, is("(((metadata." + FIELD_1 + ":[* TO *] OR metadata." + FIELD_2 + ":[* TO *])))"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +161,8 @@ public class DSpaceSolrQueryResolverTest extends AbstractQueryResolverTest {
|
||||
|
||||
String result = underTest.buildQuery(scopedFilters);
|
||||
|
||||
assertThat(result, is("((item.lastmodified:[" + escapedFromDate(DATE) + " TO *])) AND ((item.collections:"+SET+"))"));
|
||||
assertThat(result, is("((item.lastmodified:[" + escapedFromDate(
|
||||
DATE) + " TO *])) AND ((item.collections:" + SET + "))"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -8,7 +8,8 @@
|
||||
http://www.dspace.org/license/
|
||||
|
||||
-->
|
||||
<metadata xmlns="http://www.lyncode.com/xoai" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.lyncode.com/xoai http://www.lyncode.com/xsd/xoai.xsd">
|
||||
<metadata xmlns="http://www.lyncode.com/xoai" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.lyncode.com/xoai http://www.lyncode.com/xsd/xoai.xsd">
|
||||
<element name="dc">
|
||||
<element name="creator">
|
||||
<element name="en_US">
|
||||
|
Reference in New Issue
Block a user