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 d6366a3337289940626552e100262b2dda2b1cce..b16a4120ad34045c5cceef79143fd9ed0b26a4d9 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererIDIOM.java @@ -4,8 +4,14 @@ import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; -import java.util.UUID; import org.classicmayan.tools.Queries; +import org.elasticsearch.action.search.SearchResponse; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.QueryBuilder; + +import org.elasticsearch.search.SearchHit; + import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; @@ -15,7 +21,7 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstract { static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); - + private boolean foundItems; /** * @param textgrid * @param dariah @@ -35,38 +41,85 @@ public class IdentifierListDelivererIDIOM extends IdentifierListDelivererAbstrac String resTokenValue = resumptionToken; + QueryBuilder recordFilterForClassicMayan; + QueryBuilder rangeQuery; + + rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); + recordFilterForClassicMayan = QueryBuilders.boolQuery().must(rangeQuery) + .must(QueryBuilders.matchPhraseQuery("project.id", "TGPR-0e926f53-1aba-d415-ecf6-539edcd8a318")) + .must(QueryBuilders.matchPhraseQuery("format", "text/tg.inputform+rdf+xml")) + .must(QueryBuilders.matchPhraseQuery("notes", "ARTEFACT")); + ListIdentifiersType identifierList = new ListIdentifiersType(); - List<String> artefactURIs = new ArrayList<String>(); - Queries queries = new Queries(); + //List<String> artefactURIs = new ArrayList<String>(); + //Queries queries = new Queries(); + + SearchResponse scrollResp; + if (resumptionToken == null) { - artefactURIs = queries.getArtefactList(0); + //artefactURIs = queries.getArtefactList(0); + + scrollResp = OAI_ESClient.getOaiESClient() + .prepareSearch("textgrid-nonpublic") + .setScroll(TimeValue.timeValueHours(24L)) + .setTypes(OAI_ESClient.getEsType()) + .addFields("lastModified", "textgridUri", "project.id") + .setQuery(recordFilterForClassicMayan) + .setSize(30) + .execute() + .actionGet(); + // Create resumption token for every request only (we do need the same token for resuming // because we are using a hash map for counting the calls). - resTokenValue = UUID.randomUUID().toString(); + //resTokenValue = UUID.randomUUID().toString(); } else { // Use given resumption token here. - artefactURIs = queries.getArtefactList(cursorCollector.get(resumptionToken)); + scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) + .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); } - long listSize = Queries.getAmountOfArtefacts(); - int i = 0; - - for (String artefactURI : artefactURIs) { + String scrollID = scrollResp.getScrollId(); + + long completeListSize = scrollResp.getHits().totalHits(); + + //long listSize = Queries.getAmountOfArtefacts(); + if (completeListSize > 0) { + setFoundItems(true); + int i = 0; + + + for (SearchHit hit : scrollResp.getHits().getHits()) { + String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); + RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); + identifierList.getHeader() + .add(idiomRecord.getRecordById(textgridURI).getRecord().getHeader()); + } + /* for (String artefactURI : artefactURIs) { RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); identifierList.getHeader() .add(idiomRecord.getRecordById(artefactURI).getRecord().getHeader()); i++; - } - + }*/ + + // Check the need for a resumption token! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(listSize, - resumptionToken, cursorCollector, resTokenValue, 30, i); - + ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken(completeListSize, + resumptionToken, cursorCollector, scrollID, 30, i); if (resTokenForResponse != null) { identifierList.setResumptionToken(resTokenForResponse); } - + }else { + setFoundItems(false); + } return identifierList; } + + public boolean isFoundItems() { + return foundItems; + } + + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } } 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 039f823526302a33ca8c8524489fe26f925ac9c7..50b75c1a22427eacf2067912695c3314144bd6f0 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -1,11 +1,8 @@ package info.textgrid.middleware; import java.util.Hashtable; -import java.util.List; import java.util.Map; -import java.util.UUID; import org.apache.commons.logging.LogFactory; -import org.classicmayan.tools.Queries; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.query.QueryBuilder; @@ -70,7 +67,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { QueryBuilder recordFilterForClassicMayan; QueryBuilder rangeQuery; - Queries queries = new Queries(); + //Queries queries = new Queries(); //List<String> artefactURIs = queries.getArtefactList(); rangeQuery = QueryBuilders.rangeQuery("lastModified").from(from).to(to); @@ -106,14 +103,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { setFoundItems(true); int i = 0; //System.out.println("inside "); - for (SearchHit hit : scrollResp.getHits().getHits()) { - + for (SearchHit hit : scrollResp.getHits().getHits()) { i++; String textgridURI = hit.getFields().get("textgridUri").getValue().toString().replace(".0", ""); System.out.println("Processing: " + textgridURI); RecordDelivererIDIOM idiomRecord = new RecordDelivererIDIOM(true, false); recordList.getRecord().add(idiomRecord.getRecordById(textgridURI).getRecord()); - } // Check the need for a resumption token!