
java.fedora.server.oai.FedoraOAIProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fcrepo-client Show documentation
Show all versions of fcrepo-client Show documentation
The Fedora Client is a Java Library that allows API access to a Fedora Repository. The client is typically one part of a full Fedora installation.
The newest version!
/*
* -----------------------------------------------------------------------------
*
* License and Copyright: The contents of this file are subject to the
* Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
* http://www.fedora-commons.org/licenses.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The entire file consists of original code.
* Copyright © 2008 Fedora Commons, Inc.
*
Copyright © 2002-2007 The Rector and Visitors of the University of
* Virginia and Cornell University
* All rights reserved.
*
* -----------------------------------------------------------------------------
*/
package fedora.server.oai;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import fedora.oai.*;
import fedora.server.errors.ServerException;
import fedora.server.errors.UnknownSessionTokenException;
import fedora.server.utilities.DCFields;
import fedora.server.search.ObjectFields;
import fedora.server.search.Condition;
import fedora.server.search.FieldSearch;
import fedora.server.search.FieldSearchQuery;
import fedora.server.search.FieldSearchResult;
import fedora.server.utilities.StreamUtility;
/**
* Simple FieldSearch-based OAI provider.
*
* @author [email protected]
* @version $Id: FedoraOAIProvider.java 5220 2006-11-20 13:52:20Z cwilper $
*/
public class FedoraOAIProvider
implements OAIProvider {
private String m_repositoryName;
private String m_repositoryDomainName;
private String m_localname;
private String m_relpath;
private Set m_adminEmails;
private Set m_descriptions;
private List m_setInfos;
private long m_maxSets;
private long m_maxRecords;
private long m_maxHeaders;
private FieldSearch m_fieldSearch;
private Set m_formats;
private static Set s_emptySet=new HashSet();
private static String[] s_headerFields=new String[] {"pid", "dcmDate",
"fType"};
private static String[] s_headerAndDCFields=new String[] {"pid", "dcmDate",
"fType", "title", "creator", "subject", "description", "publisher",
"contributor", "date", "type", "format", "identifier", "source",
"language", "relation", "coverage", "rights"};
public FedoraOAIProvider(String repositoryName, String repositoryDomainName,
String localname, String relpath, Set adminEmails, Set friendBaseURLs,
String namespaceID, long maxSets, long maxRecords, long maxHeaders,
FieldSearch fieldSearch) {
m_repositoryName=repositoryName;
m_repositoryDomainName=repositoryDomainName;
m_localname=localname;
m_relpath=relpath;
m_adminEmails=adminEmails;
m_maxSets=maxSets;
m_maxRecords=maxRecords;
m_maxHeaders=maxHeaders;
m_fieldSearch=fieldSearch;
m_descriptions=new HashSet();
StringBuffer buf=new StringBuffer();
buf.append(" \n");
buf.append(" oai \n");
buf.append(" " + m_repositoryDomainName + " \n");
buf.append(" : \n");
buf.append(" oai:" + m_repositoryDomainName + ":" + namespaceID + ":7654 \n");
buf.append(" ");
m_descriptions.add(buf.toString());
if (friendBaseURLs!=null && friendBaseURLs.size()>0) {
buf=new StringBuffer();
buf.append(" \n");
Iterator iter=friendBaseURLs.iterator();
while (iter.hasNext()) {
buf.append(" " + (String) iter.next() + " \n");
}
buf.append(" ");
m_descriptions.add(buf.toString());
}
m_formats=new HashSet();
m_formats.add(new SimpleMetadataFormat("oai_dc",
"http://www.openarchives.org/OAI/2.0/oai_dc.xsd",
"http://www.openarchives.org/OAI/2.0/oai_dc/"));
m_setInfos=new ArrayList();
m_setInfos.add(new SimpleSetInfo("Data Objects", "objects", s_emptySet));
m_setInfos.add(new SimpleSetInfo("Behavior Mechanism Objects", "bmechs", s_emptySet));
m_setInfos.add(new SimpleSetInfo("Behavior Definition Objects", "bdefs", s_emptySet));
}
public String getRepositoryName() {
return m_repositoryName;
}
public String getBaseURL(String protocol, String port) {
return protocol + "://" + m_localname + ":" + port + m_relpath;
}
public String getProtocolVersion() {
return "2.0";
}
public Date getEarliestDatestamp() {
return new Date();
}
public DeletedRecordSupport getDeletedRecordSupport() {
return DeletedRecordSupport.NO;
}
public DateGranularitySupport getDateGranularitySupport() {
return DateGranularitySupport.SECONDS;
}
public Set getAdminEmails() {
return m_adminEmails;
}
public Set getSupportedCompressionEncodings() {
return s_emptySet;
}
public Set getDescriptions() {
return m_descriptions;
}
public Record getRecord(String identifier, String metadataPrefix)
throws CannotDisseminateFormatException, IDDoesNotExistException,
RepositoryException {
if (!metadataPrefix.equals("oai_dc")) {
throw new CannotDisseminateFormatException("Repository does not provide that format in OAI-PMH responses.");
}
String pid=getPID(identifier);
List l=null;
try {
//FIXME: use maxResults from... config instead of hardcoding 100?
l=m_fieldSearch.findObjects(s_headerAndDCFields, 100,
new FieldSearchQuery(Condition.getConditions("pid='" + pid
+ "' dcmDate>'2000-01-01'"))).objectFieldsList();
} catch (ServerException se) {
throw new RepositoryException(se.getClass().getName() + ": " + se.getMessage());
}
if (l.size()>0) {
ObjectFields f=(ObjectFields) l.get(0);
return new SimpleRecord(getHeader(f), getDCXML(f), s_emptySet);
} else {
// see if it exists
try {
l=m_fieldSearch.findObjects(new String[] {"pid"}, 1,
new FieldSearchQuery(Condition.getConditions("pid='"
+ pid + "'"))).objectFieldsList();
} catch (ServerException se) {
throw new RepositoryException(se.getClass().getName() + ": " + se.getMessage());
}
if (l.size()==0) {
throw new IDDoesNotExistException("The provided id does not match any item in the repository.");
} else {
throw new CannotDisseminateFormatException("The item doesn't even have dc_oai metadata.");
}
}
}
public List getRecords(Date from, Date until, String metadataPrefix,
String set)
throws CannotDisseminateFormatException,
NoRecordsMatchException, NoSetHierarchyException,
RepositoryException {
if (!metadataPrefix.equals("oai_dc")) {
throw new CannotDisseminateFormatException("Repository does not provide that format in OAI-PMH responses.");
}
List l=null;
FieldSearchResult fsr;
try {
fsr=m_fieldSearch.findObjects(s_headerAndDCFields, (int) getMaxRecords(),
new FieldSearchQuery(Condition.getConditions(
"dcmDate>'2000-01-01'" + getDatePart(from, until)
+ getFTypePart(set))));
l=fsr.objectFieldsList();
} catch (ServerException se) {
throw new RepositoryException(se.getClass().getName() + ": " + se.getMessage());
}
if (l.size()==0) {
throw new NoRecordsMatchException("No records match the given criteria.");
}
ArrayList
© 2015 - 2025 Weber Informatics LLC | Privacy Policy