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

added POST calls to OAIPMH request handling.

parent 9230c223
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
<parent>
<artifactId>oaipmh</artifactId>
<groupId>info.textgrid.middleware</groupId>
<version>2.15.0-SNAPSHOT</version>
<version>2.16.0-SNAPSHOT</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>oaipmh-core</artifactId>
......
package info.textgrid.middleware;
import info.textgrid.middleware.oaipmh.GetRecordType;
import info.textgrid.middleware.oaipmh.IdentifyType;
import info.textgrid.middleware.oaipmh.ListIdentifiersType;
import info.textgrid.middleware.oaipmh.ListMetadataFormatsType;
import info.textgrid.middleware.oaipmh.ListRecordsType;
import info.textgrid.middleware.oaipmh.ListSetsType;
import info.textgrid.middleware.oaipmh.OAIPMHType;
import info.textgrid.middleware.oaipmh.ObjectFactory;
import info.textgrid.middleware.oaipmh.RequestType;
import info.textgrid.middleware.oaipmh.VerbType;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBElement;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.commons.logging.LogFactory;
import info.textgrid.middleware.oaipmh.GetRecordType;
import info.textgrid.middleware.oaipmh.IdentifyType;
import info.textgrid.middleware.oaipmh.ListIdentifiersType;
import info.textgrid.middleware.oaipmh.ListMetadataFormatsType;
import info.textgrid.middleware.oaipmh.ListRecordsType;
import info.textgrid.middleware.oaipmh.ListSetsType;
import info.textgrid.middleware.oaipmh.OAIPMHType;
import info.textgrid.middleware.oaipmh.ObjectFactory;
import info.textgrid.middleware.oaipmh.RequestType;
import info.textgrid.middleware.oaipmh.VerbType;
/**
* This class takes all possible arguments of an OAI-PMH request and proceeds
* depended on the given arguments. It also deals as response handler
* This class takes all possible arguments of an OAI-PMH request and proceeds depended on the given
* arguments. It also deals as response handler
*
* @author Maximilian Brodhun: SUB
* @version 1.0
* @since 29.01.2014
*
*/
public class OAIPMHImpl implements OAIPMHProducer {
private ErrorHandler error = new ErrorHandler();
private org.apache.commons.logging.Log log = LogFactory
.getLog(OAIPMHImpl.class);
private OAI_ESClient oaiEsClient;
private RepIdentification rep;
private RecordListDeliverer recordList;
private RecordDeliverer recDeliv;
private MetadataFormatListDeliverer metadataFormatList;
private SetDeliverer setList;
private IdentifierListDeliverer identifierList;
public boolean textgrid;
public boolean dariah;
ListIdentifiersType lit = new ListIdentifiersType();
public OAIPMHImpl(
OAI_ESClient oaiEsClient,
RepIdentification rep,
RecordDeliverer recDeliv,
RecordListDeliverer recordList,
MetadataFormatListDeliverer metadataFormatList,
SetDeliverer setList,
IdentifierListDeliverer identifierList) {
this.oaiEsClient = oaiEsClient;
this.rep = rep;
this.recDeliv = recDeliv;
this.recordList = recordList;
this.metadataFormatList = metadataFormatList;
this.setList = setList;
this.identifierList = identifierList;
}
/**
* Getting The request values as QueryParam from a REST request and proceeds
* appropriate to them
*
* @return OAIPMHType object containing the whole response
*/
@Override
@GET
@Path("/")
@Produces("text/xml")
public JAXBElement<OAIPMHType> getRequest(
@QueryParam("verb") String verb,
@QueryParam("identifier") @DefaultValue("") String identifier,
@QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
@QueryParam("set") @DefaultValue("") String set,
@QueryParam("from") @DefaultValue("") String from,
@QueryParam("until") @DefaultValue("") String until,
@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken) {
ObjectFactory obf = new ObjectFactory();
OAIPMHType response = new OAIPMHType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(response);
VerbType verbParam = setVerb(verb);
RequestType request = new RequestType();
/*----Setting the responseDate of today-----*/
try {
XMLGregorianCalendar convertedDateFormat;
convertedDateFormat = OAIPMHUtillities.convertDateFormat(OAIPMHUtillities.getXMLGregorianCalendarNow().toString());
response.setResponseDate(convertedDateFormat);
} catch (ParseException e) {
log.debug("can not parse date format");
} catch (DatatypeConfigurationException e) {
log.debug("Datatype configuration failed");
}
/* converting the request values */
setFromRequestValue(from, request);
setUntilRequestValue(until, request);
setIdentifierRequestValue(identifier, request);
setMetadataPrefixRequestValue(metadataPrefix, request);
setResumptionTokenRequestValue(resumptionToken, request);
setSetRequestValue(set, request);
//request.setSet(set);
request.setVerb(verbParam);
if (textgrid == true) {
request.setValue(TGConstants.TG_REP_BASEURL);
}
if (dariah == true) {
request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
}
if (verbParam != null) {
if (verbParam.value().equals("Identify")) {
oaipmhRoot = identifyRequest(obf, response, request);
} else if (verbParam.value().equals("GetRecord")) {
oaipmhRoot = getRecordRequest(obf, response, request);
} else if (verbParam.value().equals("ListIdentifiers")) {
try {
oaipmhRoot = listIdentifiersRequest(obf, response, request);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (verbParam.value().equals("ListSets")) {
oaipmhRoot = listSetsRequest(obf, response, request);
} else if (verbParam.value().equals("ListMetadataFormats")) {
oaipmhRoot = listMetadataFormatsRequest(identifier, obf,
response, request);
} else if (verbParam.value().equals("ListRecords")) {
oaipmhRoot = listRecordsRequest(obf, response, request);
}
} else {
response.getError().add(error.setError("VerbError"));
}
response.setRequest(request);
oaipmhRoot.setValue(response);
return oaipmhRoot;
}
/**
* checks the Identify request of correctness and response including errors
* in case of an incorrect request
*/
public JAXBElement<OAIPMHType> identifyRequest(ObjectFactory obf,
OAIPMHType oai, RequestType request) {
List<String> errorValues = new ArrayList<String>();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
IdentifyType tgRepIdentificationRequest = new IdentifyType();
if (rep.requestChecker(request)) {
tgRepIdentificationRequest.setBaseURL(rep.getBaseUrl());
tgRepIdentificationRequest.setDeletedRecord(rep
.getDeletedRecordStatus());
tgRepIdentificationRequest.setEarliestDatestamp(rep
.getEarliestDatestamp());
tgRepIdentificationRequest.setGranularity(rep.getGranularity());
tgRepIdentificationRequest.setRepositoryName(rep
.getRepositoryName());
tgRepIdentificationRequest.setProtocolVersion(rep
.getProtocolVersion());
tgRepIdentificationRequest.getAdminEmail().add(
rep.getAdminMaiAddresss());
oai.setIdentify(tgRepIdentificationRequest);
} else {
if (request.getIdentifier() != null) {
errorValues.add("identifier");
}
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() != null) {
errorValues.add("ResumptionToken");
}
if (request.getUntil() != null) {
errorValues.add("Until");
}
if (request.getSet() != null) {
errorValues.add("Set");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments: " + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
/**
* checks the GetRecord request of correctness and response including errors
* in case of an incorrect request
*/
public JAXBElement<OAIPMHType> getRecordRequest(ObjectFactory obf,
OAIPMHType oai, RequestType request) {
List<String> errorValues = new ArrayList<String>();
// RecordDeliverer recDeliv = new RecordDeliverer(oaiEsClient,
// TGConstants.TGFields);
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (request.getMetadataPrefix() != null
&& !request.getMetadataPrefix().equals("oai_dc")) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)
.setValue(
"The value of the metadataPrefix: "
+ request.getMetadataPrefix()
+ " is not supported by the item identified by the value of: "
+ request.getIdentifier());
oai.getError().add(
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
}
else if (recDeliv.requestChecker(request)) {
// recDeliv.getRecordById(request.getIdentifier());
GetRecordType getRecord = new GetRecordType();
getRecord = recDeliv.getRecordById(request.getIdentifier());
if (getRecord != null) {
// getRecord = recDeliv.getRecordById(request.getIdentifier());
oai.setGetRecord(getRecord);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue(
"The value of the identifier: "
+ request.getIdentifier()
+ " is unknown or illegal in this repository");
oai.getError().add(
error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
} else {
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getResumptionToken() != null) {
errorValues.add("resumptionToken");
}
if (request.getSet() != null) {
errorValues.add("set");
}
if (request.getUntil() != null) {
errorValues.add("until");
}
if (request.getMetadataPrefix() == null) {
errorValues.add("metadataPrefix");
}
if (request.getIdentifier() == null) {
errorValues.add("identifier");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments "
+ "or is missing required arguments: "
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
/**
* checks the ListIdentifiers request of correctness and response including
* errors in case of an incorrect request
*
* @throws ParseException
*/
public JAXBElement<OAIPMHType> listIdentifiersRequest(ObjectFactory obf,
OAIPMHType oai, RequestType request) throws ParseException {
List<String> errorValues = new ArrayList<String>();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
// if (identifierList.requestChecker(request)) {
if (request.getResumptionToken() != null
&& request.getMetadataPrefix() != null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:"
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() != null
&& request.getSet() != null) {
errorValues.add("Set");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:"
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() == null
&& request.getMetadataPrefix() == null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:"
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getMetadataPrefix() != null
&& !request.getMetadataPrefix().equals(
TGConstants.METADATA_DC_PREFIX)) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)
.setValue(
"The value of the metadataPrefix: "
+ request.getMetadataPrefix()
+ " is not supported by the item identified by the value of: "
+ request.getIdentifier());
oai.getError().add(
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
} else {
// System.out.println("bla1000");
if (request.getResumptionToken() != null
&& RecordListDeliverer.cursorCollector.containsKey(request
.getResumptionToken())) {
error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN)
.setValue(
"The value of the resumptionToken argument is invalid or expired");
oai.getError().add(
error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN));
} else {
lit = identifierList.processIdentifierList(request.getFrom(),
request.getUntil(), request.getSet(),
request.getResumptionToken());
if (lit != null) {
// System.out.println("bla2000");
oai.setListIdentifiers(lit);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue(
"The combination of the values "
+ request.getFrom() + " and "
+ request.getUntil()
+ " results in an empty list");
oai.getError().add(
error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
}
}
return oaipmhRoot;
}
/**
* checks the ListSets request of correctness and response including errors
* in case of an incorrect request
*
* @throws IOException
*/
public JAXBElement<OAIPMHType> listSetsRequest(ObjectFactory obf,
OAIPMHType oai, RequestType request) {
ListSetsType sl = new ListSetsType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
sl = this.setList.setListBuilder();
oai.setListSets(sl);
return oaipmhRoot;
}
public JAXBElement<OAIPMHType> listMetadataFormatsRequest(String id,
ObjectFactory obf, OAIPMHType oai, RequestType request) {
List<String> errorValues = new ArrayList<String>();
ListMetadataFormatsType listMF = new ListMetadataFormatsType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (metadataFormatList.requestChecker(request)) {
if (id.isEmpty()) {
listMF = metadataFormatList.setMetadataFormatListWithoutId();
} else {
listMF = metadataFormatList.setMetadataFormatList(request
.getIdentifier());
}
if (listMF != null) {
oai.setListMetadataFormats(listMF);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue(
"The value of the identifier: "
+ request.getIdentifier()
+ " is unknown or illegal in this repository");
oai.getError().add(
error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
} else {
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() != null) {
errorValues.add("resumptionToken");
}
if (request.getSet() != null) {
errorValues.add("set");
}
if (request.getUntil() != null) {
errorValues.add("until");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal "
+ "arguments or is missing required arguments: "
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
public JAXBElement<OAIPMHType> listRecordsRequest(ObjectFactory obf,
OAIPMHType oai, RequestType request) {
// System.out.println("blablablabla");
List<String> errorValues = new ArrayList<String>();
ListRecordsType listRecords = new ListRecordsType();
// RecordListDeliverer recordList = new
// RecordListDeliverer(oaiEsClient,// TGConstants.TGFields);
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() != null&& request.getSet() != null) {
errorValues.add("Set");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue("The value of the metadataPrefix: " + request.getMetadataPrefix() + " is not supported by the item identified by the value of: " + request.getIdentifier());
oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
} else {
listRecords = recordList.getRecords(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken());
if (listRecords != null) {
oai.setListRecords(listRecords);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( "The combination of the values " + request.getFrom() + " and " + request.getUntil() + " results in an empty list");
oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
}
return oaipmhRoot;
}
/**
* Taking the sting from the REST request and converting into an OAIPMH verb
* type
*
* @param verb
* : what is to within the repository
* @return verbParam: the verbParam as an OAIPMH verb type
*/
public VerbType setVerb(String verb) {
VerbType verbParam = null;
if (verb == null) {
verb = "Identify";
}
if (verb != null && verb.equals("Identify")) {
verbParam = VerbType.IDENTIFY;
} else if (verb != null && verb.equals("ListMetadataFormats")) {
verbParam = VerbType.LIST_METADATA_FORMATS;
} else if (verb != null && verb.equals("ListSets")) {
verbParam = VerbType.LIST_SETS;
} else if (verb != null && verb.equals("ListIdentifiers")) {
verbParam = VerbType.LIST_IDENTIFIERS;
} else if (verb != null && verb.equals("ListRecords")) {
verbParam = VerbType.LIST_RECORDS;
} else if (verb != null && verb.equals("GetRecord")) {
verbParam = VerbType.GET_RECORD;
} else {
error.setError("VerbError");
}
return verbParam;
}
/**
* Setting the from value for the request
*
* @param from
*/
public void setFromRequestValue(String from, RequestType request) {
if (!from.isEmpty()) {
request.setFrom(from);
}
}
/**
* Setting the until value for the request
*
* @param until
*/
public void setUntilRequestValue(String until, RequestType request) {
if (!until.isEmpty()) {
request.setUntil(until);
}
}
/**
* Setting the identifier value for the request
*
* @param identifier
*/
public void setIdentifierRequestValue(String identifier, RequestType request) {
if (!identifier.isEmpty()) {
request.setIdentifier(identifier);
}
}
/**
* Setting the metadataPrefix value for the request
*
* @param metadataPrefix
*/
public void setMetadataPrefixRequestValue(String metadataPrefix,
RequestType request) {
if (!metadataPrefix.isEmpty()) {
request.setMetadataPrefix(metadataPrefix);
}
}
/**
* Setting the resumptionToken value for the request
*
* @param resumptionToken
*/
public void setResumptionTokenRequestValue(String resumptionToken,
RequestType request) {
if (!resumptionToken.isEmpty()) {
request.setResumptionToken(resumptionToken);
}
}
/**
* Setting the set value for the request
*
* @param set
*/
public void setSetRequestValue(String set, RequestType request) {
if (!set.isEmpty()) {
request.setSet(set);
}
}
public void setTextGrid(boolean textgrid) {
this.textgrid = textgrid;
}
public void setDariah(boolean dariah) {
this.dariah = dariah;
}
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
public String getVersion() {
return OaipmhServiceVersion.BUILDNAME + "-"
+ OaipmhServiceVersion.VERSION + "."
+ OaipmhServiceVersion.BUILDDATE;
}
private ErrorHandler error = new ErrorHandler();
private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class);
private OAI_ESClient oaiEsClient;
private RepIdentification rep;
private RecordListDeliverer recordList;
private RecordDeliverer recDeliv;
private MetadataFormatListDeliverer metadataFormatList;
private SetDeliverer setList;
private IdentifierListDeliverer identifierList;
public boolean textgrid;
public boolean dariah;
ListIdentifiersType lit = new ListIdentifiersType();
public OAIPMHImpl(OAI_ESClient oaiEsClient, RepIdentification rep, RecordDeliverer recDeliv,
RecordListDeliverer recordList, MetadataFormatListDeliverer metadataFormatList,
SetDeliverer setList, IdentifierListDeliverer identifierList) {
this.oaiEsClient = oaiEsClient;
this.rep = rep;
this.recDeliv = recDeliv;
this.recordList = recordList;
this.metadataFormatList = metadataFormatList;
this.setList = setList;
this.identifierList = identifierList;
}
/*
* (non-Javadoc)
*
* @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@POST
@Path("/")
@Produces("text/xml")
public JAXBElement<OAIPMHType> postRequest(String verb, String identifier, String metadataPrefix,
String set, String from, String until, String resumptionToken) {
return getRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
}
/*
* (non-Javadoc)
*
* @see info.textgrid.middleware.OAIPMHProducer#getRequest(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
@GET
@Path("/")
@Produces("text/xml")
public JAXBElement<OAIPMHType> getRequest(String verb, String identifier, String metadataPrefix,
String set, String from, String until, String resumptionToken) {
ObjectFactory obf = new ObjectFactory();
OAIPMHType response = new OAIPMHType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(response);
VerbType verbParam = setVerb(verb);
RequestType request = new RequestType();
/*----Setting the responseDate of today-----*/
try {
XMLGregorianCalendar convertedDateFormat;
convertedDateFormat = OAIPMHUtillities
.convertDateFormat(OAIPMHUtillities.getXMLGregorianCalendarNow().toString());
response.setResponseDate(convertedDateFormat);
} catch (ParseException e) {
log.debug("can not parse date format");
} catch (DatatypeConfigurationException e) {
log.debug("Datatype configuration failed");
}
/* converting the request values */
setFromRequestValue(from, request);
setUntilRequestValue(until, request);
setIdentifierRequestValue(identifier, request);
setMetadataPrefixRequestValue(metadataPrefix, request);
setResumptionTokenRequestValue(resumptionToken, request);
setSetRequestValue(set, request);
// request.setSet(set);
request.setVerb(verbParam);
if (textgrid == true) {
request.setValue(TGConstants.TG_REP_BASEURL);
}
if (dariah == true) {
request.setValue(DARIAHConstants.DARIAH_REP_BASEURL);
}
if (verbParam != null) {
if (verbParam.value().equals("Identify")) {
oaipmhRoot = identifyRequest(obf, response, request);
} else if (verbParam.value().equals("GetRecord")) {
oaipmhRoot = getRecordRequest(obf, response, request);
} else if (verbParam.value().equals("ListIdentifiers")) {
try {
oaipmhRoot = listIdentifiersRequest(obf, response, request);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else if (verbParam.value().equals("ListSets")) {
oaipmhRoot = listSetsRequest(obf, response, request);
} else if (verbParam.value().equals("ListMetadataFormats")) {
oaipmhRoot = listMetadataFormatsRequest(identifier, obf, response, request);
} else if (verbParam.value().equals("ListRecords")) {
oaipmhRoot = listRecordsRequest(obf, response, request);
}
} else {
response.getError().add(error.setError("VerbError"));
}
response.setRequest(request);
oaipmhRoot.setValue(response);
return oaipmhRoot;
}
/**
* checks the Identify request of correctness and response including errors in case of an
* incorrect request
*
* @param obf
* @param oai
* @param request
* @return
*/
public JAXBElement<OAIPMHType> identifyRequest(ObjectFactory obf, OAIPMHType oai,
RequestType request) {
List<String> errorValues = new ArrayList<String>();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
IdentifyType tgRepIdentificationRequest = new IdentifyType();
if (rep.requestChecker(request)) {
tgRepIdentificationRequest.setBaseURL(rep.getBaseUrl());
tgRepIdentificationRequest.setDeletedRecord(rep.getDeletedRecordStatus());
tgRepIdentificationRequest.setEarliestDatestamp(rep.getEarliestDatestamp());
tgRepIdentificationRequest.setGranularity(rep.getGranularity());
tgRepIdentificationRequest.setRepositoryName(rep.getRepositoryName());
tgRepIdentificationRequest.setProtocolVersion(rep.getProtocolVersion());
tgRepIdentificationRequest.getAdminEmail().add(rep.getAdminMaiAddresss());
oai.setIdentify(tgRepIdentificationRequest);
} else {
if (request.getIdentifier() != null) {
errorValues.add("identifier");
}
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() != null) {
errorValues.add("ResumptionToken");
}
if (request.getUntil() != null) {
errorValues.add("Until");
}
if (request.getSet() != null) {
errorValues.add("Set");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT)
.setValue("The request includes illegal arguments: " + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
/**
* checks the GetRecord request of correctness and response including errors in case of an
* incorrect request
*
* @param obf
* @param oai
* @param request
* @return
*/
public JAXBElement<OAIPMHType> getRecordRequest(ObjectFactory obf, OAIPMHType oai,
RequestType request) {
List<String> errorValues = new ArrayList<String>();
// RecordDeliverer recDeliv = new RecordDeliverer(oaiEsClient,
// TGConstants.TGFields);
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals("oai_dc")) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)
.setValue("The value of the metadataPrefix: " + request.getMetadataPrefix()
+ " is not supported by the item identified by the value of: "
+ request.getIdentifier());
oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
}
else if (recDeliv.requestChecker(request)) {
// recDeliv.getRecordById(request.getIdentifier());
GetRecordType getRecord = new GetRecordType();
getRecord = recDeliv.getRecordById(request.getIdentifier());
if (getRecord != null) {
// getRecord = recDeliv.getRecordById(request.getIdentifier());
oai.setGetRecord(getRecord);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The value of the identifier: "
+ request.getIdentifier() + " is unknown or illegal in this repository");
oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
} else {
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getResumptionToken() != null) {
errorValues.add("resumptionToken");
}
if (request.getSet() != null) {
errorValues.add("set");
}
if (request.getUntil() != null) {
errorValues.add("until");
}
if (request.getMetadataPrefix() == null) {
errorValues.add("metadataPrefix");
}
if (request.getIdentifier() == null) {
errorValues.add("identifier");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT)
.setValue("The request includes illegal arguments " + "or is missing required arguments: "
+ errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
/**
* checks the ListIdentifiers request of correctness and response including errors in case of an
* incorrect request
*
* @param obf
* @param oai
* @param request
* @return
* @throws ParseException
*/
public JAXBElement<OAIPMHType> listIdentifiersRequest(ObjectFactory obf, OAIPMHType oai,
RequestType request) throws ParseException {
List<String> errorValues = new ArrayList<String>();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
// if (identifierList.requestChecker(request)) {
if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() != null && request.getSet() != null) {
errorValues.add("Set");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getMetadataPrefix() != null
&& !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)
.setValue("The value of the metadataPrefix: " + request.getMetadataPrefix()
+ " is not supported by the item identified by the value of: "
+ request.getIdentifier());
oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
} else {
// System.out.println("bla1000");
if (request.getResumptionToken() != null
&& RecordListDeliverer.cursorCollector.containsKey(request.getResumptionToken())) {
error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN)
.setValue("The value of the resumptionToken argument is invalid or expired");
oai.getError().add(error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN));
} else {
lit = identifierList.processIdentifierList(request.getFrom(), request.getUntil(),
request.getSet(), request.getResumptionToken());
if (lit != null) {
// System.out.println("bla2000");
oai.setListIdentifiers(lit);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The combination of the values "
+ request.getFrom() + " and " + request.getUntil() + " results in an empty list");
oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
}
}
return oaipmhRoot;
}
/**
* checks the ListSets request of correctness and response including errors in case of an
* incorrect request
*
* @param obf
* @param oai
* @param request
* @return
*/
public JAXBElement<OAIPMHType> listSetsRequest(ObjectFactory obf, OAIPMHType oai,
RequestType request) {
ListSetsType sl = new ListSetsType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
sl = this.setList.setListBuilder();
oai.setListSets(sl);
return oaipmhRoot;
}
/**
* @param id
* @param obf
* @param oai
* @param request
* @return
*/
public JAXBElement<OAIPMHType> listMetadataFormatsRequest(String id, ObjectFactory obf,
OAIPMHType oai, RequestType request) {
List<String> errorValues = new ArrayList<String>();
ListMetadataFormatsType listMF = new ListMetadataFormatsType();
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (metadataFormatList.requestChecker(request)) {
if (id.isEmpty()) {
listMF = metadataFormatList.setMetadataFormatListWithoutId();
} else {
listMF = metadataFormatList.setMetadataFormatList(request.getIdentifier());
}
if (listMF != null) {
oai.setListMetadataFormats(listMF);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The value of the identifier: "
+ request.getIdentifier() + " is unknown or illegal in this repository");
oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
} else {
if (request.getFrom() != null) {
errorValues.add("from");
}
if (request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() != null) {
errorValues.add("resumptionToken");
}
if (request.getSet() != null) {
errorValues.add("set");
}
if (request.getUntil() != null) {
errorValues.add("until");
}
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal "
+ "arguments or is missing required arguments: " + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
}
return oaipmhRoot;
}
/**
* @param obf
* @param oai
* @param request
* @return
*/
public JAXBElement<OAIPMHType> listRecordsRequest(ObjectFactory obf, OAIPMHType oai,
RequestType request) {
// System.out.println("blablablabla");
List<String> errorValues = new ArrayList<String>();
ListRecordsType listRecords = new ListRecordsType();
// RecordListDeliverer recordList = new
// RecordListDeliverer(oaiEsClient,// TGConstants.TGFields);
JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai);
if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() != null && request.getSet() != null) {
errorValues.add("Set");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) {
errorValues.add("MetadataPrefix");
error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue(
"The request includes illegal arguments or missing requiered arguments:" + errorValues);
oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT));
} else if (request.getMetadataPrefix() != null
&& !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) {
error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)
.setValue("The value of the metadataPrefix: " + request.getMetadataPrefix()
+ " is not supported by the item identified by the value of: "
+ request.getIdentifier());
oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR));
} else {
listRecords = recordList.getRecords(request.getFrom(), request.getUntil(), request.getSet(),
request.getResumptionToken());
if (listRecords != null) {
oai.setListRecords(listRecords);
} else {
error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The combination of the values "
+ request.getFrom() + " and " + request.getUntil() + " results in an empty list");
oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH));
}
}
return oaipmhRoot;
}
/**
* Taking the sting from the REST request and converting into an OAIPMH verb type
*
* @param verb : what is to within the repository
* @return verbParam: the verbParam as an OAIPMH verb type
*/
public VerbType setVerb(String verb) {
VerbType verbParam = null;
if (verb == null) {
verb = "Identify";
}
if (verb != null && verb.equals("Identify")) {
verbParam = VerbType.IDENTIFY;
} else if (verb != null && verb.equals("ListMetadataFormats")) {
verbParam = VerbType.LIST_METADATA_FORMATS;
} else if (verb != null && verb.equals("ListSets")) {
verbParam = VerbType.LIST_SETS;
} else if (verb != null && verb.equals("ListIdentifiers")) {
verbParam = VerbType.LIST_IDENTIFIERS;
} else if (verb != null && verb.equals("ListRecords")) {
verbParam = VerbType.LIST_RECORDS;
} else if (verb != null && verb.equals("GetRecord")) {
verbParam = VerbType.GET_RECORD;
} else {
error.setError("VerbError");
}
return verbParam;
}
/**
* Setting the from value for the request
*
* @param from
*/
public void setFromRequestValue(String from, RequestType request) {
if (!from.isEmpty()) {
request.setFrom(from);
}
}
/**
* Setting the until value for the request
*
* @param until
*/
public void setUntilRequestValue(String until, RequestType request) {
if (!until.isEmpty()) {
request.setUntil(until);
}
}
/**
* Setting the identifier value for the request
*
* @param identifier
*/
public void setIdentifierRequestValue(String identifier, RequestType request) {
if (!identifier.isEmpty()) {
request.setIdentifier(identifier);
}
}
/**
* Setting the metadataPrefix value for the request
*
* @param metadataPrefix
*/
public void setMetadataPrefixRequestValue(String metadataPrefix, RequestType request) {
if (!metadataPrefix.isEmpty()) {
request.setMetadataPrefix(metadataPrefix);
}
}
/**
* Setting the resumptionToken value for the request
*
* @param resumptionToken
*/
public void setResumptionTokenRequestValue(String resumptionToken, RequestType request) {
if (!resumptionToken.isEmpty()) {
request.setResumptionToken(resumptionToken);
}
}
/**
* <p>
* Setting the set value for the request
* </p>
*
* @param set
* @param request
*/
public void setSetRequestValue(String set, RequestType request) {
if (!set.isEmpty()) {
request.setSet(set);
}
}
/**
* @param textgrid
*/
public void setTextGrid(boolean textgrid) {
this.textgrid = textgrid;
}
/**
* @param dariah
*/
public void setDariah(boolean dariah) {
this.dariah = dariah;
}
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
public String getVersion() {
return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "."
+ OaipmhServiceVersion.BUILDDATE;
}
}
package info.textgrid.middleware;
import info.textgrid.middleware.oaipmh.OAIPMHType;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.FormParam;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBElement;
/**
* <p>
* Interface to the get Request function
* </p>
*
* @author Maximilian Brodhun, SUB
* @version 1.0
......@@ -20,53 +23,76 @@ import javax.xml.bind.JAXBElement;
public interface OAIPMHProducer {
/**
*
* @param verb
* The parameter verb is a required parameter to all requests.
* Depending on it the request will be proceed. Possible values
* are: GetRecord, Identify, ListIdentifiers,
* ListMetadataFormats, ListRecords and ListSets In case of other
* verbs an error response will be send back
*
* @param identifier
* This value indicates if the request will be proceed just for a
* single identifier of the repository
* @param metadataPrefix
* To limit the response just for a special metadata format this
* value can be used. The prefix "oai_dc" has to be supported by
* all repositories
* @param set
* To represent the architecture of the repository it is possible
* to make sets which work like categories. At the moment
* textgrid does not support sets
* @param from
* Start value to filter the response for a specific interval
* @param until
* End value to filter the response for a specific interval
* @param resumptionToken
* Indicates how many value will be send back in the response
*
*/
/**
* <p>
* Getting the request values as QueryParam from a REST GET request and proceeds appropriate to
* them.
* </p>
*
* @param verb - The parameter verb is a required parameter to all requests. Depending on it the
* request will be proceed. Possible values are: GetRecord, Identify, ListIdentifiers,
* ListMetadataFormats, ListRecords and ListSets In case of other verbs an error response
* will be send back
* @param identifier - This value indicates if the request will be proceed just for a single
* identifier of the repository
* @param metadataPrefix - To limit the response just for a special metadata format this value can
* be used. The prefix "oai_dc" has to be supported by all repositories
* @param set - To represent the architecture of the repository it is possible to make sets which
* work like categories. At the moment textgrid does not support sets
* @param from - Start value to filter the response for a specific interval
* @param until - End value to filter the response for a specific interval
* @param resumptionToken - Indicates how many value will be send back in the response
* @return OAIPMHType object containing the whole response
*/
@GET
@Path("/")
@Produces(MediaType.TEXT_XML)
JAXBElement<OAIPMHType> getRequest(@QueryParam("verb") String verb,
@QueryParam("identifier") @DefaultValue("") String identifier,
@QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
@QueryParam("set") @DefaultValue("") String set,
@QueryParam("from") @DefaultValue("") String from,
@QueryParam("until") @DefaultValue("") String until,
@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken);
@GET
@Path("/")
@Produces(MediaType.TEXT_XML)
JAXBElement<OAIPMHType> getRequest(
@QueryParam("verb") String verb,
@QueryParam("identifier") @DefaultValue("") String identifier,
@QueryParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
@QueryParam("set") @DefaultValue("") String set,
@QueryParam("from") @DefaultValue("") String from,
@QueryParam("until") @DefaultValue("") String until,
@QueryParam("resumptionToken") @DefaultValue("") String resumptionToken);
/**
* <p>
* Getting the request values as FormParams from a REST POST request and proceeds appropriate to
* them.
* </p>
*
* @param verb - The parameter verb is a required parameter to all requests. Depending on it the
* request will be proceed. Possible values are: GetRecord, Identify, ListIdentifiers,
* ListMetadataFormats, ListRecords and ListSets In case of other verbs an error response
* will be send back
* @param identifier - This value indicates if the request will be proceed just for a single
* identifier of the repository
* @param metadataPrefix - To limit the response just for a special metadata format this value can
* be used. The prefix "oai_dc" has to be supported by all repositories
* @param set - To represent the architecture of the repository it is possible to make sets which
* work like categories. At the moment textgrid does not support sets
* @param from - Start value to filter the response for a specific interval
* @param until - End value to filter the response for a specific interval
* @param resumptionToken - Indicates how many value will be send back in the response
* @return OAIPMHType object containing the whole response
*/
@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
JAXBElement<OAIPMHType> postRequest(@FormParam("verb") String verb,
@FormParam("identifier") @DefaultValue("") String identifier,
@FormParam("metadataPrefix") @DefaultValue("") String metadataPrefix,
@FormParam("set") @DefaultValue("") String set,
@FormParam("from") @DefaultValue("") String from,
@FormParam("until") @DefaultValue("") String until,
@FormParam("resumptionToken") @DefaultValue("") String resumptionToken);
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
String getVersion();
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
String getVersion();
}
......@@ -4,7 +4,7 @@
<parent>
<artifactId>oaipmh</artifactId>
<groupId>info.textgrid.middleware</groupId>
<version>2.15.0-SNAPSHOT</version>
<version>2.16.0-SNAPSHOT</version>
</parent>
<groupId>info.textgrid.middleware</groupId>
<artifactId>oaipmh-webapp</artifactId>
......
......@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>info.textgrid.middleware</groupId>
<artifactId>oaipmh</artifactId>
<version>2.15.0-SNAPSHOT</version>
<version>2.16.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>DARIAHDE :: OAI-PMH DataProvider</name>
<properties>
......
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