diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDeliverer.java b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java similarity index 87% rename from oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDeliverer.java rename to oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java index 3716ee858071db51ce0b0898e76bdb84694577c9..7b01c62769ed14439fb65af693b3c2d71877815a 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDeliverer.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/IdentifierListDelivererDC.java @@ -31,16 +31,13 @@ import org.elasticsearch.search.SearchHit; * @since 20.02.2014 */ -public class IdentifierListDeliverer { +public class IdentifierListDelivererDC extends IdentifierListDelivererAbstract { - private static org.apache.commons.logging.Log log = LogFactory.getLog(IdentifierListDeliverer.class); + private static org.apache.commons.logging.Log log = LogFactory.getLog(IdentifierListDelivererDC.class); private String datestamp; private boolean idExist = true; private OAI_ESClient oaiEsClient; - private boolean textgrid; - private boolean dariah; - private String[] identifierListFields; //Fields for the elasticsearch request private String rangeField; // Field for the optional range query private String formatToFilter; // just necessary in textgrid case to just get the editions @@ -53,7 +50,8 @@ public class IdentifierListDeliverer { private static Map<String, Integer> cursorCollector = new Hashtable<String, Integer >(); private int searchResponseSize; - + + /** * In OAIPMH a ListIdentifiers request is answered by responding the * datestamp and the identifier of an object Both will be responded in a @@ -66,12 +64,8 @@ public class IdentifierListDeliverer { * @return the ListIdentifierElement with the responded header element */ - public IdentifierListDeliverer(OAI_ESClient oaiEsClient, boolean textgrid, boolean dariah) { - this.textgrid = textgrid; - this.dariah = dariah; - this.oaiEsClient = oaiEsClient; -// System.out.println("DARIAH boolean is set to: " + dariah); -// System.out.println("TEXTGRID boolean is set to: " + textgrid); + public IdentifierListDelivererDC(boolean textgrid, boolean dariah) { + super(textgrid, dariah); } @@ -107,13 +101,12 @@ public class IdentifierListDeliverer { * : end value to the range query * @return after calling the function "setListIdentifierHeader" the return * value is the whole ListIdentifiers element - * @throws ParseException */ // FIXME combine it with with getIdentifierListWithSet and check for empty set - public ListIdentifiersType processIdentifierList(String from, String to, String set, String resumptionToken) throws ParseException { + public ListIdentifiersType processIdentifierList(String from, String to, String set, String resumptionToken) { // System.out.println("JUHU"); ListIdentifiersType lit = new ListIdentifiersType(); QueryBuilder query = setOrNot(set, from, to); @@ -125,8 +118,10 @@ public class IdentifierListDeliverer { listListIdentiferValues = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken).setScroll(new TimeValue(lifeTimeResToken)).execute().actionGet(); } else{ +// System.out.println("ELSE"); // System.out.println("JUHU3: " + searchResponseSize); // System.out.println(OAI_ESClient.getClusterName()); + listListIdentiferValues = OAI_ESClient .getOaiESClient().prepareSearch(OAI_ESClient.getEsIndex()) .setTypes(OAI_ESClient.getEsType()) @@ -137,7 +132,7 @@ public class IdentifierListDeliverer { .execute() .actionGet(); // System.out.println("DAMDAMDAM"); - + System.out.println(listListIdentiferValues.getHits().getTotalHits()); } // System.out.println("JUHU3.5"); listListIdentiferValues = hitHandling(listListIdentiferValues, lit, set, listListIdentiferValues.getScrollId()); @@ -149,6 +144,7 @@ public class IdentifierListDeliverer { public SearchResponse hitHandling(SearchResponse listFurtherValues, ListIdentifiersType lit, String set, String resumptionToken){ // System.out.println("JUHU4"); // System.out.println("FOR SET: " + set); + int i = 0; for (SearchHit hit : listFurtherValues.getHits().getHits()) { i++; @@ -203,8 +199,15 @@ public class IdentifierListDeliverer { public QueryBuilder setOrNot(String set, String from, String to){ - QueryBuilder rangeQuery = QueryBuilders.rangeQuery(rangeField).from(from).to(to); - QueryBuilder formatQuery = QueryBuilders.matchPhrasePrefixQuery("format", TextGridMimetypes.DARIAH_COLLECTION); + String filterFormat = ""; + if(textgrid==true) { + filterFormat = TextGridMimetypes.EDITION; + }else { + filterFormat = TextGridMimetypes.DARIAH_COLLECTION; + } + + QueryBuilder rangeQuery = QueryBuilders.rangeQuery(rangeField).from(from).to(to); + QueryBuilder formatQuery = QueryBuilders.matchPhrasePrefixQuery("format", filterFormat); QueryBuilder query; if(set!=null){ @@ -248,31 +251,6 @@ public class IdentifierListDeliverer { return lit; } - /** - * checking the request if all necessary values are set or not allowed - * values are not set - * - * @param request - * the initially request from the OAIPMG client - * @return a boolean indicating the correctness of the request - */ - - public boolean requestChecker(RequestType request) { - boolean requestCheck; - - if (request.getResumptionToken() != null && (request.getMetadataPrefix() != null) || request.getSet() != null ){ - requestCheck = false; - } - else { - if (request.getMetadataPrefix() == null || request.getIdentifier() != null) { - requestCheck = false; - } else { - requestCheck = true; - } - } - return requestCheck; - - } public void setFormatToFilter(String formatToFilter) { this.formatToFilter = formatToFilter; @@ -339,4 +317,14 @@ public class IdentifierListDeliverer { // System.out.println(this.searchResponseSize); } + + public OAI_ESClient getOaiEsClient() { + return oaiEsClient; + } + + + public void setOaiEsClient(OAI_ESClient oaiEsClient) { + this.oaiEsClient = oaiEsClient; + } + } 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 1f83a2867b42485e0d4320b72aa761d60d683354..80f1320eb9b6acde0e64d4b9b75375ec2d3b8956 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -33,13 +33,19 @@ public class OAIPMHImpl implements OAIPMHProducer { private ErrorHandler error = new ErrorHandler(); private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); private RepIdentification rep; + private RecordListDelivererDC recordListDC; private RecordListDelivererIDIOM recordListIDIOM; + private RecordDelivererDC recDelivDC; private RecordDelivererIDIOM recDelivIDIOM; + + private IdentifierListDelivererDC identifierListDC; + private IdentifierListDelivererIDIOM identifierListIDIOM; + private MetadataFormatListDeliverer metadataFormatList; private SetDeliverer setList; - private IdentifierListDeliverer identifierList; + public boolean textgrid; public boolean dariah; @@ -56,7 +62,7 @@ public class OAIPMHImpl implements OAIPMHProducer { */ public OAIPMHImpl(RepIdentification rep, RecordDelivererDC recDelivDC,RecordDelivererIDIOM recDelivIDIOM, RecordListDelivererDC recordListDC,RecordListDelivererIDIOM recordListIDIOM, MetadataFormatListDeliverer metadataFormatList, - SetDeliverer setList, IdentifierListDeliverer identifierList) { + SetDeliverer setList, IdentifierListDelivererDC identifierList, IdentifierListDelivererIDIOM identifierListIDIOM) { this.rep = rep; this.recDelivDC = recDelivDC; this.recDelivIDIOM = recDelivIDIOM; @@ -64,7 +70,8 @@ public class OAIPMHImpl implements OAIPMHProducer { this.recordListIDIOM = recordListIDIOM; this.metadataFormatList = metadataFormatList; this.setList = setList; - this.identifierList = identifierList; + this.identifierListDC = identifierList; + this.identifierListIDIOM = identifierListIDIOM; } /* @@ -186,7 +193,6 @@ public class OAIPMHImpl implements OAIPMHProducer { // Take IDIOM if IDIOM prefix. if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - recDeliv = this.recDelivIDIOM; } @@ -220,55 +226,34 @@ public class OAIPMHImpl implements OAIPMHProducer { */ public JAXBElement<OAIPMHType> listIdentifiersRequest(ObjectFactory obf, OAIPMHType oai, RequestType request) throws ParseException { - - List<String> errorValues = new ArrayList<String>(); - JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); - - // if (identifierList.requestChecker(request)) { - - if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) { - errorValues.add("MetadataPrefix"); - this.error.setError(TGConstants.OAI_BAD_ARGUMENT, - "The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(this.error.getError()); - } else if (request.getResumptionToken() != null && request.getSet() != null) { - errorValues.add("Set"); - this.error.setError(TGConstants.OAI_BAD_ARGUMENT, - "The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(this.error.getError()); - } else if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { - errorValues.add("MetadataPrefix"); - this.error.setError(TGConstants.OAI_BAD_ARGUMENT, - "The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(this.error.getError()); - } else if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { - this.error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR, - "The value of the metadataPrefix: " + request.getMetadataPrefix() - + " is not supported by the item identified by the value of: " - + request.getIdentifier()); - oai.getError().add(this.error.getError()); - } else { - // System.out.println("bla1000"); - if (request.getResumptionToken() != null - && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken())) { - this.error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, - "The value of the resumptionToken argument is invalid or expired"); - oai.getError().add(this.error.getError()); - } else { - this.lit = this.identifierList.processIdentifierList(request.getFrom(), request.getUntil(), - request.getSet(), request.getResumptionToken()); - if (this.lit != null) { - // System.out.println("bla2000"); - oai.setListIdentifiers(this.lit); - } else { - this.error.setError(TGConstants.OAI_NO_RECORD_MATCH, "The combination of the values " - + request.getFrom() + " and " + request.getUntil() + " results in an empty list"); - oai.getError().add(this.error.getError()); - } - } - } - + + JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); + ErrorHandler requestErrors = IdentifierListDelivererAbstract.requestChecker(request); + + if (requestErrors.getError().getCode() != null) { + oai.getError().add(requestErrors.getError()); + }else { + // Default is DC. + IdentifierListDelivererInterface listDeliv = this.identifierListDC; + + // Take IDIOM if IDIOM prefix. + if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { + listDeliv = this.identifierListIDIOM; + } + ListIdentifiersType listIdentifiers = new ListIdentifiersType(); + listIdentifiers = listDeliv.processIdentifierList(request.getFrom(), request.getUntil(), + request.getSet(), request.getResumptionToken()); + + if(listIdentifiers!=null) { + oai.setListIdentifiers(listIdentifiers); + }else { + ErrorHandler idError = new ErrorHandler(); + idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " + + request.getIdentifier() + " is unknown or illegal in this repository"); + oai.getError().add(idError.getError()); + } + } + return oaipmhRoot; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java index a8d9b39ed3cebb2c883dfff641892a4708c0f1e8..628bb5d0b65e525105d1e352e74f59dc7245355e 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtillities.java @@ -146,8 +146,7 @@ public class OAIPMHUtillities { // need to check hash map! // 2. Complete list size is > 100 and we have no token: we do need one! // 3. Complete list size is <= 100 (we do not need a token! do nothing!) - System.out.println("TEST"); - System.out.println("completeListSize: " + completeListSize); + if (completeListSize > 100) { ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); 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 94f4730b76c1b9efcecbf7e0928f3cd736324c79..6af7ce1f9774c25bbcaed1ee3de930675dcdfd7e 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java @@ -96,7 +96,11 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { dateOfLastOblectModification); record.setMetadata(idiomMets()); try { - setRecordHeader(dateOfObjectCreation, "textgrid:" + id); + if(!id.startsWith("textgrid:")) { + setRecordHeader(dateOfObjectCreation, "textgrid:" + id); + }else { + setRecordHeader(dateOfObjectCreation, id); + } } catch (ParseException e) { e.printStackTrace(); //log.error(e.printStackTrace()); diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java index a8b8cc085eb019630916e3b8b28a541f9ee690bb..0b6da0d390e677a985fe664528b09b375f5a238c 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTest.java @@ -41,16 +41,18 @@ public class OaiPmhTest { private static RecordListDelivererDC recordList; private static RecordListDelivererIDIOM recordListIDIOM; - + + private static IdentifierListDelivererDC identifierList; + private static IdentifierListDelivererIDIOM identifierListIDIOM = new IdentifierListDelivererIDIOM(true, false); // TGConstants.TGWorkFields, true, false); private MetadataFormatListDeliverer metadataFormatList = new MetadataFormatListDeliverer(oaiEsClient); private SetDeliverer setListDARIAH = new SetDeliverer(oaiEsClient, false, true); private SetDeliverer setListTextGrid = new SetDeliverer(oaiEsClient, true, false); // private IdentifierListDeliverer identifierList = new IdentifierListDeliverer(oaiEsClient, // false, true); - private IdentifierListDeliverer identifierList = new IdentifierListDeliverer(oaiEsClient, true, false); + private OAIPMHImpl request = new OAIPMHImpl(this.rep, OaiPmhTest.record, OaiPmhTest.recordIDIOM, OaiPmhTest.recordList, - OaiPmhTest.recordListIDIOM, this.metadataFormatList, this.setListDARIAH, this.identifierList); + OaiPmhTest.recordListIDIOM, this.metadataFormatList, this.setListDARIAH, OaiPmhTest.identifierList, OaiPmhTest.identifierListIDIOM); /** * @throws Exception @@ -82,7 +84,11 @@ public class OaiPmhTest { recordList.setSearchResponseSize("10"); recordListIDIOM = new RecordListDelivererIDIOM(true, false); - recordListIDIOM.setOaiEsClient(oaiEsClient); + recordListIDIOM.setOaiEsClient(oaiEsClient); + + identifierList = new IdentifierListDelivererDC(true, false); + identifierList.setOaiEsClient(oaiEsClient); + identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); } /** @@ -299,22 +305,35 @@ public class OaiPmhTest { @Test @Ignore public void testListIdentifierSets() throws ParseException { - this.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); - this.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); - this.identifierList.setFormatField(TGConstants.FORMAT); - this.identifierList.setFormatToFilter(TextGridMimetypes.EDITION); - this.identifierList.setDateOfObjectCreation(TGConstants.CREATED); - this.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); - this.identifierList.setIdentifierField("textgridUri"); - + OaiPmhTest.identifierList.setFieldForRange(TGConstants.RANGE_FIELD); + OaiPmhTest.identifierList.setIdentifierListFields(TGConstants.IDENTIFIER_LIST_FIELDS); + OaiPmhTest.identifierList.setFormatField(TGConstants.FORMAT); + OaiPmhTest.identifierList.setFormatToFilter(TextGridMimetypes.EDITION); + OaiPmhTest.identifierList.setDateOfObjectCreation(TGConstants.CREATED); + OaiPmhTest.identifierList.setRepositoryObjectURIPrefix(TGConstants.ITEM_IDENTIFIER_PREFIX); + OaiPmhTest.identifierList.setIdentifierField("textgridUri"); + OaiPmhTest.identifierList.setSearchResponseSize("100"); System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); JAXBElement<OAIPMHType> p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "project:TGPR-26236625-1acc-b921-a5fa-53567c3eeb80", "", "", ""); JAXB.marshal(p, System.out); System.out.println("-----------------------------------\n"); + //project:TGPR-26236625-1acc-b921-a5fa-53567c3eeb80 } + @Test + //@Ignore + public void testListIdentifierIDIOM() throws ParseException { + + System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); + JAXBElement<OAIPMHType> p = this.request.getRequest("ListIdentifiers", "", TGConstants.METADATA_IDIOM_PREFIX, + "", "", "", ""); + JAXB.marshal(p, System.out); + System.out.println("-----------------------------------\n"); + + } + /** * @throws ParseException */ @@ -355,7 +374,7 @@ public class OaiPmhTest { } @Test - //@Ignore + @Ignore public void testListRecordSetsForIDIOM() throws ParseException { System.out.println("Test for the verb \"ListRecords\" for IDIOM with succesfull response");