Permalink
Browse files

Merge pull request #92 from atmire/dspace3-lyncode-fix

XOAI (Moved configs and bug fix)
  • Loading branch information...
2 parents 2fb2eee + 8be71cf commit fdaffdc806a954f0ab33668270f894124a95c1ee @mdiggory mdiggory committed Oct 6, 2012
Showing with 171 additions and 175 deletions.
  1. +6 −1 dspace-oai/pom.xml
  2. +5 −2 dspace-oai/src/main/java/org/dspace/xoai/DSpaceOAIDataProvider.java
  3. +7 −76 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceDatabaseItem.java
  4. +65 −8 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceItem.java
  5. +2 −2 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceItemDatabaseRepository.java
  6. +14 −14 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceItemRepository.java
  7. +2 −2 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceItemSolrRepository.java
  8. +2 −2 dspace-oai/src/main/java/org/dspace/xoai/data/DSpaceSetRepository.java
  9. +3 −3 dspace-oai/src/main/java/org/dspace/xoai/filter/DSpaceAtLeastOneMetadataFilter.java
  10. +11 −3 dspace-oai/src/main/java/org/dspace/xoai/filter/DSpaceAuthorizationFilter.java
  11. +9 −3 dspace-oai/src/main/java/org/dspace/xoai/filter/DSpaceFilter.java
  12. +3 −2 dspace-oai/src/main/java/org/dspace/xoai/filter/DSpaceMetadataExistsFilter.java
  13. +2 −1 dspace-oai/src/main/java/org/dspace/xoai/filter/DateFromFilter.java
  14. +2 −1 dspace-oai/src/main/java/org/dspace/xoai/filter/DateUntilFilter.java
  15. +7 −27 dspace-oai/src/main/java/org/dspace/xoai/filter/DspaceSetSpecFilter.java
  16. +30 −0 dspace-oai/src/main/java/org/dspace/xoai/util/MetadataNamePredicate.java
  17. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/didl.xsl
  18. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/dim.xsl
  19. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/etdms.xsl
  20. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/marc.xsl
  21. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/mets.xsl
  22. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/mods.xsl
  23. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/oai_dc.xsl
  24. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/ore.xsl
  25. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/qdc.xsl
  26. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/rdf.xsl
  27. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/uketd_dc.xsl
  28. 0 dspace/config/{modules → crosswalks}/oai/metadataFormats/xoai.xsl
  29. 0 dspace/config/{modules → crosswalks}/oai/transformers/driver.xsl
  30. 0 dspace/config/{modules → crosswalks}/oai/transformers/openaire.xsl
  31. 0 dspace/config/{modules → crosswalks}/oai/xoai.xml
  32. +0 −27 dspace/config/crosswalks/oaidc.properties
  33. +1 −1 dspace/config/modules/oai.cfg
