Skip to content
Snippets Groups Projects
Commit b9c8014b authored by Stefan E. Funk's avatar Stefan E. Funk
Browse files

...and more refactoring of OAIPMH creation... using template now for XML generation.

parent 9cdf812d
No related branches found
No related tags found
No related merge requests found
...@@ -153,28 +153,79 @@ ...@@ -153,28 +153,79 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<!-- We use this plugin to ensure that our usage of the maven-jaxb2-plugin
is JDK 8 compatible in absence of a fix for https://java.net/jira/browse/MAVEN_JAXB2_PLUGIN-80. -->
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>${properties-maven-plugin.version}</version>
<executions>
<execution>
<id>set-additional-system-properties</id>
<goals>
<goal>set-system-properties</goal>
</goals>
</execution>
</executions>
<configuration>
<properties>
<property>
<name>javax.xml.accessExternalSchema</name>
<value>file,http</value>
</property>
</properties>
</configuration>
</plugin>
<plugin> <plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId> <groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId> <artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version> <version>0.14.0</version>
<executions> <executions>
<execution> <execution>
<id>generate-oaidc</id>
<goals> <goals>
<goal>generate</goal> <goal>generate</goal>
</goals> </goals>
<configuration>
<schemaDirectory>./src/main/resources/xsd/oaidc</schemaDirectory>
<bindingDirectory>./src/main/resources/binding</bindingDirectory>
<generatePackage>info.textgrid.middleware.oaidc</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/oaidc</generateDirectory>
<args>
<arg>-extension</arg>
<arg>-Xnamespace-prefix</arg>
</args>
</configuration>
</execution>
<execution>
<id>generate-oaipmh</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- <schemas> -->
<!-- <schema> -->
<!-- <url>https://www.openarchives.org/OAI/2.0/OAI-PMH.xsd</url> -->
<!-- </schema> -->
<!-- </schemas> -->
<schemaDirectory>./src/main/resources/xsd/oaipmh</schemaDirectory>
<bindingDirectory>./src/main/resources/binding</bindingDirectory>
<generatePackage>info.textgrid.middleware.oaipmh</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/oaipmh</generateDirectory>
<args>
<arg>-extension</arg>
<arg>-Xnamespace-prefix</arg>
</args>
</configuration>
</execution> </execution>
</executions> </executions>
<configuration> <dependencies>
<generatePackage>info.textgrid.middleware.oaipmh</generatePackage> <dependency>
<schemaDirectory>src/main/xsd</schemaDirectory> <groupId>org.jvnet.jaxb2_commons</groupId>
<schemaIncludes> <artifactId>jaxb2-namespace-prefix</artifactId>
<include>*.xsd</include> <version>1.3</version>
</schemaIncludes> </dependency>
<bindingDirectory>src/main/xsd</bindingDirectory> </dependencies>
<bindingIncludes>
<include>**/*.xjb</include>
</bindingIncludes>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
......
...@@ -3,10 +3,10 @@ package info.textgrid.middleware; ...@@ -3,10 +3,10 @@ package info.textgrid.middleware;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXB; import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import info.textgrid.middleware.oaipmh.ElementType; import info.textgrid.middleware.oaidc.ElementType;
import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.MetadataType;
import info.textgrid.middleware.oaipmh.OaiDcType; import info.textgrid.middleware.oaidc.OaiDcType;
import info.textgrid.middleware.oaipmh.ObjectFactory; import info.textgrid.middleware.oaidc.ObjectFactory;
/** /**
* <p> * <p>
...@@ -312,10 +312,6 @@ public final class DublinCoreBuilder { ...@@ -312,10 +312,6 @@ public final class DublinCoreBuilder {
*/ */
public MetadataType getDC() { public MetadataType getDC() {
this.metadata.setAny(this.oaiDcObj.createDc(this.tgMappedDC)); this.metadata.setAny(this.oaiDcObj.createDc(this.tgMappedDC));
System.out.println(" ##");
JAXB.marshal(this.metadata, System.out);
return this.metadata; return this.metadata;
} }
......
package info.textgrid.middleware; package info.textgrid.middleware;
import java.io.File;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBElement;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
...@@ -25,11 +27,28 @@ import info.textgrid.middleware.oaipmh.VerbType; ...@@ -25,11 +27,28 @@ import info.textgrid.middleware.oaipmh.VerbType;
* </p> * </p>
* *
* @author Maximilian Brodhun, SUB Göttingen * @author Maximilian Brodhun, SUB Göttingen
* @version 2019-05-28 * @author Stefan E. Funk, SUB Göttingen
* @version 2019-10-17
* @since 2014-01-29 * @since 2014-01-29
*/ */
public class OAIPMHImpl implements OAIPMHProducer { public class OAIPMHImpl implements OAIPMHProducer {
// **
// FINAL
// **
private static final String OAIPMH_XML_TEMPLATE =
"../oaipmh-core/src/main/resources/templates/oaipmh-template.xml";
// **
// STATIC
// **
private static ObjectFactory obf = new ObjectFactory();
// **
// PRIVATE
// **
private ErrorHandler error = new ErrorHandler(); private ErrorHandler error = new ErrorHandler();
private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class);
private RepIdentification rep; private RepIdentification rep;
...@@ -46,6 +65,10 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -46,6 +65,10 @@ public class OAIPMHImpl implements OAIPMHProducer {
private MetadataFormatListDeliverer metadataFormatList; private MetadataFormatListDeliverer metadataFormatList;
private SetDeliverer setList; private SetDeliverer setList;
// **
// PUBLIC
// **
public boolean textgrid; public boolean textgrid;
public boolean dariah; public boolean dariah;
...@@ -81,23 +104,43 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -81,23 +104,43 @@ public class OAIPMHImpl implements OAIPMHProducer {
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see info.textgrid.middleware.OAIPMHProducer#postRequest(String, String, String, String, * @see info.textgrid.middleware.OAIPMHProducer#postRequest(java.lang.String, java.lang.String,
* String, String, String) * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/ */
public JAXBElement<OAIPMHtype> postRequest(String verb, String identifier, String metadataPrefix, public JAXBElement<OAIPMHtype> postRequest(String verb, String identifier, String metadataPrefix,
String set, String from, String until, String resumptionToken) { String set, String from, String until, String resumptionToken) {
return handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
JAXBElement<OAIPMHtype> result = null;
try {
result = handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
* @see info.textgrid.middleware.OAIPMHProducer#getRequest(String, String, String, String, String, * @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String,
* String, String) * java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/ */
public JAXBElement<OAIPMHtype> getRequest(String verb, String identifier, String metadataPrefix, public JAXBElement<OAIPMHtype> getRequest(String verb, String identifier, String metadataPrefix,
String set, String from, String until, String resumptionToken) { String set, String from, String until, String resumptionToken) {
return handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
JAXBElement<OAIPMHtype> result = null;
try {
result = handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
} }
/** /**
...@@ -114,16 +157,13 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -114,16 +157,13 @@ public class OAIPMHImpl implements OAIPMHProducer {
* incorrect request. * incorrect request.
* </p> * </p>
* *
* @param obf * @param oaipmhRoot
* @param oai
* @param request * @param request
* @return * @return
*/ */
public JAXBElement<OAIPMHtype> identifyRequest(ObjectFactory obf, OAIPMHtype oai, public OAIPMHtype identifyRequest(OAIPMHtype oaipmhRoot, RequestType request) {
RequestType request) {
List<String> errorValues = new ArrayList<String>(); List<String> errorValues = new ArrayList<String>();
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai);
IdentifyType tgRepIdentificationRequest = new IdentifyType(); IdentifyType tgRepIdentificationRequest = new IdentifyType();
if (this.rep.requestChecker(request)) { if (this.rep.requestChecker(request)) {
...@@ -135,7 +175,7 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -135,7 +175,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
tgRepIdentificationRequest.setRepositoryName(this.rep.getRepositoryName()); tgRepIdentificationRequest.setRepositoryName(this.rep.getRepositoryName());
tgRepIdentificationRequest.setProtocolVersion(this.rep.getProtocolVersion()); tgRepIdentificationRequest.setProtocolVersion(this.rep.getProtocolVersion());
tgRepIdentificationRequest.getAdminEmail().add(this.rep.getAdminMaiAddresss()); tgRepIdentificationRequest.getAdminEmail().add(this.rep.getAdminMaiAddresss());
oai.setIdentify(tgRepIdentificationRequest); oaipmhRoot.setIdentify(tgRepIdentificationRequest);
} else { } else {
if (request.getIdentifier() != null) { if (request.getIdentifier() != null) {
...@@ -159,35 +199,31 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -159,35 +199,31 @@ public class OAIPMHImpl implements OAIPMHProducer {
this.error.setError(TGConstants.OAI_BAD_ARGUMENT, this.error.setError(TGConstants.OAI_BAD_ARGUMENT,
"The request includes illegal arguments: " + errorValues); "The request includes illegal arguments: " + errorValues);
oai.getError().add(this.error.getError()); oaipmhRoot.getError().add(this.error.getError());
} }
return oaipmhRoot; return oaipmhRoot;
} }
/** /**
* checks the GetRecord request of correctness and response including errors in case of an * <p>
* incorrect request * Checks the GetRecord request of correctness and response including errors in case of an
* incorrect request.
* </p>
* *
* @param obf * @param oaipmhRoot
* @param oai
* @param request * @param request
* @return * @return
*/ */
public JAXBElement<OAIPMHtype> getRecordRequest(ObjectFactory obf, OAIPMHtype oai, public OAIPMHtype getRecordRequest(OAIPMHtype oaipmhRoot, RequestType request) {
RequestType request) {
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai); // Check request. In GetRecord: allowed parameters: identifier, metadataPrefix, verb forbidden:
// resumptionToken, from, till, set optional: no one.
/**
* Check request. In GetRecord: allowed parameters: identifier, metadataPrefix, verb forbidden:
* resumptionToken, from, till, set optional: no one
*/
ErrorHandler requestErrors = RecordDelivererAbstract.requestChecker(request); ErrorHandler requestErrors = RecordDelivererAbstract.requestChecker(request);
if (requestErrors.getError().getCode() != null) { if (requestErrors.getError().getCode() != null) {
oai.getError().add(requestErrors.getError()); oaipmhRoot.getError().add(requestErrors.getError());
} }
// Get Record Request is done HERE! // Get Record Request is done HERE!
...@@ -208,12 +244,12 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -208,12 +244,12 @@ public class OAIPMHImpl implements OAIPMHProducer {
getRecord = recDeliv.getRecordById(id); getRecord = recDeliv.getRecordById(id);
if (getRecord != null) { if (getRecord != null) {
oai.setGetRecord(getRecord); oaipmhRoot.setGetRecord(getRecord);
} else { } else {
ErrorHandler idError = new ErrorHandler(); ErrorHandler idError = new ErrorHandler();
idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: "
+ request.getIdentifier() + " is unknown or illegal in this repository"); + request.getIdentifier() + " is unknown or illegal in this repository");
oai.getError().add(idError.getError()); oaipmhRoot.getError().add(idError.getError());
} }
} }
...@@ -221,24 +257,23 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -221,24 +257,23 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* checks the ListIdentifiers request of correctness and response including errors in case of an * <p>
* incorrect request * Checks the ListIdentifiers request of correctness and response including errors in case of an
* incorrect request.
* </p>
* *
* @param obf
* @param oai * @param oai
* @param request * @param request
* @return * @return
* @throws ParseException * @throws ParseException
*/ */
public JAXBElement<OAIPMHtype> listIdentifiersRequest(ObjectFactory obf, OAIPMHtype oai, public OAIPMHtype listIdentifiersRequest(OAIPMHtype oaipmhRoot, RequestType request)
RequestType request) throws ParseException { throws ParseException {
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai);
ErrorHandler requestErrors = IdentifierListDelivererAbstract.requestChecker(request); ErrorHandler requestErrors = IdentifierListDelivererAbstract.requestChecker(request);
if (requestErrors.getError().getValue() != null) { if (requestErrors.getError().getValue() != null) {
oai.getError().add(requestErrors.getError()); oaipmhRoot.getError().add(requestErrors.getError());
} else { } else {
// If metadataFormat IS SET, set recordListDeliverer accordingly. // If metadataFormat IS SET, set recordListDeliverer accordingly.
...@@ -266,31 +301,16 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -266,31 +301,16 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
} }
// // Default is DC.
//
// IdentifierListDelivererInterface listDeliv = this.identifierListDC;
//
// this.log.info("Actual Value of IDIOM MetsMods Boolean is: "
// + IdentifierListDelivererAbstract.isIdiomMets());
// this.log.info("Actual Value of DublinCore Boolean is: "
// + IdentifierListDelivererAbstract.isDublinCore());
//
// if (IdentifierListDelivererAbstract.isIdiomMets()) {
// listDeliv = this.identifierListIDIOM;
// } else if (IdentifierListDelivererAbstract.isDublinCore()) {
// listDeliv = this.identifierListDC;
// }
ListIdentifiersType listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(), ListIdentifiersType listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(),
request.getUntil(), request.getSet(), request.getResumptionToken()); request.getUntil(), request.getSet(), request.getResumptionToken());
if (listIdentifiers != null) { if (listIdentifiers != null) {
oai.setListIdentifiers(listIdentifiers); oaipmhRoot.setListIdentifiers(listIdentifiers);
} else { } else {
ErrorHandler idError = new ErrorHandler(); ErrorHandler idError = new ErrorHandler();
idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: "
+ request.getIdentifier() + " is unknown or illegal in this repository"); + request.getIdentifier() + " is unknown or illegal in this repository");
oai.getError().add(idError.getError()); oaipmhRoot.getError().add(idError.getError());
} }
} }
...@@ -298,36 +318,31 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -298,36 +318,31 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* checks the ListSets request of correctness and response including errors in case of an * <p>
* incorrect request * Checks the ListSets request of correctness and response including errors in case of an
* incorrect request.
* </p>
* *
* @param obf
* @param oai * @param oai
* @param request * @param request
* @return * @return
*/ */
public JAXBElement<OAIPMHtype> listSetsRequest(ObjectFactory obf, OAIPMHtype oai, public OAIPMHtype listSetsRequest(OAIPMHtype oaipmhRoot, RequestType request) {
RequestType request) {
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai);
ListSetsType sl = this.setList.setListBuilder(); ListSetsType sl = this.setList.setListBuilder();
oai.setListSets(sl); oaipmhRoot.setListSets(sl);
return oaipmhRoot; return oaipmhRoot;
} }
/** /**
* @param id * @param id
* @param obf * @param oaipmhRoot
* @param oai
* @param request * @param request
* @return * @return
*/ */
public JAXBElement<OAIPMHtype> listMetadataFormatsRequest(String id, ObjectFactory obf, public OAIPMHtype listMetadataFormatsRequest(String id, OAIPMHtype oaipmhRoot,
OAIPMHtype oai, RequestType request) { RequestType request) {
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai);
List<String> errorValues = new ArrayList<String>(); List<String> errorValues = new ArrayList<String>();
ListMetadataFormatsType listMF = new ListMetadataFormatsType(); ListMetadataFormatsType listMF = new ListMetadataFormatsType();
...@@ -341,14 +356,16 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -341,14 +356,16 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
if (listMF != null) { if (listMF != null) {
oaipmhRoot.setListMetadataFormats(listMF);
oai.setListMetadataFormats(listMF);
} else { } else {
this.error.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " this.error.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: "
+ request.getIdentifier() + " is unknown or illegal in this repository"); + request.getIdentifier() + " is unknown or illegal in this repository");
oai.getError().add(this.error.getError()); oaipmhRoot.getError().add(this.error.getError());
} }
} else { }
else {
if (request.getFrom() != null) { if (request.getFrom() != null) {
errorValues.add("from"); errorValues.add("from");
} }
...@@ -367,29 +384,24 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -367,29 +384,24 @@ public class OAIPMHImpl implements OAIPMHProducer {
this.error.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal " this.error.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal "
+ "arguments or is missing required arguments: " + errorValues); + "arguments or is missing required arguments: " + errorValues);
oai.getError().add(this.error.getError()); oaipmhRoot.getError().add(this.error.getError());
} }
return oaipmhRoot; return oaipmhRoot;
} }
/** /**
* @param obf
* @param oai * @param oai
* @param request * @param request
* @return * @return
*/ */
public JAXBElement<OAIPMHtype> listRecordsRequest(ObjectFactory obf, OAIPMHtype oai, public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) {
RequestType request) {
// Create OAIPMH root object.
JAXBElement<OAIPMHtype> oaipmhRoot = getOAIPMHRoot(obf, oai);
// Check request's syntax. // Check request's syntax.
ErrorHandler requestErrors = RecordListDelivererAbstract.requestChecker(request); ErrorHandler requestErrors = RecordListDelivererAbstract.requestChecker(request);
if (requestErrors.getError().getCode() != null) { if (requestErrors.getError().getCode() != null) {
oai.getError().add(requestErrors.getError()); oaipmhRoot.getError().add(requestErrors.getError());
} else { } else {
// If metadataFormat IS SET, set recordListDeliverer accordingly. // If metadataFormat IS SET, set recordListDeliverer accordingly.
...@@ -420,7 +432,7 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -420,7 +432,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
request.getSet(), request.getResumptionToken()); request.getSet(), request.getResumptionToken());
if (listRecords != null) { if (listRecords != null) {
oai.setListRecords(listRecords); oaipmhRoot.setListRecords(listRecords);
} }
} }
...@@ -428,7 +440,9 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -428,7 +440,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Taking the sting from the REST request and converting into an OAIPMH verb type * <p>
* Taking the sting from the REST request and converting into an OAIPMH verb type.
* </p>
* *
* @param verb : what is to within the repository * @param verb : what is to within the repository
* @return verbParam: the verbParam as an OAIPMH verb type * @return verbParam: the verbParam as an OAIPMH verb type
...@@ -454,7 +468,7 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -454,7 +468,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
} else if (verb != null && verb.equals("GetRecord")) { } else if (verb != null && verb.equals("GetRecord")) {
verbParam = VerbType.GET_RECORD; verbParam = VerbType.GET_RECORD;
} else { } else {
// FIXME // FIXME What must be fixed here? --fu
this.error.setError("VerbError", "Illegal OAI verb"); this.error.setError("VerbError", "Illegal OAI verb");
} }
...@@ -462,11 +476,12 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -462,11 +476,12 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Setting the from value for the request * <p>
* Setting the from value for the request.
* </p>
* *
* @param from * @param from
*/ */
public void setFromRequestValue(String from, RequestType request) { public void setFromRequestValue(String from, RequestType request) {
if (!from.isEmpty()) { if (!from.isEmpty()) {
request.setFrom(from); request.setFrom(from);
...@@ -474,7 +489,9 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -474,7 +489,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Setting the until value for the request * <p>
* Setting the until value for the request.
* </p>
* *
* @param until * @param until
*/ */
...@@ -485,7 +502,9 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -485,7 +502,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Setting the identifier value for the request * <p>
* Setting the identifier value for the request.
* </p>
* *
* @param identifier * @param identifier
*/ */
...@@ -496,7 +515,9 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -496,7 +515,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Setting the metadataPrefix value for the request * <p>
* Setting the metadataPrefix value for the request.
* </p>
* *
* @param metadataPrefix * @param metadataPrefix
*/ */
...@@ -507,7 +528,9 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -507,7 +528,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
/** /**
* Setting the resumptionToken value for the request * <p>
* Setting the resumptionToken value for the request.
* </p>
* *
* @param resumptionToken * @param resumptionToken
*/ */
...@@ -558,15 +581,17 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -558,15 +581,17 @@ public class OAIPMHImpl implements OAIPMHProducer {
* @param until * @param until
* @param resumptionToken * @param resumptionToken
* @return * @return
* @throws ParseException
*/ */
private JAXBElement<OAIPMHtype> handleRequest(String verb, String identifier, private JAXBElement<OAIPMHtype> handleRequest(String verb, String identifier,
String metadataPrefix, String set, String from, String until, String resumptionToken) { String metadataPrefix, String set, String from, String until, String resumptionToken)
throws ParseException {
JAXBElement<OAIPMHtype> result; JAXBElement<OAIPMHtype> result;
ObjectFactory obf = new ObjectFactory(); // Create new OAIPMH XML document from template, set result.
OAIPMHtype response = new OAIPMHtype(); // OAIPMHtype response = JAXB.unmarshal(new File(OAIPMH_XML_TEMPLATE), OAIPMHtype.class);
result = getOAIPMHRoot(obf, response); OAIPMHtype response = obf.createOAIPMHtype();
VerbType verbParam = setVerb(verb); VerbType verbParam = setVerb(verb);
RequestType request = new RequestType(); RequestType request = new RequestType();
...@@ -601,22 +626,17 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -601,22 +626,17 @@ public class OAIPMHImpl implements OAIPMHProducer {
if (verbParam != null) { if (verbParam != null) {
if (verbParam.value().equals("Identify")) { if (verbParam.value().equals("Identify")) {
result = identifyRequest(obf, response, request); response = identifyRequest(response, request);
} else if (verbParam.value().equals("GetRecord")) { } else if (verbParam.value().equals("GetRecord")) {
result = getRecordRequest(obf, response, request); response = getRecordRequest(response, request);
} else if (verbParam.value().equals("ListIdentifiers")) { } else if (verbParam.value().equals("ListIdentifiers")) {
try { response = listIdentifiersRequest(response, request);
result = listIdentifiersRequest(obf, response, request);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (verbParam.value().equals("ListSets")) { } else if (verbParam.value().equals("ListSets")) {
result = listSetsRequest(obf, response, request); response = listSetsRequest(response, request);
} else if (verbParam.value().equals("ListMetadataFormats")) { } else if (verbParam.value().equals("ListMetadataFormats")) {
result = listMetadataFormatsRequest(identifier, obf, response, request); response = listMetadataFormatsRequest(identifier, response, request);
} else if (verbParam.value().equals("ListRecords")) { } else if (verbParam.value().equals("ListRecords")) {
result = listRecordsRequest(obf, response, request); response = listRecordsRequest(response, request);
} }
} else { } else {
this.error.setError("VerbError", "Illegal OAI verb"); this.error.setError("VerbError", "Illegal OAI verb");
...@@ -624,21 +644,7 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -624,21 +644,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
} }
response.setRequest(request); response.setRequest(request);
result.setValue(response); result = obf.createOAIPMH(response);
return result;
}
/**
* @param obf
* @param oai
* @return
*/
private static JAXBElement<OAIPMHtype> getOAIPMHRoot(ObjectFactory obf, OAIPMHtype oai) {
JAXBElement<OAIPMHtype> result = obf.createOAIPMH(oai);
// TODO Add DC XSD URL for xsi:schemaLocation.
return result; return result;
} }
......
...@@ -15,10 +15,8 @@ import info.textgrid.middleware.oaipmh.OAIPMHtype; ...@@ -15,10 +15,8 @@ import info.textgrid.middleware.oaipmh.OAIPMHtype;
import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes; import info.textgrid.namespaces.middleware.tgcrud.common.TextGridMimetypes;
/** /**
*
* @author Maximilian Brodhun, SUB Göttingen * @author Maximilian Brodhun, SUB Göttingen
* @author Stefan E. Funk, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen
*
*/ */
public class OaiPmhTest { public class OaiPmhTest {
...@@ -215,7 +213,6 @@ public class OaiPmhTest { ...@@ -215,7 +213,6 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/** /**
* @throws ParseException * @throws ParseException
*/ */
...@@ -228,7 +225,6 @@ public class OaiPmhTest { ...@@ -228,7 +225,6 @@ public class OaiPmhTest {
"", "", "", "", ""); "", "", "", "", "");
JAXB.marshal(p, System.out); JAXB.marshal(p, System.out);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/** /**
...@@ -251,6 +247,9 @@ public class OaiPmhTest { ...@@ -251,6 +247,9 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test @Test
@Ignore @Ignore
public void testListIdentifierWithResumptionTokenDC() throws ParseException { public void testListIdentifierWithResumptionTokenDC() throws ParseException {
...@@ -266,7 +265,6 @@ public class OaiPmhTest { ...@@ -266,7 +265,6 @@ public class OaiPmhTest {
"", "", "", ""); "", "", "", "");
JAXB.marshal(p, System.out); JAXB.marshal(p, System.out);
String resToken = ""; String resToken = "";
for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.cursorCollector.entrySet()) { for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.cursorCollector.entrySet()) {
resToken = entry.getKey(); resToken = entry.getKey();
...@@ -283,10 +281,12 @@ public class OaiPmhTest { ...@@ -283,10 +281,12 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test @Test
@Ignore @Ignore
public void testListIdentifierIDIOMInvalidResumptionToken() throws ParseException { public void testListIdentifierIDIOMInvalidResumptionToken() throws ParseException {
System.out System.out
.println("Test for the verb \"ListIdentifiers\" in IDIOM with an invalid resumption token"); .println("Test for the verb \"ListIdentifiers\" in IDIOM with an invalid resumption token");
JAXBElement<OAIPMHtype> p = this.request.getRequest("ListIdentifiers", "", "", JAXBElement<OAIPMHtype> p = this.request.getRequest("ListIdentifiers", "", "",
...@@ -295,6 +295,9 @@ public class OaiPmhTest { ...@@ -295,6 +295,9 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test @Test
@Ignore @Ignore
public void testListIdentifierIDIOMWithResumptionToken() throws ParseException { public void testListIdentifierIDIOMWithResumptionToken() throws ParseException {
...@@ -319,7 +322,6 @@ public class OaiPmhTest { ...@@ -319,7 +322,6 @@ public class OaiPmhTest {
System.out.println(IdentifierListDelivererIDIOM.cursorCollector); System.out.println(IdentifierListDelivererIDIOM.cursorCollector);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/** /**
...@@ -369,11 +371,12 @@ public class OaiPmhTest { ...@@ -369,11 +371,12 @@ public class OaiPmhTest {
System.out.println("HASH MAP AFTER: "); System.out.println("HASH MAP AFTER: ");
System.out.println(RecordListDelivererDC.cursorCollector); System.out.println(RecordListDelivererDC.cursorCollector);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test @Test
@Ignore @Ignore
public void testListRecordWithResumptionTokenForIDIOM() throws ParseException { public void testListRecordWithResumptionTokenForIDIOM() throws ParseException {
...@@ -384,7 +387,6 @@ public class OaiPmhTest { ...@@ -384,7 +387,6 @@ public class OaiPmhTest {
""); "");
JAXB.marshal(p, System.out); JAXB.marshal(p, System.out);
String resToken = ""; String resToken = "";
for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.cursorCollector.entrySet()) { for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.cursorCollector.entrySet()) {
resToken = entry.getKey(); resToken = entry.getKey();
...@@ -397,10 +399,8 @@ public class OaiPmhTest { ...@@ -397,10 +399,8 @@ public class OaiPmhTest {
System.out.println(RecordListDelivererIDIOM.cursorCollector); System.out.println(RecordListDelivererIDIOM.cursorCollector);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/** /**
* @throws ParseException * @throws ParseException
*/ */
...@@ -453,8 +453,6 @@ public class OaiPmhTest { ...@@ -453,8 +453,6 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/** /**
* @throws ParseException * @throws ParseException
*/ */
...@@ -496,7 +494,9 @@ public class OaiPmhTest { ...@@ -496,7 +494,9 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test @Test
@Ignore @Ignore
public void testEmptyRequest() throws ParseException { public void testEmptyRequest() throws ParseException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment