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

reset to previous code. something went wrong...

parent f57fcc91
No related branches found
No related tags found
No related merge requests found
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;
/**
* <p>
* This class takes all possible arguments of an OAI-PMH request and proceeds depended on the given
* arguments. It also deals as response handler.
* </p>
* arguments. It also deals as response handler
*
* @author Maximilian Brodhun, SUB Göttingen
* @version 2018-05-16
* @since 2014-01-29
* @author Maximilian Brodhun: SUB
* @version 1.0
* @since 29.01.2014
*
*/
public class OAIPMHImpl implements OAIPMHProducer {
private ErrorHandler error = new ErrorHandler();
......@@ -49,15 +51,6 @@ public class OAIPMHImpl implements OAIPMHProducer {
ListIdentifiersType lit = new ListIdentifiersType();
/**
* @param oaiEsClient
* @param rep
* @param recDeliv
* @param recordList
* @param metadataFormatList
* @param setList
* @param identifierList
*/
public OAIPMHImpl(OAI_ESClient oaiEsClient, RepIdentification rep, RecordDeliverer recDeliv,
RecordListDeliverer recordList, MetadataFormatListDeliverer metadataFormatList,
SetDeliverer setList, IdentifierListDeliverer identifierList) {
......@@ -70,57 +63,100 @@ public class OAIPMHImpl implements OAIPMHProducer {
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 handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
// }
/*
* (non-Javadoc)
/**
* <p>
* Getting The request values as QueryParam from a REST request and proceeds appropriate to them.
* </p>
*
* @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)
* @return OAIPMHType object containing the whole response
*/
@Override
@GET
@Path("/")
@Produces("text/xml")
public JAXBElement<OAIPMHType> getRequest(String verb, String identifier, String metadataPrefix,
String set, String from, String until, String resumptionToken) {
return handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken);
}
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;
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
public String getVersion() {
return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "."
+ OaipmhServiceVersion.BUILDDATE;
}
/**
* 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();
......@@ -167,15 +203,10 @@ public class OAIPMHImpl implements OAIPMHProducer {
/**
* 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);
......@@ -237,10 +268,6 @@ public class OAIPMHImpl implements OAIPMHProducer {
* 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,
......@@ -301,32 +328,25 @@ public class OAIPMHImpl implements OAIPMHProducer {
* checks the ListSets request of correctness and response including errors in case of an
* incorrect request
*
* @param obf
* @param oai
* @param request
* @return
* @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;
}
/**
* @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);
......@@ -372,15 +392,8 @@ public class OAIPMHImpl implements OAIPMHProducer {
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();
......@@ -432,7 +445,6 @@ public class OAIPMHImpl implements OAIPMHProducer {
* @return verbParam: the verbParam as an OAIPMH verb type
*/
public VerbType setVerb(String verb) {
VerbType verbParam = null;
if (verb == null) {
......@@ -465,9 +477,11 @@ public class OAIPMHImpl implements OAIPMHProducer {
*/
public void setFromRequestValue(String from, RequestType request) {
if (!from.isEmpty()) {
request.setFrom(from);
}
}
/**
......@@ -475,10 +489,13 @@ public class OAIPMHImpl implements OAIPMHProducer {
*
* @param until
*/
public void setUntilRequestValue(String until, RequestType request) {
if (!until.isEmpty()) {
request.setUntil(until);
}
}
/**
......@@ -486,7 +503,9 @@ public class OAIPMHImpl implements OAIPMHProducer {
*
* @param identifier
*/
public void setIdentifierRequestValue(String identifier, RequestType request) {
if (!identifier.isEmpty()) {
request.setIdentifier(identifier);
}
......@@ -497,10 +516,13 @@ public class OAIPMHImpl implements OAIPMHProducer {
*
* @param metadataPrefix
*/
public void setMetadataPrefixRequestValue(String metadataPrefix, RequestType request) {
if (!metadataPrefix.isEmpty()) {
request.setMetadataPrefix(metadataPrefix);
}
}
/**
......@@ -508,121 +530,46 @@ public class OAIPMHImpl implements OAIPMHProducer {
*
* @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;
}
// **
// PRIVATE METHODS
// **
/**
* @param verb
* @param identifier
* @param metadataPrefix
* @param set
* @param from
* @param until
* @param resumptionToken
* @return
*/
private JAXBElement<OAIPMHType> handleRequest(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;
@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 2018-05-16
* @since 2014-01-15
* @version 1.0
* @since 15.01.2014
*/
public interface OAIPMHProducer {
/**
* <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);
// /**
// * <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);
/**
*
* @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
*
*/
@POST
@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);
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
String getVersion();
/**
* @return
*/
@GET
@Path("/version")
@Produces(MediaType.TEXT_PLAIN)
String getVersion();
}
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