diff --git a/oaipmh-core/pom.xml b/oaipmh-core/pom.xml index bd0a82afa0cb925a5fedfecead745c542e2c5fee..31c9ba12ab31b8af430facb02dd1a7332ff847b2 100644 --- a/oaipmh-core/pom.xml +++ b/oaipmh-core/pom.xml @@ -134,34 +134,17 @@ <format property="BUILDDATE" pattern="yyyyMMddHHmm" /> </tstamp> <echo - file="./src/main/java/info/textgrid/middleware/OaipmhServiceVersion.java"> - package - info.textgrid.middleware; - public - final - class - OaipmhServiceVersion { - private - OaipmhServiceVersion() { + file="./src/main/java/info/textgrid/middleware/OAIPMHServiceVersion.java"> + package info.textgrid.middleware; + public final class + OAIPMHServiceVersion { + private OAIPMHServiceVersion() { // } + public static final String VERSION = "${project.version}"; + public static final String BUILDDATE = "${BUILDDATE}"; public - static - final - String - VERSION - = - "${project.version}"; - public static - final - String - BUILDDATE = - "${BUILDDATE}"; - public static final String - BUILDNAME - = - "${project.artifactId}"; - }</echo> + static final String BUILDNAME = "${project.artifactId}"; }</echo> </tasks> </configuration> </execution> diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/.gitignore b/oaipmh-core/src/main/java/info/textgrid/middleware/.gitignore index 1eaedf14d2390cd9142b89a80d876e11e76b12bf..96d426505d716a260e0becd70cd80e227a4b4b38 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/.gitignore +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/.gitignore @@ -1 +1,2 @@ /OaipmhServiceVersion.java +/OAIPMHServiceVersion.java diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IDIOMImages.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IDIOMImages.java index fd3ad45fb96a2ea74ec094096cdfc97b8fe9ee35..78018c032928be4e9d96b6b25924fc32ffebe07c 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IDIOMImages.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IDIOMImages.java @@ -21,13 +21,14 @@ import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.classicmayan.tools.ImageMetsMods; import org.classicmayan.tools.MediaHarvester; -import org.classicmayan.tools.TextGridUri; import org.json.JSONArray; import org.json.JSONException; import org.w3c.dom.Document; import org.xml.sax.InputSource; import org.xml.sax.SAXException; +import info.textgrid.clients.CrudClient; import info.textgrid.clients.tgcrud.CrudClientException; +import info.textgrid.clients.tgcrud.TextGridObject; import info.textgrid.middleware.oaipmh.GetRecordType; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListIdentifiersType; @@ -39,6 +40,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** * */ +// FIXME Why do we have to implement three classes?? public class IDIOMImages implements RecordDelivererInterface, RecordListDelivererInterface, IdentifierListDelivererInterface { @@ -48,10 +50,11 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere private String perPage; private String pageNumber; private int totalHits; - private String rbacSessionID; + private String idiomRbacSessionID; + private String idiomTgcrudEndpoint; - protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - protected static Map<String, String> fromUntilCollector = new Hashtable<String, String>(); + private static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + private static Map<String, String> fromUntilCollector = new Hashtable<String, String>(); /** * @@ -60,6 +63,14 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere // } + /** + * + */ + public IDIOMImages(String tgcrudEndpoint, String rbacSessionID) { + this.idiomTgcrudEndpoint = tgcrudEndpoint; + this.idiomRbacSessionID = rbacSessionID; + } + /** * * @throws JSONException @@ -114,7 +125,7 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere String dateStamp = mediaList.getJSONObject(i).get("created_at").toString(); String identifier = mediaList.getJSONObject(i).get("id").toString(); - record.setHeader(buildOAIPMH_RecordHeader(dateStamp, identifier)); + record.setHeader(buildOAIPMHRecordHeader(dateStamp, identifier)); imageMetsModsList.getRecord().add(record); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block @@ -170,7 +181,8 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere * */ @Override - public GetRecordType getRecordById(String id) throws JSONException, IOException, ParseException { + public GetRecordType getRecordById(final String id) + throws JSONException, IOException, ParseException { GetRecordType singleImageMetsMods = new GetRecordType(); RecordType conedaKorRecord = new RecordType(); @@ -179,33 +191,43 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; - ImageMetsMods immByTGURI = null; + ImageMetsMods immByTGObject = null; + String changedID = id; if (!id.startsWith("textgrid:")) { - id = "textgrid:" + id; + changedID = "textgrid:" + id; } - log.fine("processing id: " + id); + log.fine("processing id: " + changedID); + log.fine("tgcrud endpoint: " + this.idiomTgcrudEndpoint); + log.fine("tgcrud rbac sid: " + OAIPMHUtilities.hideSID(this.idiomRbacSessionID)); try { - immByTGURI = new ImageMetsMods(new TextGridUri(id), this.rbacSessionID); - log.fine("image id/title: " + immByTGURI.getID() + " / " + immByTGURI.getTitle()); + // Get TG-crud client. + CrudClient cc = new CrudClient(this.idiomTgcrudEndpoint).enableGzipCompression(); + TextGridObject tgo = + cc.read().setTextgridUri(changedID).setSid(this.idiomRbacSessionID).execute(); + + // Get image object. + immByTGObject = new ImageMetsMods(tgo); + + log.fine("image id/title: " + immByTGObject.getID() + " / " + immByTGObject.getTitle()); builder = factory.newDocumentBuilder(); - log.fine("immByTGURI: " + (immByTGURI != null ? immByTGURI.getXML() : "NULL")); + log.fine("immByTGURI: " + immByTGObject.getXML()); - Document doc = builder.parse(new InputSource(new StringReader(immByTGURI.getXML()))); + Document doc = builder.parse(new InputSource(new StringReader(immByTGObject.getXML()))); metadataMets.setAny(doc.getDocumentElement()); conedaKorRecord.setMetadata(metadataMets); - if (id.contains(".")) { - conedaKorRecord.setHeader(buildOAIPMH_RecordHeader( - OAIPMHUtilities.datestampAsString(immByTGURI.getCreationDate()), - id.substring(0, id.indexOf(".")))); + if (changedID.contains(".")) { + conedaKorRecord.setHeader(buildOAIPMHRecordHeader( + OAIPMHUtilities.datestampAsString(immByTGObject.getCreationDate()), + changedID.substring(0, changedID.indexOf(".")))); } else { - conedaKorRecord.setHeader(buildOAIPMH_RecordHeader( - OAIPMHUtilities.datestampAsString(immByTGURI.getCreationDate()), id)); + conedaKorRecord.setHeader(buildOAIPMHRecordHeader( + OAIPMHUtilities.datestampAsString(immByTGObject.getCreationDate()), changedID)); } singleImageMetsMods.setRecord(conedaKorRecord); @@ -218,40 +240,12 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere return singleImageMetsMods; } - /* - * public ListRecordsType getAllMedia() throws JSONException, IOException, ParseException, - * SAXException, TransformerFactoryConfigurationError, TransformerException{ ListRecordsType - * imageMetsModsList = new ListRecordsType(); MediaHarvester mediaHarvester = new - * MediaHarvester(getKindID(),getPerPage(), getPageNumber()); int perPage = 100; - * setTotalHits(mediaHarvester.getTotalMedia()); for(int j=1; j*perPage<=100 ;j++){ mediaHarvester - * = new MediaHarvester(getKindID(),getPerPage(), Integer.toString(j)); JSONArray mediaList = - * mediaHarvester.getMediaListFromConedaKor().getJSONArray("records"); int harvestedEntities = - * j*perPage; DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - * DocumentBuilder builder; for(int i=0; i<mediaList.length(); i++){ try{ ImageMetsMods imm = new - * ImageMetsMods(mediaList.getJSONObject(i)); - * - * - * builder = factory.newDocumentBuilder(); Document doc = builder.parse(new InputSource(new - * StringReader(imm.getXML()))); - * - * RecordType record = new RecordType(); MetadataType metadataMets = new MetadataType(); - * metadataMets.setAny(doc.getDocumentElement()); record.setMetadata(metadataMets); - * imageMetsModsList.getRecord().add(record); //printXML(doc); - * - * } catch (ParserConfigurationException e) { // TODO Auto-generated catch block - * e.printStackTrace(); } - * - * } - * - * } return imageMetsModsList; } - */ - /** * @param dateStamp * @param Identifier * @return */ - public HeaderType buildOAIPMH_RecordHeader(String dateStamp, String Identifier) { + public HeaderType buildOAIPMHRecordHeader(String dateStamp, String Identifier) { HeaderType recordHeader = new HeaderType(); recordHeader.setDatestamp(dateStamp); @@ -405,15 +399,43 @@ public class IDIOMImages implements RecordDelivererInterface, RecordListDelivere /** * @return */ - public String getRbacSessionID() { - return this.rbacSessionID; + public String getIdiomRbacSessionID() { + return this.idiomRbacSessionID; } /** - * @param rbacSessionID + * @param idiomRbacSessionID + */ + public void setIdiomRbacSessionID(String idiomRbacSessionID) { + this.idiomRbacSessionID = idiomRbacSessionID; + } + + /** + * @return + */ + public String getIdiomTgcrudEndpoint() { + return this.idiomTgcrudEndpoint; + } + + /** + * @param idiomTgcrudEndpoint + */ + public void setIdiomTgcrudEndpoint(String idiomTgcrudEndpoint) { + this.idiomTgcrudEndpoint = idiomTgcrudEndpoint; + } + + /** + * @return + */ + public static Map<String, Integer> getCursorCollector() { + return cursorCollector; + } + + /** + * @return */ - public void setRbacSessionID(String rbacSessionID) { - this.rbacSessionID = rbacSessionID; + public static Map<String, String> getFromUntilCollector() { + return fromUntilCollector; } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java index fc210f4f01ec0b22785c76fbc64837146a61debd..bbe1aad3bb625385905a5b7d3660060780b7495b 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererAbstract.java @@ -25,23 +25,22 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; public abstract class IdentifierListDelivererAbstract implements IdentifierListDelivererInterface { // ** - // FINALS + // STATIC // ** - protected static final int lifeTimeResToken = 100; + private static Logger log = Logger.getLogger(IdentifierListDelivererAbstract.class.getName()); // ** - // STATIC + // FINALS // ** - // FIXME Why is a global logger defined here? - private static Logger log = Logger.getGlobal(); + protected static final int lifeTimeResToken = 100; // ** // CLASS // ** - protected OAI_ESClient oaiEsClient; + protected OAIPMHElasticSearchClient oaiEsClient; protected boolean textgrid; protected boolean dariah; @@ -173,11 +172,11 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD } // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( + ResumptionTokenType responseToken = OAIPMHUtilities.getResumptionToken( listFurtherValues.getHits().getTotalHits(), resumptionToken, cursorCollector, listFurtherValues.getScrollId(), this.searchResponseSize, i); - if (resTokenForResponse != null) { - lit.setResumptionToken(resTokenForResponse); + if (responseToken != null) { + lit.setResumptionToken(responseToken); } return listFurtherValues; @@ -347,19 +346,6 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD this.rangeField = fieldForRange; } - /** - * @return - */ - public OAI_ESClient getOaiEsClient() { - return this.oaiEsClient; - } - - /** - * @param oaiEsClient - */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { - this.oaiEsClient = oaiEsClient; - } /** * @param lit @@ -509,4 +495,18 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD this.specFieldPrefix = specFieldPrefix; } + /** + * @return + */ + public OAIPMHElasticSearchClient getOaiEsClient() { + return this.oaiEsClient; + } + + /** + * @param oaiEsClient + */ + public void setOaiEsClient(OAIPMHElasticSearchClient oaiEsClient) { + this.oaiEsClient = oaiEsClient; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java index d75e52f85c701c01e85c5deb0444f079824896ca..3458d5f46b71b90ed52ea054cb44b4ee0423671e 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java @@ -27,7 +27,7 @@ import info.textgrid.middleware.oaipmh.ListIdentifiersType; */ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { - protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + private static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); /** * <p> @@ -96,4 +96,15 @@ public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { return lit; } + // ** + // GETTERS & SETTERS + // ** + + /** + * @return + */ + public static Map<String, Integer> getCursorCollector() { + return cursorCollector; + } + } 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 bd7475ee9b57a5e202a5d27d6f1e2c2ca433c843..d68d884989c0921f9a3de287e3c0d5e65766d9f2 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.text.ParseException; import java.util.Hashtable; import java.util.Map; +import java.util.logging.Logger; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchScrollRequest; @@ -19,7 +20,9 @@ import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** - * + * @author Max Brodhun, SUB Göttingen + * @author Stefan E. Funk, SUB Göttingen + * @version 2022-09-21 */ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract { @@ -27,7 +30,11 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac // STATICS // ** - protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + private static Logger log = Logger.getLogger(IdentifierListDelivererIDIOM.class.getName()); + + private static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + + private RecordDelivererIDIOM idiomRecord; // ** // CLASS @@ -44,41 +51,30 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac super(textgrid, dariah); } - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.IdentifierListDelivererAbstract#processIdentifierList(java.lang. - * String, java.lang.String, java.lang.String, java.lang.String) + /** + * */ @Override public ListIdentifiersType processIdentifierList(final String from, final String to, final String set, final String resumptionToken) throws ParseException, IOException { ListIdentifiersType identifierList = new ListIdentifiersType(); - BoolQueryBuilder recordFilterForClassicMayan; - - BoolQueryBuilder both; - RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); - BoolQueryBuilder test = QueryBuilders.boolQuery().must( + BoolQueryBuilder projectQuery = QueryBuilders.boolQuery().must( QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")); - - BoolQueryBuilder artefact = QueryBuilders.boolQuery() + BoolQueryBuilder artefactQuery = QueryBuilders.boolQuery() .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); - - BoolQueryBuilder conedakor = QueryBuilders.boolQuery() + BoolQueryBuilder conedakorQuery = QueryBuilders.boolQuery() .must(QueryBuilders.matchPhraseQuery("format", "application/json")) .must(QueryBuilders.matchPhraseQuery("notes", "ConedaKorMediumData")); + BoolQueryBuilder both = QueryBuilders.boolQuery().should(artefactQuery).should(conedakorQuery); - both = QueryBuilders.boolQuery().should(artefact).should(conedakor); - - BoolQueryBuilder bla = QueryBuilders.boolQuery().must(rangeQuery) - .must(test.filter(both)); - + BoolQueryBuilder bla = + QueryBuilders.boolQuery().must(rangeQuery).must(projectQuery.filter(both)); recordFilterForClassicMayan = bla; SearchResponse scrollResp; @@ -92,6 +88,9 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac searchSourceBuilder.size(this.idiomResponseSize); searchRequest.source(searchSourceBuilder); + log.fine("es elient/index: " + (this.oaiEsClient == null ? "null" : this.oaiEsClient) + "/" + + (this.oaiEsClient == null ? "null" : this.oaiEsClient.getEsIndex())); + if (resumptionToken != null) { SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); scrollRequest.scroll(TimeValue.timeValueHours(24L)); @@ -111,15 +110,11 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac // TODO Auto-generated catch block e.printStackTrace(); } - // scrollResp = OAI_ESClient.getEsClient().prepareSearchScroll(resumptionToken) - // .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); } String scrollID = scrollResp.getScrollId(); long completeListSize = scrollResp.getHits().totalHits; - - // long listSize = Queries.getAmountOfArtefacts(); if (completeListSize > 0) { setFoundItems(true); int i = 0; @@ -129,18 +124,21 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac String textgridURI = OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), "textgridUri"); - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); - - identifierList.getHeader() - .add(idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord().getHeader()); + // IF we really do need the RecordDelivererIDIOM object here, we have to set the + // elasticsearch client! + this.idiomRecord.setOaiEsClient(this.oaiEsClient); + // FIXME BTW: We only need ID and DATESTAMP for ListIdentifiers, WHY do we get every + // complete RECORD?? + identifierList.getHeader().add(this.idiomRecord + .getRecordById(textgridURI.replace(".0", "")).getRecord().getHeader()); } // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, + ResumptionTokenType responseToken = OAIPMHUtilities.getResumptionToken(completeListSize, resumptionToken, cursorCollector, scrollID, this.idiomResponseSize, i); - if (resTokenForResponse != null) { - identifierList.setResumptionToken(resTokenForResponse); + if (responseToken != null) { + identifierList.setResumptionToken(responseToken); } } else { setFoundItems(false); @@ -163,4 +161,25 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac this.idiomResponseSize = idiomResponseSize; } + /** + * @return + */ + public static Map<String, Integer> getCursorCollector() { + return cursorCollector; + } + + /** + * @return + */ + public RecordDelivererIDIOM getIdiomRecord() { + return this.idiomRecord; + } + + /** + * @param idiomRecord + */ + public void setIdiomRecord(RecordDelivererIDIOM idiomRecord) { + this.idiomRecord = idiomRecord; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbstract.java similarity index 88% rename from oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java rename to oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbstract.java index 249d014d355530edd9ffeaeeb6103b4c80f082c7..81dfae0452d75e74d33b8557a31250e8d5a45737 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbs.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererAbstract.java @@ -7,14 +7,14 @@ import info.textgrid.middleware.oaipmh.RequestType; /** * */ -public abstract class MetadataFormatListDelivererAbs +public abstract class MetadataFormatListDelivererAbstract implements MetadataFormatListDelivererInterface { // // CLASS // - protected OAI_ESClient oaiEsClient; + protected OAIPMHElasticSearchClient oaiEsClient; private boolean idExist = true; @@ -22,7 +22,7 @@ public abstract class MetadataFormatListDelivererAbs * @param textgrid * @param dariah */ - public MetadataFormatListDelivererAbs() { + public MetadataFormatListDelivererAbstract() { // } @@ -92,14 +92,14 @@ public abstract class MetadataFormatListDelivererAbs /** * @return */ - public OAI_ESClient getOaiEsClient() { + public OAIPMHElasticSearchClient getOaiEsClient() { return this.oaiEsClient; } /** * @param oaiEsClient */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { + public void setOaiEsClient(OAIPMHElasticSearchClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java index f609e84675304ff600dc391428ad4105725b9404..38ac270b2d45cd9715da22c98373cdf7df13d103 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererDH.java @@ -5,7 +5,7 @@ import info.textgrid.middleware.oaipmh.ListMetadataFormatsType; /** * */ -public class MetadataFormatListDelivererDH extends MetadataFormatListDelivererAbs { +public class MetadataFormatListDelivererDH extends MetadataFormatListDelivererAbstract { /** * @param textgrid @@ -15,13 +15,10 @@ public class MetadataFormatListDelivererDH extends MetadataFormatListDelivererAb // NOTE We do not have specific metadata formats for DHREP right now. } - /* - * (non-Javadoc) - * - * @see - * info.textgrid.middleware.MetadataFormatListDelivererInterface#setMetadataFormatList(java.lang. - * String) + /** + * */ + @Override public ListMetadataFormatsType setMetadataFormatList(String id) { // Get things from abstract class. return super.setMetadataFormatList(); diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java index 4ccb0ea2c202516d062a48a00a3de671dfd03a1c..0e003c06fb8580fc7cb51dcf3ea96d5b67cd1b9b 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/MetadataFormatListDelivererTG.java @@ -12,7 +12,7 @@ import info.textgrid.middleware.oaipmh.MetadataFormatType; /** * */ -public class MetadataFormatListDelivererTG extends MetadataFormatListDelivererAbs { +public class MetadataFormatListDelivererTG extends MetadataFormatListDelivererAbstract { /** * @@ -77,17 +77,12 @@ public class MetadataFormatListDelivererTG extends MetadataFormatListDelivererAb // Get things from abstract class. ListMetadataFormatsType result = super.setMetadataFormatList(); - // Add metadata format for IDIOM. + // Add metadata format for IDIOM METS. MetadataFormatType mftIdiomMets = new MetadataFormatType(); mftIdiomMets.setMetadataPrefix(OAIPMHConstants.METADATA_IDIOM_PREFIX); mftIdiomMets.setMetadataNamespace(OAIPMHUtilities.METS_NAMESPACE); mftIdiomMets.setSchema(OAIPMHUtilities.METS_SCHEMA_LOCATION); - MetadataFormatType idiomImages = new MetadataFormatType(); - idiomImages.setMetadataNamespace(OAIPMHUtilities.IDIOM_IMAGE_NAMESPACE); - idiomImages.setSchema(OAIPMHUtilities.IDIOM_IMAGE_SCHEMA_LOCATION); - - result.getMetadataFormat().add(idiomImages); result.getMetadataFormat().add(mftIdiomMets); return result; diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHClient.java similarity index 83% rename from oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java rename to oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHClient.java index f5bcfd8a6390756d37654ffe9bd6fd73011da309..1f4e496e91f30bef6959987c74b88010a6f8bb12 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OaiPmhClient.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHClient.java @@ -11,7 +11,7 @@ import org.apache.cxf.jaxrs.client.JAXRSClientFactory; /** * */ -public class OaiPmhClient { +public class OAIPMHClient { private String identifier; private String metadataPrefix; @@ -24,7 +24,7 @@ public class OaiPmhClient { /** * @param endpoint */ - public OaiPmhClient(String endpoint) { + public OAIPMHClient(String endpoint) { this.producer = JAXRSClientFactory.create(endpoint + "/oai", OAIPMHProducer.class); } @@ -32,7 +32,7 @@ public class OaiPmhClient { * @param verb * @return * @throws ParseException - * @throws IOException + * @throws IOException */ public String request(String verb) throws ParseException, IOException { return this.producer.getRequest(verb, this.identifier, this.metadataPrefix, this.set, this.from, @@ -46,8 +46,8 @@ public class OaiPmhClient { @Path("/version") @Produces(MediaType.TEXT_PLAIN) public String getVersion() { - return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "+" - + OaipmhServiceVersion.BUILDDATE; + return OAIPMHServiceVersion.BUILDNAME + "-" + OAIPMHServiceVersion.VERSION + "+" + + OAIPMHServiceVersion.BUILDDATE; } -} \ No newline at end of file +} diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHElasticSearchClient.java similarity index 87% rename from oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java rename to oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHElasticSearchClient.java index 541403255f6a35bd82fe890309de94f66b7cd552..f56d3cf50aeee1619b85ea2b98779bae083aee68 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAI_ESClient.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHElasticSearchClient.java @@ -13,10 +13,10 @@ import org.elasticsearch.client.RestHighLevelClient; * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-07 + * @version 2022-09-08 * @since 2014-01-09 */ -public class OAI_ESClient { +public class OAIPMHElasticSearchClient { private String url; private int[] ports; @@ -30,11 +30,11 @@ public class OAI_ESClient { * Constructor for the connection to an ElasticSearch index. * </p> * - * @param url address for the ELasticSearch connection - * @param port for the ElasticSearch connection - * @param clusterName indicating the name of the cluster where the index exists + * @param url Address for the ELasticSearch connection + * @param ports Ports for the ElasticSearch connection + * @param itemLimit Limit of items returned */ - public OAI_ESClient(String url, int[] ports, int itemLimit) { + public OAIPMHElasticSearchClient(String url, int[] ports, int itemLimit) { this.setUrl(url); this.setPorts(ports); diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java index bd9c1685a01791420cd670175aada10ac2ae7ea6..915594c5f5f689bf70a77c3b298a8cf8d10d7e14 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -31,7 +31,7 @@ import info.textgrid.middleware.oaipmh.VerbType; * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-07 + * @version 2022-09-21 * @since 2014-01-29 */ public class OAIPMHImpl implements OAIPMHProducer { @@ -71,12 +71,14 @@ public class OAIPMHImpl implements OAIPMHProducer { private RecordDelivererIDIOM recordIDIOM; private RecordDelivererDATACITE recordDATACITE; + private MetadataFormatListDelivererInterface metadataFormatList; + private SetListDeliverer setList; + private IdentifierListDelivererDC identifierListDC; private IdentifierListDelivererIDIOM identifierListIDIOM; private IdentifierListDelivererDATACITE identifierListDATACITE; - private MetadataFormatListDelivererInterface metadataFormatList; - private SetListDeliverer setList; + private IDIOMImages idiomImages; // ** // PUBLIC @@ -124,13 +126,14 @@ public class OAIPMHImpl implements OAIPMHProducer { this.recordListIDIOM = recordListIDIOM; this.recordListDATACITE = recordListDATACITE; + this.metadataFormatList = metadataFormatList; + this.setList = setList; + this.identifierListDC = identifierList; this.identifierListIDIOM = identifierListIDIOM; this.identifierListDATACITE = identifierListDATACITE; - this.metadataFormatList = metadataFormatList; - - this.setList = setList; + this.idiomImages = imageList; } /* @@ -208,8 +211,8 @@ public class OAIPMHImpl implements OAIPMHProducer { */ @Override public String getVersion() { - return OaipmhServiceVersion.BUILDNAME + "-" + OaipmhServiceVersion.VERSION + "+" - + OaipmhServiceVersion.BUILDDATE; + return OAIPMHServiceVersion.BUILDNAME + "-" + OAIPMHServiceVersion.VERSION + "+" + + OAIPMHServiceVersion.BUILDDATE; } /** @@ -295,6 +298,9 @@ public class OAIPMHImpl implements OAIPMHProducer { // Take IDIOM if IDIOM prefix. if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX)) { recDeliv = this.recordIDIOM; + + log.fine(" ## creating RecordDelivererIDIOM"); + } if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { recDeliv = this.recordDATACITE; @@ -303,9 +309,20 @@ public class OAIPMHImpl implements OAIPMHProducer { // Finally start the QUERY! GetRecordType getRecord = new GetRecordType(); + log.fine(" ## created RecordDelivererIDIOM"); + String id = request.getIdentifier(); + + log.fine(" ## ID = " + id); + try { + + log.fine(" ## calling getRecordById"); + getRecord = recDeliv.getRecordById(id); + + log.fine(" ## called getRecordById"); + } catch (ParseException | DatatypeConfigurationException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -336,7 +353,7 @@ public class OAIPMHImpl implements OAIPMHProducer { */ public OAIPMHtype listIdentifiersRequest(OAIPMHtype oaipmhRoot, RequestType request) throws ParseException { - IDIOMImages imm = new IDIOMImages(); + // Check request first. ErrorHandler requestErrors = IdentifierListDelivererAbstract.requestChecker(request); if (requestErrors.getError().getValue() != null) { @@ -361,14 +378,13 @@ public class OAIPMHImpl implements OAIPMHProducer { // format we shall use. else { // Token is from DC request. - if (IdentifierListDelivererDC.cursorCollector != null - && IdentifierListDelivererDC.cursorCollector - .containsKey(request.getResumptionToken())) { + if (IdentifierListDelivererDC.getCursorCollector() != null && IdentifierListDelivererDC + .getCursorCollector().containsKey(request.getResumptionToken())) { idListDeliv = this.identifierListDC; } // Token is from IDIOM request. - else if (IdentifierListDelivererIDIOM.cursorCollector != null - && IdentifierListDelivererIDIOM.cursorCollector + else if (IdentifierListDelivererIDIOM.getCursorCollector() != null + && IdentifierListDelivererIDIOM.getCursorCollector() .containsKey(request.getResumptionToken())) { idListDeliv = this.identifierListIDIOM; } @@ -379,14 +395,14 @@ public class OAIPMHImpl implements OAIPMHProducer { idListDeliv = this.identifierListDATACITE; } // Token is from IDIOMImages request. - else if (IDIOMImages.cursorCollector != null - && IDIOMImages.cursorCollector - .containsKey(request.getResumptionToken())) { - idListDeliv = imm; - imm.setKindID("1"); - imm.setPerPage("100"); - imm.setPageNumber( - Integer.toString(IDIOMImages.cursorCollector.get(request.getResumptionToken()))); + else if (IDIOMImages.getCursorCollector() != null + && IDIOMImages.getCursorCollector().containsKey(request.getResumptionToken())) { + // TODO Make configurable in config file?? + this.idiomImages.setKindID("1"); + this.idiomImages.setPerPage("100"); + this.idiomImages.setPageNumber( + Integer.toString(IDIOMImages.getCursorCollector().get(request.getResumptionToken()))); + idListDeliv = this.idiomImages; } // We have got an invalid resumptionToken here! else { @@ -529,8 +545,6 @@ public class OAIPMHImpl implements OAIPMHProducer { public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) throws ParseException, IOException { - IDIOMImages imm = new IDIOMImages(); - // Check request first. ErrorHandler requestErrors = RecordListDelivererAbstract.requestChecker(request); if (requestErrors.getError().getCode() != null) { @@ -546,6 +560,9 @@ public class OAIPMHImpl implements OAIPMHProducer { recListDeliv = this.recordListDC; } if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_IDIOM_PREFIX)) { + + log.fine(" ## creating RecordListDelivererIDIOM"); + recListDeliv = this.recordListIDIOM; } if (request.getMetadataPrefix().equals(OAIPMHConstants.METADATA_OPENAIRE_PREFIX)) { @@ -563,8 +580,11 @@ public class OAIPMHImpl implements OAIPMHProducer { recListDeliv = this.recordListDC; } // Token is from IDIOM request. - else if (RecordListDelivererIDIOM.cursorCollector != null - && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken())) { + else if (RecordListDelivererIDIOM.getCursorCollector() != null && RecordListDelivererIDIOM + .getCursorCollector().containsKey(request.getResumptionToken())) { + + log.fine(" ## creating RecordListDelivererIDIOM restok"); + recListDeliv = this.recordListIDIOM; } // Token is from DATACITE request. @@ -573,14 +593,15 @@ public class OAIPMHImpl implements OAIPMHProducer { .containsKey(request.getResumptionToken())) { recListDeliv = this.recordListDATACITE; } - // Token is from DATACITE request. - else if (IDIOMImages.cursorCollector != null - && IDIOMImages.cursorCollector.containsKey(request.getResumptionToken())) { - imm.setKindID("1"); - imm.setPerPage("100"); - imm.setPageNumber( - Integer.toString(IDIOMImages.cursorCollector.get(request.getResumptionToken()))); - recListDeliv = imm; + // Token is from IDIOMImages request. + else if (IDIOMImages.getCursorCollector() != null + && IDIOMImages.getCursorCollector().containsKey(request.getResumptionToken())) { + // TODO Make configurable in config file?? + this.idiomImages.setKindID("1"); + this.idiomImages.setPerPage("100"); + this.idiomImages.setPageNumber( + Integer.toString(IDIOMImages.getCursorCollector().get(request.getResumptionToken()))); + recListDeliv = this.idiomImages; } // We have got an invalid resumptionToken here! else { @@ -592,12 +613,16 @@ public class OAIPMHImpl implements OAIPMHProducer { } } + log.fine(" ## creating ListRecordsType"); + ListRecordsType listRecords = recListDeliv.getRecords( request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); + log.fine(" ## created ListRecordsType"); + if (listRecords != null) { oaipmhRoot.setListRecords(listRecords); } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java index ed39fd6aaa39a514dca6bc32c866547bd74ae136..aea29bc2447b377524d1ad807233e3a50f28f6ec 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java @@ -264,10 +264,10 @@ public class OAIPMHUtilities { final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, final int searchResponseSize, final int i) { - log.fine("Creating a ResumptionToken:\n " + "CompleteListSize: " + completeListSize + "\n" - + "ResumptionToken: " + resumptionToken + "\n" + "CursorCollector: " + cursorCollector - + "\n" + "ScrollID: " + scrollID + "\n" + "SearchResponseSize: " + searchResponseSize + "\n" - + "IterationStep: " + i); + log.fine("Creating a ResumptionToken:\n" + " CompleteListSize: " + completeListSize + "\n" + + " ResumptionToken: " + resumptionToken + "\n" + " CursorCollector: " + cursorCollector + + "\n" + " ScrollID: " + scrollID + "\n" + " SearchResponseSize: " + searchResponseSize + + "\n" + " IterationStep: " + i); int cursor; @@ -480,17 +480,25 @@ public class OAIPMHUtilities { * @return * @throws IOException */ - protected static GetResponse getRcordByIDFromElasticSearch(OAI_ESClient theESClient, + protected static GetResponse getRcordByIDFromElasticSearch(OAIPMHElasticSearchClient theESClient, String idInElasticSearchIndex, String[] includes, String[] excludes) throws IOException { + log.fine("id in es index: " + idInElasticSearchIndex); + log.fine("include/exclude: " + includes.length + "/" + excludes.length); + // Setting the source context for fetching the fields from the elastic search index FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + log.fine("esclient/index: " + (theESClient != null ? theESClient : "null") + "/" + + (theESClient != null ? theESClient.getEsIndex() : "null")); + // Building the getRequest against the elastic search index GetRequest getRequest = new GetRequest(theESClient.getEsIndex(), theESClient.getEsType(), idInElasticSearchIndex) .fetchSourceContext(fetchSourceContext); + log.fine("get request id: " + getRequest.id()); + // Declaration of the result from the get-request GetResponse esResultObject = theESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); @@ -627,7 +635,7 @@ public class OAIPMHUtilities { * @param theID * @return A valid setSpec value for the set. */ - protected static String getSetSpec(String theSetSpec, String theSpecPrefix, String theID) { + public static String getSetSpec(String theSetSpec, String theSpecPrefix, String theID) { String result = theSetSpec; @@ -644,6 +652,26 @@ public class OAIPMHUtilities { return result; } + /** + * @param theSID + * @return + */ + public static String hideSID(String theSID) { + + String result = "(null or empty)"; + + if (theSID != null && !theSID.isEmpty()) { + int size = theSID.length(); + if (size < 5) { + result = "(sid existing and too short)"; + } else { + result = theSID.substring(0, 4) + "..."; + } + } + + return result; + } + // ** // GETTERS & SETTERS // ** diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java index 1fbfba358392a404432d24d8c9f724b1fb393d30..a27af1c74d8c17f2e7e787ba7d66720411b166b3 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererAbstract.java @@ -15,7 +15,7 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac protected boolean textgrid; protected boolean dariah; - protected OAI_ESClient oaiEsClient; + protected OAIPMHElasticSearchClient oaiEsClient; protected String[] fields; protected String[] workFields; @@ -297,14 +297,14 @@ public abstract class RecordDelivererAbstract implements RecordDelivererInterfac /** * @return */ - public OAI_ESClient getOaiEsClient() { + public OAIPMHElasticSearchClient getOaiEsClient() { return this.oaiEsClient; } /** * @param oaiEsClient */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { + public void setOaiEsClient(OAIPMHElasticSearchClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java index 68fd8b8e674ff171ffd2fd31235960a4122a7149..74f10c0b9e912345774726c396393c0aa04e11ca 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDATACITE.java @@ -1,11 +1,8 @@ package info.textgrid.middleware; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.text.ParseException; import java.util.List; -import java.util.Properties; import java.util.logging.Logger; import javax.xml.datatype.DatatypeConfigurationException; import org.elasticsearch.common.Strings; @@ -64,7 +61,7 @@ public class RecordDelivererDATACITE extends RecordDelivererAbstract { private JSONObject jsonObj = new JSONObject(); // This variables contains the field requested in the ElasticSearch Index. The content will be - // given by a configuration file + // given by a configuration file. private String oarIdentifierField; private String oarSizeField; private String[] oarTitleFields; @@ -84,9 +81,6 @@ public class RecordDelivererDATACITE extends RecordDelivererAbstract { private String relationToWorkObject; private String handle; - // // This variable contains the XML-content for a whole OpenAire file - // private Resource resource = new Resource(); - /** * @param textgrid flag to indicate that the content of the record is context of the TextGrid * Repository. @@ -98,10 +92,8 @@ public class RecordDelivererDATACITE extends RecordDelivererAbstract { super(textgrid, dariah); } - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) + /** + * */ @Override public GetRecordType getRecordById(final String idInElasticSearchIndex) @@ -886,83 +878,6 @@ public class RecordDelivererDATACITE extends RecordDelivererAbstract { // GETTERS & SETTERS // ** - /** - * <p> - * Set all the props from config file, if bean can not be configured by spring if doing a new - * RecordDelivererDATACITE(). - * </p> - * - * @throws IOException - */ - protected void setConfigFileProps() throws IOException { - - // FIXME Let spring configure this anyhow! We have all settings in our beans.xml anyway! - // FIXME Configure config file name differently! - InputStream input = new FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); - - Properties p = new Properties(); - p.load(input); - - // Set basic fields. - this.fields = OAIPMHUtilities.fetchFieldsFromPropFile("fields", p); - this.setWorkFields(OAIPMHUtilities.fetchFieldsFromPropFile("workFields", p)); - - this.setFormatField(p.getProperty("formatField")); - this.setFormatToFilter(p.getProperty("formatToFilter")); - this.setDateOfObjectCreation(p.getProperty("dateOfObjectCreation")); - this.setRelationToFurtherMetadataObject(p.getProperty("relationToFurtherMetadataObject")); - this.setRepositoryObjectURIPrefix(p.getProperty("repositoryObjectURIPrefix")); - this.setIdentifierField(p.getProperty("identifierField")); - - // Set DC fields. - this.setContributor(OAIPMHUtilities.fetchFieldsFromPropFile("contributorList", p)); - this.setCoverage(OAIPMHUtilities.fetchFieldsFromPropFile("coverageList", p)); - this.setCreator(OAIPMHUtilities.fetchFieldsFromPropFile("creatorList", p)); - this.setDates(OAIPMHUtilities.fetchFieldsFromPropFile("dateList", p)); - this.setDescriptions(OAIPMHUtilities.fetchFieldsFromPropFile("descriptionList", p)); - this.setFormats(OAIPMHUtilities.fetchFieldsFromPropFile("formatList", p)); - this.setIdentifiers(OAIPMHUtilities.fetchFieldsFromPropFile("identifierList", p)); - this.setLanguages(OAIPMHUtilities.fetchFieldsFromPropFile("languageList", p)); - this.setPublishers(OAIPMHUtilities.fetchFieldsFromPropFile("publisherList", p)); - this.setRelations(OAIPMHUtilities.fetchFieldsFromPropFile("relationList", p)); - this.setRights(OAIPMHUtilities.fetchFieldsFromPropFile("rightsList", p)); - this.setSources(OAIPMHUtilities.fetchFieldsFromPropFile("sourceList", p)); - this.setSubjects(OAIPMHUtilities.fetchFieldsFromPropFile("subjectList", p)); - this.setTitles(OAIPMHUtilities.fetchFieldsFromPropFile("titleList", p)); - this.setTypes(OAIPMHUtilities.fetchFieldsFromPropFile("typeList", p)); - - // Set OpenAire config fields. - this.setOarIdentifierField(p.getProperty("oar.identifierField")); - this.setOarSizeField(p.getProperty("oar.sizeField")); - this.setOarTitleFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.titleFields", p)); - this.setOarDateFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.dateFields", p)); - this.setOarContributorFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.contributorFields", p)); - this.setOarCreatorFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.creatorFields", p)); - this.setOarLanguageFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.languageFields", p)); - this.setOarAlternateIdentifierFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.alternateIdentifierFields", p)); - this.setOarFormatFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.formatFields", p)); - this.setOarRightsFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.rightsFields", p)); - this.setOarDescriptionFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.descriptionFields", p)); - this.setOarRelatedIdentifierFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.relatedIdentifierFields", p)); - this.setOarGeoLocationFields( - OAIPMHUtilities.fetchFieldsFromPropFile("oar.geoLocationFields", p)); - this.setOarVersionFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.versionFields", p)); - this.setOarSubjectFields(OAIPMHUtilities.fetchFieldsFromPropFile("oar.subjectFields", p)); - - // Set more fields. - this.setRelationToWorkObject(p.getProperty("oar.relationToWorkObject")); - this.setHandle(p.getProperty("oar.handle")); - this.setSpecFieldPrefix(p.getProperty("specFieldPrefix")); - this.setSpecField(p.getProperty("specField")); - - input.close(); - } - /** * @return */ diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java index fd2325f4d638cd85222efa56150d39a3c483d924..9dcc625d9b133d3f1c794387356b4a0950238ee5 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java @@ -49,89 +49,98 @@ public class RecordDelivererDC extends RecordDelivererAbstract { changedId = changedId.replace(this.repositoryObjectURIPrefix, ""); } + log.fine("id: " + id); + log.fine("changed id: " + changedId); + // Get ES response, get record for given ID. - GetResponse esResultObject = null; + String[] includes = this.fields; + String[] excludes = Strings.EMPTY_ARRAY; try { - String[] includes = this.fields; - String[] excludes = Strings.EMPTY_ARRAY; - - esResultObject = + GetResponse esResultObject = OAIPMHUtilities.getRcordByIDFromElasticSearch(this.oaiEsClient, id, includes, excludes); - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - log.severe("could not fetch the result of elasticsearch"); - } - - if (esResultObject.isExists()) { - String identifier; - - // ** - // DARIAH - // ** - - if (this.dariah == true) { - dublinCoreBuilder = putContentIntoDCFieldListsDH(esResultObject); - JSONObject json = new JSONObject(esResultObject.getSourceAsMap()); - identifier = OAIPMHUtilities.fieldLoader(json, this.identifierField); - - String dateOfCreation = "NO_DATE_SET!"; - if (OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation) != null) { - try { - dateOfCreation = OAIPMHUtilities - .convertDateFormat( - OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation).toString()) - .toXMLFormat(); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DatatypeConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + log.fine("es result id/size: " + (esResultObject != null + ? esResultObject.getId() + "/" + esResultObject.getFields().size() + : "null")); + + if (esResultObject != null && esResultObject.isExists()) { + String identifier; + + // ** + // DARIAH + // ** + + if (this.dariah == true) { + dublinCoreBuilder = putContentIntoDCFieldListsDH(esResultObject); + JSONObject json = new JSONObject(esResultObject.getSourceAsMap()); + identifier = OAIPMHUtilities.fieldLoader(json, this.identifierField); + + String dateOfCreation = "NO_DATE_SET!"; + if (OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation) != null) { + try { + dateOfCreation = OAIPMHUtilities + .convertDateFormat( + OAIPMHUtilities.fieldLoader(json, this.dateOfObjectCreation).toString()) + .toXMLFormat(); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } + + String setSpec = OAIPMHUtilities.fieldLoader(json, this.specField); + String setSpecValue = + OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + + record.setHeader( + OAIPMHUtilities.computeResponseHeader(dateOfCreation, identifier, setSpecValue)); + record.setMetadata(dublinCoreBuilder.getDC()); } - String setSpec = OAIPMHUtilities.fieldLoader(json, this.specField); - String setSpecValue = OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + // ** + // TEXTGRID + // ** - record.setHeader( - OAIPMHUtilities.computeResponseHeader(dateOfCreation, identifier, setSpecValue)); - record.setMetadata(dublinCoreBuilder.getDC()); - } + if (this.textgrid == true + && esResultObject.getSourceAsMap().get(this.formatField).equals(this.formatToFilter)) { - // ** - // TEXTGRID - // ** - - if (this.textgrid == true - && esResultObject.getSourceAsMap().get(this.formatField).equals(this.formatToFilter)) { - - String workUri = DublinCoreFieldLoader - .fillListFromTGWorkValues(esResultObject, - new String[] {this.relationToFurtherMetadataObject}) - .get(0); - workUri = workUri.substring(this.repositoryObjectURIPrefix.length()); - dublinCoreBuilder = - putContentIntoDCFieldListsTG(esResultObject, furtherDCElements(workUri)); - identifier = esResultObject.getSourceAsMap().get(this.identifierField).toString(); - String dateOfCreation = - esResultObject.getSourceAsMap().get(this.dateOfObjectCreation).toString(); - - String setSpec = DublinCoreFieldLoader - .fillListFromTGWorkValues(esResultObject, TGConstants.RELATIONS_LIST).get(0); - String setSpecValue = OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); - - record.setHeader(OAIPMHUtilities.computeResponseHeader( - OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, - setSpecValue)); - record.setMetadata(dublinCoreBuilder.getDC()); - } + log.fine("---processing tg result---"); - getRecordType.setRecord(record); + String workUri = DublinCoreFieldLoader.fillListFromTGWorkValues(esResultObject, + new String[] {this.relationToFurtherMetadataObject}).get(0); - } else { - return null; + log.fine("work uri: " + workUri); + + workUri = workUri.substring(this.repositoryObjectURIPrefix.length()); + dublinCoreBuilder = + putContentIntoDCFieldListsTG(esResultObject, furtherDCElements(workUri)); + identifier = esResultObject.getSourceAsMap().get(this.identifierField).toString(); + String dateOfCreation = + esResultObject.getSourceAsMap().get(this.dateOfObjectCreation).toString(); + + String setSpec = DublinCoreFieldLoader + .fillListFromTGWorkValues(esResultObject, TGConstants.RELATIONS_LIST).get(0); + String setSpecValue = + OAIPMHUtilities.getSetSpec(setSpec, this.specFieldPrefix, identifier); + + record.setHeader(OAIPMHUtilities.computeResponseHeader( + OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, + setSpecValue)); + record.setMetadata(dublinCoreBuilder.getDC()); + } + + getRecordType.setRecord(record); + + } else { + return null; + } + + } catch (IOException e) { + // TODO Auto-generated catch block + log.severe("could not fetch the result of elasticsearch"); } return getRecordType; diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java index 453a6c486ee90756a08ce3ea9a35a42bdf3c3298..bbf05513b38dbb251a87ac9149676e7b8521d892 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java @@ -24,7 +24,7 @@ import info.textgrid.middleware.oaipmh.RecordType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-07 + * @version 2022-09-21 * @since 2019-03-12 */ @Component @@ -32,10 +32,11 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { private static Logger log = Logger.getLogger(RecordDelivererIDIOM.class.getName()); - private String dateOfLastObjectModification; - private String objectType; + private IDIOMImages idiomImages; RecordType record = new RecordType(); + private String dateOfLastObjectModification; + private String objectType; /** * @param textgrid @@ -45,67 +46,6 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { super(textgrid, dariah); } - /** - * <p> - * ElasticSearch request in non-public index to get the datestamps for the object creation and - * last modification date in TextGridRep. - * </p> - * - * @param idInDatabase - * @throws ParseException - * @throws IOException - */ - public void setDatestamps(String idInDatabase) throws ParseException, IOException { - - String changedId = idInDatabase; - - // FIXME NOT USED?? - // String[] includes = new String[] {TGConstants.CREATED, TGConstants.MODIFIED_FIELD}; - // String[] excludes = Strings.EMPTY_ARRAY; - // FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); - - if (idInDatabase.startsWith("textgrid:")) { - changedId = idInDatabase.substring("textgrid:".length()); - } - - if (!idInDatabase.contains(".0")) { - // changedId = changedId.substring(0,changedId.length() - 1) + "0"; - changedId = changedId + ".0"; - } - - // FIXME NOT USED?? - // GetRequest getRequest = - // new GetRequest("textgrid-nonpublic", OAI_ESClient.getEsType(), changedId) - // .fetchSourceContext(fetchSourceContext); - - // FIXME NOT USED?? - // GetResponse objectInDatabase = null; - // try { - // objectInDatabase = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); - // } catch (IOException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - JSONObject json = new JSONObject(); - String[] fields = {TGConstants.CREATED, TGConstants.MODIFIED_FIELD, "notes"}; - - // FIXME Is a NEW client instance used here or the one from the abstract class? We do need - // non-public data here! - this.oaiEsClient.setEsIndex("textgrid-nonpublic"); - - json = new JSONObject(OAIPMHUtilities - .getRcordByIDFromElasticSearch(this.oaiEsClient, changedId, fields, Strings.EMPTY_ARRAY) - .getSource()); - - this.dateOfObjectCreation = - OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED)); - - this.dateOfLastObjectModification = OAIPMHUtilities - .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.MODIFIED_FIELD)); - - this.setObjectType(OAIPMHUtilities.fieldLoader(json, "notes")); - } - /** * <p> * Building the record XML object for the OAI-PMH response. @@ -121,7 +61,7 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { log.fine("identifier: " + id); - setDatestamps(id); + setDatestampsAndObjectType(id); // Get TG URI and TG base URI from ID. String tgURI = id; @@ -133,13 +73,11 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { tgBaseURI = tgBaseURI.replace(".0", ""); log.fine("tg uri/base uri: " + tgURI + "/" + tgBaseURI); + log.fine("object type is: " + this.objectType); + log.fine(this.objectType + " doc/dom: " + this.dateOfObjectCreation + "/" + + this.dateOfLastObjectModification); - log.fine("object type is: " + this.getObjectType()); - - if (this.getObjectType().equals("ARTEFACT")) { - - log.fine("artefact doc/dom: " + this.dateOfObjectCreation + "/" - + this.dateOfLastObjectModification); + if (this.objectType.equals("ARTEFACT")) { try { ClassicMayanMetsMods metsmods = new ClassicMayanMetsMods( @@ -157,8 +95,14 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { // TODO Auto-generated catch block e.printStackTrace(); } - } else if (this.getObjectType().startsWith("ConedaKorMediumData")) { - GetRecordType idi = new IDIOMImages().getRecordById(id); + } + + else if (this.objectType.startsWith("ConedaKorMediumData")) { + + log.fine("calling idiom image getRecordById()"); + + GetRecordType idi = this.idiomImages.getRecordById(id); + // Fixes #64 if (idi != null) { this.record = idi.getRecord(); @@ -220,6 +164,47 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { return metadataMets; } + /** + * <p> + * ElasticSearch request in non-public index to get the datestamps for the object creation and + * last modification date in TextGridRep. + * </p> + * + * @param idInDatabase + * @throws ParseException + * @throws IOException + */ + private void setDatestampsAndObjectType(String idInDatabase) throws ParseException, IOException { + + String changedId = idInDatabase; + + if (idInDatabase.startsWith("textgrid:")) { + changedId = idInDatabase.substring("textgrid:".length()); + } + + if (!idInDatabase.contains(".0")) { + changedId = changedId + ".0"; + } + + log.fine("changedId: " + changedId); + + JSONObject json = new JSONObject(); + String[] fields = {TGConstants.CREATED, TGConstants.MODIFIED_FIELD, "notes"}; + + json = new JSONObject(OAIPMHUtilities + .getRcordByIDFromElasticSearch(this.oaiEsClient, changedId, fields, Strings.EMPTY_ARRAY) + .getSource()); + + this.dateOfObjectCreation = + OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED)); + + this.dateOfLastObjectModification = OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.MODIFIED_FIELD)); + + this.objectType = OAIPMHUtilities.fieldLoader(json, "notes"); + } + + // ** // GETTERS & SETTERS // ** @@ -227,15 +212,15 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { /** * @return */ - public String getObjectType() { - return this.objectType; + public IDIOMImages getIdiomImages() { + return this.idiomImages; } /** - * @param objectType + * @param idiomImages */ - public void setObjectType(String objectType) { - this.objectType = objectType; + public void setIdiomImages(IDIOMImages idiomImages) { + this.idiomImages = idiomImages; } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java index 109532f683d994ff995c2e25cacbf680759d3d84..c4e4c40968e5b548d99e2a3f821c67aa5d0d8f16 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java @@ -14,7 +14,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; */ public abstract class RecordListDelivererAbstract implements RecordListDelivererInterface { - protected OAI_ESClient oaiEsClient; + protected OAIPMHElasticSearchClient oaiEsClient; protected boolean textgrid; protected boolean dariah; @@ -180,14 +180,14 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer /** * @return */ - public OAI_ESClient getOaiEsClient() { + public OAIPMHElasticSearchClient getOaiEsClient() { return this.oaiEsClient; } /** * @param oaiEsClient */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { + public void setOaiEsClient(OAIPMHElasticSearchClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java index 0315d98df5add257aadb89972f237eec12c20c61..2f52c1ca7efdec5697a83b0962a0daa036526712 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDATACITE.java @@ -24,7 +24,7 @@ import info.textgrid.middleware.oaipmh.RecordType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-07 + * @version 2022-09-08 * @since 2020-06-13 */ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { @@ -37,6 +37,8 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + private RecordDelivererDATACITE dataciteRecord; + /** * @param textgrid * @param dariah @@ -52,14 +54,7 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) throws ParseException, IOException { - ListRecordsType openAireRecordList = new ListRecordsType(); - - // Create one RecordDeliverer only, to configure all fields only ONCE. - // FIXME May be solved using spring configuration, but I do not know how! - RecordDelivererDATACITE openAireRecord = - new RecordDelivererDATACITE(this.textgrid, this.dariah); - // Must be done here, as spring does not configure this bean if instantiated with "new". - openAireRecord.setConfigFileProps(); + ListRecordsType recordList = new ListRecordsType(); List<String> URIList = getUriList(from, to, set, resumptionToken); for (String uri : URIList) { @@ -79,14 +74,13 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { // DARIAH // ** - try { - GetRecordType grt = openAireRecord.getRecordById(eventuallyChangedUri); + GetRecordType grt = this.dataciteRecord.getRecordById(eventuallyChangedUri); RecordType record = grt.getRecord(); // Header is already set by getRecordById(). - openAireRecordList.getRecord().add(record); + recordList.getRecord().add(record); } catch (DatatypeConfigurationException e) { // TODO Auto-generated catch block @@ -94,9 +88,9 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { } } - openAireRecordList.setResumptionToken(getResTokenForResponse()); + recordList.setResumptionToken(getResTokenForResponse()); - return openAireRecordList; + return recordList; } /** @@ -126,7 +120,7 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { // Add new record with set metadata in it (to also find collection metadata in Repository // Search!) - + // FIXME Did we do this?? } if (this.textgrid == true) { @@ -251,4 +245,22 @@ public class RecordListDelivererDATACITE extends RecordListDelivererAbstract { return uriList; } + // ** + // GETTERS & SETTERS + // ** + + /** + * @return + */ + public RecordDelivererDATACITE getDataciteRecord() { + return this.dataciteRecord; + } + + /** + * @param dataciteRecord + */ + public void setDataciteRecord(RecordDelivererDATACITE dataciteRecord) { + this.dataciteRecord = dataciteRecord; + } + } 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 77f37df62dea06dfd8e2c96af40d3a35cd8b2e56..3dcab2361da91a580164d1f34d574c475b468811 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java @@ -264,16 +264,16 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract { // Check the need for a resumption token! - log.fine(" ## completeListSize: " + completeListSize); - log.fine(" ## resumptionToken: " + resumptionToken); - log.fine(" ## scrollid: " + scrollID); - log.fine(" ## searchResponseSize: " + this.searchResponseSize); + log.fine("completeListSize: " + completeListSize); + log.fine("resumptionToken: " + resumptionToken); + log.fine("scrollid: " + scrollID); + log.fine("searchResponseSize: " + this.searchResponseSize); ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i); if (resTokenForResponse != null) { - log.fine(" ## resTokenForResponse: " + resTokenForResponse.getValue()); + log.fine("resTokenForResponse: " + resTokenForResponse.getValue()); } recordList.setResumptionToken(resTokenForResponse); 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 a689c517155680715fa5703cbe1aa8721385c5da..05bc663317c44d4ab7eea89876a4b3c1518dc0ac 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -23,7 +23,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2022-09-07 + * @version 2022-09-19 * @since */ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { @@ -33,9 +33,13 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { // ** private static Logger log = Logger.getLogger(RecordListDelivererIDIOM.class.getName()); + private static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); + // ** + // CLASS + // ** + private RecordDelivererIDIOM idiomRecord; // Set default to 30, can be changed in oaipmh.properties. private int idiomResponseSize = 30; @@ -56,28 +60,24 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { ListRecordsType recordList = new ListRecordsType(); - BoolQueryBuilder recordFilterForClassicMayan; - - BoolQueryBuilder both; - RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); - BoolQueryBuilder test = QueryBuilders.boolQuery().must( + BoolQueryBuilder projectQuery = QueryBuilders.boolQuery().must( QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")); - BoolQueryBuilder artefact = QueryBuilders.boolQuery() + BoolQueryBuilder artefactQuery = QueryBuilders.boolQuery() .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); - BoolQueryBuilder conedakor = QueryBuilders.boolQuery() + BoolQueryBuilder conedakorQuery = QueryBuilders.boolQuery() .must(QueryBuilders.matchPhraseQuery("format", "application/json")) .must(QueryBuilders.matchPhraseQuery("notes", "ConedaKorMediumData")); - both = QueryBuilders.boolQuery().should(artefact).should(conedakor); + BoolQueryBuilder both = QueryBuilders.boolQuery().should(artefactQuery).should(conedakorQuery); BoolQueryBuilder queryBuilder = - QueryBuilders.boolQuery().must(rangeQuery).must(test.filter(both)); - recordFilterForClassicMayan = queryBuilder; + QueryBuilders.boolQuery().must(rangeQuery).must(projectQuery.filter(both)); + BoolQueryBuilder recordFilterForClassicMayan = queryBuilder; // QueryBuilders.boolQuery().must(rangeQuery).should(recordFilteroClassicMayanARTEFACT).should(recordFilterForClassicMayanCONEDAKOR); SearchResponse scrollResp; @@ -133,34 +133,13 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { log.fine("record type: " + recordType); log.fine("textgridURI: " + textgridURI); - RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); - // FIXME Record type is coped with in RecordDelivererIDIOM, so we do not have to use a - // conditional here. - // if (recordType.equals("ARTEFACT")) { - - GetRecordType idi = idiomRecord.getRecordById(textgridURI.replace(".0", "")); + GetRecordType idi = this.idiomRecord.getRecordById(textgridURI.replace(".0", "")); log.fine("idi.header: " + (idi == null ? "null" : idi.getRecord().getHeader())); recordList.getRecord().add(idi.getRecord()); - // } else if (recordType.startsWith("ConedaKorMediumData")) { - // - // GetRecordType idi = new IDIOMImages().getRecordById(textgridURI); - // - // log.fine("idi.header: " + (idi == null ? "null" : idi.getRecord().getHeader())); - // - // // Fixes #64 - // if (idi != null) { - // // If image is complete/has metadata (whatever?), set IDIOM image record. - // recordList.getRecord().add(idi.getRecord()); - // } - // // else { - // // // If image is incomplete/has no metadata (whatever?), set "normal" record? - // // recordList.getRecord() - // // .add(idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord()); - // // } - // } + log.fine("record added: " + idi.getRecord().getHeader().getIdentifier()); } // Check the need for a resumption token! @@ -169,12 +148,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { if (resTokenForResponse != null) { recordList.setResumptionToken(resTokenForResponse); } - } else - - { + } else { setFoundItems(false); } + log.fine("record list size: " + recordList.getRecord().size()); + return recordList; } @@ -196,4 +175,25 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { this.idiomResponseSize = idiomResponseSize; } + /** + * @return + */ + public RecordDelivererIDIOM getIdiomRecord() { + return this.idiomRecord; + } + + /** + * @param idiomRecord + */ + public void setIdiomRecord(RecordDelivererIDIOM idiomRecord) { + this.idiomRecord = idiomRecord; + } + + /** + * @return + */ + public static Map<String, Integer> getCursorCollector() { + return cursorCollector; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java index e5e053751c2de0e603ffb1ddf664158ba51e98f4..04be7ab961177073b11b6d72831e7f89001b0055 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/SetListDeliverer.java @@ -43,7 +43,7 @@ public class SetListDeliverer { private boolean textgrid; private boolean dariah; - private OAI_ESClient oaiEsClient; + private OAIPMHElasticSearchClient oaiEsClient; /** * @param oaiEsClient @@ -343,14 +343,14 @@ public class SetListDeliverer { /** * @return */ - public OAI_ESClient getOaiEsClient() { + public OAIPMHElasticSearchClient getOaiEsClient() { return this.oaiEsClient; } /** * @param oaiEsClient */ - public void setOaiEsClient(OAI_ESClient oaiEsClient) { + public void setOaiEsClient(OAIPMHElasticSearchClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java deleted file mode 100644 index b1290437cc1281db0cb4d52f87e40f3052f9985e..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestDH.java +++ /dev/null @@ -1,204 +0,0 @@ -package info.textgrid.middleware; - -import java.text.ParseException; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import info.textgrid.middleware.oaipmh.DeletedRecordType; -import info.textgrid.middleware.oaipmh.GranularityType; -import info.textgrid.middleware.common.TextGridMimetypes; - -/** - * FIXME: Add documentation how to use this class, use SSH tunnel? - */ -@Ignore -public class OaiPmhTestDH { - - public static OAI_ESClient oaiEsClient; - - private static RecordDelivererDC record; - private static RecordListDelivererDC recordList; - private static IdentifierListDelivererDC identifierList; - private static MetadataFormatListDelivererInterface metadataFormatList = - new MetadataFormatListDelivererDH(); - private static SetListDeliverer setListDARIAH = new SetListDeliverer(false, true); - - // private static OpenAireRecord openAireRecord; - private static RecordDelivererDATACITE recordDATACITE; - // private static OpenAireRecordList openAireRecordList; - private static RecordListDelivererDATACITE recordListDATACITE; - // private static OpenAireIdentifierList openAireIdentifierList; - private static IdentifierListDelivererDATACITE identifierListDATACITE; - private static IDIOMImages idiomImages; - private DeletedRecordType deletedRecordType = DeletedRecordType.NO; - private GranularityType granularityType = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; - private RepIdentification rep = new RepIdentification("DARIAH-DE Repository", - "https://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", - this.granularityType, "2.0", "funk@sub.uni-goettingen.de"); - - /** - * FIXME: it should not be necessary to put idiom record variables for a DARIAH test case - */ - private static RecordDelivererIDIOM recordIDIOM; - private static RecordListDelivererIDIOM recordListIDIOM; - private static IdentifierListDelivererIDIOM identifierListIDIOM = - new IdentifierListDelivererIDIOM(true, false); - - private OAIPMHImpl request = - new OAIPMHImpl(this.rep, - OaiPmhTestDH.record, - OaiPmhTestDH.recordIDIOM, - OaiPmhTestDH.recordDATACITE, - OaiPmhTestDH.recordList, - OaiPmhTestDH.recordListIDIOM, - OaiPmhTestDH.recordListDATACITE, - OaiPmhTestDH.metadataFormatList, - OaiPmhTestDH.setListDARIAH, - OaiPmhTestDH.identifierList, - OaiPmhTestDH.identifierListIDIOM, - // OaiPmhTestDH.openAireIdentifierList); - OaiPmhTestDH.identifierListDATACITE, - OaiPmhTestDH.idiomImages); - - OAIPMHUtilities settings = new OAIPMHUtilities(); - - /** - * @throws Exception - */ - @BeforeClass - public static void setUp() throws Exception { - int[] ports = new int[] {9202}; - oaiEsClient = new OAI_ESClient("localhost", ports, 100); - oaiEsClient.setEsIndex("dariah-public"); - oaiEsClient.setEsType("metadata"); - - record = new RecordDelivererDC(false, true); - record.setOaiEsClient(oaiEsClient); - record.setWorkFields(OAIPMHConstants.TEST_DARIAH_FIELDS); - } - - /** - * @throws ParseException - */ - @Test - public void testGetRequestIdentify() throws ParseException { - System.out.println("Test for the verb \"Identify\" with succesfull response"); - String r = this.request.getRequest("Identify", "", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testGetRequestGetRecordDariah() throws ParseException { - - OaiPmhTestDH.record.setContributor(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); - OaiPmhTestDH.record.setCoverage(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); - OaiPmhTestDH.record.setCreator(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); - OaiPmhTestDH.record.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); - OaiPmhTestDH.record.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); - OaiPmhTestDH.record.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); - OaiPmhTestDH.record.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); - OaiPmhTestDH.record.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); - OaiPmhTestDH.record.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); - OaiPmhTestDH.record.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); - OaiPmhTestDH.record.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); - OaiPmhTestDH.record.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); - OaiPmhTestDH.record.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); - OaiPmhTestDH.record.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); - OaiPmhTestDH.record.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); - OaiPmhTestDH.record.setFields(OAIPMHConstants.TEST_DARIAH_FIELDS); - OaiPmhTestDH.record.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); - OaiPmhTestDH.record.setFormatToFilter("metadata"); - OaiPmhTestDH.record.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); - OaiPmhTestDH.record - .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); - OaiPmhTestDH.record.setIdentifierField("administrativeMetadata.dcterms:identifier"); - - System.out.println("Test for the verb \"GetRecord\" for DARIAH with succesfull response"); - String p = this.request.getRequest("GetRecord", "hdl:21.T11991/0000-0005-E1AA-D", "oai_dc", "", - "", "", ""); - System.out.println(p); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListRecordsDariah() throws ParseException { - - OaiPmhTestDH.recordList.setContributors(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); - OaiPmhTestDH.recordList.setCoverages(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); - OaiPmhTestDH.recordList.setCreators(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); - OaiPmhTestDH.recordList.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); - OaiPmhTestDH.recordList.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); - OaiPmhTestDH.recordList.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); - OaiPmhTestDH.recordList.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); - OaiPmhTestDH.recordList.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); - OaiPmhTestDH.recordList.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); - OaiPmhTestDH.recordList.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); - OaiPmhTestDH.recordList.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); - OaiPmhTestDH.recordList.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); - OaiPmhTestDH.recordList.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); - OaiPmhTestDH.recordList.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); - OaiPmhTestDH.recordList.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); - OaiPmhTestDH.recordList.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); - OaiPmhTestDH.recordList.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_CREATED); - OaiPmhTestDH.recordList.setRangeField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); - OaiPmhTestDH.recordList.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); - OaiPmhTestDH.recordList.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); - OaiPmhTestDH.recordList.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); - OaiPmhTestDH.recordList.setModifiedField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); - OaiPmhTestDH.recordList - .setRelationToFurtherMetadataObject("descriptiveMetadata.dc:relation"); - OaiPmhTestDH.recordList.setSearchResponseSize(100); - - String r = this.request.getRequest("ListRecords", "", "oai_dc", "21.T11991/0000-0003-718E-E", - "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListSetsDARIAH() throws ParseException { - - OaiPmhTestDH.setListDARIAH.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); - OaiPmhTestDH.setListDARIAH.setFormatToFilter(OAIPMHConstants.TEST_DARIAH_COLLECTION_MIMETYPE); - OaiPmhTestDH.setListDARIAH.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); - OaiPmhTestDH.setListDARIAH - .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); - OaiPmhTestDH.setListDARIAH.setIdentifierField("administrativeMetadata.dcterms:identifier"); - OaiPmhTestDH.setListDARIAH - .setSpecFieldPrefix(OAIPMHConstants.TEST_DARIAH_COLLECTIONREGISTRY_PREFIX); - String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - - /** - * @throws ParseException - */ - @Test - public void testListIdentifiersDARIAH() throws ParseException { - - OaiPmhTestDH.identifierList.setFieldForRange(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); - OaiPmhTestDH.identifierList - .setIdentifierListFields(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST_FIELDS); - OaiPmhTestDH.identifierList - .setDateOfObjectCreation("administrativeMetadata.dcterms:modified"); - OaiPmhTestDH.identifierList - .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); - OaiPmhTestDH.identifierList.setIdentifierField("administrativeMetadata.dcterms:identifier"); - OaiPmhTestDH.identifierList.setSearchResponseSize("100"); - String r = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); - System.out.println(r); - System.out.println("-----------------------------------\n"); - } - -} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java deleted file mode 100644 index 02f272b4d78bb156a15ffc2f151528b56390ff66..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestUtilities.java +++ /dev/null @@ -1,169 +0,0 @@ -package info.textgrid.middleware; - -import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import javax.ws.rs.core.Response; -import org.apache.cxf.jaxrs.client.Client; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.http.HttpStatus; - -/** - * <p> - * Some online tests for the TextGrid OAIMPH service. - * </p> - * - * @author Stefan E. Funk, SUB Göttingen - */ -public class OaiPmhTestUtilities { - - // ** - // FINALS - // ** - - protected static final String OAI_DC_PREFIX = "oai_dc"; - protected static final String OAI_DATACITE_PREFIX = "oai_datacite"; - protected static final String OAI_IDIOMMETS_PREFIX = "oai_idiom_mets"; - - protected static final String EXPECTED_OAIDC_FORMAT_CONTENT = "<oai_dc:dc>"; - protected static final String EXPECTED_IDIOMMETS_FORMAT_CONTENT = "<mets "; - protected static final String EXPECTED_DATACITE_FORMAT_CONTENT = "<datacite:resource>"; - - protected static final String NO_SET = null; - protected static final String ERROR = " >>> ERROR"; - protected static final String OK = " >>> OKIDOKI"; - protected static final String TESTING = "\n >>> TESTING "; - protected static final String NO_THREAD_NAME = ""; - protected static final String NOT_TESTED = " >>> NOT_TESTED"; - protected static final String NO_TOKEN = "-1"; - - protected static final String VERB_LIST_IDENTIFIERS = "ListIdentifiers"; - protected static final String VERB_LIST_RECORDS = "ListRecords"; - protected static final String VERB_GET_RECORD = "GetRecord"; - protected static final String VERB_IDENTIFY = "Identify"; - protected static final String VERB_LIST_METADATA_FORMATS = "ListMetadataFormats"; - protected static final String VERB_LIST_SETS = "ListSets"; - protected static final boolean NO_METADATA_FORMAT_WITH_RESTOK = false; - protected static final boolean METADATA_FORMAT_WITH_RESTOK = true; - protected static final String NO_FROM = null; - protected static final String NO_UNTIL = null; - // Time to wait between the single queries using resumption tokens in milliseconds. - protected static final Long TIME = 275l; - - protected static final long OAIPMH_CLIENT_TIMEOUT = 120000; - - /** - * @param theClient - * @param thePath - * @return - * @throws IOException - */ - protected static Response getHttpResponse(Client theClient, String thePath) throws IOException { - return getHttpResponse(theClient, thePath, ""); - } - - /** - * @param theClient - * @param thePath - * @param theThreadName - * @return - * @throws IOException - */ - protected static Response getHttpResponse(Client theClient, String thePath, String theThreadName) - throws IOException { - - Response result; - - try { - Thread.sleep(TIME); - } catch (InterruptedException e) { - // Nothing interrupts here! - } - - WebClient w = WebClient.fromClient(theClient).replaceQuery(thePath); - - System.out.println("\t" + theThreadName + "HTTP GET " + w.getCurrentURI()); - - result = w.get(); - - // Check HTTP status. - int status = result.getStatus(); - - if (status != HttpStatus.SC_OK) { - System.err.println("\t" + theThreadName + "status: " + status); - System.err.println(ERROR); - assertTrue(false); - } else { - System.out.println("\t" + theThreadName + "status: " + status); - } - - return result; - } - - /** - * @param theMillis - * @return - */ - public static String getDurationInSecs(long theMillis) { - - int SECS_IN_MILLIS = 1000; - int secs = SECS_IN_MILLIS; - - return theMillis / secs + " second" + ((theMillis / secs) != 1 ? "s" : ""); - } - - /** - * <p> - * Loads a resource. - * </p> - * - * TODO Put together with the method in TGCrudServiceUtilities! Maybe create a first build maven - * module for utility things. - * - * @param {@link String} The resource to search for. - * @return {@link File} The resource. - * @throws IOException - */ - protected static File getResource(String resPart) throws IOException { - - File res; - - // If we have an absolute resPart, just return the file. - if (resPart.startsWith(File.separator)) { - return new File(resPart); - } - - URL url = ClassLoader.getSystemClassLoader().getResource(resPart); - if (url == null) { - throw new IOException("Resource '" + resPart + "' not found"); - } - try { - res = new File(url.toURI()); - } catch (URISyntaxException ue) { - res = new File(url.getPath()); - } - - return res; - } - - /** - * @param theProperty - * @return - */ - protected static List<String> getListFromProperties(String theProperty) { - - List<String> result = new ArrayList<String>(); - - String parts[] = theProperty.split(","); - for (String part : parts) { - result.add(part.trim()); - } - - return result; - } - -} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java deleted file mode 100644 index b15c4f2ada23c366a5eee71eb210c69071cc6d47..0000000000000000000000000000000000000000 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java +++ /dev/null @@ -1,1538 +0,0 @@ -package info.textgrid.middleware; - -import static org.junit.Assert.assertTrue; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import javax.ws.rs.core.Response; -import org.apache.cxf.helpers.IOUtils; -import org.apache.cxf.jaxrs.client.Client; -import org.apache.cxf.jaxrs.client.JAXRSClientFactory; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.transport.http.HTTPConduit; -import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; -import org.apache.http.HttpStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -/** - * <p> - * Some online tests for the TextGrid OAIMPH service. - * </p> - * - * @author Stefan E. Funk, SUB Göttingen - */ -// @Ignore -public class OaiPmhTextgridOnlineTests { - - // ** - // FINALS - // ** - - // private static final String PROPERTIES_FILE = "oaipmh.test.textgridlab-org.properties"; - // TODO There is NO IDIOM test data for testing on dev.textgridlab.org! So eventually all - // IDIOM tests will fail! - private static final String PROPERTIES_FILE = "oaipmh.test.dev-textgridlab-org.properties"; - - // ** - // STATICS - // ** - - // Some JAXRS things. - private static String oaipmhEndpoint; - private static OAIPMHProducer JAXRSClient; - static Client oaipmhWebClient; - - // Properties - private static String expectedListSets; - private static String checkGetRecordDC; - private static String expectedGetRecordDC; - private static String checkGetRecordIDIOM; - private static String checkGetRecordIDIOM_Images; - private static String expectedGetRecordIDIOM_Images; - private static String expectedGetRecordIDIOM; - private static String checkGetRecordDATACITE; - private static String expectedGetRecordDATACITE; - private static String checkListRecordsDC; - private static String checkListRecordsDCFrom; - private static String checkListRecordsDCUntil; - private static String checkListRecordsIDIOMFrom; - private static String checkListRecordsIDIOMUntil; - private static String checkListRecordsDATACITEFrom; - private static String checkListRecordsDATACITEUntil; - private static String checkListIdentifiersSet; - private static int checkListIdentifiersPagesToTestIDIOM; - private static int checkListIdentifiersRecordsPerPageIDIOM; - private static List<String> checkGetRecordIDList = new ArrayList<String>(); - - // ** - // PREPARATIONS - // ** - - /** - * @throws Exception - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - - // Load properties file. - Properties p = new Properties(); - p.load(new FileInputStream(OaiPmhTestUtilities.getResource(PROPERTIES_FILE))); - - System.out.println("Properties file: " + PROPERTIES_FILE); - p.list(System.out); - - // Get other needed properties. - oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); - expectedListSets = p.getProperty("expectedListSets"); - checkGetRecordDC = p.getProperty("checkGetRecordDC"); - expectedGetRecordDC = p.getProperty("expectedGetRecordDC"); - checkGetRecordIDIOM = p.getProperty("checkGetRecordIDIOM"); - checkGetRecordIDIOM_Images = p.getProperty("checkGetRecordIDIOM_Images"); - expectedGetRecordIDIOM_Images = p.getProperty("expectedGetRecordIDIOM_Images"); - expectedGetRecordIDIOM = p.getProperty("expectedGetRecordIDIOM"); - checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE"); - expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE"); - checkListRecordsDC = p.getProperty("checkListRecordsDC"); - checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom"); - checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil"); - checkListRecordsIDIOMFrom = p.getProperty("checkListRecordsIDIOMFrom"); - checkListRecordsIDIOMUntil = p.getProperty("checkListRecordsIDIOMUntil"); - checkListRecordsDATACITEFrom = p.getProperty("checkListRecordsDATACITEFrom"); - checkListRecordsDATACITEUntil = p.getProperty("checkListRecordsDATACITEUntil"); - checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet"); - checkListIdentifiersPagesToTestIDIOM = - Integer.parseInt(p.getProperty("checkListIdentifiersPagesToTestIDIOM")); - checkListIdentifiersRecordsPerPageIDIOM = - Integer.parseInt(p.getProperty("checkListIdentifiersRecordsPerPageIDIOM")); - checkGetRecordIDList = - OaiPmhTestUtilities.getListFromProperties((String) p.get("checkGetRecordIDList")); - - // Get OAI-PMH REST endpoint and HTTP client. - System.out.println("Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--"); - - // Get proxy first, set policy. - JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint, OAIPMHProducer.class); - HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit(); - HTTPClientPolicy policy = new HTTPClientPolicy(); - policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT); - conduit.setClient(policy); - - // Create Web Client from Web Proxy. - oaipmhWebClient = WebClient.client(JAXRSClient); - } - - /** - * @throws Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - // - } - - /** - * @throws Exception - */ - @Before - public void setUp() throws Exception { - // - } - - /** - * @throws Exception - */ - @After - public void tearDown() throws Exception { - // - } - - // ** - // TESTS - // ** - - /** - * @throws IOException - */ - @Test - public void testGetVersion() throws IOException { - - String shouldStartWith = "oaipmh-core"; - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetVersion()"); - - String versionString = JAXRSClient.getVersion(); - - if (!versionString.startsWith(shouldStartWith)) { - System.err.println( - OaiPmhTestUtilities.ERROR + ": response should start with '" + shouldStartWith + "'"); - assertTrue(false); - } - - System.out.println("\tresponse: " + versionString); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testRootUrl() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testRootUrl()"); - - // Still hard coded in OAIPMH service! - String shouldContain = "textgridrep.org"; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, "oai", - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { - System.err.println("\tstatus: " + status); - System.err - .println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContain + "'"); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testIdentify() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testIdentify()"); - - // Still hard coded in OAIPMH service! - String shouldContain = "textgridrep.org"; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - "verb=" + OaiPmhTestUtilities.VERB_IDENTIFY, OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { - System.err.println("\tstatus: " + status); - System.err - .println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContain + "'"); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListMetadataFormats() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListMetadataFormats()"); - - String shouldContainDC = OaiPmhTestUtilities.OAI_DC_PREFIX; - String shouldContainIDIOM = OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX; - String shouldContainDATACITE = OaiPmhTestUtilities.OAI_DATACITE_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - "verb=" + OaiPmhTestUtilities.VERB_LIST_METADATA_FORMATS, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK || !response.contains(shouldContainDC) - || !response.contains(shouldContainIDIOM) || !response.contains(shouldContainDATACITE)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContainDC - + "' and '" + shouldContainIDIOM + "' and '" + shouldContainDATACITE + "'"); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListSets() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListSets()"); - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - "verb=" + OaiPmhTestUtilities.VERB_LIST_SETS, OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK || !response.contains(expectedListSets)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedListSets + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordOAIDC() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordOAIDC()"); - - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordDC + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_DC_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordDC)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordDC + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordOAIDCNoPrefix() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordOAIDCNoPrefix()"); - - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordDC + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_DC_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordDC)) { - System.err.println("\tstatus: " + status); - System.err.println( - OaiPmhTestUtilities.ERROR + ": response should contain '" - + checkGetRecordDC + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordIDIOMMETS() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordIDIOMMETS()"); - - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordIDIOM + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordIDIOM)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordIDIOM + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordIDIOMMETS_Image() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordIDIOMMETS_Image()"); - - String path = - "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" + checkGetRecordIDIOM_Images - + "&metadataPrefix=" + OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordIDIOM_Images)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordIDIOM_Images + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordIDIOMMETSNoPrefix() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordIDIOMMETSNoPrefix()"); - - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordIDIOM + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordIDIOM)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordIDIOM + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordDATACITE() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordDATACITE()"); - - String path = "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordDATACITE + "&metadataPrefix=" - + OaiPmhTestUtilities.OAI_DATACITE_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordDATACITE)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordDATACITE + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testGetRecordDATACITENoPrefix() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testGetRecordDATACITENoPrefix()"); - - String path = - "verb=" + OaiPmhTestUtilities.VERB_GET_RECORD + "&identifier=" - + checkGetRecordDATACITE - + "&metadataPrefix=" + OaiPmhTestUtilities.OAI_DATACITE_PREFIX; - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path, - OaiPmhTestUtilities.NO_THREAD_NAME); - int status = httpResponse.getStatus(); - String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - if (status != HttpStatus.SC_OK - || !response.contains(expectedGetRecordDATACITE)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR + ": response should contain '" - + expectedGetRecordDATACITE + "'"); - System.err.println(response); - assertTrue(false); - } - - System.out.println("\tresponse: " + response); - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListRecordsOAIDCMorePages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsOAIDCMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, checkListRecordsDC, - OaiPmhTestUtilities.OAI_DC_PREFIX, 20, 100, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListRecordsOAIDCMorePagesFromUntil() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsOAIDCMorePagesFromUntil()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, checkListRecordsDC, - OaiPmhTestUtilities.OAI_DC_PREFIX, 0, 100, OaiPmhTestUtilities.NO_THREAD_NAME, - checkListRecordsDCFrom, checkListRecordsDCUntil, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test(expected = IOException.class) - public void testListRecordsIDIOMMETSSomePagesAndMetadataFormatWithRestok() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING - + "testListRecordsIDIOMMETSSomePagesAndMetadataFormatWithRestok()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 3, 30, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - // @Ignore - public void testListRecordsIDIOMMETSAllPages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsIDIOMMETSAllPages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 0, 30, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * NOTE The amount of records will change due to changes on the data! Please check from and until - * values before! - * - * @throws IOException - */ - @Test - @Ignore - public void testListRecordsIDIOMMETSMorePagesFromUntil() throws IOException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testListRecordsIDIOMMETSMorePagesFromUntil()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 6, 30, OaiPmhTestUtilities.NO_THREAD_NAME, - checkListRecordsIDIOMFrom, - checkListRecordsIDIOMUntil, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListRecordsIDIOMMETSMorePages() throws IOException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testListRecordsIDIOMMETSMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 6, 30, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListRecordsDATACITEMorePages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsDATACITEMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 15, 100, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - // @Ignore - public void testListRecordsDATACITEAllPages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsDATACITEAllPages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 0, 100, OaiPmhTestUtilities.NO_THREAD_NAME, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListRecordsDATACITEMorePagesFromUntil() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListRecordsDATACITEMorePagesFromUntil()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_RECORDS, OaiPmhTestUtilities.NO_SET, - OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 15, 100, OaiPmhTestUtilities.NO_THREAD_NAME, - checkListRecordsDATACITEFrom, - checkListRecordsDATACITEUntil, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListIdentifiersOAIDCMorePages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListIdentifiersOAIDCMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - checkListIdentifiersSet, OaiPmhTestUtilities.OAI_DC_PREFIX, 30, - 100, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test(expected = IOException.class) - public void testListIdentifiersOAIDCMorePagesAndMetadataFormatWithRestok() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING - + "testListIdentifiersOAIDCMorePagesAndMetadataFormatWithRestok()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - checkListIdentifiersSet, OaiPmhTestUtilities.OAI_DC_PREFIX, 30, - 100, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - @Ignore - public void testListIdentifiersIDIOMMETSAllPages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListIdentifiersIDIOMMETSAllPages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 0, 30, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListIdentifiersIDIOMMETSMorePages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListIdentifiersIDIOMMETSMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 6, 30, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test(expected = IOException.class) - public void testListIdentifiersIDIOMMETSSomePagesAndMetadataFormatWithRestok() - throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING - + "testListIdentifiersIDIOMMETSSomePagesAndMetadataFormatWithRestok()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 3, 30, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - */ - @Test - public void testListIdentifiersDATACITEMorePages() throws IOException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testListIdentifiersDATACITEMorePages()"); - - testList(oaipmhWebClient, OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 22, 100, - OaiPmhTestUtilities.NO_THREAD_NAME, OaiPmhTestUtilities.NO_FROM, - OaiPmhTestUtilities.NO_UNTIL, OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - - System.out.println(OaiPmhTestUtilities.OK); - } - - /** - * @throws IOException - * @throws ExecutionException - * @throws InterruptedException - */ - @Test - public void testListIdentifiersConcurrentlyIDIOMMETSMorePages() - throws IOException, InterruptedException, ExecutionException { - - System.out.println( - OaiPmhTestUtilities.TESTING + "testListIdentifiersConcurrentlyIDIOMMETSMorePages()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 3, 30, "C1")); - Future<Boolean> f2 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 5, 30, "C2")); - Future<Boolean> f3 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 8, 30, "C2")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [C1]=" + f1.get() + ", [C2]=" + f2.get() - + ", [C3]=" + f3.get()); - } - - /** - * @throws IOException - * @throws ExecutionException - * @throws InterruptedException - */ - @Test - public void testListRecordsConcurrentlyIDIOMMETSMorePages() - throws IOException, InterruptedException, ExecutionException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testListRecordsConcurrentlyIDIOMMETSMorePages()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 2, 30, "D1")); - Future<Boolean> f2 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 3, 30, "D2")); - Future<Boolean> f3 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 4, 30, "D3")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [D1]=" + f1.get() + ", [D2]=" + f2.get() - + ", [D3]=" + f3.get()); - } - - /** - * @throws IOException - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListIdentifiersDC() - throws InterruptedException, ExecutionException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListIdentifiersDC()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 36, 100, "A1")); - Future<Boolean> f2 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 27, 100, "A2")); - Future<Boolean> f3 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 19, 100, "A3")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() - + ", [A3]=" + f3.get()); - } - - /** - * @throws IOException - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListIdentifiersIDIOMMETS() - throws InterruptedException, ExecutionException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListIdentifiersIDIOM()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 13, 30, "A1")); - Future<Boolean> f2 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 35, 30, "A2")); - Future<Boolean> f3 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, 11, 30, "A3")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() - + ", [A3]=" + f3.get()); - } - - /** - * @throws IOException - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListIdentifiersDATACITE() - throws InterruptedException, ExecutionException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListIdentifiersDATACITE()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 13, 100, "A1")); - Future<Boolean> f2 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 20, 100, "A2")); - Future<Boolean> f3 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DATACITE_PREFIX, 8, 100, "A3")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() - + ", [A3]=" + f3.get()); - } - - /** - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListIdentifiersDCAndIDIOMMETS() - throws InterruptedException, ExecutionException { - - System.out.println( - OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListIdentifiersDCAndIDIOMMets()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 53, 100, "DC1")); - Future<Boolean> f2 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 28, 100, "DC2")); - Future<Boolean> f3 = executor - .submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_IDENTIFIERS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, - checkListIdentifiersPagesToTestIDIOM, - checkListIdentifiersRecordsPerPageIDIOM, - "IDIOM")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() - + ", [IDIOM]=" + f3.get()); - } - - /** - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListRecordsDC() - throws InterruptedException, ExecutionException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListRecordsDC()"); - - ExecutorService executor = Executors.newFixedThreadPool(4); - - Future<Boolean> f1 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 44, 100, "DC1")); - Future<Boolean> f2 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 33, 100, "DC2")); - Future<Boolean> f3 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 66, 100, "DC3")); - Future<Boolean> f4 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 28, 100, "DC4")); - - executor.shutdown(); - - System.out.println( - OaiPmhTestUtilities.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() + ", [DC3]=" - + f3.get() + ", [DC4]=" + f4.get()); - } - - /** - * @throws IOException - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testRestokConcurrentlyListRecords() throws InterruptedException, ExecutionException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testRestokConcurrentlyListRecords()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 6, 100, "B1")); - Future<Boolean> f2 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 7, 100, "B2")); - Future<Boolean> f3 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 8, 100, "B3")); - Future<Boolean> f4 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 9, 100, "B4")); - - executor.shutdown(); - - System.out.println( - OaiPmhTestUtilities.OK + ": [B1]=" + f1.get() + ", [B2]=" + f2.get() + ", [B3]=" + f3.get() - + ", [B4]=" + f4.get()); - } - - /** - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testListRecordsRestokConcurrentlyDCAndIDIOMMETS() - throws InterruptedException, ExecutionException { - - System.out - .println(OaiPmhTestUtilities.TESTING + "testListRecordsRestokConcurrentlyDCAndIDIOMMets()"); - - ExecutorService executor = Executors.newFixedThreadPool(3); - - Future<Boolean> f1 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 34, 100, "DC1")); - Future<Boolean> f2 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_DC_PREFIX, 27, 100, "DC2")); - Future<Boolean> f3 = - executor.submit(new OaiPmhResumptionTokenTestThread(OaiPmhTestUtilities.VERB_LIST_RECORDS, - OaiPmhTestUtilities.NO_SET, OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX, - checkListIdentifiersPagesToTestIDIOM, - checkListIdentifiersRecordsPerPageIDIOM, - "IDIOM")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() - + ", [IOIOM]=" + f3.get()); - } - - /** - * @throws IOException - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testConcurrentlyOAIDCGetRecord() throws InterruptedException, ExecutionException { - - System.out.println(OaiPmhTestUtilities.TESTING + "testConcurrentlyOAIDCGetRecord()"); - - ExecutorService executor = Executors.newFixedThreadPool(18); - - Future<Boolean> f1 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(0), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f2 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(1), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f3 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(2), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f4 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(3), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f5 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(4), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f6 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(5), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f7 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(6), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f8 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(7), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f9 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(8), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f10 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(9), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f11 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(10), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f12 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(11), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f13 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(12), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f14 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(13), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f15 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(14), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f16 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(15), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f17 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(16), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - Future<Boolean> f18 = executor - .submit(new OaiPmhGetRecordTestThread(OaiPmhTestUtilities.VERB_GET_RECORD, - checkGetRecordIDList.get(17), - OaiPmhTestUtilities.OAI_DC_PREFIX, - "GR[" + checkGetRecordIDList.get(0) + "]")); - - executor.shutdown(); - - System.out.println(OaiPmhTestUtilities.OK + "[GR1]=" + f1.get() + ", [GR2]=" + f2.get() - + ", [GR3]=" + f3.get() + ", [GR4]=" + f4.get() + ", [GR5]=" + f5.get() + ", [GR6]=" - + f6.get() + ", [GR7]=" + f7.get() + ", [GR8]=" + f8.get() + ", [GR9]=" + f9.get() - + ", [GR10]=" + f10.get() + ", [GR11]=" + f11.get() + ", [GR12]=" + f12.get() - + ", [GR13]=" + f13.get() + ", [GR14]=" + f14.get() + ", [GR15]=" + f15.get() - + ", [GR16]=" + f16.get() + ", [GR17]=" + f17.get() + ", [GR18]=" + f18.get()); - } - - /** - * <p> - * Starts a new OAI-PMH thread. - * </p> - */ - - private class OaiPmhResumptionTokenTestThread implements Callable<Boolean> { - - protected String verb; - protected String set; - protected String metadataPrefix; - protected int numberOfPagesToTest; - protected int recordsExpectedPerRequest; - protected String threadName; - - /** - * @param theVerb - * @param theSet - * @param theMetadataPrefix - * @param numberOfPagesToTest - * @param recordsExpectedPerRequest - */ - public OaiPmhResumptionTokenTestThread(String theVerb, String theSet, String theMetadataPrefix, - int numberOfPagesToTest, int recordsExpectedPerRequest, String theThreadName) { - this.verb = theVerb; - this.set = theSet; - this.metadataPrefix = theMetadataPrefix; - this.numberOfPagesToTest = numberOfPagesToTest; - this.recordsExpectedPerRequest = recordsExpectedPerRequest; - this.threadName = theThreadName; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Thread#run() - */ - @Override - public Boolean call() throws IOException { - testList(oaipmhWebClient, this.verb, this.set, this.metadataPrefix, - this.numberOfPagesToTest, this.recordsExpectedPerRequest, this.threadName, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL, - OaiPmhTestUtilities.NO_METADATA_FORMAT_WITH_RESTOK); - return true; - } - } - - /** - * <p> - * Starts a new OAI-PMH thread. - * </p> - */ - - private class OaiPmhGetRecordTestThread implements Callable<Boolean> { - - protected String verb; - protected String identifier; - protected String metadataPrefix; - protected String threadName; - - /** - * @param theVerb - * @param theIdentifier - * @param theMetadataPrefix - * @param theThreadName - */ - public OaiPmhGetRecordTestThread(String theVerb, String theIdentifier, String theMetadataPrefix, - String theThreadName) { - this.verb = theVerb; - this.identifier = theIdentifier; - this.metadataPrefix = theMetadataPrefix; - this.threadName = theThreadName; - } - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.Callable#call() - */ - @Override - public Boolean call() throws IOException { - - String url = "verb=" + this.verb + "&identifier=" + this.identifier + "&metadataPrefix=" - + this.metadataPrefix; - OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, url, this.threadName); - - return true; - } - } - - // ** - // PRIVATE METHODS - // ** - - /** - * TODO Generalise in OaiPmhTestUtilities! - * - * @param theClient - * @param theVerb - * @param theSet - * @param theMetadataPrefix - * @param maxNumberOfPagesToTest - * @param recordsExpectedPerRequest - * @param theThreadName - * @param from - * @param until - * @param resumptionTokenANDMetadataPrefix - * @throws IOException - */ - protected static void testList(Client theClient, final String theVerb, final String theSet, - final String theMetadataPrefix, final int maxNumberOfPagesToTest, - final int recordsExpectedPerRequest, final String theThreadName, final String from, - final String until, final boolean resumptionTokenANDMetadataPrefix) throws IOException { - - String threadName = tn(theThreadName); - - long startTime = System.currentTimeMillis(); - - String testOccurance = "header"; - if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) { - testOccurance = "record"; - } - - String path = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; - - if (theSet != null) { - path += "&set=" + theSet; - } - - if (from != null && until != null) { - path += "&from=" + from + "&until=" + until; - } - - Response httpResponse = OaiPmhTestUtilities.getHttpResponse(theClient, path, threadName); - int status = httpResponse.getStatus(); - - int loopCount = 1; - long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\t" + threadName + "time: " - + OaiPmhTestUtilities.getDurationInSecs(timeRunning) + " (loop " + loopCount - + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + ")"); - - String responseString = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - - // Test resumption token tags. - String restok = examineResumptionTokenTag(responseString, testOccurance, - OaiPmhTestUtilities.NO_TOKEN, recordsExpectedPerRequest, loopCount, threadName); - - // Test general metadata content (if verb is listRecords!), must go conform with the metadata - // prefix setting. - if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) { - examineContent(responseString, theMetadataPrefix); - } - - while (status == HttpStatus.SC_OK && !restok.equals(OaiPmhTestUtilities.NO_TOKEN)) { - loopCount += 1; - synchronized (threadName) { - if (maxNumberOfPagesToTest > 0 && loopCount > maxNumberOfPagesToTest) { - System.out - .println("\t" + threadName + "TESTING ONLY " + maxNumberOfPagesToTest + " pages!"); - break; - } - path = "verb=" + theVerb + "&resumptionToken=" + restok; - if (resumptionTokenANDMetadataPrefix) { - path += "&metadataPrefix=" + theMetadataPrefix; - } - httpResponse = OaiPmhTestUtilities.getHttpResponse(theClient, path, threadName); - timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\t" + threadName + "time: " - + OaiPmhTestUtilities.getDurationInSecs(timeRunning) + " (loop " + loopCount - + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + ")"); - - // Test resumption token tags. - responseString = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); - restok = examineResumptionTokenTag(responseString, testOccurance, restok, - recordsExpectedPerRequest, loopCount, threadName); - - // Test general metadata content (if verb is listRecords!), must go conform with the - // metadata // prefix setting. - if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) { - examineContent(responseString, theMetadataPrefix); - } - } - } - - // Only check for max loops, if we do have less loops and no resumption token, it will be fine, - // too! - if (!restok.equals(OaiPmhTestUtilities.NO_TOKEN) && loopCount < maxNumberOfPagesToTest) { - System.out.println(threadName + OaiPmhTestUtilities.ERROR + ": Must have done " - + maxNumberOfPagesToTest + " loops, but did only " + loopCount); - assertTrue(false); - } - - // Check for single loop, we need MORE! - if (loopCount == 1) { - System.out - .println(threadName + OaiPmhTestUtilities.ERROR + ": Must have more than one loop!"); - assertTrue(false); - } - - System.out.println("\t" + threadName + OaiPmhTestUtilities.OK); - } - - /** - * TODO Generalise in OaiPmhTestUtilities! - * - * @param theResponse - * @param recordOrHeader - * @param oldtok - * @param recordsExpectedPerRequest - * @param loopCount - * @param theThreadName - * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is - * existing, tag is existing and has no token value. - * @throws IOException - */ - public static String examineResumptionTokenTag(final String theResponseString, - final String recordOrHeader, final String oldtok, final int recordsExpectedPerRequest, - final int loopCount, final String theThreadName) throws IOException { - - // Test for OAIPMH errors. - if (theResponseString.contains("<error code=\"badArgument\">")) { - String message = - theThreadName + OaiPmhTestUtilities.ERROR + " IN OAIPMH RESPONSE: " + theResponseString; - System.out.println(message); - throw new IOException(message); - } - - // Count response objects at first. - int recordCount = 0; - int i = theResponseString.indexOf("<" + recordOrHeader + ">", 0); - while (i != -1) { - recordCount++; - i++; - i = theResponseString.indexOf("<" + recordOrHeader + ">", i); - } - - System.out.println("\t" + theThreadName + recordOrHeader + "s: " + recordCount); - - // Check if token tag is existing. - int tokStart = theResponseString.indexOf("<resumptionToken"); - int tokEnd = theResponseString.indexOf("</resumptionToken"); - - if (tokStart == -1 && tokEnd == -1) { - System.out.println("\t" + theThreadName + "token: no token"); - - return OaiPmhTestUtilities.NO_TOKEN; - } - - String restokTmp = theResponseString.substring(tokStart, tokEnd); - // Get token tag. - String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1).trim(); - System.out.println("\t" + theThreadName + "tokentag: " + toktag); - - // Get token. - String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim(); - System.out.println("\t" + theThreadName + "token: " + restok); - - // Check if old and new token are equal or not. - boolean tokchanged = !oldtok.equals(restok); - System.out.println("\t" + theThreadName + "tokchngd: " + tokchanged); - - // Get completeListSize and cursor. - String sizeStr = toktag.substring(toktag.indexOf("completeListSize=\"") + 18); - int size = Integer.parseInt(sizeStr.substring(0, sizeStr.indexOf("\""))); - String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8); - int cursor = Integer.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); - System.out.println("\t" + theThreadName + "size: " + size + " / " + cursor); - - // If token is provided, test cursor and element count! - if (!restok.isEmpty()) { - synchronized (OaiPmhTextgridOnlineTests.class) { - // Check <record> or <header> count, must be recordsExpectedPerRequest! - if (recordCount != recordsExpectedPerRequest) { - String message = - OaiPmhTestUtilities.ERROR + ": " + recordOrHeader + " count mismatch, must be " - + recordsExpectedPerRequest + " if token is provided, but is " + recordCount; - assertTrue(message, false); - } - if (size <= recordsExpectedPerRequest) { - String message = - OaiPmhTestUtilities.ERROR + ": completeListSize count mismatch, must be > " - + recordsExpectedPerRequest + " if token is provided, but is " + size; - assertTrue(message, false); - } - if (cursor != recordsExpectedPerRequest * loopCount) { - String message = OaiPmhTestUtilities.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 % recordsExpectedPerRequest. - if (recordCount != size % recordsExpectedPerRequest) { - System.err.println(theThreadName + OaiPmhTestUtilities.ERROR + ": " + recordOrHeader - + " count mismatch, should be " + size % recordsExpectedPerRequest + ", but is " - + recordCount); - assertTrue(false); - } - - // No resumption token available in response. - return OaiPmhTestUtilities.NO_TOKEN; - } - - return restok; - } - - /** - * @param theThreadName - * @return - */ - private static String tn(String theThreadName) { - - String result = theThreadName; - - if (theThreadName != null && !theThreadName.equals("") && !theThreadName.endsWith(" ")) { - result = "[" + theThreadName + "] "; - } - - return result; - } - - /** - * @param theResponseString - * @param theMetadataFormat - */ - private static void examineContent(String theResponseString, String theMetadataFormat) { - - // Check for correct metadata content according to metadata prefix. - if (theMetadataFormat.equals(OaiPmhTestUtilities.OAI_DC_PREFIX) - && !theResponseString - .contains("metadataPrefix=\"" + OaiPmhTestUtilities.OAI_DC_PREFIX + "\"") - && !theResponseString.contains(OaiPmhTestUtilities.EXPECTED_OAIDC_FORMAT_CONTENT)) { - System.out - .println(OaiPmhTestUtilities.OAI_DC_PREFIX + " needs to deliver content with schema: " - + OaiPmhTestUtilities.EXPECTED_OAIDC_FORMAT_CONTENT + "!"); - - System.out.println("ERROR:\n" + theResponseString); - - assertTrue(false); - } else if (theMetadataFormat.equals(OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX) - && !theResponseString.contains( - "metadataPrefix=\"" + OaiPmhTestUtilities.EXPECTED_IDIOMMETS_FORMAT_CONTENT + "\"") - && !theResponseString.contains(OaiPmhTestUtilities.EXPECTED_IDIOMMETS_FORMAT_CONTENT)) { - System.out.println( - OaiPmhTestUtilities.OAI_IDIOMMETS_PREFIX + " needs to deliver content with schema: " - + OaiPmhTestUtilities.EXPECTED_IDIOMMETS_FORMAT_CONTENT + "!"); - - System.out.println("ERROR:\n" + theResponseString); - - assertTrue(false); - } else if (theMetadataFormat.equals(OaiPmhTestUtilities.OAI_DATACITE_PREFIX) - && !theResponseString - .contains("metadataPrefix=\"" + OaiPmhTestUtilities.OAI_DATACITE_PREFIX + "\"") - && !theResponseString.contains(OaiPmhTestUtilities.EXPECTED_DATACITE_FORMAT_CONTENT)) { - System.out.println( - OaiPmhTestUtilities.OAI_DATACITE_PREFIX + " needs to deliver content with schema: " - + OaiPmhTestUtilities.EXPECTED_DATACITE_FORMAT_CONTENT + "!"); - - System.out.println("ERROR:\n" + theResponseString); - - assertTrue(false); - } else { - System.out.println(theResponseString); - } - } - -} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestDHOAIPMHLocally.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestDHOAIPMHLocally.java new file mode 100644 index 0000000000000000000000000000000000000000..b613e8c5ec35ba6872408d9f284947a5829ebd31 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestDHOAIPMHLocally.java @@ -0,0 +1,227 @@ +package info.textgrid.middleware.test; + +import java.text.ParseException; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.oaipmh.DeletedRecordType; +import info.textgrid.middleware.oaipmh.GranularityType; +import info.textgrid.middleware.IDIOMImages; +import info.textgrid.middleware.IdentifierListDelivererDATACITE; +import info.textgrid.middleware.IdentifierListDelivererDC; +import info.textgrid.middleware.IdentifierListDelivererIDIOM; +import info.textgrid.middleware.MetadataFormatListDelivererDH; +import info.textgrid.middleware.MetadataFormatListDelivererInterface; +import info.textgrid.middleware.OAIPMHConstants; +import info.textgrid.middleware.OAIPMHElasticSearchClient; +import info.textgrid.middleware.OAIPMHImpl; +import info.textgrid.middleware.OAIPMHUtilities; +import info.textgrid.middleware.RecordDelivererDATACITE; +import info.textgrid.middleware.RecordDelivererDC; +import info.textgrid.middleware.RecordDelivererIDIOM; +import info.textgrid.middleware.RecordListDelivererDATACITE; +import info.textgrid.middleware.RecordListDelivererDC; +import info.textgrid.middleware.RecordListDelivererIDIOM; +import info.textgrid.middleware.RepIdentification; +import info.textgrid.middleware.SetListDeliverer; +import info.textgrid.middleware.common.TextGridMimetypes; + +/** + * FIXME: Add documentation how to use this class, use SSH tunnel? + */ +@Ignore +public class TestDHOAIPMHLocally { + + public static OAIPMHElasticSearchClient oaiEsClient; + + private static RecordDelivererDC record; + private static RecordListDelivererDC recordList; + private static IdentifierListDelivererDC identifierList; + private static MetadataFormatListDelivererInterface metadataFormatList = + new MetadataFormatListDelivererDH(); + private static SetListDeliverer setListDARIAH = new SetListDeliverer(false, true); + + // private static OpenAireRecord openAireRecord; + private static RecordDelivererDATACITE recordDATACITE; + // private static OpenAireRecordList openAireRecordList; + private static RecordListDelivererDATACITE recordListDATACITE; + // private static OpenAireIdentifierList openAireIdentifierList; + private static IdentifierListDelivererDATACITE identifierListDATACITE; + private static IDIOMImages idiomImages; + private DeletedRecordType deletedRecordType = DeletedRecordType.NO; + private GranularityType granularityType = GranularityType.YYYY_MM_DD_THH_MM_SS_Z; + private RepIdentification rep = new RepIdentification("DARIAH-DE Repository", + "https://trep.de.dariah.eu", this.deletedRecordType, "2011-06-11T02:32:40Z", + this.granularityType, "2.0", "funk@sub.uni-goettingen.de"); + + /** + * FIXME: it should not be necessary to put idiom record variables for a DARIAH test case + */ + private static RecordDelivererIDIOM recordIDIOM; + private static RecordListDelivererIDIOM recordListIDIOM; + private static IdentifierListDelivererIDIOM identifierListIDIOM = + new IdentifierListDelivererIDIOM(true, false); + + private OAIPMHImpl request = + new OAIPMHImpl(this.rep, + TestDHOAIPMHLocally.record, + TestDHOAIPMHLocally.recordIDIOM, + TestDHOAIPMHLocally.recordDATACITE, + TestDHOAIPMHLocally.recordList, + TestDHOAIPMHLocally.recordListIDIOM, + TestDHOAIPMHLocally.recordListDATACITE, + TestDHOAIPMHLocally.metadataFormatList, + TestDHOAIPMHLocally.setListDARIAH, + TestDHOAIPMHLocally.identifierList, + TestDHOAIPMHLocally.identifierListIDIOM, + // OaiPmhTestDH.openAireIdentifierList); + TestDHOAIPMHLocally.identifierListDATACITE, + TestDHOAIPMHLocally.idiomImages); + + OAIPMHUtilities settings = new OAIPMHUtilities(); + + /** + * @throws Exception + */ + @BeforeClass + public static void setUp() throws Exception { + int[] ports = new int[] {9202}; + oaiEsClient = new OAIPMHElasticSearchClient("localhost", ports, 100); + oaiEsClient.setEsIndex("dariah-public"); + oaiEsClient.setEsType("metadata"); + + record = new RecordDelivererDC(false, true); + record.setOaiEsClient(oaiEsClient); + record.setWorkFields(OAIPMHConstants.TEST_DARIAH_FIELDS); + } + + /** + * @throws ParseException + */ + @Test + public void testGetRequestIdentify() throws ParseException { + System.out.println("Test for the verb \"Identify\" with succesfull response"); + String r = this.request.getRequest("Identify", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testGetRequestGetRecordDariah() throws ParseException { + + TestDHOAIPMHLocally.record.setContributor(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); + TestDHOAIPMHLocally.record.setCoverage(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); + TestDHOAIPMHLocally.record.setCreator(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); + TestDHOAIPMHLocally.record.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); + TestDHOAIPMHLocally.record.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); + TestDHOAIPMHLocally.record.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); + TestDHOAIPMHLocally.record.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); + TestDHOAIPMHLocally.record.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); + TestDHOAIPMHLocally.record.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); + TestDHOAIPMHLocally.record.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); + TestDHOAIPMHLocally.record.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); + TestDHOAIPMHLocally.record.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); + TestDHOAIPMHLocally.record.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); + TestDHOAIPMHLocally.record.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); + TestDHOAIPMHLocally.record.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); + TestDHOAIPMHLocally.record.setFields(OAIPMHConstants.TEST_DARIAH_FIELDS); + TestDHOAIPMHLocally.record.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + TestDHOAIPMHLocally.record.setFormatToFilter("metadata"); + TestDHOAIPMHLocally.record + .setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + TestDHOAIPMHLocally.record + .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + TestDHOAIPMHLocally.record.setIdentifierField("administrativeMetadata.dcterms:identifier"); + + System.out.println("Test for the verb \"GetRecord\" for DARIAH with succesfull response"); + String p = this.request.getRequest("GetRecord", "hdl:21.T11991/0000-0005-E1AA-D", "oai_dc", "", + "", "", ""); + System.out.println(p); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListRecordsDariah() throws ParseException { + + TestDHOAIPMHLocally.recordList.setContributors(OAIPMHConstants.TEST_DARIAH_CONTRIBUTOR_LIST); + TestDHOAIPMHLocally.recordList.setCoverages(OAIPMHConstants.TEST_DARIAH_COVERAGE_LIST); + TestDHOAIPMHLocally.recordList.setCreators(OAIPMHConstants.TEST_DARIAH_CREATOR_LIST); + TestDHOAIPMHLocally.recordList.setDates(OAIPMHConstants.TEST_DARIAH_DATE_LIST); + TestDHOAIPMHLocally.recordList.setDescriptions(OAIPMHConstants.TEST_DARIAH_DESCRIPTION_LIST); + TestDHOAIPMHLocally.recordList.setFormats(OAIPMHConstants.TEST_DARIAH_FORMAT_LIST); + TestDHOAIPMHLocally.recordList.setIdentifiers(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST); + TestDHOAIPMHLocally.recordList.setLanguages(OAIPMHConstants.TEST_DARIAH_LANGUAGE_LIST); + TestDHOAIPMHLocally.recordList.setPublishers(OAIPMHConstants.TEST_DARIAH_PUBLISHER_LIST); + TestDHOAIPMHLocally.recordList.setRelations(OAIPMHConstants.TEST_DARIAH_RELATIONS_LIST); + TestDHOAIPMHLocally.recordList.setRights(OAIPMHConstants.TEST_DARIAH_RIGHTS_LIST); + TestDHOAIPMHLocally.recordList.setSources(OAIPMHConstants.TEST_DARIAH_SOURCE_LIST); + TestDHOAIPMHLocally.recordList.setSubjects(OAIPMHConstants.TEST_DARIAH_SUBJECT_LIST); + TestDHOAIPMHLocally.recordList.setTitles(OAIPMHConstants.TEST_DARIAH_TITLE_LIST); + TestDHOAIPMHLocally.recordList.setTypes(OAIPMHConstants.TEST_DARIAH_TYPE_LIST); + TestDHOAIPMHLocally.recordList.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + TestDHOAIPMHLocally.recordList.setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_CREATED); + TestDHOAIPMHLocally.recordList.setRangeField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + TestDHOAIPMHLocally.recordList + .setDateOfObjectCreation(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); + TestDHOAIPMHLocally.recordList.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); + TestDHOAIPMHLocally.recordList.setFormatToFilter(TextGridMimetypes.DARIAH_COLLECTION); + TestDHOAIPMHLocally.recordList.setModifiedField(OAIPMHConstants.TEST_DARIAH_MODIFIED_FIELD); + TestDHOAIPMHLocally.recordList + .setRelationToFurtherMetadataObject("descriptiveMetadata.dc:relation"); + TestDHOAIPMHLocally.recordList.setSearchResponseSize(100); + + String r = this.request.getRequest("ListRecords", "", "oai_dc", "21.T11991/0000-0003-718E-E", + "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListSetsDARIAH() throws ParseException { + + TestDHOAIPMHLocally.setListDARIAH.setFormatField(OAIPMHConstants.TEST_DARIAH_FORMAT); + TestDHOAIPMHLocally.setListDARIAH + .setFormatToFilter(OAIPMHConstants.TEST_DARIAH_COLLECTION_MIMETYPE); + TestDHOAIPMHLocally.setListDARIAH.setIdentifierField(OAIPMHConstants.TEST_DARIAH_IDENTIFIER); + TestDHOAIPMHLocally.setListDARIAH + .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + TestDHOAIPMHLocally.setListDARIAH + .setIdentifierField("administrativeMetadata.dcterms:identifier"); + TestDHOAIPMHLocally.setListDARIAH + .setSpecFieldPrefix(OAIPMHConstants.TEST_DARIAH_COLLECTIONREGISTRY_PREFIX); + String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + + /** + * @throws ParseException + */ + @Test + public void testListIdentifiersDARIAH() throws ParseException { + + TestDHOAIPMHLocally.identifierList.setFieldForRange(OAIPMHConstants.TEST_DARIAH_RANGE_FIELD); + TestDHOAIPMHLocally.identifierList + .setIdentifierListFields(OAIPMHConstants.TEST_DARIAH_IDENTIFIER_LIST_FIELDS); + TestDHOAIPMHLocally.identifierList + .setDateOfObjectCreation("administrativeMetadata.dcterms:modified"); + TestDHOAIPMHLocally.identifierList + .setRepositoryObjectURIPrefix(OAIPMHConstants.TEST_DARIAH_ITEM_IDENTIFIER_PREFIX); + TestDHOAIPMHLocally.identifierList + .setIdentifierField("administrativeMetadata.dcterms:identifier"); + TestDHOAIPMHLocally.identifierList.setSearchResponseSize("100"); + String r = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); + System.out.println(r); + System.out.println("-----------------------------------\n"); + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestOAIPMHUtilities.java similarity index 97% rename from oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java rename to oaipmh-core/src/test/java/info/textgrid/middleware/test/TestOAIPMHUtilities.java index ef6827e8eda78b7b376545601b9add74dc99499a..f43f39f4961ae6adf76e03c8562324be962e615d 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/TestOAIPMHUtilities.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestOAIPMHUtilities.java @@ -1,7 +1,8 @@ -package info.textgrid.middleware; +package info.textgrid.middleware.test; import static org.junit.Assert.assertTrue; import org.junit.Test; +import info.textgrid.middleware.OAIPMHUtilities; /** * diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestTGOAIPMHLocally.java similarity index 71% rename from oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java rename to oaipmh-core/src/test/java/info/textgrid/middleware/test/TestTGOAIPMHLocally.java index 0a410c38a720a416021e07c4b76b0e3fe9f37122..0b2e8ac862d8456702c0f74e99fe3ca77cfd48f4 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTestTG.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/TestTGOAIPMHLocally.java @@ -1,4 +1,4 @@ -package info.textgrid.middleware; +package info.textgrid.middleware.test; import java.io.IOException; import java.text.ParseException; @@ -12,6 +12,26 @@ import org.json.JSONObject; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import info.textgrid.middleware.DublinCoreBuilder; +import info.textgrid.middleware.IDIOMImages; +import info.textgrid.middleware.IdentifierListDelivererDATACITE; +import info.textgrid.middleware.IdentifierListDelivererDC; +import info.textgrid.middleware.IdentifierListDelivererIDIOM; +import info.textgrid.middleware.MetadataFormatListDelivererInterface; +import info.textgrid.middleware.MetadataFormatListDelivererTG; +import info.textgrid.middleware.OAIPMHConstants; +import info.textgrid.middleware.OAIPMHElasticSearchClient; +import info.textgrid.middleware.OAIPMHImpl; +import info.textgrid.middleware.OAIPMHUtilities; +import info.textgrid.middleware.RecordDelivererDATACITE; +import info.textgrid.middleware.RecordDelivererDC; +import info.textgrid.middleware.RecordDelivererIDIOM; +import info.textgrid.middleware.RecordListDelivererDATACITE; +import info.textgrid.middleware.RecordListDelivererDC; +import info.textgrid.middleware.RecordListDelivererIDIOM; +import info.textgrid.middleware.RepIdentification; +import info.textgrid.middleware.SetListDeliverer; +import info.textgrid.middleware.TGConstants; import info.textgrid.middleware.common.TextGridMimetypes; import info.textgrid.middleware.oaipmh.DeletedRecordType; import info.textgrid.middleware.oaipmh.GranularityType; @@ -22,13 +42,15 @@ import info.textgrid.middleware.oaipmh.GranularityType; * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen */ -public class OaiPmhTestTG { +@Ignore +public class TestTGOAIPMHLocally { // ** // STATICS // ** - public static OAI_ESClient oaiEsClient; + public static OAIPMHElasticSearchClient oaiEsClient; + private static RecordDelivererDC record; private static RecordDelivererIDIOM recordIDIOM; private static RecordDelivererDATACITE recordDATACITE; @@ -55,18 +77,18 @@ public class OaiPmhTestTG { private MetadataFormatListDelivererInterface metadataFormatList = new MetadataFormatListDelivererTG(); private OAIPMHImpl request = new OAIPMHImpl(this.rep, - OaiPmhTestTG.record, - OaiPmhTestTG.recordIDIOM, - OaiPmhTestTG.recordDATACITE, - OaiPmhTestTG.recordList, - OaiPmhTestTG.recordListIDIOM, - OaiPmhTestTG.recordListDATACITE, + TestTGOAIPMHLocally.record, + TestTGOAIPMHLocally.recordIDIOM, + TestTGOAIPMHLocally.recordDATACITE, + TestTGOAIPMHLocally.recordList, + TestTGOAIPMHLocally.recordListIDIOM, + TestTGOAIPMHLocally.recordListDATACITE, this.metadataFormatList, - OaiPmhTestTG.setListTextGrid, - OaiPmhTestTG.identifierList, - OaiPmhTestTG.identifierListIDIOM, - OaiPmhTestTG.identifierListDATACITE, - OaiPmhTestTG.idiomImages); + TestTGOAIPMHLocally.setListTextGrid, + TestTGOAIPMHLocally.identifierList, + TestTGOAIPMHLocally.identifierListIDIOM, + TestTGOAIPMHLocally.identifierListDATACITE, + TestTGOAIPMHLocally.idiomImages); OAIPMHUtilities settings = new OAIPMHUtilities(); @@ -77,7 +99,7 @@ public class OaiPmhTestTG { public static void setUp() throws Exception { int[] ports = new int[] {9202}; - oaiEsClient = new OAI_ESClient("localhost", ports, 100); + oaiEsClient = new OAIPMHElasticSearchClient("localhost", ports, 100); oaiEsClient.setEsIndex("textgrid-public"); oaiEsClient.setEsType("metadata"); @@ -88,14 +110,13 @@ public class OaiPmhTestTG { recordIDIOM = new RecordDelivererIDIOM(true, false); recordIDIOM.setOaiEsClient(oaiEsClient); - /* - * openAireRecord = new OpenAireRecord(true, false); openAireRecord.setOaiEsClient(oaiEsClient); - * - * openAireRecordList = new OpenAireRecordList(true, false); - * - * openAireIdentifierList = new OpenAireIdentifierList(true, false); - */ + recordDATACITE = new RecordDelivererDATACITE(true, false); + recordDATACITE.setOaiEsClient(oaiEsClient); + recordListDATACITE = new RecordListDelivererDATACITE(true, false); + recordListDATACITE.setOaiEsClient(oaiEsClient); + + identifierListIDIOM = new IdentifierListDelivererIDIOM(true, false); recordList = new RecordListDelivererDC(true, false); recordList.setFields(TGConstants.TGFields); recordList.setWorkFields(TGConstants.TGWorkFields); @@ -340,7 +361,7 @@ public class OaiPmhTestTG { public void testGetRequestListRecordsIDIOMImagesWithResToken() throws ParseException { System.out.println("Test for the verb \"ListRecords\" with successful response for IMAGES"); - IDIOMImages.cursorCollector.put("2930c87d-5209-4b14-9d6a-72f10476d947", 129); + IDIOMImages.getCursorCollector().put("2930c87d-5209-4b14-9d6a-72f10476d947", 129); String p = this.request.getRequest("ListRecords", "", "", "", "", "", "2930c87d-5209-4b14-9d6a-72f10476d947"); System.out.println(p); @@ -355,7 +376,7 @@ public class OaiPmhTestTG { public void testGetRequestListIdentifiersIDIOMImageswithResToken() throws ParseException { System.out.println("Test for the verb \"ListIdentifiers\" with successful response"); - IDIOMImages.cursorCollector.put("8eea2c07-7dc9-4404-a106-c1412b9ce8b4", 129); + IDIOMImages.getCursorCollector().put("8eea2c07-7dc9-4404-a106-c1412b9ce8b4", 129); String p = this.request.getRequest("ListIdentifiers", "", "", "", "", "", "8eea2c07-7dc9-4404-a106-c1412b9ce8b4"); System.out.println(p); @@ -439,12 +460,14 @@ public class OaiPmhTestTG { @Test public void testListIdentifierSetsDC() throws ParseException { - OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); - OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + TestTGOAIPMHLocally.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + TestTGOAIPMHLocally.identifierList + .setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + TestTGOAIPMHLocally.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + TestTGOAIPMHLocally.identifierList + .setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + TestTGOAIPMHLocally.identifierList.setIdentifierField("textgridUri"); + TestTGOAIPMHLocally.identifierList.setSearchResponseSize("100"); System.out.println("Test for the verb \"ListIdentifiers\" with successful response"); String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "2000-02-05", "", "junk"); @@ -459,26 +482,29 @@ public class OaiPmhTestTG { @Ignore public void testListIdentifierWithResumptionTokenDC() throws ParseException { - OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); - OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + TestTGOAIPMHLocally.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + TestTGOAIPMHLocally.identifierList + .setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + TestTGOAIPMHLocally.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + TestTGOAIPMHLocally.identifierList + .setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + TestTGOAIPMHLocally.identifierList.setIdentifierField("textgridUri"); + TestTGOAIPMHLocally.identifierList.setSearchResponseSize("100"); System.out.println("Test for the verb \"ListIdentifiers\" with successful response"); String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "", "", ""); System.out.println(p); String resToken = ""; - for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.cursorCollector.entrySet()) { + for (Map.Entry<String, Integer> entry : IdentifierListDelivererDC.getCursorCollector() + .entrySet()) { resToken = entry.getKey(); } System.out.println("HASH MAP BEFORE: "); - System.out.println(IdentifierListDelivererDC.cursorCollector); + System.out.println(IdentifierListDelivererDC.getCursorCollector()); System.out.println(resToken); String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); System.out.println(p2); System.out.println("HASH MAP AFTER: "); - System.out.println(IdentifierListDelivererDC.cursorCollector); + System.out.println(IdentifierListDelivererDC.getCursorCollector()); System.out.println("-----------------------------------\n"); } @@ -521,14 +547,14 @@ public class OaiPmhTestTG { "", "", "", ""); System.out.println(p); String resToken = ""; - for (Map.Entry<String, Integer> entry : IdentifierListDelivererIDIOM.cursorCollector + for (Map.Entry<String, Integer> entry : IdentifierListDelivererIDIOM.getCursorCollector() .entrySet()) { resToken = entry.getKey(); } String p2 = this.request.getRequest("ListIdentifiers", "", "", "", "", "", resToken); System.out.println(p2); System.out.println("HASH MAP AFTER: "); - System.out.println(IdentifierListDelivererIDIOM.cursorCollector); + System.out.println(IdentifierListDelivererIDIOM.getCursorCollector()); System.out.println("-----------------------------------\n"); } @@ -539,30 +565,33 @@ public class OaiPmhTestTG { @Ignore public void testListRecordSets() throws ParseException { - OaiPmhTestTG.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); - OaiPmhTestTG.recordList.setCoverages(TGConstants.COVERAGE_LIST); - OaiPmhTestTG.recordList.setCreators(TGConstants.CREATOR_LIST); - OaiPmhTestTG.recordList.setDates(TGConstants.DATE_LIST); - OaiPmhTestTG.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); - OaiPmhTestTG.recordList.setFormats(TGConstants.FORMAT_LIST); - OaiPmhTestTG.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); - OaiPmhTestTG.recordList.setLanguages(TGConstants.LANGUAGE_LIST); - OaiPmhTestTG.recordList.setPublishers(TGConstants.PUBLISHER_LIST); - OaiPmhTestTG.recordList.setRelations(TGConstants.RELATIONS_LIST); - OaiPmhTestTG.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); - OaiPmhTestTG.recordList.setRights(TGConstants.RIGHTS_LIST); - OaiPmhTestTG.recordList.setSources(TGConstants.SOURCE_LIST); - OaiPmhTestTG.recordList.setSubjects(TGConstants.SUBJECT_LIST); - OaiPmhTestTG.recordList.setTitles(TGConstants.TITLE_LIST); - OaiPmhTestTG.recordList.setTypes(TGConstants.TYPE_LIST); - OaiPmhTestTG.recordList.setFormatField(TGConstants.FORMAT); - OaiPmhTestTG.recordList.setFormatToFilter(TextGridMimetypes.EDITION); - OaiPmhTestTG.recordList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTestTG.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); - OaiPmhTestTG.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTestTG.recordList.setRangeField(TGConstants.CREATED); - OaiPmhTestTG.recordList.setModifiedField(TGConstants.MODIFIED_FIELD); - OaiPmhTestTG.recordList.setIdentifierField("textgridUri"); + TestTGOAIPMHLocally.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); + TestTGOAIPMHLocally.recordList.setCoverages(TGConstants.COVERAGE_LIST); + TestTGOAIPMHLocally.recordList.setCreators(TGConstants.CREATOR_LIST); + TestTGOAIPMHLocally.recordList.setDates(TGConstants.DATE_LIST); + TestTGOAIPMHLocally.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); + TestTGOAIPMHLocally.recordList.setFormats(TGConstants.FORMAT_LIST); + TestTGOAIPMHLocally.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); + TestTGOAIPMHLocally.recordList.setLanguages(TGConstants.LANGUAGE_LIST); + TestTGOAIPMHLocally.recordList.setPublishers(TGConstants.PUBLISHER_LIST); + TestTGOAIPMHLocally.recordList.setRelations(TGConstants.RELATIONS_LIST); + TestTGOAIPMHLocally.recordList + .setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + TestTGOAIPMHLocally.recordList.setRights(TGConstants.RIGHTS_LIST); + TestTGOAIPMHLocally.recordList.setSources(TGConstants.SOURCE_LIST); + TestTGOAIPMHLocally.recordList.setSubjects(TGConstants.SUBJECT_LIST); + TestTGOAIPMHLocally.recordList.setTitles(TGConstants.TITLE_LIST); + TestTGOAIPMHLocally.recordList.setTypes(TGConstants.TYPE_LIST); + TestTGOAIPMHLocally.recordList.setFormatField(TGConstants.FORMAT); + TestTGOAIPMHLocally.recordList.setFormatToFilter(TextGridMimetypes.EDITION); + TestTGOAIPMHLocally.recordList.setDateOfObjectCreation(TGConstants.CREATED); + TestTGOAIPMHLocally.recordList + .setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); + TestTGOAIPMHLocally.recordList + .setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + TestTGOAIPMHLocally.recordList.setRangeField(TGConstants.CREATED); + TestTGOAIPMHLocally.recordList.setModifiedField(TGConstants.MODIFIED_FIELD); + TestTGOAIPMHLocally.recordList.setIdentifierField("textgridUri"); System.out.println("Test for the verb \"ListRecords\" with sets with successful response"); // String p = this.request.getRequest("ListRecords", "", "oai_dc", @@ -592,12 +621,13 @@ public class OaiPmhTestTG { "", "", ""); System.out.println(p); String resToken = ""; - for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.cursorCollector.entrySet()) { + for (Map.Entry<String, Integer> entry : RecordListDelivererIDIOM.getCursorCollector() + .entrySet()) { resToken = entry.getKey(); String p2 = this.request.getRequest("ListRecords", "", "", "", "", "", resToken); System.out.println(p2); System.out.println("HASH MAP AFTER: "); - System.out.println(RecordListDelivererIDIOM.cursorCollector); + System.out.println(RecordListDelivererIDIOM.getCursorCollector()); System.out.println("-----------------------------------\n"); } } @@ -622,31 +652,34 @@ public class OaiPmhTestTG { @Ignore public void testListRecords2() throws ParseException { - OaiPmhTestTG.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); - OaiPmhTestTG.recordList.setCoverages(TGConstants.COVERAGE_LIST); - OaiPmhTestTG.recordList.setCreators(TGConstants.CREATOR_LIST); - OaiPmhTestTG.recordList.setDates(TGConstants.DATE_LIST); - OaiPmhTestTG.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); - OaiPmhTestTG.recordList.setFormats(TGConstants.FORMAT_LIST); - OaiPmhTestTG.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); - OaiPmhTestTG.recordList.setLanguages(TGConstants.LANGUAGE_LIST); - OaiPmhTestTG.recordList.setPublishers(TGConstants.PUBLISHER_LIST); - OaiPmhTestTG.recordList.setRelations(TGConstants.RELATIONS_LIST); - OaiPmhTestTG.recordList.setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); - OaiPmhTestTG.recordList.setRights(TGConstants.RIGHTS_LIST); - OaiPmhTestTG.recordList.setSources(TGConstants.SOURCE_LIST); - OaiPmhTestTG.recordList.setSubjects(TGConstants.SUBJECT_LIST); - OaiPmhTestTG.recordList.setTitles(TGConstants.TITLE_LIST); - OaiPmhTestTG.recordList.setTypes(TGConstants.TYPE_LIST); - OaiPmhTestTG.recordList.setFormatField(TGConstants.FORMAT); - OaiPmhTestTG.recordList.setFormatToFilter(TextGridMimetypes.EDITION); - OaiPmhTestTG.recordList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTestTG.recordList.setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); - OaiPmhTestTG.recordList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - OaiPmhTestTG.recordList.setRangeField(TGConstants.CREATED); - OaiPmhTestTG.recordList.setModifiedField(TGConstants.CREATED); - OaiPmhTestTG.recordList.setIdentifierField(TGConstants.URI); - OaiPmhTestTG.recordList.setSearchResponseSize(100); + TestTGOAIPMHLocally.recordList.setContributors(TGConstants.CONTRIBUTOR_LIST); + TestTGOAIPMHLocally.recordList.setCoverages(TGConstants.COVERAGE_LIST); + TestTGOAIPMHLocally.recordList.setCreators(TGConstants.CREATOR_LIST); + TestTGOAIPMHLocally.recordList.setDates(TGConstants.DATE_LIST); + TestTGOAIPMHLocally.recordList.setDescriptions(TGConstants.DESCRIPTION_LIST); + TestTGOAIPMHLocally.recordList.setFormats(TGConstants.FORMAT_LIST); + TestTGOAIPMHLocally.recordList.setIdentifiers(TGConstants.IDENTIFIER_LIST); + TestTGOAIPMHLocally.recordList.setLanguages(TGConstants.LANGUAGE_LIST); + TestTGOAIPMHLocally.recordList.setPublishers(TGConstants.PUBLISHER_LIST); + TestTGOAIPMHLocally.recordList.setRelations(TGConstants.RELATIONS_LIST); + TestTGOAIPMHLocally.recordList + .setRelationsForWork(TGConstants.RELATIONS_FOR_WORK_LIST); + TestTGOAIPMHLocally.recordList.setRights(TGConstants.RIGHTS_LIST); + TestTGOAIPMHLocally.recordList.setSources(TGConstants.SOURCE_LIST); + TestTGOAIPMHLocally.recordList.setSubjects(TGConstants.SUBJECT_LIST); + TestTGOAIPMHLocally.recordList.setTitles(TGConstants.TITLE_LIST); + TestTGOAIPMHLocally.recordList.setTypes(TGConstants.TYPE_LIST); + TestTGOAIPMHLocally.recordList.setFormatField(TGConstants.FORMAT); + TestTGOAIPMHLocally.recordList.setFormatToFilter(TextGridMimetypes.EDITION); + TestTGOAIPMHLocally.recordList.setDateOfObjectCreation(TGConstants.CREATED); + TestTGOAIPMHLocally.recordList + .setRelationToFurtherMetadataObject(TGConstants.EDITION_ISEDITIONOF); + TestTGOAIPMHLocally.recordList + .setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + TestTGOAIPMHLocally.recordList.setRangeField(TGConstants.CREATED); + TestTGOAIPMHLocally.recordList.setModifiedField(TGConstants.CREATED); + TestTGOAIPMHLocally.recordList.setIdentifierField(TGConstants.URI); + TestTGOAIPMHLocally.recordList.setSearchResponseSize(100); String r = this.request.getRequest("ListRecords", "", "oai_dc", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); @@ -683,10 +716,10 @@ public class OaiPmhTestTG { @Ignore public void testListSetsTG() throws ParseException { - OaiPmhTestTG.setListTextGrid.setFormatField("format"); - OaiPmhTestTG.setListTextGrid.setFormatToFilter(TextGridMimetypes.EDITION); - OaiPmhTestTG.setListTextGrid.setIdentifierField("textgridUri"); - OaiPmhTestTG.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); + TestTGOAIPMHLocally.setListTextGrid.setFormatField("format"); + TestTGOAIPMHLocally.setListTextGrid.setFormatToFilter(TextGridMimetypes.EDITION); + TestTGOAIPMHLocally.setListTextGrid.setIdentifierField("textgridUri"); + TestTGOAIPMHLocally.setListTextGrid.setRepositoryObjectURIPrefix("textgrid:"); String r = this.request.getRequest("ListSets", "", "", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); @@ -698,12 +731,13 @@ public class OaiPmhTestTG { @Test public void testEmptyRequest() throws ParseException { - OaiPmhTestTG.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - OaiPmhTestTG.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - OaiPmhTestTG.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - OaiPmhTestTG.identifierList.setIdentifierField("textgridUri"); - OaiPmhTestTG.identifierList.setRepositoryObjectURIPrefix("textgrid:"); - OaiPmhTestTG.identifierList.setSearchResponseSize("100"); + TestTGOAIPMHLocally.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + TestTGOAIPMHLocally.identifierList + .setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + TestTGOAIPMHLocally.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + TestTGOAIPMHLocally.identifierList.setIdentifierField("textgridUri"); + TestTGOAIPMHLocally.identifierList.setRepositoryObjectURIPrefix("textgrid:"); + TestTGOAIPMHLocally.identifierList.setSearchResponseSize("100"); String r = this.request.getRequest("", "", "", "", "", "", ""); System.out.println(r); System.out.println("-----------------------------------\n"); diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java new file mode 100644 index 0000000000000000000000000000000000000000..8fe72c04d40072b05a3db29c8ffe5cc8613d7310 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/OAIPMHUtilitiesOnline.java @@ -0,0 +1,596 @@ +package info.textgrid.middleware.test.online; + +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import javax.ws.rs.core.Response; +import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.jaxrs.client.Client; +import org.apache.cxf.jaxrs.client.JAXRSClientFactory; +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.cxf.transport.http.HTTPConduit; +import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; +import org.apache.http.HttpStatus; +import info.textgrid.middleware.OAIPMHProducer; + +/** + * <p> + * Some online tests for the TextGrid OAIMPH service. + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + */ +public class OAIPMHUtilitiesOnline { + + // ** + // FINALS + // ** + + public static final String OAI_DC_PREFIX = "oai_dc"; + public static final String OAI_DATACITE_PREFIX = "oai_datacite"; + public static final String OAI_IDIOMMETS_PREFIX = "oai_idiom_mets"; + + public static final String VERB_LIST_IDENTIFIERS = "ListIdentifiers"; + public static final String VERB_LIST_RECORDS = "ListRecords"; + public static final String VERB_GET_RECORD = "GetRecord"; + public static final String VERB_IDENTIFY = "Identify"; + public static final String VERB_LIST_METADATA_FORMATS = "ListMetadataFormats"; + public static final String VERB_LIST_SETS = "ListSets"; + + public static final String HEADER_ID_START_TAG = "<identifier>"; + public static final String HEADER_ID_END_TAG = "</identifier>"; + + public static final String EXPECTED_OAIDC_FORMAT_CONTENT = "<oai_dc:dc>"; + public static final String EXPECTED_IDIOMMETS_FORMAT_CONTENT = "<mets "; + public static final String EXPECTED_DATACITE_FORMAT_CONTENT = "<datacite:resource>"; + + public static final String OK = ">>> OKIDOKI"; + public static final String TESTING = "\n >>> TESTING "; + public static final String NOT_TESTED = " >>> NOT_TESTED"; + public static final String NO_TOKEN = "-1"; + + public static final String NO_SET = null; + public static final String NO_THREAD_NAME = ""; + public static final boolean NO_METADATA_FORMAT_WITH_RESTOK = false; + public static final boolean METADATA_FORMAT_WITH_RESTOK = true; + public static final String NO_FROM = null; + public static final String NO_UNTIL = null; + public static final String NO_QUERY = ""; + + // Time to wait between the single queries using resumption tokens in milliseconds. + public static final Long TIME = 275l; + + public static final String HDL_PREFIX = "hdl:"; + public static final String STAR_PREFIX = "***"; + public static final String OAI_PATH = "oai"; + public static final String VERSION_PATH = "oai/version"; + + public static final long OAIPMH_CLIENT_TIMEOUT = 120000; + + /** + * @param theClient + * @param theQuery + * @return + * @throws IOException + */ + public static Response getOAIHttpResponse(Client theClient, String theQuery) + throws IOException { + return getHttpResponse(theClient, NO_THREAD_NAME, OAI_PATH, theQuery); + } + + /** + * @param theClient + * @param theThreadName + * @param theQuery + * @return + * @throws IOException + */ + public static Response getOAIHttpResponse(Client theClient, String theThreadName, + String theQuery) throws IOException { + return getHttpResponse(theClient, theThreadName, OAI_PATH, theQuery); + } + + /** + * @param theClient + * @return + * @throws IOException + */ + public static Response getVersionHttpResponse(Client theClient) throws IOException { + return getHttpResponse(theClient, NO_THREAD_NAME, VERSION_PATH, NO_QUERY); + } + + /** + * @param theClient + * @param theThreadName + * @param thePath + * @param theQuery + * @return + * @throws IOException + */ + protected static Response getHttpResponse(Client theClient, String theThreadName, String thePath, + String theQuery) throws IOException { + + Response result; + + try { + Thread.sleep(TIME); + } catch (InterruptedException e) { + // Nothing interrupts here! + } + + WebClient w = WebClient.fromClient(theClient).path(thePath).replaceQuery(theQuery); + + System.out.println("\t" + theThreadName + "HTTP GET " + w.getCurrentURI()); + + result = w.get(); + + // Check HTTP status. + int status = result.getStatus(); + + if (status != HttpStatus.SC_OK) { + String message = theThreadName + "status: " + status; + assertTrue(message, false); + } else { + System.out.println("\t" + theThreadName + "status: " + status); + } + + return result; + } + + /** + * @param theMillis + * @return + */ + public static String getDurationInSecs(long theMillis) { + + int SECS_IN_MILLIS = 1000; + int secs = SECS_IN_MILLIS; + + return theMillis / secs + " second" + ((theMillis / secs) != 1 ? "s" : ""); + } + + /** + * <p> + * Loads a resource. + * </p> + * + * TODO Put together with the method in TGCrudServiceUtilities! Maybe create a first build maven + * module for utility things. + * + * @param {@link String} The resource to search for. + * @return {@link File} The resource. + * @throws IOException + */ + public static File getResource(String resPart) throws IOException { + + File res; + + // If we have an absolute resPart, just return the file. + if (resPart.startsWith(File.separator)) { + return new File(resPart); + } + + URL url = ClassLoader.getSystemClassLoader().getResource(resPart); + if (url == null) { + throw new IOException("Resource '" + resPart + "' not found"); + } + try { + res = new File(url.toURI()); + } catch (URISyntaxException ue) { + res = new File(url.getPath()); + } + + return res; + } + + /** + * @param theProperty + * @return + */ + public static List<String> getListFromProperties(String theProperty) { + + List<String> result = new ArrayList<String>(); + + String parts[] = theProperty.split(","); + for (String part : parts) { + result.add(part.trim()); + } + + return result; + } + + /** + * @return + * @throws IOException + * @throws FileNotFoundException + */ + public static Properties getPropertiesFromFile(String theConfigFile) + throws FileNotFoundException, IOException { + + Properties result = null; + + // Load properties file. + result = new Properties(); + result.load(new FileInputStream(getResource(theConfigFile))); + + System.out.println("Properties file: " + theConfigFile); + result.list(System.out); + + return result; + } + + /** + * @param theEndpoint + * @return + */ + public static Client getOAIPMHWEebClient(String theEndpoint) { + + Client result = null; + + // Get OAI-PMH REST endpoint and HTTP client. + System.out.println("Getting OAI-PMH HTTP client --> " + theEndpoint + " <--"); + + // Get proxy first, set policy. + OAIPMHProducer JAXRSClient = JAXRSClientFactory.create(theEndpoint, OAIPMHProducer.class); + HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit(); + HTTPClientPolicy policy = new HTTPClientPolicy(); + policy.setReceiveTimeout(OAIPMHUtilitiesOnline.OAIPMH_CLIENT_TIMEOUT); + conduit.setClient(policy); + + // Create Web Client from Web Proxy. + result = WebClient.client(JAXRSClient); + + return result; + } + + // ** + // TG used methods + // ** + + /** + * @param theClient + * @param theVerb + * @param theSet + * @param theMetadataPrefix + * @param maxNumberOfPagesToTest + * @param recordsExpectedPerRequest + * @param theThreadName + * @param from + * @param until + * @param resumptionTokenANDMetadataPrefix + * @throws IOException + */ + public static void examineTGList(Client theClient, final String theVerb, final String theSet, + final String theMetadataPrefix, final int maxNumberOfPagesToTest, + final int recordsExpectedPerRequest, final String theThreadName, final String from, + final String until, final boolean resumptionTokenANDMetadataPrefix) throws IOException { + + String threadName = tn(theThreadName); + + long startTime = System.currentTimeMillis(); + + String testOccurance = "header"; + if (theVerb.equals(VERB_LIST_RECORDS)) { + testOccurance = "record"; + } + + String query = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; + + if (theSet != null) { + query += "&set=" + theSet; + } + + if (from != null && until != null) { + query += "&from=" + from + "&until=" + until; + } + + Response httpResponse = getOAIHttpResponse(theClient, threadName, query); + int status = httpResponse.getStatus(); + + int loopCount = 1; + long timeRunning = System.currentTimeMillis() - startTime; + System.out.println("\t" + threadName + "time: " + getDurationInSecs(timeRunning) + " (loop " + + loopCount + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + ")"); + + String responseString = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + // Test resumption token tags. + String restok = examineTGResumptionTokenTag(responseString, testOccurance, NO_TOKEN, + recordsExpectedPerRequest, loopCount, threadName); + + // Test if the header identifiers are sound. + if (theVerb.equals(VERB_LIST_RECORDS)) { + examineTGHeader(responseString, recordsExpectedPerRequest); + } + + // Test general metadata content (if verb is listRecords!), must go conform with the metadata + // prefix setting. + if (theVerb.equals(VERB_LIST_RECORDS)) { + examineTGContent(responseString, theMetadataPrefix); + } + + while (status == HttpStatus.SC_OK && !restok.equals(NO_TOKEN)) { + loopCount += 1; + synchronized (threadName) { + if (maxNumberOfPagesToTest > 0 && loopCount > maxNumberOfPagesToTest) { + System.out.println( + "\t" + threadName + ">>> TESTING ONLY " + maxNumberOfPagesToTest + " pages!"); + break; + } + query = "verb=" + theVerb + "&resumptionToken=" + restok; + if (resumptionTokenANDMetadataPrefix) { + query += "&metadataPrefix=" + theMetadataPrefix; + } + httpResponse = getOAIHttpResponse(theClient, threadName, query); + timeRunning = System.currentTimeMillis() - startTime; + System.out.println("\t" + threadName + "time: " + getDurationInSecs(timeRunning) + " (loop " + + loopCount + (maxNumberOfPagesToTest != 0 ? "/" + maxNumberOfPagesToTest : "") + ")"); + + // Test resumption token tags. + responseString = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + restok = examineTGResumptionTokenTag(responseString, testOccurance, restok, + recordsExpectedPerRequest, loopCount, threadName); + + // Test if the header identifiers are sound. + if (theVerb.equals(VERB_LIST_RECORDS)) { + examineTGHeader(responseString, recordsExpectedPerRequest); + } + + // Test general metadata content (if verb is listRecords!), must go conform with the + // metadata prefix setting. + if (theVerb.equals(VERB_LIST_RECORDS)) { + examineTGContent(responseString, theMetadataPrefix); + } + } + } + + // Only check for max loops, if we do have less loops and no resumption token, it will be fine, + // too! + if (!restok.equals(NO_TOKEN) && loopCount < maxNumberOfPagesToTest) { + String message = threadName + ": Must have done " + maxNumberOfPagesToTest + + " loops, but did only " + loopCount; + assertTrue(message, false); + } + + // Check for single loop, we need MORE! + if (loopCount == 1) { + String message = threadName + ": Must have more than one loop!"; + assertTrue(message, false); + } + + System.out.println("\t" + threadName + OK); + } + + /** + * @param theResponse + * @param recordOrHeader + * @param oldtok + * @param recordsExpectedPerRequest + * @param loopCount + * @param theThreadName + * @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 examineTGResumptionTokenTag(final String theResponseString, + final String recordOrHeader, final String oldtok, final int recordsExpectedPerRequest, + final int loopCount, final String theThreadName) throws IOException { + + // Test for OAIPMH errors. + if (theResponseString.contains("<error code=\"badArgument\">")) { + String message = theThreadName + ": ERROR IN OAIPMH RESPONSE: " + theResponseString; + System.out.println(message); + throw new IOException(message); + } + + // Count response objects at first. + int recordCount = 0; + int i = theResponseString.indexOf("<" + recordOrHeader + ">", 0); + while (i != -1) { + recordCount++; + i++; + i = theResponseString.indexOf("<" + recordOrHeader + ">", i); + } + + System.out.println("\t" + theThreadName + recordOrHeader + "s: " + recordCount); + + // Check if token tag is existing. + int tokStart = theResponseString.indexOf("<resumptionToken"); + int tokEnd = theResponseString.indexOf("</resumptionToken"); + + if (tokStart == -1 && tokEnd == -1) { + System.out.println("\t" + theThreadName + "token: no token"); + + return NO_TOKEN; + } + + String restokTmp = theResponseString.substring(tokStart, tokEnd); + // Get token tag. + String toktag = restokTmp.substring(0, restokTmp.indexOf(">") + 1).trim(); + System.out.println("\t" + theThreadName + "tokentag: " + toktag); + + // Get token. + String restok = restokTmp.substring(restokTmp.indexOf(">") + 1).trim(); + System.out.println("\t" + theThreadName + "token: " + restok); + + // Check if old and new token are equal or not. + boolean tokchanged = !oldtok.equals(restok); + System.out.println("\t" + theThreadName + "tokchngd: " + tokchanged); + + // Get completeListSize and cursor. + String sizeStr = toktag.substring(toktag.indexOf("completeListSize=\"") + 18); + int size = Integer.parseInt(sizeStr.substring(0, sizeStr.indexOf("\""))); + String cursorStr = toktag.substring(toktag.indexOf("cursor=\"") + 8); + int cursor = Integer.parseInt(cursorStr.substring(0, cursorStr.indexOf("\""))); + System.out.println("\t" + theThreadName + "size: " + size + " / " + cursor); + + // If token is provided, test cursor and element count! + if (!restok.isEmpty()) { + synchronized (OAIPMHUtilitiesOnline.class) { + // Check <record> or <header> count, must be recordsExpectedPerRequest! + if (recordCount != recordsExpectedPerRequest) { + String message = recordOrHeader + " count mismatch, must be " + + recordsExpectedPerRequest + " if token is provided, but is " + recordCount; + assertTrue(message, false); + } + if (size <= recordsExpectedPerRequest) { + String message = "completeListSize count mismatch, must be > " + + recordsExpectedPerRequest + " if token is provided, but is " + size; + assertTrue(message, false); + } + if (cursor != recordsExpectedPerRequest * loopCount) { + String message = "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 % recordsExpectedPerRequest. + if (recordCount != size % recordsExpectedPerRequest) { + String message = theThreadName + ": " + recordOrHeader + " count mismatch, should be " + + size % recordsExpectedPerRequest + ", but is " + recordCount; + assertTrue(message, false); + } + + // No resumption token available in response. + return NO_TOKEN; + } + + return restok; + } + + /** + * @param theResponseString + * @param theMetadataFormat + */ + private static void examineTGContent(String theResponseString, String theMetadataFormat) { + + // Check for correct metadata content according to metadata prefix. + if (theMetadataFormat.equals(OAI_DC_PREFIX) + && !theResponseString.contains("metadataPrefix=\"" + OAI_DC_PREFIX + "\"") + && !theResponseString.contains(EXPECTED_OAIDC_FORMAT_CONTENT)) { + + String message = OAI_DC_PREFIX + " needs to deliver content with schema: " + + EXPECTED_OAIDC_FORMAT_CONTENT + "!"; + assertTrue(message, false); + + } else if (theMetadataFormat.equals(OAI_IDIOMMETS_PREFIX) + && !theResponseString + .contains("metadataPrefix=\"" + EXPECTED_IDIOMMETS_FORMAT_CONTENT + "\"") + && !theResponseString.contains(EXPECTED_IDIOMMETS_FORMAT_CONTENT)) { + + String message = OAI_IDIOMMETS_PREFIX + " needs to deliver content with schema: " + + EXPECTED_IDIOMMETS_FORMAT_CONTENT + "!"; + assertTrue(message, false); + + } else if (theMetadataFormat.equals(OAI_DATACITE_PREFIX) + && !theResponseString.contains("metadataPrefix=\"" + OAI_DATACITE_PREFIX + "\"") + && !theResponseString.contains(EXPECTED_DATACITE_FORMAT_CONTENT)) { + + String message = OAI_DATACITE_PREFIX + " needs to deliver content with schema: " + + EXPECTED_DATACITE_FORMAT_CONTENT + "!"; + assertTrue(message, false); + + } else { + // DEBUG ONLY! + // System.out.println(theResponseString); + // DEBUG ONLY! + } + } + + /** + * <p> + * Check for correct metadata content according to metadata prefix --> We do need to check if we + * have different identifiers in the response. + * </p> + * + * @param theResponseString + * @param recordsExpectedPerRequest + */ + private static void examineTGHeader(String theResponseString, int recordsExpectedPerRequest) { + boolean IDSUnique = examineTGHeaderIDs(theResponseString); + if (IDSUnique) { + String message = "Duplicate IDs in the response!"; + assertTrue(message, false); + } + } + + /** + * <p> + * Creates a hash set containing all the ID values from a certain tag. Used to count elements such + * as <identifier> in OAI-PMH header list responses. We want to know here, if we have ID + * duplicates in one request. + * </p> + * + * @param theResponseString + * @return + */ + private static boolean examineTGHeaderIDs(String theResponseString) { + + boolean result = false; + HashSet<String> idHash = new HashSet<String>(); + + int startID = 0; + int endID = 0; + String id = ""; + int count = 0; + // Look for all the header ID tags. + while (startID != -1) { + count++; + startID = theResponseString.indexOf(HEADER_ID_START_TAG, endID); + endID = theResponseString.indexOf(HEADER_ID_END_TAG, startID); + id = theResponseString.substring(startID + HEADER_ID_START_TAG.length(), endID); + idHash.add(id); + } + // Remove "-1" ID again (and the respective counter). + idHash.remove(id); + count--; + + // Check for ID count: Hash size (unique IDs!) must be equal to the count of ID headers! + if (count != idHash.size()) { + String message = + "We must have " + count + " unique IDs in the headers, but we got only " + idHash.size(); + assertTrue(message, false); + } + + return result; + } + + // ** + // DH used methods + // ** + + // FIXME + + // ** + // Commonly used (TG & DH) methods + // ** + + /** + * @param theThreadName + * @return + */ + private static String tn(String theThreadName) { + + String result = theThreadName; + + if (theThreadName != null && !theThreadName.equals("") && !theThreadName.endsWith(" ")) { + result = "[" + theThreadName + "] "; + } + + return result; + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java similarity index 68% rename from oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java rename to oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java index 640131966c7f10b3c60a113e727ed68491720528..96708e134b9c1e2e5faff81a2423fd8db6b30a67 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhDariahdeOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/dh/TestDHOAIPMHOnline.java @@ -1,4 +1,4 @@ -package info.textgrid.middleware; +package info.textgrid.middleware.test.online.dh; import static org.junit.Assert.assertTrue; import java.io.FileInputStream; @@ -10,10 +10,6 @@ import java.util.Properties; import javax.ws.rs.core.Response; import org.apache.cxf.helpers.IOUtils; import org.apache.cxf.jaxrs.client.Client; -import org.apache.cxf.jaxrs.client.JAXRSClientFactory; -import org.apache.cxf.jaxrs.client.WebClient; -import org.apache.cxf.transport.http.HTTPConduit; -import org.apache.cxf.transports.http.configuration.HTTPClientPolicy; import org.apache.http.HttpStatus; import org.junit.After; import org.junit.AfterClass; @@ -21,6 +17,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; /** * <p> @@ -30,7 +27,7 @@ import org.junit.Test; * @author Stefan E. Funk, SUB Göttingen */ @Ignore -public class OaiPmhDariahdeOnlineTests { +public class TestDHOAIPMHOnline { // ** // FINALS @@ -39,16 +36,12 @@ public class OaiPmhDariahdeOnlineTests { private static final String PROPERTIES_FILE = "oaipmh.test.repository-de-dariah-eu.properties"; // private static final String PROPERTIES_FILE = "oaipmh.test.trep-de-dariah-eu.properties"; - private static final String HDL_PREFIX = "hdl:"; - private static final String STAR_PREFIX = "***"; - // ** // STATICS // ** // Some JAXRS things. private static String oaipmhEndpoint; - private static OAIPMHProducer JAXRSClient; private static Client oaipmhWebClient; // Properties @@ -80,8 +73,7 @@ public class OaiPmhDariahdeOnlineTests { // Load properties file. Properties p = new Properties(); - p.load(new FileInputStream( - OaiPmhTestUtilities.getResource(PROPERTIES_FILE))); + p.load(new FileInputStream(OAIPMHUtilitiesOnline.getResource(PROPERTIES_FILE))); System.out.println("Properties file: " + PROPERTIES_FILE); p.list(System.out); @@ -106,23 +98,11 @@ public class OaiPmhDariahdeOnlineTests { checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet"); checkListIdentifiersSetExpectedPages = Integer.parseInt(p.getProperty("checkListIdentifiersSetExpectedPages").trim()); - checkGetRecordIDList = OaiPmhTestUtilities - .getListFromProperties((String) p.get("checkGetRecordIDList")); - - // Get OAI-PMH REST endpoint and HTTP client. - System.out.println( - "Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--"); - - // Get proxy first, set policy. - JAXRSClient = JAXRSClientFactory.create(oaipmhEndpoint, - OAIPMHProducer.class); - HTTPConduit conduit = WebClient.getConfig(JAXRSClient).getHttpConduit(); - HTTPClientPolicy policy = new HTTPClientPolicy(); - policy.setReceiveTimeout(OaiPmhTestUtilities.OAIPMH_CLIENT_TIMEOUT); - conduit.setClient(policy); - - // Create Web Client from Web Proxy. - oaipmhWebClient = WebClient.client(JAXRSClient); + checkGetRecordIDList = + OAIPMHUtilitiesOnline.getListFromProperties((String) p.get("checkGetRecordIDList")); + + // Get web client from endpoint. + oaipmhWebClient = OAIPMHUtilitiesOnline.getOAIPMHWEebClient(oaipmhEndpoint); } /** @@ -161,19 +141,20 @@ public class OaiPmhDariahdeOnlineTests { String shouldStartWith = "oaipmh-core"; - System.out.println(OaiPmhTestUtilities.TESTING + "#GETVERSION for '" + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#GETVERSION for '" + shouldStartWith + "'"); - String versionString = JAXRSClient.getVersion(); + Response response = OAIPMHUtilitiesOnline.getVersionHttpResponse(oaipmhWebClient); + int status = response.getStatus(); + String versionString = IOUtils.readStringFromStream((InputStream) response.getEntity()); - if (!versionString.startsWith(shouldStartWith)) { - System.err.println(OaiPmhTestUtilities.ERROR - + ": response should start with '" + shouldStartWith + "'"); - assertTrue(false); + if (status != HttpStatus.SC_OK && !versionString.startsWith(shouldStartWith)) { + String message = "[" + status + "]: response should start with '" + shouldStartWith + "'"; + assertTrue(message, false); } System.out.println("\tresponse: " + versionString); - System.out.println(OaiPmhTestUtilities.OK); + System.out.println(OAIPMHUtilitiesOnline.OK); } /** @@ -221,25 +202,21 @@ public class OaiPmhDariahdeOnlineTests { String verb = "Identify"; String shouldContain = "DARIAH-DE Repository"; - System.out.println(OaiPmhTestUtilities.TESTING + "#IDENTIFY"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#IDENTIFY"); - Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - "verb=" + verb); + Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, "verb=" + verb); int status = response.getStatus(); String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity()); - if (status != HttpStatus.SC_OK - || !responseString.contains(shouldContain)) { - System.err.println("\tstatus: " + status); - System.err.println(OaiPmhTestUtilities.ERROR - + ": response should contain '" + shouldContain + "'"); - assertTrue(false); + if (status != HttpStatus.SC_OK || !responseString.contains(shouldContain)) { + String message = "[" + status + "]: response should contain '" + shouldContain + "'"; + assertTrue(message, false); } System.out.println("\tresponse: " + responseString); - System.out.println(OaiPmhTestUtilities.OK); + System.out.println(OAIPMHUtilitiesOnline.OK); } /** @@ -256,9 +233,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListRecordsDC() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET); + testList("ListRecords", "oai_dc", OAIPMHUtilitiesOnline.NO_SET); } /** @@ -267,7 +244,7 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListRecordsSetDC() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); int pages = testList("ListRecords", "oai_dc", checkListRecordsSet); @@ -284,19 +261,19 @@ public class OaiPmhDariahdeOnlineTests { String uri = checkListRecordsSet; - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS - HDL PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS - HDL PREFIX"); - if (!uri.startsWith(HDL_PREFIX)) { - assertTrue("missing '" + HDL_PREFIX + "' prefix!", false); + if (!uri.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { + assertTrue("missing '" + OAIPMHUtilitiesOnline.HDL_PREFIX + "' prefix!", false); } int pages1 = testList("ListRecords", "oai_dc", uri); if (pages1 != checkListRecordsSetExpectedPages) { System.out.println(pages1 + " != " + checkListRecordsSetExpectedPages); } - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS - NO PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS - NO PREFIX"); - if (checkListRecordsSet.startsWith(HDL_PREFIX)) { + if (checkListRecordsSet.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { uri = checkListRecordsSet.substring(4); } int pages2 = testList("ListRecords", "oai_dc", uri); @@ -306,7 +283,7 @@ public class OaiPmhDariahdeOnlineTests { // Check pages count. if (pages1 != checkListRecordsSetExpectedPages || pages2 != checkListRecordsSetExpectedPages) { - assertTrue("pages count does not match", false); + assertTrue("page count does not match", false); } } @@ -319,10 +296,10 @@ public class OaiPmhDariahdeOnlineTests { // TODO Un-ignore if identifier check is implemented! - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS - STAR PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS - STAR PREFIX"); - if (checkListRecordsSet.startsWith(HDL_PREFIX)) { - checkListRecordsSet = STAR_PREFIX + checkListRecordsSet.substring(4); + if (checkListRecordsSet.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { + checkListRecordsSet = OAIPMHUtilitiesOnline.STAR_PREFIX + checkListRecordsSet.substring(4); } int pages3 = testList("ListRecords", "oai_dc", checkListRecordsSet); @@ -337,9 +314,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListRecordsDCFromUntil() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList("ListRecords", "oai_dc", OaiPmhTestUtilities.NO_SET, + testList("ListRecords", "oai_dc", OAIPMHUtilitiesOnline.NO_SET, checkListRecordsDCFrom, checkListRecordsDCUntil); } @@ -349,9 +326,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListRecordsDATASITE() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET); + testList("ListRecords", "oai_datacite", OAIPMHUtilitiesOnline.NO_SET); } /** @@ -360,9 +337,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListRecordsDATASITEFromUntil() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTRECORDS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTRECORDS"); - testList("ListRecords", "oai_datacite", OaiPmhTestUtilities.NO_SET, + testList("ListRecords", "oai_datacite", OAIPMHUtilitiesOnline.NO_SET, checkListRecordsDATACITEFrom, checkListRecordsDATACITEUntil); } @@ -373,7 +350,7 @@ public class OaiPmhDariahdeOnlineTests { @Ignore public void testGetRecordDC() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#GETRECORD"); String identifier = ""; String shouldContain = ""; @@ -391,7 +368,7 @@ public class OaiPmhDariahdeOnlineTests { @Ignore public void testGetRecordDATASITE() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#GETRECORD"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#GETRECORD"); String identifier = ""; String shouldContain = ""; @@ -408,9 +385,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListIdentifiersDC() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); - testList("ListIdentifiers", "oai_dc", OaiPmhTestUtilities.NO_SET); + testList("ListIdentifiers", "oai_dc", OAIPMHUtilitiesOnline.NO_SET); } /** @@ -419,7 +396,7 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListIdentifiersSetDC() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); int pages = testList("ListIdentifiers", "oai_dc", checkListIdentifiersSet); @@ -436,10 +413,10 @@ public class OaiPmhDariahdeOnlineTests { String uri = checkListIdentifiersSet; - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS - HDL PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS - HDL PREFIX"); - if (!uri.startsWith(HDL_PREFIX)) { - assertTrue("missing '" + HDL_PREFIX + "' prefix!", false); + if (!uri.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { + assertTrue("missing '" + OAIPMHUtilitiesOnline.HDL_PREFIX + "' prefix!", false); } System.out.println("uri: " + uri); int pages1 = testList("ListIdentifiers", "oai_dc", uri); @@ -447,9 +424,9 @@ public class OaiPmhDariahdeOnlineTests { System.out.println(pages1 + " != " + checkListIdentifiersSetExpectedPages); } - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS - NO PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS - NO PREFIX"); - if (checkListIdentifiersSet.startsWith(HDL_PREFIX)) { + if (checkListIdentifiersSet.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { uri = checkListIdentifiersSet.substring(4); } System.out.println("uri: " + uri); @@ -474,10 +451,11 @@ public class OaiPmhDariahdeOnlineTests { // TODO Un-ignore if identifier check is implemented! - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS - STAR PREFIX"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS - STAR PREFIX"); - if (checkListIdentifiersSet.startsWith(HDL_PREFIX)) { - checkListIdentifiersSet = STAR_PREFIX + checkListIdentifiersSet.substring(4); + if (checkListIdentifiersSet.startsWith(OAIPMHUtilitiesOnline.HDL_PREFIX)) { + checkListIdentifiersSet = + OAIPMHUtilitiesOnline.STAR_PREFIX + checkListIdentifiersSet.substring(4); } System.out.println("uri: " + checkListIdentifiersSet); int pages3 = testList("ListIdentifiers", "oai_dc", checkListIdentifiersSet); @@ -492,9 +470,9 @@ public class OaiPmhDariahdeOnlineTests { @Test public void testListIdentifiersDATASITE() throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTIDENTIFIERS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTIDENTIFIERS"); - testList("ListIdentifiers", "oai_datacite", OaiPmhTestUtilities.NO_SET); + testList("ListIdentifiers", "oai_datacite", OAIPMHUtilitiesOnline.NO_SET); } // ** @@ -502,7 +480,7 @@ public class OaiPmhDariahdeOnlineTests { // ** /** - * TODO Generalise in OaiPmhTestUtilities! + * TODO Generalise in OAIPMHUtilitiesOnline! * * @param theResponse * @return Resumption token string, if existing, -1 if either no <resumptionToken> tag is @@ -514,8 +492,7 @@ public class OaiPmhDariahdeOnlineTests { // Test for OAIPMH errors. if (theResponseString.contains("<error code=\"badArgument\">")) { - System.err.println(OaiPmhTestUtilities.ERROR + " IN OAIPMH RESPONSE: " + theResponseString); - assertTrue(false); + assertTrue("ERROR IN OAIPMH RESPONSE: " + theResponseString, false); } // Count response objects at first. @@ -565,21 +542,18 @@ public class OaiPmhDariahdeOnlineTests { // If token is provided, and we have less than 100 elements: mekkern! if (!restok.isEmpty()) { - synchronized (OaiPmhDariahdeOnlineTests.class) { + synchronized (TestDHOAIPMHOnline.class) { // Check <record> or <header> count, must be 100! - if (recordCount != 100) { - System.err.println(OaiPmhTestUtilities.ERROR + ": " - + recordOrHeader - + " count mismatch, must be 100 if token is provided, but is " - + recordCount); - } - if (size <= 100) { - System.err.println(OaiPmhTestUtilities.ERROR - + ": completeListSize count mismatch, must be > 100 if token is provided, but is " - + size); + String message = ""; + if (recordCount > 100) { + message = recordOrHeader + " count mismatch, must be 100 if token is provided, but is " + + recordCount; + } else { + message = + "completeListSize count mismatch, must be > 100 if token is provided, but is " + size; } if (recordCount != 100 || size <= 100) { - assertTrue(false); + assertTrue(message, false); } } } @@ -588,10 +562,9 @@ public class OaiPmhDariahdeOnlineTests { else { // Check <record> count, must be completeListSize % 100. if (recordCount != size % 100) { - System.err.println(OaiPmhTestUtilities.ERROR + ": " - + recordOrHeader + " count mismatch, should be " - + size % 100 + ", but is " + recordCount); - assertTrue(false); + String message = + recordOrHeader + " count mismatch, should be " + size % 100 + ", but is " + recordCount; + assertTrue(message, false); } // No resumption token available in response. @@ -611,7 +584,7 @@ public class OaiPmhDariahdeOnlineTests { private static int testList(String theVerb, String theMetadataPrefix, String theSet) throws IOException { return testList(theVerb, theMetadataPrefix, theSet, - OaiPmhTestUtilities.NO_FROM, OaiPmhTestUtilities.NO_UNTIL); + OAIPMHUtilitiesOnline.NO_FROM, OAIPMHUtilitiesOnline.NO_UNTIL); } /** @@ -633,46 +606,45 @@ public class OaiPmhDariahdeOnlineTests { long startTime = System.currentTimeMillis(); String testOccurance = "header"; - if (theVerb.equals(OaiPmhTestUtilities.VERB_LIST_RECORDS)) { + if (theVerb.equals(OAIPMHUtilitiesOnline.VERB_LIST_RECORDS)) { testOccurance = "record"; } - String path = "verb=" + theVerb + "&metadataPrefix=" + String query = "verb=" + theVerb + "&metadataPrefix=" + theMetadataPrefix; if (theSet != null && !theSet.isEmpty()) { - path += "&set=" + theSet; + query += "&set=" + theSet; } if (from != null && until != null) { - path += "&from=" + from + "&until=" + until; + query += "&from=" + from + "&until=" + until; } - Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - path); + Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); int status = response.getStatus(); long timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); + System.out.println("\ttime: " + OAIPMHUtilitiesOnline.getDurationInSecs(timeRunning)); String restok = examineResumptionTokenTag(responseString, testOccurance, ""); examineIdentifiers(responseString); result = 1; while (status == HttpStatus.SC_OK && !restok.equals("-1")) { - path = "verb=" + theVerb + "&resumptionToken=" + restok; - response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, path); + query = "verb=" + theVerb + "&resumptionToken=" + restok; + response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); responseString = IOUtils.readStringFromStream((InputStream) response.getEntity()); timeRunning = System.currentTimeMillis() - startTime; - System.out.println("\ttime: " + OaiPmhTestUtilities.getDurationInSecs(timeRunning)); + System.out.println("\ttime: " + OAIPMHUtilitiesOnline.getDurationInSecs(timeRunning)); restok = examineResumptionTokenTag(responseString, testOccurance, restok); examineIdentifiers(responseString); result++; } System.out.println("\tpage amount: " + result); - System.out.println(OaiPmhTestUtilities.OK); + System.out.println(OAIPMHUtilitiesOnline.OK); return result; } @@ -684,28 +656,22 @@ public class OaiPmhDariahdeOnlineTests { private static void testListSet(String theSet, String theExpectedResponse) throws IOException { - String verb = "ListSets"; - - System.out.println(OaiPmhTestUtilities.TESTING + "#LISTSETS"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#LISTSETS"); - Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - "verb=" + verb); + Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + "verb=" + OAIPMHUtilitiesOnline.VERB_LIST_SETS); int status = response.getStatus(); String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity()); - if (status != HttpStatus.SC_OK - || !responseString.contains(theExpectedResponse)) { - System.err.println("\tstatus: " + status); - System.err.println( - OaiPmhTestUtilities.ERROR + ": response should contain '" + theExpectedResponse + "'"); - System.err.println(responseString); - assertTrue(false); + if (status != HttpStatus.SC_OK || !responseString.contains(theExpectedResponse)) { + String message = "[" + status + "] response should contain '" + theExpectedResponse + "'"; + assertTrue(message, false); } System.out.println("\tresponse: " + responseString); - System.out.println(OaiPmhTestUtilities.OK); + System.out.println(OAIPMHUtilitiesOnline.OK); } /** @@ -716,24 +682,21 @@ public class OaiPmhDariahdeOnlineTests { private static void testRootURL(String theURL, String shouldContain) throws IOException { - System.out.println(OaiPmhTestUtilities.TESTING + "#ROOTURL"); + System.out.println(OAIPMHUtilitiesOnline.TESTING + "#ROOTURL"); - Response response = OaiPmhTestUtilities.getHttpResponse(oaipmhWebClient, - theURL); + Response response = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, theURL); int status = response.getStatus(); String responseString = IOUtils .readStringFromStream((InputStream) response.getEntity()); if (status != HttpStatus.SC_OK || !responseString.contains(shouldContain)) { - System.err.println("\tstatus: " + status); - System.err - .println(OaiPmhTestUtilities.ERROR + ": response should contain '" + shouldContain + "'"); - assertTrue(false); + String message = "[" + status + "] response should contain '" + shouldContain + "'"; + assertTrue(message, false); } System.out.println("\tresponse: " + responseString); - System.out.println(OaiPmhTestUtilities.OK); + System.out.println(OAIPMHUtilitiesOnline.OK); } /** @@ -743,9 +706,8 @@ public class OaiPmhDariahdeOnlineTests { */ private static void examineIdentifiers(String theResponseString) throws IOException { if (theResponseString.contains("<identifier>hdl:21</identifier>")) { - System.err.println(OaiPmhTestUtilities.ERROR - + " IN OAIPMH RESPONSE: identifier tag is corrupt!" + theResponseString); - assertTrue(false); + String message = "ERROR IN OAIPMH RESPONSE: identifier tag is corrupt!" + theResponseString; + assertTrue(message, false); } } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TGOAIPMHResumptionTokenThread.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TGOAIPMHResumptionTokenThread.java new file mode 100644 index 0000000000000000000000000000000000000000..3cbbf1c06ea464038bcbbcc313e0847d3f291765 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TGOAIPMHResumptionTokenThread.java @@ -0,0 +1,61 @@ +package info.textgrid.middleware.test.online.tg; + +import java.io.IOException; +import java.util.concurrent.Callable; +import org.apache.cxf.jaxrs.client.Client; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; + + + +/** + * <p> + * Starts a new OAI-PMH thread. + * </p> + */ + +public class TGOAIPMHResumptionTokenThread implements Callable<Boolean> { + + protected Client client; + protected String verb; + protected String set; + protected String metadataPrefix; + protected int numberOfPagesToTest; + protected int recordsExpectedPerRequest; + protected String threadName; + + /** + * @param theClient + * @param theVerb + * @param theSet + * @param theMetadataPrefix + * @param numberOfPagesToTest + * @param recordsExpectedPerRequest + * @param theThreadName + */ + public TGOAIPMHResumptionTokenThread(Client theClient, String theVerb, String theSet, + String theMetadataPrefix, int numberOfPagesToTest, int recordsExpectedPerRequest, + String theThreadName) { + this.client = theClient; + this.verb = theVerb; + this.set = theSet; + this.metadataPrefix = theMetadataPrefix; + this.numberOfPagesToTest = numberOfPagesToTest; + this.recordsExpectedPerRequest = recordsExpectedPerRequest; + this.threadName = theThreadName; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Thread#run() + */ + @Override + public Boolean call() throws IOException { + OAIPMHUtilitiesOnline.examineTGList(this.client, this.verb, this.set, this.metadataPrefix, + this.numberOfPagesToTest, this.recordsExpectedPerRequest, this.threadName, + OAIPMHUtilitiesOnline.NO_FROM, OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + return true; + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/ClassicMayanTest.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestClassicMayanOnline.java similarity index 82% rename from oaipmh-core/src/test/java/info/textgrid/middleware/ClassicMayanTest.java rename to oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestClassicMayanOnline.java index 899cbe7b3417117f4d8a08d7ab0e086d4081f5bb..f574034f090f782e6813876c31f92a0cbe580ecf 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/ClassicMayanTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestClassicMayanOnline.java @@ -1,4 +1,4 @@ -package info.textgrid.middleware; +package info.textgrid.middleware.test.online.tg; import java.io.IOException; import java.text.ParseException; @@ -13,13 +13,15 @@ import org.junit.Ignore; import org.junit.Test; import org.w3c.dom.Document; import org.xml.sax.SAXException; -import info.textgrid.middleware.oaipmh.OAIPMHtype; +import info.textgrid.middleware.IDIOMImages; /** * */ -@Ignore -public class ClassicMayanTest { +// @Ignore +public class TestClassicMayanOnline { + + // FIXME Check ignored tests!! Do they make any sense?? /** * @throws JSONException @@ -30,10 +32,11 @@ public class ClassicMayanTest { * @throws TransformerException */ @Test + @Ignore public void testGetRecord() throws JSONException, IOException, SAXException, ParseException, TransformerFactoryConfigurationError, TransformerException { - IDIOMImages imageList = new IDIOMImages(); + IDIOMImages imageList = new IDIOMImages("idiomTgcrudEndpoint", "idiomRbacSessionID"); Document document; try { @@ -55,10 +58,11 @@ public class ClassicMayanTest { * @throws TransformerException */ @Test + @Ignore public void testGetMediaList() throws JSONException, IOException, ParseException, SAXException, TransformerFactoryConfigurationError, TransformerException { - IDIOMImages imageList = new IDIOMImages(); + IDIOMImages imageList = new IDIOMImages("idiomTgcrudEndpoint", "idiomRbacSessionID"); imageList.setKindID("1"); imageList.setPerPage("100"); @@ -84,11 +88,12 @@ public class ClassicMayanTest { * @throws TransformerException */ @Test + @Ignore public void testOAIPMHRequest() throws JSONException, IOException, ParseException, SAXException, TransformerFactoryConfigurationError, TransformerException { - OAIPMHtype request = new OAIPMHtype(); - IDIOMImages imageList = new IDIOMImages(); + // OAIPMHtype request = new OAIPMHtype(); + IDIOMImages imageList = new IDIOMImages("idiomTgcrudEndpoint", "idiomRbacSessionID"); imageList.setKindID("1"); imageList.setPerPage("100"); diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java new file mode 100644 index 0000000000000000000000000000000000000000..a59f218b9a3e3143322b63a08661dd0502f06490 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGBasicsOnline.java @@ -0,0 +1,229 @@ +package info.textgrid.middleware.test.online.tg; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import javax.ws.rs.core.Response; +import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.jaxrs.client.Client; +import org.apache.http.HttpStatus; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; + +/** + * <p> + * Some basic online tests for the TextGrid OAIMPH service. + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + */ +@Ignore +public class TestTGBasicsOnline { + + // ** + // FINALS + // ** + + // private static final String PROPERTIES_FILE = "oaipmh.test.textgridlab-org.properties"; + // TODO There is NO IDIOM test data for testing on dev.textgridlab.org! So eventually all + // IDIOM tests will fail! + private static final String PROPERTIES_FILE = "oaipmh.test.dev-textgridlab-org.properties"; + + // ** + // STATICS + // ** + + // Some JAXRS things. + private static String oaipmhEndpoint; + static Client oaipmhWebClient; + + // Properties + private static String expectedListSets; + + // ** + // PREPARATIONS + // ** + + /** + * @throws Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + // Get properties. + Properties p = OAIPMHUtilitiesOnline.getPropertiesFromFile(PROPERTIES_FILE); + + // Set properties. + oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); + + expectedListSets = p.getProperty("expectedListSets"); + + // Get OAI-PMH REST endpoint and HTTP client. + System.out.println("Getting OAI-PMH HTTP client --> " + oaipmhEndpoint + " <--"); + + // Get web client from endpoint. + oaipmhWebClient = OAIPMHUtilitiesOnline.getOAIPMHWEebClient(oaipmhEndpoint); + } + + /** + * @throws Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + // + } + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + // + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + // + } + + // ** + // TESTS + // ** + + /** + * @throws IOException + */ + @Test + public void testGetVersion() throws IOException { + + String shouldStartWith = "oaipmh-core"; + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testGetVersion()"); + + Response httpResponse = OAIPMHUtilitiesOnline.getVersionHttpResponse(oaipmhWebClient); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.startsWith(shouldStartWith)) { + String message = "response should start with '" + shouldStartWith + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testRootUrl() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testRootUrl()"); + + // TODO Still hard coded in OAIPMH service! + String shouldContain = "textgridrep.org"; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, "/"); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { + String message = "[" + status + "] response should contain '" + shouldContain + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testIdentify() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testIdentify()"); + + // TODO Still hard coded in OAIPMH service! + String shouldContain = "textgridrep.org"; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + "verb=" + OAIPMHUtilitiesOnline.VERB_IDENTIFY); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(shouldContain)) { + String message = "[" + status + "] response should contain '" + shouldContain + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListMetadataFormats() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListMetadataFormats()"); + + String shouldContainDC = OAIPMHUtilitiesOnline.OAI_DC_PREFIX; + String shouldContainIDIOM = OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX; + String shouldContainDATACITE = OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + "verb=" + OAIPMHUtilitiesOnline.VERB_LIST_METADATA_FORMATS); + + int status = httpResponse.getStatus(); + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(shouldContainDC) + || !response.contains(shouldContainIDIOM) || !response.contains(shouldContainDATACITE)) { + String message = "[" + status + "] response should contain '" + shouldContainDC + "' and '" + + shouldContainIDIOM + "' and '" + shouldContainDATACITE + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListSets() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListSets()"); + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + "verb=" + OAIPMHUtilitiesOnline.VERB_LIST_SETS); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(expectedListSets)) { + String message = "[" + status + "] response should contain '" + expectedListSets + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java new file mode 100644 index 0000000000000000000000000000000000000000..0c10181bcaf2bf70093e16c57bfd40723c79368e --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGGetRecordOnline.java @@ -0,0 +1,386 @@ +package info.textgrid.middleware.test.online.tg; + +import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import javax.ws.rs.core.Response; +import org.apache.cxf.helpers.IOUtils; +import org.apache.cxf.jaxrs.client.Client; +import org.apache.http.HttpStatus; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; + +/** + * <p> + * Some online tests for the TextGrid OAIMPH service --> verb=GetRecord <-- + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + * @version 2022-09-21 + * @since 2022-09-08 + */ +@Ignore +public class TestTGGetRecordOnline { + + // ** + // FINALS + // ** + + // private static final String PROPERTIES_FILE = "oaipmh.test.textgridlab-org.properties"; + // TODO There is NO IDIOM test data for testing on dev.textgridlab.org! So eventually all + // IDIOM tests will fail! + protected static final String PROPERTIES_FILE = "oaipmh.test.dev-textgridlab-org.properties"; + + // ** + // STATICS + // ** + + // Some JAXRS things. + private static String oaipmhEndpoint; + static Client oaipmhWebClient; + + // Properties + private static String checkGetRecordDC; + private static String expectedGetRecordDC; + + private static String checkGetRecordDATACITE; + private static String expectedGetRecordDATACITE; + + private static String checkGetRecordIDIOM; + private static String expectedGetRecordIDIOM; + + private static String checkGetRecordIDIOMImage; + private static String expectedGetRecordIDIOMImage; + + private static List<String> checkGetRecordIDList = new ArrayList<String>(); + + // ** + // PREPARATIONS + // ** + + /** + * @throws Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + // Get properties. + Properties p = OAIPMHUtilitiesOnline.getPropertiesFromFile(PROPERTIES_FILE); + + // Set properties. + oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); + + checkGetRecordDC = p.getProperty("checkGetRecordDC"); + expectedGetRecordDC = p.getProperty("expectedGetRecordDC"); + + checkGetRecordDATACITE = p.getProperty("checkGetRecordDATACITE"); + expectedGetRecordDATACITE = p.getProperty("expectedGetRecordDATACITE"); + + checkGetRecordIDIOM = p.getProperty("checkGetRecordIDIOM"); + expectedGetRecordIDIOM = p.getProperty("expectedGetRecordIDIOM"); + + checkGetRecordIDIOMImage = p.getProperty("checkGetRecordIDIOMImage"); + expectedGetRecordIDIOMImage = p.getProperty("expectedGetRecordIDIOMImage"); + + checkGetRecordIDList = + OAIPMHUtilitiesOnline.getListFromProperties((String) p.get("checkGetRecordIDList")); + + // Get web client from endpoint. + oaipmhWebClient = OAIPMHUtilitiesOnline.getOAIPMHWEebClient(oaipmhEndpoint); + } + + /** + * @throws Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + // + } + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + // + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + // + } + + // ** + // TESTS + // ** + + /** + * @throws IOException + */ + @Test + public void testGetRecordOAIDC() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testGetRecordOAIDC()"); + + String query = "verb=" + OAIPMHUtilitiesOnline.VERB_GET_RECORD + "&identifier=" + + checkGetRecordDC + "&metadataPrefix=" + OAIPMHUtilitiesOnline.OAI_DC_PREFIX; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, query); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(expectedGetRecordDC)) { + String message = "[" + status + "] response should contain '" + expectedGetRecordDC + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordIDIOMMETS() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testGetRecordIDIOMMETS()"); + + String query = "verb=" + OAIPMHUtilitiesOnline.VERB_GET_RECORD + "&identifier=" + + checkGetRecordIDIOM + "&metadataPrefix=" + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + query); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(expectedGetRecordIDIOM)) { + String message = "[" + status + "] response should contain '" + expectedGetRecordIDIOM + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordIDIOMMETSImage() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testGetRecordIDIOMMETS_Image()"); + + String query = + "verb=" + OAIPMHUtilitiesOnline.VERB_GET_RECORD + "&identifier=" + checkGetRecordIDIOMImage + + "&metadataPrefix=" + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + query); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(expectedGetRecordIDIOMImage)) { + String message = + "[" + status + "] response should contain '" + expectedGetRecordIDIOMImage + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testGetRecordDATACITE() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testGetRecordDATACITE()"); + + String query = "verb=" + OAIPMHUtilitiesOnline.VERB_GET_RECORD + "&identifier=" + + checkGetRecordDATACITE + "&metadataPrefix=" + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX; + + Response httpResponse = OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, + query); + int status = httpResponse.getStatus(); + + String response = IOUtils.readStringFromStream((InputStream) httpResponse.getEntity()); + + if (status != HttpStatus.SC_OK || !response.contains(expectedGetRecordDATACITE)) { + String message = + "[" + status + "] response should contain '" + expectedGetRecordDATACITE + "'"; + assertTrue(message, false); + } + + System.out.println("\tresponse: " + response); + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testConcurrentlyOAIDCGetRecord() throws InterruptedException, ExecutionException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testConcurrentlyOAIDCGetRecord()"); + + ExecutorService executor = Executors.newFixedThreadPool(18); + + Future<Boolean> f1 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(0), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f2 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(1), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f3 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(2), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f4 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(3), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f5 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(4), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f6 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(5), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f7 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(6), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f8 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(7), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f9 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(8), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f10 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(9), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f11 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(10), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f12 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(11), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f13 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(12), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f14 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(13), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f15 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(14), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f16 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(15), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f17 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(16), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + Future<Boolean> f18 = + executor.submit(new OaiPmhGetRecordTestThread(OAIPMHUtilitiesOnline.VERB_GET_RECORD, + checkGetRecordIDList.get(17), OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + "GR[" + checkGetRecordIDList.get(0) + "]")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + "[GR1]=" + f1.get() + + ", [GR2]=" + f2.get() + + ", [GR3]=" + f3.get() + + ", [GR4]=" + f4.get() + + ", [GR5]=" + f5.get() + + ", [GR6]=" + f6.get() + + ", [GR7]=" + f7.get() + + ", [GR8]=" + f8.get() + + ", [GR9]=" + f9.get() + + ", [GR10]=" + f10.get() + + ", [GR11]=" + f11.get() + + ", [GR12]=" + f12.get() + + ", [GR13]=" + f13.get() + + ", [GR14]=" + f14.get() + + ", [GR15]=" + f15.get() + + ", [GR16]=" + f16.get() + + ", [GR17]=" + f17.get() + + ", [GR18]=" + f18.get()); + } + + /** + * <p> + * Starts a new OAI-PMH thread. + * </p> + */ + private class OaiPmhGetRecordTestThread implements Callable<Boolean> { + + protected String verb; + protected String identifier; + protected String metadataPrefix; + protected String threadName; + + /** + * @param theVerb + * @param theIdentifier + * @param theMetadataPrefix + * @param theThreadName + */ + public OaiPmhGetRecordTestThread(String theVerb, String theIdentifier, String theMetadataPrefix, + String theThreadName) { + this.verb = theVerb; + this.identifier = theIdentifier; + this.metadataPrefix = theMetadataPrefix; + this.threadName = theThreadName; + } + + /** + * + */ + @Override + public Boolean call() throws IOException { + + String query = "verb=" + this.verb + "&identifier=" + this.identifier + "&metadataPrefix=" + + this.metadataPrefix; + OAIPMHUtilitiesOnline.getOAIHttpResponse(oaipmhWebClient, this.threadName, query); + + return true; + } + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java new file mode 100644 index 0000000000000000000000000000000000000000..b057cd8a1ec50139a25d9bdefd254d195e6fa8e8 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListIdentifiersOnline.java @@ -0,0 +1,451 @@ +package info.textgrid.middleware.test.online.tg; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.apache.cxf.jaxrs.client.Client; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; + +/** + * <p> + * Some online tests for the TextGrid OAIMPH service --> verb=ListIdentifiers <-- + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + * @version 2022-09-21 + * @since 2022-09-12 + */ +@Ignore +public class TestTGListIdentifiersOnline { + + // ** + // FINALS + // ** + + // private static final String PROPERTIES_FILE = "oaipmh.test.textgridlab-org.properties"; + // TODO There is NO IDIOM test data for testing on dev.textgridlab.org! So eventually all + // IDIOM tests will fail! + protected static final String PROPERTIES_FILE = "oaipmh.test.dev-textgridlab-org.properties"; + + // ** + // STATICS + // ** + + // Some JAXRS things. + private static String oaipmhEndpoint; + static Client oaipmhWebClient; + + // Properties + + private static String checkListIdentifiersSet; + private static int checkListIdentifiersPagesToTestIDIOM; + private static int checkListIdentifiersRecordsPerPageIDIOM; + + // ** + // PREPARATIONS + // ** + + /** + * @throws Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + // Get properties. + Properties p = OAIPMHUtilitiesOnline.getPropertiesFromFile(PROPERTIES_FILE); + + // Set properties. + oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); + + checkListIdentifiersSet = p.getProperty("checkListIdentifiersSet"); + checkListIdentifiersPagesToTestIDIOM = + Integer.parseInt(p.getProperty("checkListIdentifiersPagesToTestIDIOM")); + checkListIdentifiersRecordsPerPageIDIOM = + Integer.parseInt(p.getProperty("checkListIdentifiersRecordsPerPageIDIOM")); + + // Get web client from endpoint. + oaipmhWebClient = OAIPMHUtilitiesOnline.getOAIPMHWEebClient(oaipmhEndpoint); + } + + /** + * @throws Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + // + } + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + // + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + // + } + + // ** + // TESTS + // ** + + /** + * @throws IOException + */ + @Test + public void testListIdentifiersOAIDCMorePages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListIdentifiersOAIDCMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + checkListIdentifiersSet, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 30, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test(expected = IOException.class) + public void testListIdentifiersOAIDCMorePagesAndMetadataFormatWithRestok() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + + "testListIdentifiersOAIDCMorePagesAndMetadataFormatWithRestok()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + checkListIdentifiersSet, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 30, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + @Ignore + public void testListIdentifiersIDIOMMETSAllPages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListIdentifiersIDIOMMETSAllPages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 0, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListIdentifiersIDIOMMETSMorePages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListIdentifiersIDIOMMETSMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 6, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test(expected = IOException.class) + public void testListIdentifiersIDIOMMETSSomePagesAndMetadataFormatWithRestok() + throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + + "testListIdentifiersIDIOMMETSSomePagesAndMetadataFormatWithRestok()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 3, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListIdentifiersDATACITEMorePages() throws IOException { + + System.out + .println(OAIPMHUtilitiesOnline.TESTING + "testListIdentifiersDATACITEMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 22, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + * @throws ExecutionException + * @throws InterruptedException + */ + @Test + public void testListIdentifiersConcurrentlyIDIOMMETSMorePages() + throws IOException, InterruptedException, ExecutionException { + + System.out.println( + OAIPMHUtilitiesOnline.TESTING + "testListIdentifiersConcurrentlyIDIOMMETSMorePages()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor + .submit(new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 3, 30, + "C1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 5, 30, + "C2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 8, 30, + "C2")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [C1]=" + f1.get() + ", [C2]=" + f2.get() + + ", [C3]=" + f3.get()); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersDC() + throws InterruptedException, ExecutionException { + + System.out + .println(OAIPMHUtilitiesOnline.TESTING + "testRestokConcurrentlyListIdentifiersDC()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 36, 100, + "A1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 27, 100, + "A2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 19, 100, + "A3")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + + ", [A3]=" + f3.get()); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersIDIOMMETS() + throws InterruptedException, ExecutionException { + + System.out + .println( + OAIPMHUtilitiesOnline.TESTING + "testRestokConcurrentlyListIdentifiersIDIOM()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 13, 30, + "A1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 35, 30, + "A2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 11, 30, + "A3")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + + ", [A3]=" + f3.get()); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersDATACITE() + throws InterruptedException, ExecutionException { + + System.out + .println( + OAIPMHUtilitiesOnline.TESTING + "testRestokConcurrentlyListIdentifiersDATACITE()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 13, 100, + "A1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 20, 100, + "A2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 8, 100, + "A3")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [A1]=" + f1.get() + ", [A2]=" + f2.get() + + ", [A3]=" + f3.get()); + } + + /** + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListIdentifiersDCAndIDIOMMETS() + throws InterruptedException, ExecutionException { + + System.out.println( + OAIPMHUtilitiesOnline.TESTING + + "testRestokConcurrentlyListIdentifiersDCAndIDIOMMets()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 53, 100, + "DC1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 28, 100, + "DC2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_IDENTIFIERS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + checkListIdentifiersPagesToTestIDIOM, + checkListIdentifiersRecordsPerPageIDIOM, + "IDIOM")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() + + ", [IDIOM]=" + f3.get()); + } + +} diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java new file mode 100644 index 0000000000000000000000000000000000000000..4705ef22de04c5b3979b9f9f38155903cfeb1b44 --- /dev/null +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/test/online/tg/TestTGListRecordsOnline.java @@ -0,0 +1,496 @@ +package info.textgrid.middleware.test.online.tg; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.apache.cxf.jaxrs.client.Client; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import info.textgrid.middleware.test.online.OAIPMHUtilitiesOnline; + +/** + * <p> + * Some online tests for the TextGrid OAIMPH service --> verb=ListRecords <-- + * </p> + * + * @author Stefan E. Funk, SUB Göttingen + * @version 2022-09-21 + * @since 2022-09-12 + */ +@Ignore +public class TestTGListRecordsOnline { + + // ** + // FINALS + // ** + + // private static final String PROPERTIES_FILE = "oaipmh.test.textgridlab-org.properties"; + // TODO There is NO IDIOM test data for testing on dev.textgridlab.org! So eventually all + // IDIOM tests will fail! + protected static final String PROPERTIES_FILE = "oaipmh.test.dev-textgridlab-org.properties"; + + // ** + // STATICS + // ** + + // Some JAXRS things. + private static String oaipmhEndpoint; + static Client oaipmhWebClient; + + // Properties + private static String checkListRecordsDCSet; + private static String checkListRecordsDCFrom; + private static String checkListRecordsDCUntil; + private static String checkListRecordsDATACITEFrom; + private static String checkListRecordsDATACITEUntil; + private static String checkListRecordsIDIOMFrom; + private static String checkListRecordsIDIOMUntil; + private static int checkListIdentifiersPagesToTestIDIOM; + private static int checkListIdentifiersRecordsPerPageIDIOM; + + // ** + // PREPARATIONS + // ** + + /** + * @throws Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + + // Get properties. + Properties p = OAIPMHUtilitiesOnline.getPropertiesFromFile(PROPERTIES_FILE); + + // Set properties. + oaipmhEndpoint = p.getProperty("oaipmhEndpoint"); + + checkListRecordsDCSet = p.getProperty("checkListRecordsDCSet"); + checkListRecordsDCFrom = p.getProperty("checkListRecordsDCFrom"); + checkListRecordsDCUntil = p.getProperty("checkListRecordsDCUntil"); + + checkListRecordsDATACITEFrom = p.getProperty("checkListRecordsDATACITEFrom"); + checkListRecordsDATACITEUntil = p.getProperty("checkListRecordsDATACITEUntil"); + + checkListRecordsIDIOMFrom = p.getProperty("checkListRecordsIDIOMFrom"); + checkListRecordsIDIOMUntil = p.getProperty("checkListRecordsIDIOMUntil"); + + // Get web client from endpoint. + oaipmhWebClient = OAIPMHUtilitiesOnline.getOAIPMHWEebClient(oaipmhEndpoint); + } + + /** + * @throws Exception + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + // + } + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + // + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + // + } + + // ** + // TESTS + // ** + + /** + * @throws IOException + */ + @Test + public void testListRecordsOAIDCMorePages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsOAIDCMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 18, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsOAIDCSetMorePages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsOAIDCSetMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + checkListRecordsDCSet, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 20, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + @Ignore + public void testListRecordsOAIDCAllPages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsOAIDCAllPages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 0, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsOAIDCMorePagesFromUntil() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsOAIDCMorePagesFromUntil()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + checkListRecordsDCSet, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 0, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + checkListRecordsDCFrom, + checkListRecordsDCUntil, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test(expected = IOException.class) + public void testListRecordsIDIOMMETSSomePagesAndMetadataFormatWithRestok() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + + "testListRecordsIDIOMMETSSomePagesAndMetadataFormatWithRestok()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 3, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + @Ignore + public void testListRecordsIDIOMMETSAllPages() throws IOException { + + // FIXME + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsIDIOMMETSAllPages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 0, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * NOTE The amount of records will change due to changes on the data! Please check from and until + * values before! + * + * @throws IOException + */ + @Test + public void testListRecordsIDIOMMETSMorePagesFromUntil() throws IOException { + + System.out + .println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsIDIOMMETSMorePagesFromUntil()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 6, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + checkListRecordsIDIOMFrom, + checkListRecordsIDIOMUntil, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsIDIOMMETSMorePages() throws IOException { + + System.out + .println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsIDIOMMETSMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + 6, 30, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsDATACITEMorePages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsDATACITEMorePages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 15, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + @Ignore + public void testListRecordsDATACITEAllPages() throws IOException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsDATACITEAllPages()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 0, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + OAIPMHUtilitiesOnline.NO_FROM, + OAIPMHUtilitiesOnline.NO_UNTIL, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + */ + @Test + public void testListRecordsDATACITEMorePagesFromUntil() throws IOException { + + System.out + .println(OAIPMHUtilitiesOnline.TESTING + "testListRecordsDATACITEMorePagesFromUntil()"); + + OAIPMHUtilitiesOnline.examineTGList(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DATACITE_PREFIX, + 15, 100, + OAIPMHUtilitiesOnline.NO_THREAD_NAME, + checkListRecordsDATACITEFrom, + checkListRecordsDATACITEUntil, + OAIPMHUtilitiesOnline.NO_METADATA_FORMAT_WITH_RESTOK); + + System.out.println(OAIPMHUtilitiesOnline.OK); + } + + /** + * @throws IOException + * @throws ExecutionException + * @throws InterruptedException + */ + @Test + public void testListRecordsConcurrentlyIDIOMMETSMorePages() + throws IOException, InterruptedException, ExecutionException { + + System.out + .println( + OAIPMHUtilitiesOnline.TESTING + "testListRecordsConcurrentlyIDIOMMETSMorePages()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, 2, 30, "D1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, 3, 30, "D2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, 4, 30, "D3")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [D1]=" + f1.get() + ", [D2]=" + f2.get() + + ", [D3]=" + f3.get()); + } + + + /** + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListRecordsDC() + throws InterruptedException, ExecutionException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testRestokConcurrentlyListRecordsDC()"); + + ExecutorService executor = Executors.newFixedThreadPool(4); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 44, 100, "DC1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 33, 100, "DC2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 66, 100, "DC3")); + Future<Boolean> f4 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 28, 100, "DC4")); + + executor.shutdown(); + + System.out.println( + OAIPMHUtilitiesOnline.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() + ", [DC3]=" + + f3.get() + ", [DC4]=" + f4.get()); + } + + /** + * @throws IOException + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testRestokConcurrentlyListRecords() throws InterruptedException, ExecutionException { + + System.out.println(OAIPMHUtilitiesOnline.TESTING + "testRestokConcurrentlyListRecords()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 6, 100, "B1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 7, 100, "B2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 8, 100, "B3")); + Future<Boolean> f4 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, OAIPMHUtilitiesOnline.OAI_DC_PREFIX, 9, 100, "B4")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [B1]=" + f1.get() + ", [B2]=" + f2.get() + + ", [B3]=" + f3.get() + ", [B4]=" + f4.get()); + } + + /** + * @throws InterruptedException + * @throws ExecutionException + */ + @Test + public void testListRecordsRestokConcurrentlyDCAndIDIOMMETS() + throws InterruptedException, ExecutionException { + + System.out.println( + OAIPMHUtilitiesOnline.TESTING + "testListRecordsRestokConcurrentlyDCAndIDIOMMets()"); + + ExecutorService executor = Executors.newFixedThreadPool(3); + + Future<Boolean> f1 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 34, 100, + "DC1")); + Future<Boolean> f2 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_DC_PREFIX, + 27, 100, + "DC2")); + Future<Boolean> f3 = executor.submit( + new TGOAIPMHResumptionTokenThread(oaipmhWebClient, + OAIPMHUtilitiesOnline.VERB_LIST_RECORDS, + OAIPMHUtilitiesOnline.NO_SET, + OAIPMHUtilitiesOnline.OAI_IDIOMMETS_PREFIX, + checkListIdentifiersPagesToTestIDIOM, + checkListIdentifiersRecordsPerPageIDIOM, + "IDIOM")); + + executor.shutdown(); + + System.out.println(OAIPMHUtilitiesOnline.OK + ": [DC1]=" + f1.get() + ", [DC2]=" + f2.get() + + ", [IOIOM]=" + f3.get()); + } + +} diff --git a/oaipmh-core/src/test/resources/oaipmh.test.dev-textgridlab-org.properties b/oaipmh-core/src/test/resources/oaipmh.test.dev-textgridlab-org.properties index ebfefb54791c5d1f2df6e2aafea8ca93047be1a5..4d07edba85923641a0fafdc2f7d7d401356dd178 100644 --- a/oaipmh-core/src/test/resources/oaipmh.test.dev-textgridlab-org.properties +++ b/oaipmh-core/src/test/resources/oaipmh.test.dev-textgridlab-org.properties @@ -1,26 +1,38 @@ # OAI-PMH host -oaipmhEndpoint = https://dev.textgridlab.org/1.0/tgoaipmh/oai -# ListSets -expectedListSets = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c -# GetRecord +oaipmhEndpoint = https://dev.textgridlab.org/1.0/tgoaipmh + +# GetRecord --> TestGetRecordONLINE.class checkGetRecordDC = textgrid:vqn0.0 expectedGetRecordDC = Heidi -checkGetRecordIDIOM = textgrid:2sg18.0 -expectedGetRecordIDIOM = Aguateca -checkGetRecordIDIOM_Images = 11669 -expectedGetRecordIDIOM_Images = Bonampak + checkGetRecordDATACITE = textgrid:mq05.0 expectedGetRecordDATACITE = Weise Klugredenn + +checkGetRecordIDIOM = textgrid:2sg18.0 +expectedGetRecordIDIOM = Aguateca + +checkGetRecordIDIOMImage = textgrid:3vcgs.0 +expectedGetRecordIDIOMImage = Edzna, Hieroglyphic Stairway 1, HS.1:1-10, HS.1:45-47, HS.1:48-49 +#checkGetRecordIDIOMImage = textgrid:407sf.0 +#expectedGetRecordIDIOMImage = Acanceh, Structure 1, Stucco Frieze, Detail + checkGetRecordIDList = textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0, textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0 + # ListRecords -checkListRecordsDC = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c +checkListRecordsDCSet = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c checkListRecordsDCFrom = 2012-01-04T01:00:00 checkListRecordsDCUntil = 2012-01-04T12:00:00 + checkListRecordsIDIOMFrom = 2012-01-04T01:00:00 checkListRecordsIDIOMUntil = 2012-01-04T12:00:00 + checkListRecordsDATACITEFrom = 2012-01-04T01:00:00 checkListRecordsDATACITEUntil = 2012-01-04T12:00:00 + # ListIdentifiers checkListIdentifiersSet = project:TGPR-59722e29-efcb-330f-b9b4-5ef2fb08edab checkListIdentifiersPagesToTestIDIOM = 10 checkListIdentifiersRecordsPerPageIDIOM = 30 + +# ListSets +expectedListSets = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c diff --git a/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties b/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties index db6888109fc0ed7c5f48682154ff60f33f9b0951..b123de236aa2458961d410bea1b4b3b5a99ce0f6 100644 --- a/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties +++ b/oaipmh-core/src/test/resources/oaipmh.test.textgridlab-org.properties @@ -1,7 +1,11 @@ # OAI-PMH host oaipmhEndpoint = https://textgridlab.org/1.0/tgoaipmh/oai + # ListSets expectedListSets = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c + +!! Please CHECK config !! + # GetRecord checkGetRecordDC = textgrid:vqn0.0 expectedGetRecordDC = Heidi @@ -12,6 +16,7 @@ expectedGetRecordIDIOM_Images = Aguateca checkGetRecordDATACITE = textgrid:mq05.0 expectedGetRecordDATACITE = Weise Klugredenn checkGetRecordIDList = textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0, textgrid:mq05.0, textgrid:jgv6.0, textgrid:w7rz.0, textgrid:w36b.0, textgrid:mcdv.0, textgrid:v0qx.0, textgrid:xkck.0, textgrid:t3m1.0, textgrid:10rsq.0 + # ListRecords checkListRecordsDC = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c checkListRecordsDCFrom = 2012-01-04T01:00:00 @@ -20,6 +25,7 @@ checkListRecordsIDIOMFrom = 2012-01-04T01:00:00 checkListRecordsIDIOMUntil = 2012-01-04T12:00:00 checkListRecordsDATACITEFrom = 2012-01-04T01:00:00 checkListRecordsDATACITEUntil = 2012-01-04T12:00:00 + # ListIdentifiers checkListIdentifiersSet = project:TGPR-372fe6dc-57f2-6cd4-01b5-2c4bbefcfd3c checkListIdentifiersPagesToTestIDIOM = 10 diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml index e70113f3638edcd2d054f14e5bc4bec1da8f16ab..9fd17263dba9f77d040ded3efda66c6e22172569 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/beans.xml @@ -30,10 +30,10 @@ <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean> - <!-- ES client bean --> + <!-- ES client beans --> <bean id="ElasticSearchClient" - class="info.textgrid.middleware.OAI_ESClient"> + class="info.textgrid.middleware.OAIPMHElasticSearchClient"> <constructor-arg index="0" value="${elasticSearch.url}" /> <constructor-arg index="1" @@ -44,6 +44,19 @@ <property name="esType" value="${elasticSearch.type}" /> </bean> + <bean id="NonpublicElasticSearchClient" + class="info.textgrid.middleware.OAIPMHElasticSearchClient"> + <constructor-arg index="0" + value="${elasticSearch.url}" /> + <constructor-arg index="1" + value="${elasticSearch.ports}" /> + <constructor-arg index="2" + value="${elasticSearch.itemLimit}" /> + <property name="esIndex" + value="${elasticSearch.nonpublicIndex}" /> + <property name="esType" value="${elasticSearch.type}" /> + </bean> + <!-- Main class bean --> <bean id="oai" class="info.textgrid.middleware.OAIPMHImpl"> @@ -65,6 +78,14 @@ <property name="dariah" value="${dariah}" /> </bean> + <bean id="IDIOMImages" + class="info.textgrid.middleware.IDIOMImages"> + <property name="idiomTgcrudEndpoint" + value="${idiomTgcrudEndpoint}" /> + <property name="idiomRbacSessionID" + value="${idiomRbacSessionID}" /> + </bean> + <!-- Define all implementing classes here, chose needed class in main config file! --> <bean id="MetadataFormatListDelivererDH" @@ -75,11 +96,6 @@ class="info.textgrid.middleware.MetadataFormatListDelivererTG"> </bean> - <bean id="IDIOMImages" - class="info.textgrid.middleware.IDIOMImages"> - <property name="rbacSessionID" value="${rbacSessionID}" /> - </bean> - <!-- Bean for verb=Identify --> <bean id="RepIdentification" @@ -97,7 +113,7 @@ <!-- Beans for verb=GetRecord --> - <bean scope="prototype" id="RecordDC" + <bean id="RecordDC" class="info.textgrid.middleware.RecordDelivererDC"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> @@ -174,7 +190,10 @@ <property name="specFieldPrefix" value="${specFieldPrefix}" /> <property name="specField" value="${specField}" /> - <property name="oaiEsClient" ref="ElasticSearchClient" /> + <property name="oaiEsClient" + ref="NonpublicElasticSearchClient" /> + + <property name="idiomImages" ref="IDIOMImages" /> </bean> <bean id="RecordDATACITE" @@ -287,18 +306,36 @@ <property name="oaiEsClient" ref="ElasticSearchClient" /> </bean> - <bean scope="prototype" id="RecordListIDIOM" + <bean id="RecordListIDIOM" class="info.textgrid.middleware.RecordListDelivererIDIOM"> <constructor-arg index="0" value="${textgrid}" /> <constructor-arg index="1" value="${dariah}" /> - <!-- TODO Why we don't need any property definitions here? --> + <property name="fields" value="${fields}" /> + <property name="workFields" value="${workFields}" /> + <property name="dateOfObjectCreation" + value="${dateOfObjectCreation}" /> + <property name="relationToFurtherMetadataObject" + value="${relationToFurtherMetadataObject}" /> + <property name="repositoryObjectURIPrefix" + value="${repositoryObjectURIPrefix}" /> + <property name="modifiedField" value="${modifiedField}" /> + <property name="identifierField" value="${identifierField}" /> + <property name="rangeField" value="${rangeField}" /> + <property name="formatField" value="${formatField}" /> + <property name="formatToFilter" value="${formatToFilter}" /> + <property name="searchResponseSize" + value="${searchResponseSize}" /> + <property name="specFieldPrefix" value="${specFieldPrefix}" /> + <property name="specField" value="${specField}" /> <property name="idiomResponseSize" value="${idiomResponseSize}" /> - <property name="oaiEsClient" ref="ElasticSearchClient" /> - </bean> + <property name="oaiEsClient" + ref="NonpublicElasticSearchClient" /> + <property name="idiomRecord" ref="RecordIDIOM" /> + </bean> <bean id="RecordListDATACITE" class="info.textgrid.middleware.RecordListDelivererDATACITE"> @@ -370,8 +407,10 @@ <property name="idiomResponseSize" value="${idiomResponseSize}" /> - <property name="oaiEsClient" ref="ElasticSearchClient" /> - </bean> + <property name="oaiEsClient" + ref="NonpublicElasticSearchClient" /> + <property name="idiomRecord" ref="RecordIDIOM" /> + </bean> <bean id="ListIdentifierDATACITE" class="info.textgrid.middleware.IdentifierListDelivererDATACITE"> diff --git a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties index 86f2b80b5dc9f0e652c2ef8f0998b8b3533b7cd5..8a189fce5665601539f598823d7185dbefb6fff5 100644 --- a/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties +++ b/oaipmh-webapp/src/main/webapp/WEB-INF/oaipmh.textgrid.properties @@ -117,5 +117,8 @@ specFieldPrefix = project: ######################################## idiomResponseSize = 30 -# We do need a TextGrid RBAC Session ID for accessing unpublished image objects from TG-crud. -rbacSessionID = urglimurgli +# NONPUBLIC index only TextGrid IDIOM queries! +elasticSearch.nonpublicIndex = *** +# We do need a TG-crud endpoint and a TextGrid RBAC Session ID for accessing unpublished image objects from TG-crud. +idiomTgcrudEndpoint = *** +idiomRbacSessionID = *** diff --git a/pom.xml b/pom.xml index 4cc22313cd6d29fcc807ad126d7dbfa19d0668bb..b67dcbc5d733da37c32a556cd0e7a86656ac9e6d 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ <maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version> <maven-eclipse-plugin.version>2.10</maven-eclipse-plugin.version> <maven-jaxb2-plugin.version>0.14.0</maven-jaxb2-plugin.version> - <mets-mods-mapping.version>1.1.43-SNAPSHOT</mets-mods-mapping.version> + <mets-mods-mapping.version>2.0.0</mets-mods-mapping.version> <package-info-maven-plugin.version>1.4.5</package-info-maven-plugin.version> <properties-maven-plugin.version>1.0-alpha-2</properties-maven-plugin.version> <rdf4j-repository-api.version>3.0.2</rdf4j-repository-api.version> @@ -132,4 +132,4 @@ <url>https://nexus.gwdg.de/repository/maven-dariah-public/</url> </repository> </distributionManagement> -</project> \ No newline at end of file +</project>