diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java index 7f6285a90aa6d0b8fb9df582eef1f651941a7bc6..291c9c31188ca54c541666f25baf2cc33f377adb 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/DublinCoreBuilder.java @@ -4,282 +4,327 @@ import info.textgrid.middleware.oaipmh.ElementType; import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.OaiDcType; import info.textgrid.middleware.oaipmh.ObjectFactory; - - import java.util.List; - - import javax.xml.bind.JAXBElement; /** - * The DublinCoreBuilder is responsible for generating a List of JAXBElements in DublinCore standard. - * Each function get a list of strings representing the mapped textgrid metadata for the specific DC-field + * <p> + * The DublinCoreBuilder is responsible for generating a List of JAXBElements in DublinCore + * standard. Each function get a list of strings representing the mapped textgrid metadata for the + * specific DC-field + * </p> * * @author Maximilian Brodhun SUB * @version 1.1 * @since 18.02.2014 - * */ public final class DublinCoreBuilder { - - private OaiDcType tgMappedDC = new OaiDcType(); - private ObjectFactory oaiDcObj = new ObjectFactory(); - private MetadataType metadata = new MetadataType(); - - /** - * Constructor to build an DublinCore element for an OAIPMH request by getting textGrid metadata - * @param tgMappedDC - * @param oaiDcObj2 - */ - - public DublinCoreBuilder(OaiDcType tgMappedDC, ObjectFactory oaiDcObj2){ - - this.tgMappedDC = tgMappedDC; - this.oaiDcObj = oaiDcObj2; - - } - - /** - * Takes a Stringlist containing the contributors and build the specific dublinCore element for each - * @param contributors - */ - - public void setContributor(List<String> contributors){ - - for (String dccontributor : contributors) { - - ElementType contributorElement = new ElementType(); - JAXBElement<ElementType> dcCoreContributor = getOaiDcObj().createContributor(contributorElement); - contributorElement.setValue(dccontributor); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreContributor); - } - } - - /** - * Takes a Stringlist containing the creators and build the specific dublinCore element for each - * @param creators - */ - public void setCreator(List<String> creators){ - - for (String dccreator : creators) { - - ElementType creatorElement = new ElementType(); - JAXBElement<ElementType> dcCoreCreator = getOaiDcObj().createCreator(creatorElement); - creatorElement.setValue(dccreator); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreCreator); - - } - - } - - /** - * Takes a Stringlist containing the coverages and build the specific dublinCore element for each - * @param coverages - */ - public void setCoverage(List<String> coverages){ - for (String dccoverage : coverages) { - ElementType coverageElement = new ElementType(); - JAXBElement<ElementType> dcCoreCoverage = getOaiDcObj().createCoverage(coverageElement); - coverageElement.setValue(dccoverage); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreCoverage); - } - - } - - /** - * Takes a Stringlist containing the dates and build the specific dublinCore element for each - * @param dates - */ - public void setDate(List<String> dates){ - for (String dcdate : dates) { - ElementType dateElement = new ElementType(); - JAXBElement<ElementType> dcCoreDate = getOaiDcObj().createDate(dateElement); - dateElement.setValue(dcdate); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreDate); - } - - - } - - /** - * Takes a Stringlist containing the descriptions and build the specific dublinCore element for each - * @param descriptions - */ - public void setDescription(List<String> descriptions){ - for (String dcdescription : descriptions) { - ElementType descriptionElement = new ElementType(); - JAXBElement<ElementType> dcCoreDescription = getOaiDcObj().createDescription(descriptionElement); - descriptionElement.setValue(dcdescription); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreDescription); - } - - } - - /** - * Takes a Stringlist containing the formats and build the specific dublinCore element for each - * @param formats - */ - public void setFormat(List<String> formats){ - for (String dcformat : formats) { - ElementType formatElement = new ElementType(); - JAXBElement<ElementType> dcCoreFormat = getOaiDcObj().createFormat(formatElement); - formatElement.setValue(dcformat); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreFormat); - } - - } - - /** - * Takes a Stringlist containing the identifiers and build the specific dublinCore element for each - * @param identifiers - */ - public void setIdentifier(List<String> identifiers){ - for (String dcidentifier : identifiers) { - ElementType identifierElement = new ElementType(); - JAXBElement<ElementType> dcCoreIdentifier = getOaiDcObj().createIdentifier(identifierElement); - identifierElement.setValue(dcidentifier); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreIdentifier); - } - - } - - /** - * Takes a Stringlist containing the languages and build the specific dublinCore element for each - * @param languages - */ - public void setLanguage(List<String> languages){ - for (String dclanguage : languages) { - ElementType languageElement = new ElementType(); - JAXBElement<ElementType> dcCoreLanguage = getOaiDcObj().createLanguage(languageElement); - languageElement.setValue(dclanguage); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreLanguage); - } - - } - - /** - * Takes a Stringlist containing the publishers and build the specific dublinCore element for each - * @param publishers - */ - public void setPublisher(List<String> publishers){ - for (String dcpublisher : publishers) { - ElementType publisherElement = new ElementType(); - JAXBElement<ElementType> dcCorePublisher = getOaiDcObj().createPublisher(publisherElement); - publisherElement.setValue(dcpublisher); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCorePublisher); - } - - } - - /** - * Takes a Stringlist containing the relations and build the specific dublinCore element for each - * @param relations - */ - public void setRelation(List<String> relations){ - for (String dcrelation : relations) { - ElementType relationElement = new ElementType(); - JAXBElement<ElementType> dcCoreRelation = getOaiDcObj().createRelation(relationElement); - relationElement.setValue(dcrelation); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreRelation); - } - - } - - /** - * Takes a Stringlist containing the rights and build the specific dublinCore element for each - * @param rights - */ - public void setRights(List<String> rights){ - for (String dcrights : rights) { - ElementType rightsElement = new ElementType(); - JAXBElement<ElementType> dcCoreRights = getOaiDcObj().createRights(rightsElement); - rightsElement.setValue(dcrights); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreRights); - } - - } - - /** - * Takes a Stringlist containing the sources and build the specific dublinCore element for each - * @param sources - */ - public void setSource(List<String> sources){ - for (String dcsource : sources) { - ElementType sourcesElement = new ElementType(); - JAXBElement<ElementType> dcCoreSource = getOaiDcObj().createSource(sourcesElement); - sourcesElement.setValue(dcsource); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreSource); - } - - } - - /** - * Takes a Stringlist containing the subjects and build the specific dublinCore element for each - * @param subjects - */ - public void setSubject(List<String> subjects){ - for (String dcsubject : subjects) { - ElementType subjectElement = new ElementType(); - JAXBElement<ElementType> dcCoreSubject = getOaiDcObj().createSubject(subjectElement); - subjectElement.setValue(dcsubject); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreSubject); - } - - } - - /** - * Takes a Stringlist containing the titles and build the specific dublinCore element for each - * @param titles - */ - public void setTitle(List<String> titles){ - for (String dctitle : titles) { - ElementType titlesElement = new ElementType(); - JAXBElement<ElementType> dcCoreTitle = getOaiDcObj().createTitle(titlesElement); - titlesElement.setValue(dctitle); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreTitle); - } - - } - - /** - * Takes a Stringlist containing the types and build the specific dublinCore element for each - * @param types - */ - public void setType(List<String> types){ - for (String dctype : types) { - ElementType typeElement = new ElementType(); - JAXBElement<ElementType> dcCoreType = getOaiDcObj().createType(typeElement); - typeElement.setValue(dctype); - getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreType); - } - - } - - /** - * fetching dublinCore element and putting it into the metadata element for the OAIPMH record response - * @return metadata element with the dublinCore values for a specific object - */ - public MetadataType getDC(){ - metadata.setAny(getOaiDcObj().createDc(getTgMappedDC())); - return metadata; - } - - /** - * - * @return tgMappedDc - */ - public OaiDcType getTgMappedDC() { - return tgMappedDC; - } - - /** - * - * @return oaiDcObj - */ - public ObjectFactory getOaiDcObj() { - return oaiDcObj; - } + private OaiDcType tgMappedDC = new OaiDcType(); + private ObjectFactory oaiDcObj = new ObjectFactory(); + private MetadataType metadata = new MetadataType(); + + /** + * <p> + * Constructor to build an DublinCore element for an OAIPMH request by getting textGrid metadata + * </p> + * + * @param tgMappedDC + * @param oaiDcObj2 + */ + public DublinCoreBuilder(OaiDcType tgMappedDC, ObjectFactory oaiDcObj2) { + this.tgMappedDC = tgMappedDC; + this.oaiDcObj = oaiDcObj2; + } + + /** + * <p> + * Takes a Stringlist containing the contributors and build the specific dublinCore element for + * each + * </p> + * + * @param contributors + */ + public void setContributor(List<String> contributors) { + + for (String dccontributor : contributors) { + ElementType contributorElement = new ElementType(); + JAXBElement<ElementType> dcCoreContributor = + getOaiDcObj().createContributor(contributorElement); + contributorElement.setValue(dccontributor); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreContributor); + } + } + + /** + * <p> + * Takes a Stringlist containing the creators and build the specific dublinCore element for each + * </p> + * + * @param creators + */ + public void setCreator(List<String> creators) { + + for (String dccreator : creators) { + ElementType creatorElement = new ElementType(); + JAXBElement<ElementType> dcCoreCreator = getOaiDcObj().createCreator(creatorElement); + creatorElement.setValue(dccreator); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreCreator); + } + } + + /** + * <P> + * Takes a Stringlist containing the coverages and build the specific dublinCore element for each + * </p> + * + * @param coverages + */ + public void setCoverage(List<String> coverages) { + + for (String dccoverage : coverages) { + ElementType coverageElement = new ElementType(); + JAXBElement<ElementType> dcCoreCoverage = getOaiDcObj().createCoverage(coverageElement); + coverageElement.setValue(dccoverage); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreCoverage); + } + } + + /** + * <p> + * Takes a Stringlist containing the dates and build the specific dublinCore element for each + * </p> + * + * @param dates + */ + public void setDate(List<String> dates) { + + for (String dcdate : dates) { + ElementType dateElement = new ElementType(); + JAXBElement<ElementType> dcCoreDate = getOaiDcObj().createDate(dateElement); + dateElement.setValue(dcdate); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreDate); + } + } + + /** + * <p> + * Takes a Stringlist containing the descriptions and build the specific dublinCore element for + * each + * </p> + * + * @param descriptions + */ + public void setDescription(List<String> descriptions) { + + for (String dcdescription : descriptions) { + ElementType descriptionElement = new ElementType(); + JAXBElement<ElementType> dcCoreDescription = + getOaiDcObj().createDescription(descriptionElement); + descriptionElement.setValue(dcdescription); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreDescription); + } + } + + /** + * <p> + * Takes a Stringlist containing the formats and build the specific dublinCore element for each + * </p> + * + * @param formats + */ + public void setFormat(List<String> formats) { + + for (String dcformat : formats) { + ElementType formatElement = new ElementType(); + JAXBElement<ElementType> dcCoreFormat = getOaiDcObj().createFormat(formatElement); + formatElement.setValue(dcformat); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreFormat); + } + } + + /** + * <p> + * Takes a Stringlist containing the identifiers and build the specific dublinCore element for + * each + * </p> + * + * @param identifiers + */ + public void setIdentifier(List<String> identifiers) { + + for (String dcidentifier : identifiers) { + ElementType identifierElement = new ElementType(); + JAXBElement<ElementType> dcCoreIdentifier = getOaiDcObj().createIdentifier(identifierElement); + identifierElement.setValue(dcidentifier); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreIdentifier); + } + } + + /** + * <p> + * Takes a Stringlist containing the languages and build the specific dublinCore element for each + * </p> + * + * @param languages + */ + public void setLanguage(List<String> languages) { + + for (String dclanguage : languages) { + ElementType languageElement = new ElementType(); + JAXBElement<ElementType> dcCoreLanguage = getOaiDcObj().createLanguage(languageElement); + languageElement.setValue(dclanguage); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreLanguage); + } + } + + /** + * <p> + * Takes a Stringlist containing the publishers and build the specific dublinCore element for each + * </p> + * + * @param publishers + */ + public void setPublisher(List<String> publishers) { + + for (String dcpublisher : publishers) { + ElementType publisherElement = new ElementType(); + JAXBElement<ElementType> dcCorePublisher = getOaiDcObj().createPublisher(publisherElement); + publisherElement.setValue(dcpublisher); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCorePublisher); + } + } + + /** + * <p> + * Takes a Stringlist containing the relations and build the specific dublinCore element for each + * </p> + * + * @param relations + */ + public void setRelation(List<String> relations) { + + for (String dcrelation : relations) { + ElementType relationElement = new ElementType(); + JAXBElement<ElementType> dcCoreRelation = getOaiDcObj().createRelation(relationElement); + relationElement.setValue(dcrelation); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreRelation); + } + } + + /** + * <p> + * Takes a Stringlist containing the rights and build the specific dublinCore element for each + * </p> + * + * @param rights + */ + public void setRights(List<String> rights) { + + for (String dcrights : rights) { + ElementType rightsElement = new ElementType(); + JAXBElement<ElementType> dcCoreRights = getOaiDcObj().createRights(rightsElement); + rightsElement.setValue(dcrights); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreRights); + } + } + + /** + * <p> + * Takes a Stringlist containing the sources and build the specific dublinCore element for each + * </p> + * + * @param sources + */ + public void setSource(List<String> sources) { + + for (String dcsource : sources) { + ElementType sourcesElement = new ElementType(); + JAXBElement<ElementType> dcCoreSource = getOaiDcObj().createSource(sourcesElement); + sourcesElement.setValue(dcsource); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreSource); + } + } + + /** + * <p> + * Takes a Stringlist containing the subjects and build the specific dublinCore element for each + * </p> + * + * @param subjects + */ + public void setSubject(List<String> subjects) { + + for (String dcsubject : subjects) { + ElementType subjectElement = new ElementType(); + JAXBElement<ElementType> dcCoreSubject = getOaiDcObj().createSubject(subjectElement); + subjectElement.setValue(dcsubject); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreSubject); + } + } + + /** + * <p> + * Takes a Stringlist containing the titles and build the specific dublinCore element for each + * </p> + * + * @param titles + */ + public void setTitle(List<String> titles) { + + for (String dctitle : titles) { + ElementType titlesElement = new ElementType(); + JAXBElement<ElementType> dcCoreTitle = getOaiDcObj().createTitle(titlesElement); + titlesElement.setValue(dctitle); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreTitle); + } + } + + /** + * <p> + * Takes a Stringlist containing the types and build the specific dublinCore element for each + * </p> + * + * @param types + */ + public void setType(List<String> types) { + + for (String dctype : types) { + ElementType typeElement = new ElementType(); + JAXBElement<ElementType> dcCoreType = getOaiDcObj().createType(typeElement); + typeElement.setValue(dctype); + getTgMappedDC().getTitleOrCreatorOrSubject().add(dcCoreType); + } + } + + /** + * <p> + * fetching dublinCore element and putting it into the metadata element for the OAIPMH record + * response + * </p> + * + * @return metadata element with the dublinCore values for a specific object + */ + public MetadataType getDC() { + this.metadata.setAny(getOaiDcObj().createDc(getTgMappedDC())); + return this.metadata; + } + + /** + * + * @return tgMappedDc + */ + public OaiDcType getTgMappedDC() { + return this.tgMappedDC; + } + + /** + * + * @return oaiDcObj + */ + public ObjectFactory getOaiDcObj() { + return this.oaiDcObj; + } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java index e7872c591e4aee38a316e9142f283a8e082c0e14..e98e1f5e206831b341c8bd8d6a98ea544f750101 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java @@ -5,49 +5,66 @@ import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.UUID; - import org.classicmayan.tools.Queries; - import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; -public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract{ - - static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - public IdentifierListDelivererIDIOM(boolean textgrid, boolean dariah) { - super(textgrid, dariah); - } - - public ListIdentifiersType processIdentifierList(String from, String to, String set, String resumptionToken) { - ListIdentifiersType lit = new ListIdentifiersType(); - List<String> artefactURIs = new ArrayList<String>(); - Queries querisForArtefactList = new Queries(); - if(resumptionToken==null) { - artefactURIs = querisForArtefactList.getArtefactList(0); - }else { - artefactURIs = querisForArtefactList.getArtefactList(cursorCollector.get(resumptionToken)); - } - - long listSize = Queries.getAmountOfArtefacts(); - int i=0; - UUID uuid = UUID.randomUUID(); - String resTokenValue = uuid.toString(); - resumptionToken = uuid.toString(); - - for(String artefactURI : artefactURIs) { - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); - lit.getHeader().add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader()); - } - - // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtillities.getResumptionToken( - listSize, resumptionToken, cursorCollector, resTokenValue, 30, i); - - if (resTokenForResponse != null) { - lit.setResumptionToken(resTokenForResponse); - } - - return lit; - } - +/** + * + */ +public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract { + + static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + + /** + * @param textgrid + * @param dariah + */ + public IdentifierListDelivererIDIOM(boolean textgrid, boolean dariah) { + super(textgrid, dariah); + } + + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.IdentifierListDelivererAbstract#processIdentifierList(java.lang. + * String, java.lang.String, java.lang.String, java.lang.String) + */ + public ListIdentifiersType processIdentifierList(final String from, final String to, + final String set, final String resumptionToken) { + + String resTokenValue = resumptionToken; + + ListIdentifiersType lit = new ListIdentifiersType(); + List<String> artefactURIs = new ArrayList<String>(); + Queries querisForArtefactList = new Queries(); + if (resumptionToken == null) { + // Create resumption token for every request only (we do need the same token for resuming + // because we are using a hash map for counting the calls). + resTokenValue = UUID.randomUUID().toString(); + artefactURIs = querisForArtefactList.getArtefactList(0); + } else { + // Use given resumption token here. + artefactURIs = querisForArtefactList.getArtefactList(cursorCollector.get(resumptionToken)); + } + + long listSize = Queries.getAmountOfArtefacts(); + int i = 0; + + for (String artefactURI : artefactURIs) { + RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); + lit.getHeader().add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader()); + } + + // Check the need for a resumption token! + ResumptionTokenType resTokenForResponse = OAIPMHUtillities.getResumptionToken( + listSize, resumptionToken, cursorCollector, resTokenValue, 30, i); + + if (resTokenForResponse != null) { + lit.setResumptionToken(resTokenForResponse); + } + + return lit; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java index 8f111ab8f028ab1398268b3c68377d83252f6a41..11c8ecc3904ad542925177e0558d994a53cb1281 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java @@ -3,7 +3,6 @@ package info.textgrid.middleware; import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; import info.textgrid.middleware.oaipmh.MetadataFormatType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; - import java.math.BigInteger; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -11,16 +10,16 @@ import java.util.Date; import java.util.GregorianCalendar; import java.util.Map; import java.util.TimeZone; - import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; - import org.apache.commons.logging.LogFactory; /** - * OAIPMHUtillities is responsible to implement all necessary functions to - * implement the arguments of a request + * <p> + * OAIPMHUtillities is responsible to implement all necessary functions to implement the arguments + * of a request + * </p> * * @author Maximilian Brodhun: SUB * @version 1.0 @@ -29,171 +28,165 @@ import org.apache.commons.logging.LogFactory; */ public class OAIPMHUtillities { - private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); - /** - * Since textGrid just supports dc the only returned MetadataFormat is - * dublinCore - * - * @return - */ - public MetadataFormatType setMetadataFormats() { - - MetadataFormatType tgDublinCore = new MetadataFormatType(); - tgDublinCore.setMetadataNamespace("http://www.openarchives.org/OAI/2.0/oai_dc/"); - tgDublinCore.setMetadataPrefix("oai:dc"); - tgDublinCore.setSchema("http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); - - return tgDublinCore; - } - - /** - * producing the list of all metadata formats - * - * @return tgRepMetadaFormats - */ - public ListMetadataFormatsType setMetadataFormatList() { - - ListMetadataFormatsType tgRepMetadataFormats = new ListMetadataFormatsType(); - MetadataFormatType tgDublinCore = setMetadataFormats(); - tgRepMetadataFormats.getMetadataFormat().add(tgDublinCore); - - return tgRepMetadataFormats; - } - - /** - * calculating the current date and give it back as XMLGregorianCalendar - * - * @return now - * @throws DatatypeConfigurationException - */ - public static XMLGregorianCalendar getXMLGregorianCalendarNow() - throws DatatypeConfigurationException { - - GregorianCalendar gregorianCalendar = new GregorianCalendar(); - DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); - XMLGregorianCalendar now = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar); - - return now; - } - - /** - * Converting a given string representing a date value into the date format - * required for OAIPMH and give it back as XMLGregorianCalendar - * - * @param originalDateTimeString - * @return xmlCal - * @throws ParseException - * @throws DatatypeConfigurationException - */ - public static XMLGregorianCalendar convertDateFormat( - String originalDateTimeString) throws ParseException, - DatatypeConfigurationException { - - SimpleDateFormat tgItemTime = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.S"); - Date date = tgItemTime.parse(originalDateTimeString); - SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - outFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); - String output2 = outFormatter.format(date); - XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(output2); - - return xmlCal; - } - - /** - * Converting a given string representing a date value into the date format - * required for OAIPMH and give it back as string - * - * @param originalDateTimeString - * @return dateOutputAsString - * @throws ParseException - */ - public static String datestampAsString(String originalDateTimeString) - throws ParseException { - - SimpleDateFormat tgItemTime = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss.S"); - Date date = tgItemTime.parse(originalDateTimeString); - SimpleDateFormat outFormatter = new SimpleDateFormat( - "yyyy-MM-dd'T'HH:mm:ss'Z'"); - outFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); - String dateOutputAsString = outFormatter.format(date); - - return dateOutputAsString; - } - - /** - * <p> - * Returns a resumptionToken for a search, if necessary. - * </p> - * - * TODO Check if we really must put all these references in! - * - * @param completeListSize - * @param resumptionToken - * @param cursorCollector - * @param scrollID - * @param searchResponseSize - * @param i - * @return A resumption token if applicable, null otherwise. - */ - public static ResumptionTokenType getResumptionToken( - final long completeListSize, final String resumptionToken, - Map<String, Integer> cursorCollector, final String scrollID, - final int searchResponseSize, final int i) { - - log.info("Creating a ResumptionToken:\n " + - "CompleteListSize: " + completeListSize + "\n" + - "ResumptionToken: " + resumptionToken + "\n" + - "CursorCollector: " + cursorCollector + "\n" + - "ScrollID: " + scrollID + "\n" + - "SearchResponseSize: " + scrollID + "\n" + - "IterationStep: " + i); - - int cursor; - - // Three cases here: - // 1. Complete list size is > 100 and a token already is existing: we - // need to check hash map! - // 2. Complete list size is > 100 and we have no token: we do need one! - // 3. Complete list size is <= 100 (we do not need a token! do nothing!) - - if (completeListSize > 100) { - ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); - - if (resumptionToken != null - && cursorCollector.containsKey(resumptionToken)) { - cursor = cursorCollector.get(resumptionToken).intValue() + i; - resTokenForResponse - .setCursor(BigInteger.valueOf((long) cursor)); - cursorCollector.put(scrollID, cursor); - } else { - resTokenForResponse.setCursor(BigInteger - .valueOf(searchResponseSize)); - cursorCollector.put(scrollID, searchResponseSize); - cursor = 0; - } - - // Set resumption token string if cursor is less then complete list - // size: More objects can be delivered! - if (cursor < completeListSize) { - resTokenForResponse.setValue(scrollID); - } - - // Remove resumption token string if cursor is bigger then or equal - // complete list size: This is the last response, no more objects - // are available! - if (cursor >= completeListSize) { - resTokenForResponse.setValue(""); - } - - // Set complete list size. - resTokenForResponse.setCompleteListSize(BigInteger - .valueOf(completeListSize)); - - return resTokenForResponse; - } - - return null; - } + + /** + * + */ + private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + + /** + * Since textGrid just supports dc the only returned MetadataFormat is dublinCore + * + * @return + */ + public MetadataFormatType setMetadataFormats() { + + MetadataFormatType tgDublinCore = new MetadataFormatType(); + tgDublinCore.setMetadataNamespace("http://www.openarchives.org/OAI/2.0/oai_dc/"); + tgDublinCore.setMetadataPrefix("oai:dc"); + tgDublinCore.setSchema("http://www.openarchives.org/OAI/2.0/oai_dc.xsd"); + + return tgDublinCore; + } + + /** + * producing the list of all metadata formats + * + * @return tgRepMetadaFormats + */ + public ListMetadataFormatsType setMetadataFormatList() { + + ListMetadataFormatsType tgRepMetadataFormats = new ListMetadataFormatsType(); + MetadataFormatType tgDublinCore = setMetadataFormats(); + tgRepMetadataFormats.getMetadataFormat().add(tgDublinCore); + + return tgRepMetadataFormats; + } + + /** + * calculating the current date and give it back as XMLGregorianCalendar + * + * @return now + * @throws DatatypeConfigurationException + */ + public static XMLGregorianCalendar getXMLGregorianCalendarNow() + throws DatatypeConfigurationException { + + GregorianCalendar gregorianCalendar = new GregorianCalendar(); + DatatypeFactory datatypeFactory = DatatypeFactory.newInstance(); + XMLGregorianCalendar now = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar); + + return now; + } + + /** + * Converting a given string representing a date value into the date format required for OAIPMH + * and give it back as XMLGregorianCalendar + * + * @param originalDateTimeString + * @return xmlCal + * @throws ParseException + * @throws DatatypeConfigurationException + */ + public static XMLGregorianCalendar convertDateFormat(String originalDateTimeString) + throws ParseException, DatatypeConfigurationException { + + SimpleDateFormat tgItemTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); + Date date = tgItemTime.parse(originalDateTimeString); + SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + outFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); + String output2 = outFormatter.format(date); + XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(output2); + + return xmlCal; + } + + /** + * Converting a given string representing a date value into the date format required for OAIPMH + * and give it back as string + * + * @param originalDateTimeString + * @return dateOutputAsString + * @throws ParseException + */ + public static String datestampAsString(String originalDateTimeString) throws ParseException { + + SimpleDateFormat tgItemTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); + Date date = tgItemTime.parse(originalDateTimeString); + SimpleDateFormat outFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + outFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); + String dateOutputAsString = outFormatter.format(date); + + return dateOutputAsString; + } + + /** + * <p> + * Returns a resumptionToken for a search, if necessary. + * </p> + * + * TODO Check if we really must put all these references in! + * + * @param completeListSize + * @param resumptionToken + * @param cursorCollector + * @param scrollID + * @param searchResponseSize + * @param i + * @return A resumption token if applicable, null otherwise. + */ + public static ResumptionTokenType getResumptionToken(final long completeListSize, + final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, + final int searchResponseSize, final int i) { + + log.info("Creating a ResumptionToken:\n " + + "CompleteListSize: " + completeListSize + "\n" + + "ResumptionToken: " + resumptionToken + "\n" + + "CursorCollector: " + cursorCollector + "\n" + + "ScrollID: " + scrollID + "\n" + + "SearchResponseSize: " + scrollID + "\n" + + "IterationStep: " + i); + + int cursor; + + // Three cases here: + // 1. Complete list size is > searchResponseSize and a token already is existing: we need to + // check hash map! + // 2. Complete list size is > searchResponseSize and we have no token: we do need one! + // 3. Complete list size is <= searchResponseSize (we do not need a token! do nothing!) + + if (completeListSize > searchResponseSize) { + ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); + + if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { + cursor = cursorCollector.get(resumptionToken).intValue() + i; + resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + cursorCollector.put(scrollID, cursor); + } else { + resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); + cursorCollector.put(scrollID, searchResponseSize); + cursor = 0; + } + + // Set resumption token string if cursor is less then complete list size: More objects can be + // delivered! + if (cursor < completeListSize) { + resTokenForResponse.setValue(scrollID); + } + + // Remove resumption token string if cursor is bigger then or equal complete list size: This + // is the last response, no more objects are available! + if (cursor >= completeListSize) { + resTokenForResponse.setValue(""); + } + + // Set complete list size. + resTokenForResponse.setCompleteListSize(BigInteger.valueOf(completeListSize)); + + return resTokenForResponse; + } + + return null; + } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java index 82993449dd25bf99cf9094fa8cd52f3c2d376125..930c63c849a0e9e421d7489acd74a5c92570f691 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java @@ -98,8 +98,6 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { private int searchResponseSize; /** - * @param fields - * @param workFields * @param textgrid * @param dariah */ @@ -135,7 +133,6 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { return null; } - /** * <p> * The fetchFields function filters all edition and fetch the specified fields @@ -386,11 +383,12 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { * @param headerIdentifier * @return */ - public HeaderType setHeader(String set, String headerIdentifier) { + public HeaderType setHeader(final String set, final String headerIdentifier) { HeaderType header = new HeaderType(); - String identifierForHeader = ""; + String identifierForHeader = headerIdentifier; + // Set date in XML format. try { header.setDatestamp(OAIPMHUtillities.convertDateFormat(this.modifiedValue).toXMLFormat()); } catch (ParseException e) { @@ -400,14 +398,24 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { // TODO Auto-generated catch block e.printStackTrace(); } - if (this.textgrid == true) - identifierForHeader = this.identifiers.get(0); - if (identifierForHeader.startsWith("https://textgridrep.org/")) { + + // Set header specific for TextGrid objects (remove URL). + if (this.textgrid == true) { + + // if (this.identifiers.get(0) != null) { + // identifierForHeader = this.identifiers.get(0); + // + // System.out.println(" #1# " + headerIdentifier + " = " + identifierForHeader); + // } else { + // System.out.println(" #2# " + headerIdentifier); + // } + identifierForHeader = identifierForHeader.replaceFirst("https://textgridrep.org/", ""); - header.setIdentifier(identifierForHeader); - } else { - header.setIdentifier(headerIdentifier); } + + header.setIdentifier(identifierForHeader); + + // Set set :-) if (set != null) { header.getSetSpec().add(set); } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java index e27089a3614d23044b4cffe9b5fbf87ba417b56e..5acd58112a19f6c5d28196d0fa919b7f0fc484db 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -57,7 +57,10 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { * java.lang.String, java.lang.String, java.lang.String) */ @Override - public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) { + public ListRecordsType getRecords(final String from, final String to, final String set, + final String resumptionToken) { + + String resTokenValue = resumptionToken; log.info("Started List Records with booleans for DARIAH: " + this.dariah + " and TextGrid: " + this.textgrid); @@ -67,32 +70,33 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { Queries queries = new Queries(); if (resumptionToken == null) { artefactURIs = queries.getArtefactList(0); + // Create resumption token for every request only (we do need the same token for resuming + // because we are using a hash map for counting the calls). + resTokenValue = UUID.randomUUID().toString(); } else { // FIXME @Max: Hier gibt's eine NPE, wenn ein resumptionToken für oai_dc existiert. Komisch? + + // Use given resumption token here. artefactURIs = queries.getArtefactList(cursorCollector.get(resumptionToken)); } long listSize = Queries.getAmountOfArtefacts(); int i = 0; - UUID uuid = UUID.randomUUID(); - String resTokenValue = uuid.toString(); - resumptionToken = uuid.toString(); - for (String artefactURI : artefactURIs) { - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); recordList.getRecord().add(idiomRecord.getRecordById(artefactURI).getRecord()); i++; } // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtillities.getResumptionToken( - listSize, resumptionToken, cursorCollector, resTokenValue, 100, i); + ResumptionTokenType resTokenForResponse = OAIPMHUtillities.getResumptionToken(listSize, + resumptionToken, cursorCollector, resTokenValue, 30, i); if (resTokenForResponse != null) { recordList.setResumptionToken(resTokenForResponse); } + return recordList; } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java index e615e1e6e9ec6b13cdc51d6e3702e6bdd509386d..835a0ca679f29f0d3cf3bd4970604f7f59f4d0fd 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java @@ -22,9 +22,18 @@ import info.textgrid.utils.httpclient.TGHttpResponse; */ public class OaiPmhTextgridOnlineTests { + private static final String OAI_DC_PREFIX = "oai_dc"; + private static final String OAI_IDIOMMETS_PREFIX = "oai_idiom_mets"; + private static final String NO_SET = null; + // The OAIPMH host to be tested. - // private static String host = "http://textgrid-esx1.gwdg.de/1.0/tgoaipmh/"; + // private static String host = "http://dev.textgridlab.org/1.0/tgoaipmh/"; // private static String host = "http://textgridlab.org/1.0/tgoaipmh/"; + + // NOTE Test with "mvn jetty:run" in oaipmh-webapp module folder and SSH tunneling "ssh -L + // 9302:localhost:9302 -l username textgrid-esx2.gwdg.de", please use original OAIPMH config file + // from /etc/dhrep/oaipmh/oaipmh.textgrid.properties and copy it to + // /etc/dhrep/oaipmh/oaipmh.config on your local machine! private static String host = "http://localhost:8095/oaipmh/"; // Some output finals. @@ -146,6 +155,35 @@ public class OaiPmhTextgridOnlineTests { System.out.println(OK); } + /** + * @throws IOException + */ + @Test + public void testListMetadataFormats() throws IOException { + + String verb = "ListMetadataFormats"; + String shouldContainOaidc = "oai_dc"; + String shouldContainOaiidiommets = "oai_idiom_mets"; + + System.out.println(TESTING + "#LISTMETADATAFORMATS"); + + TGHttpResponse httpResponse = getHttpResponse(host + "oai?verb=" + verb); + int status = httpResponse.getStatusCode(); + + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); + + if (status != HttpStatus.SC_OK || !response.contains(shouldContainOaidc) + || !response.contains(shouldContainOaiidiommets)) { + System.err.println("\tstatus: " + status); + System.err.println(ERROR + ": response should contain '" + shouldContainOaidc + "' and '" + + shouldContainOaiidiommets + "'"); + assertTrue(false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OK); + } + /** * @throws IOException */ @@ -184,77 +222,138 @@ public class OaiPmhTextgridOnlineTests { * @throws IOException */ @Test - public void testListRecordsSinglePage() throws IOException { + public void testGetRecordOAIDC() throws IOException { + + System.out.println(TESTING + "#GETRECORD OAI_DC"); + + String identifier = "textgrid:254w6"; + + String url = host + "oai?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=" + + OAI_DC_PREFIX; + + if (!host.contains("dev.textgridlab.org")) { + getHttpResponse(url); + } + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordIDIOMMETS() throws IOException { + + System.out.println(TESTING + "#GETRECORD IDIOMMETS"); + + String identifier = "textgrid:254w6"; + + String url = host + "oai?verb=GetRecord&identifier=" + identifier + "&metadataPrefix=" + + OAI_IDIOMMETS_PREFIX; + + if (!host.contains("dev.textgridlab.org")) { + getHttpResponse(url); + } + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsOAIDCSinglePage() throws IOException { - System.out.println(TESTING + "#LISTRECORDS with expected single page (without token)"); + System.out.println(TESTING + "#LISTRECORDS OAI_DC with expected single page (without token)"); // IIIF String set = "project:TGPR-2e532567-c3e3-36f5-3ecc-520cea7904cc"; - testList("ListRecords", set); + testList("ListRecords", set, OAI_DC_PREFIX, 100); } /** * @throws IOException */ @Test - public void testListRecordsMorePages() throws IOException { + public void testListRecordsOAIDCMorePages() throws IOException { System.out.println(TESTING + "#LISTRECORDS with expected resumption token usage"); - // Testing set: Digitale Bibliothek (TODO Find another project with less - // records for testing!). + // Testing set: Digitale Bibliothek (TODO Find another project with less records for testing!). String set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; // Testing set: IIIF // String set = "project:TGPR-2e532567-c3e3-36f5-3ecc-520cea7904cc"; // Use fu's test project, if test instance used in host name. - if (host.contains("textgrid-esx1.gwdg.de")) { + if (host.contains("dev.textgridlab.org")) { // Testing set: fu's shakespeare. set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d"; // Testing set: Digitale Bibliothek. // set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; } - testList("ListRecords", set); + testList("ListRecords", set, OAI_DC_PREFIX, 100); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsIDIOMMETSMorePages() throws IOException { + + System.out + .println(TESTING + "#LISTRECORDS OAI_IDIOM_METS with expected resumption token usage"); + + // Do not test on dev.textgridlab.org. + if (!host.contains("dev.textgridlab.org")) { + testList("ListRecords", NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30); + } } /** * @throws IOException */ @Test - // @Ignore - public void testListIdentifierSinglePage() throws IOException { + public void testListIdentifierOAIDCSinglePage() throws IOException { - System.out.println(TESTING + "#LISTIDENTIFIERS with expected single page (without token)"); + System.out + .println(TESTING + "#LISTIDENTIFIERS OAI_DC with expected single page (without token)"); // IIIF String set = "project:TGPR-2e532567-c3e3-36f5-3ecc-520cea7904cc"; - testList("ListIdentifiers", set); + testList("ListIdentifiers", set, OAI_DC_PREFIX, 100); } /** * @throws IOException */ @Test - public void testListIdentifiersMorePages() throws IOException { + public void testListIdentifiersOAIDCMorePages() throws IOException { - System.out.println(TESTING + "#LISTIDENTIFIERS with expected resumption token usage"); + System.out.println(TESTING + "#LISTIDENTIFIERS OAI_DC with expected resumption token usage"); - // Testing set: Digitale Bibliothek (TODO Find another project with less - // records for testing!). + // Testing set: Digitale Bibliothek (TODO Find another project with less records for testing!). String set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; // Testing set: IIIF // String set = "project:TGPR-2e532567-c3e3-36f5-3ecc-520cea7904cc"; // Use fu's test project, if test instance used in host name. - if (host.contains("textgrid-esx1.gwdg.de")) { + if (host.contains("dev.textgridlab.org")) { // Testing set: fu's shakespeare. set = "project:TGPR-962c949c-56a3-7134-9265-582f29a0992d"; // Testing set: Digitale Bibliothek. // set = "project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c"; } - testList("ListIdentifiers", set); + testList("ListIdentifiers", set, OAI_DC_PREFIX, 100); + } + + /** + * @throws IOException + */ + @Test + public void testListIdentifiersIDIOMMETSMorePages() throws IOException { + + System.out + .println(TESTING + "#LISTIDENTIFIERS OAI_IDIOM_METS with expected resumption token usage"); + + testList("ListIdentifiers", NO_SET, OAI_IDIOMMETS_PREFIX, 3, 30); } // ** @@ -301,17 +400,19 @@ public class OaiPmhTextgridOnlineTests { /** * @param theResponse + * @param recordOrHeader + * @param oldtok + * @param recordsExpectedPerRequest + * @param loopCount * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is * existing, tag is existing and has no token value. * @throws IOException */ private static String examineResumptionTokenTag(TGHttpResponse theResponse, String recordOrHeader, - String oldtok) throws IOException { + String oldtok, int recordsExpectedPerRequest, int loopCount) throws IOException { String res = IOUtils.readStringFromStream(theResponse.getInputstream()); - // System.out.println(res); - // Test for OAIPMH errors. if (res.contains("<error code=\"badArgument\">")) { System.err.println(ERROR + " IN OAIPMH RESPONSE: " + res); @@ -359,31 +460,34 @@ public class OaiPmhTextgridOnlineTests { int cursor = Integer.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); System.out.println("\tsize: " + size + " / " + cursor); - // If token is provided, and we have less than 100 elements: mekkern! + // If token is provided, test cursor and element count! if (!restok.isEmpty()) { synchronized (OaiPmhTextgridOnlineTests.class) { - // Check <record> or <header> count, must be 100! - if (recordCount != 100) { - System.err.println(ERROR + ": " + recordOrHeader - + " count mismatch, must be 100 if token is provided, but is " + recordCount); + // Check <record> or <header> count, must be recordsExpectedPerRequest! + if (recordCount != recordsExpectedPerRequest) { + String message = ERROR + ": " + recordOrHeader + " count mismatch, must be " + + recordsExpectedPerRequest + " if token is provided, but is " + recordCount; + assertTrue(message, false); } - if (size <= 100) { - System.err.println(ERROR - + ": completeListSize count mismatch, must be > 100 if token is provided, but is " - + size); + if (size <= recordsExpectedPerRequest) { + String message = ERROR + ": completeListSize count mismatch, must be > " + + recordsExpectedPerRequest + " if token is provided, but is " + size; + assertTrue(message, false); } - if (recordCount != 100 || size <= 100) { - assertTrue(false); + if (cursor != recordsExpectedPerRequest * loopCount) { + String message = ERROR + ": cursor must be " + (loopCount * recordsExpectedPerRequest) + + " in loop " + loopCount + ", but is " + cursor; + assertTrue(message, false); } } } // If no token is provided, stop querying. else { - // Check <record> count, must be completeListSize % 100. - if (recordCount != size % 100) { + // Check <record> count, must be completeListSize % recordsExpectedPerRequest. + if (recordCount != size % recordsExpectedPerRequest) { System.err.println(ERROR + ": " + recordOrHeader + " count mismatch, should be " - + size % 100 + ", but is " + recordCount); + + size % recordsExpectedPerRequest + ", but is " + recordCount); assertTrue(false); } @@ -410,9 +514,26 @@ public class OaiPmhTextgridOnlineTests { /** * @param theVerb + * @param theSet + * @param theMetadataPrefix + * @param expectedRecordsPerRequest * @throws IOException */ - private static void testList(String theVerb, String theSet) throws IOException { + private static void testList(String theVerb, String theSet, String theMetadataPrefix, + int expectedRecordsPerRequest) throws IOException { + testList(theVerb, theSet, theMetadataPrefix, 0, expectedRecordsPerRequest); + } + + /** + * @param theVerb + * @param theSet + * @param metadataPrefix + * @param numberOfPagesToTest + * @param recordsExpectedPerRequest + * @throws IOException + */ + private static void testList(String theVerb, String theSet, String metadataPrefix, + int numberOfPagesToTest, int recordsExpectedPerRequest) throws IOException { long startTime = System.currentTimeMillis(); @@ -421,24 +542,36 @@ public class OaiPmhTextgridOnlineTests { testOccurance = "record"; } - String prefix = "oai_dc"; + String url = host + "oai?verb=" + theVerb + "&metadataPrefix=" + metadataPrefix; - String url = host + "oai?verb=" + theVerb + "&metadataPrefix=" + prefix + "&set=" + theSet; + if (theSet != null) { + url += "&set=" + theSet; + } TGHttpResponse httpResponse = getHttpResponse(url); int status = httpResponse.getStatusCode(); + int loopCount = 1; long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + getDurationInSecs(timeRunning)); + System.out.println("\ttime: " + getDurationInSecs(timeRunning) + " (loop " + loopCount + + (numberOfPagesToTest != 0 ? "/" + numberOfPagesToTest : "") + ")"); - String restok = examineResumptionTokenTag(httpResponse, testOccurance, ""); + String restok = examineResumptionTokenTag(httpResponse, testOccurance, "", + recordsExpectedPerRequest, loopCount); while (status == HttpStatus.SC_OK && !restok.equals("-1")) { + loopCount += 1; + if (numberOfPagesToTest > 0 && loopCount > numberOfPagesToTest) { + System.out.println("\tTESTING ONLY " + numberOfPagesToTest + " pages!"); + break; + } url = host + "oai?verb=" + theVerb + "&resumptionToken=" + restok; httpResponse = getHttpResponse(url); timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + getDurationInSecs(timeRunning)); - restok = examineResumptionTokenTag(httpResponse, testOccurance, restok); + System.out.println("\ttime: " + getDurationInSecs(timeRunning) + " (loop " + loopCount + + (numberOfPagesToTest != 0 ? "/" + numberOfPagesToTest : "") + ")"); + restok = examineResumptionTokenTag(httpResponse, testOccurance, restok, + recordsExpectedPerRequest, loopCount); } System.out.println(OK);