View
@@ -75,7 +75,7 @@
<dependency>
<groupId>com.lyncode</groupId>
<artifactId>xoai</artifactId>
- <version>2.2.0</version>
+ <version>2.2.5</version>
</dependency>
<dependency>
<groupId>org.dspace</groupId>
@@ -101,6 +101,11 @@
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>13.0</version>
+ </dependency>
</dependencies>
@@ -60,12 +60,15 @@ public void init()
}
catch (com.lyncode.xoai.dataprovider.exceptions.ConfigurationException e)
{
- System.out.println("Unable to configure XOAI (OAI 2.0 Core)");
+ System.out.println("Unable to configure XOAI (XOAI 2.0 Core)");
e.printStackTrace();
}
catch (SolrServerException e)
{
- System.out.println("Unable to configure XOAI (OAI 2.0 Core)");
+ System.out.println("Unable to connect to Solr Server");
+ e.printStackTrace();
+ } catch (Exception e) {
+ System.out.println("Unable to initialize XOAI.");
e.printStackTrace();
}
}
@@ -9,7 +9,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;
@@ -19,14 +18,18 @@
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
+import org.dspace.xoai.util.MetadataNamePredicate;
import org.dspace.xoai.util.XOAICacheManager;
import org.dspace.xoai.util.XOAIDatabaseManager;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
import com.lyncode.xoai.dataprovider.core.ItemMetadata;
import com.lyncode.xoai.dataprovider.core.ReferenceSet;
import com.lyncode.xoai.dataprovider.data.AbstractAbout;
import com.lyncode.xoai.dataprovider.exceptions.MetadataBindException;
import com.lyncode.xoai.dataprovider.xml.xoai.Element;
+import com.lyncode.xoai.dataprovider.xml.xoai.Element.Field;
/**
*
@@ -35,7 +38,9 @@
public class DSpaceDatabaseItem extends DSpaceItem
{
private static Logger log = LogManager.getLogger(DSpaceDatabaseItem.class);
-
+
+
+
private static List<ReferenceSet> getSets(Item item)
{
List<ReferenceSet> sets = new ArrayList<ReferenceSet>();
@@ -127,80 +132,6 @@ public ItemMetadata getMetadata()
return metadata;
}
- private List<String> getMetadata(List<Element> elems, String[] parts)
- {
- List<String> list = new ArrayList<String>();
- if (parts.length > 1)
- {
- if (parts[0].equals("*"))
- {
- for (Element e : elems)
- {
- if (e.getElement() != null)
- list.addAll(this.getMetadata(e.getElement(),
- Arrays.copyOfRange(parts, 1, parts.length)));
- }
- }
- else
- {
- Element e = getElement(elems, parts[0]);
- if (e != null)
- list.addAll(this.getMetadata(e.getElement(),
- Arrays.copyOfRange(parts, 1, parts.length)));
- }
- }
- else if (parts.length == 1)
- {
- // Here we could have reached our target (named fields)
- for (Element e : elems)
- {
- for (Element.Field f : e.getField())
- {
- if (parts[0].equals("*"))
- list.add(f.getValue());
- else if (parts[0].equals(f.getName()))
- list.add(f.getValue());
- }
- }
-
- if (parts[0].equals("*"))
- {
- for (Element e : elems)
- {
- if (e.getElement() != null)
- list.addAll(this.getMetadata(e.getElement(),
- Arrays.copyOfRange(parts, 1, parts.length)));
- }
- }
- else
- {
- Element e = getElement(elems, parts[0]);
- if (e != null)
- list.addAll(this.getMetadata(e.getElement(),
- Arrays.copyOfRange(parts, 1, parts.length)));
- }
- }
- else
- {
- // Here we have reached our target (unnamed fields)
- for (Element e : elems)
- {
- for (Element.Field f : e.getField())
- {
- if (f.getName() == null || f.getName().equals(""))
- list.add(f.getValue());
- }
- }
- }
- return list;
- }
-
- public List<String> getMetadata(String field)
- {
- String[] parts = field.split(Pattern.quote("."));
- return getMetadata(this.getMetadata().getMetadata().getElement(), parts);
- }
-
public Item getItem()
{
return item;
@@ -9,37 +9,94 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.regex.Pattern;
import org.dspace.core.ConfigurationManager;
+import org.dspace.xoai.util.MetadataNamePredicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
import com.lyncode.xoai.dataprovider.data.AbstractAbout;
import com.lyncode.xoai.dataprovider.data.AbstractItem;
+import com.lyncode.xoai.dataprovider.xml.xoai.Element;
+import com.lyncode.xoai.dataprovider.xml.xoai.Element.Field;
/**
*
* @author Lyncode Development Team <dspace@lyncode.com>
*/
public abstract class DSpaceItem extends AbstractItem
{
+ 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)
+ {
+ _prefix = ConfigurationManager.getProperty("oai",
+ "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 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>();
+ }
+
@Override
public List<AbstractAbout> getAbout()
{
return new ArrayList<AbstractAbout>();
}
protected abstract String getHandle ();
-
- private String _prefix = null;
@Override
public String getIdentifier()
{
- if (_prefix == null)
- {
- _prefix = ConfigurationManager.getProperty("oai",
- "identifier.prefix");
- }
- return "oai:" + _prefix + ":" + this.getHandle();
+ return buildIdentifier(getHandle());
}
}
@@ -153,7 +153,7 @@ private ListItemsResults getResult(String query, String countQuery, List<Object>
}
@Override
- protected ListItemsResults getItems(List<Filter> filters, int offset,
+ public ListItemsResults getItems(List<Filter> filters, int offset,
int length)
{
List<Object> parameters = new ArrayList<Object>();
@@ -207,7 +207,7 @@ protected ListItemsResults getItems(List<Filter> filters, int offset,
}
@Override
- protected ListItemIdentifiersResult getItemIdentifiers(
+ public ListItemIdentifiersResult getItemIdentifiers(
List<Filter> filters, int offset, int length)
{
List<Object> parameters = new ArrayList<Object>();
Oops, something went wrong.

0 comments on commit fdaffdc

Please sign in to comment.