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 e8d3f3c5d4830c59126ff192f3743676f507a5f5..1fe528d9d5f6c97fc1a6122bcaa79d5a08fb6306 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -83,19 +83,19 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param identifierListIDIOM */ public OAIPMHImpl( - RepIdentification rep, //0 - RecordDelivererDC recDelivDC, //1 - RecordDelivererIDIOM recDelivIDIOM, //2 - OpenAireRecord openAireRecord, //3 - RecordListDelivererDC recordListDC, //4 - RecordListDelivererIDIOM recordListIDIOM, //5 - OpenAireRecordList openAireRecordList, //6 - MetadataFormatListDeliverer metadataFormatList, //7 - SetDeliverer setList, //8 - IdentifierListDelivererDC identifierList, //9 - IdentifierListDelivererIDIOM identifierListIDIOM, //10 - OpenAireIdentifierList openAireIdentifierList //11 - ) { + RepIdentification rep, // 0 + RecordDelivererDC recDelivDC, // 1 + RecordDelivererIDIOM recDelivIDIOM, // 2 + OpenAireRecord openAireRecord, // 3 + RecordListDelivererDC recordListDC, // 4 + RecordListDelivererIDIOM recordListIDIOM, // 5 + OpenAireRecordList openAireRecordList, // 6 + MetadataFormatListDeliverer metadataFormatList, // 7 + SetDeliverer setList, // 8 + IdentifierListDelivererDC identifierList, // 9 + IdentifierListDelivererIDIOM identifierListIDIOM, // 10 + OpenAireIdentifierList openAireIdentifierList // 11 + ) { this.rep = rep; this.recDelivDC = recDelivDC; this.recDelivIDIOM = recDelivIDIOM; @@ -122,11 +122,10 @@ public class OAIPMHImpl implements OAIPMHProducer { String result = ""; try { - result = getStringFromJAXBOAIElement(verb, handleRequest(verb, identifier, metadataPrefix, set, from, until, resumptionToken)); - - } catch (ParseException e) { + + } catch (ParseException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -144,19 +143,19 @@ public class OAIPMHImpl implements OAIPMHProducer { String set, String from, String until, String resumptionToken) { String result = ""; - + try { result = getStringFromJAXBOAIElement(verb, handleRequest( - verb, - identifier, - metadataPrefix, - set, - from, - until, - resumptionToken)); - - } catch (ParseException e) { + verb, + identifier, + metadataPrefix, + set, + from, + until, + resumptionToken)); + + } catch (ParseException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } @@ -257,28 +256,31 @@ public class OAIPMHImpl implements OAIPMHProducer { if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { recDeliv = this.recDelivIDIOM; } - if(request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)) { - recDeliv = this.openAireRecord; + if (request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)) { + recDeliv = this.openAireRecord; } - + // Finally start the QUERY! GetRecordType getRecord = new GetRecordType(); String id = request.getIdentifier(); try { - getRecord = recDeliv.getRecordById(id); - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (DatatypeConfigurationException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + getRecord = recDeliv.getRecordById(id); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (DatatypeConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if (getRecord != null) { oaipmhRoot.setGetRecord(getRecord); } else { - ErrorHandler idError = new ErrorHandler(); + ErrorHandler idError = new ErrorHandler(); idError.setError(TGConstants.OAI_ID_DOES_NOT_EXIST, "No matching identifier "); oaipmhRoot.getError().add(idError.getError()); } @@ -312,10 +314,10 @@ public class OAIPMHImpl implements OAIPMHProducer { if (request.getMetadataPrefix() != null) { if (request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)) { idListDeliv = this.identifierListDC; - } else if(request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - idListDeliv = this.identifierListIDIOM; - } else if(request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)) { - idListDeliv = this.openAireIdentifierList; + } else if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { + idListDeliv = this.identifierListIDIOM; + } else if (request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)) { + idListDeliv = this.openAireIdentifierList; } } @@ -328,21 +330,22 @@ public class OAIPMHImpl implements OAIPMHProducer { && IdentifierListDelivererIDIOM.cursorCollector .containsKey(request.getResumptionToken()); boolean restokOpenAireExisting = OAIPMHUtilities.cursorCollector != null - && IdentifierListDelivererAbstract.cursorCollector.containsKey(request.getResumptionToken()); + && IdentifierListDelivererAbstract.cursorCollector + .containsKey(request.getResumptionToken()); if (restokDCExisting) { idListDeliv = this.identifierListDC; } else if (restokIDIOMExisting) { - idListDeliv = this.identifierListIDIOM; + idListDeliv = this.identifierListIDIOM; } else if (restokOpenAireExisting) { - idListDeliv = this.openAireIdentifierList; + idListDeliv = this.openAireIdentifierList; } } ListIdentifiersType listIdentifiers = null; try { - System.out.println("GET FROM: " + request.getFrom()); - System.out.println("GET UNTIL: " + request.getUntil()); - + System.out.println("GET FROM: " + request.getFrom()); + System.out.println("GET UNTIL: " + request.getUntil()); + listIdentifiers = idListDeliv.processIdentifierList(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); } catch (IOException e) { @@ -351,7 +354,7 @@ public class OAIPMHImpl implements OAIPMHProducer { } if (listIdentifiers != null) { - oaipmhRoot.setListIdentifiers(listIdentifiers); + oaipmhRoot.setListIdentifiers(listIdentifiers); } else { ErrorHandler idError = new ErrorHandler(); idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " @@ -377,38 +380,34 @@ public class OAIPMHImpl implements OAIPMHProducer { ListSetsType sl = this.setList.setListBuilder(); - if (this.setList.requestChecker(request)) { - oaipmhRoot.setListSets(sl); - }else { - List<String> errorValues = new ArrayList<String>(); - ErrorHandler badArgument = new ErrorHandler(); - if (request.getIdentifier() != null) { - errorValues.add("identifier"); - } - if (request.getFrom() != null) { - errorValues.add("from"); - } - if (request.getMetadataPrefix() != null) { - errorValues.add("metadataPrefix"); - } - if (request.getResumptionToken() != null) { - errorValues.add("ResumptionToken"); - } - if (request.getUntil() != null) { - errorValues.add("until"); - } - if (request.getSet() != null) { - errorValues.add("set"); - } - - badArgument.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments: " + errorValues); - oaipmhRoot.getError().add(badArgument.getError()); - } + oaipmhRoot.setListSets(sl); + } else { + List<String> errorValues = new ArrayList<String>(); + ErrorHandler badArgument = new ErrorHandler(); + if (request.getIdentifier() != null) { + errorValues.add("identifier"); + } + if (request.getFrom() != null) { + errorValues.add("from"); + } + if (request.getMetadataPrefix() != null) { + errorValues.add("metadataPrefix"); + } + if (request.getResumptionToken() != null) { + errorValues.add("ResumptionToken"); + } + if (request.getUntil() != null) { + errorValues.add("until"); + } + if (request.getSet() != null) { + errorValues.add("set"); + } - - - + badArgument.setError(TGConstants.OAI_BAD_ARGUMENT, + "The request includes illegal arguments: " + errorValues); + oaipmhRoot.getError().add(badArgument.getError()); + } return oaipmhRoot; } @@ -472,9 +471,11 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param oai * @param request * @return - * @throws ParseException + * @throws ParseException + * @throws IOException */ - public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) throws ParseException { + public OAIPMHtype listRecordsRequest(OAIPMHtype oaipmhRoot, RequestType request) + throws ParseException, IOException { // Check request's syntax. ErrorHandler requestErrors = RecordListDelivererAbstract.requestChecker(request); @@ -486,17 +487,17 @@ public class OAIPMHImpl implements OAIPMHProducer { // If metadataFormat IS SET, set recordListDeliverer accordingly. RecordListDelivererInterface recListDeliv = null; if (request.getMetadataPrefix() != null) { - if(request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)) { + if (request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)) { recListDeliv = this.recordListDC; - } - if(request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)){ + } + if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { recListDeliv = this.recordListIDIOM; } - if(request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)){ + if (request.getMetadataPrefix().equals(TGConstants.METADATA_OPENAIRE_PREFIX)) { recListDeliv = this.openAireRecordList; } } - + // If metadata format IS NOT SET, check resumption token hash maps to decide if we have to // serve oai_dc or idiom_mets metadata format. else { @@ -504,37 +505,37 @@ public class OAIPMHImpl implements OAIPMHProducer { && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); boolean restokIDIOMExisting = RecordListDelivererIDIOM.cursorCollector != null && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); -//<<<<<<< HEAD -// -//======= + // <<<<<<< HEAD + // + // ======= boolean restokOpenAireExisting = RecordListDelivererAbstract.cursorCollector != null - && RecordListDelivererAbstract.cursorCollector.containsKey(request.getResumptionToken()); -//>>>>>>> feature/elastic6 + && RecordListDelivererAbstract.cursorCollector + .containsKey(request.getResumptionToken()); + // >>>>>>> feature/elastic6 if (restokDCExisting) { recListDeliv = this.recordListDC; } else if (restokIDIOMExisting) { - + recListDeliv = this.recordListIDIOM; - } else if (restokOpenAireExisting) { + } else if (restokOpenAireExisting) { recListDeliv = this.openAireRecordList; - } - } + } + } - ListRecordsType listRecords = recListDeliv. - getRecords( - request.getFrom(), - request.getUntil(), + ListRecordsType listRecords = recListDeliv.getRecords( + request.getFrom(), + request.getUntil(), request.getSet(), request.getResumptionToken()); if (listRecords != null) { - /*if (this.recordListDC.getResultSize() == 0) { - requestErrors.setError("RecordMatchError", - "The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list."); - oaipmhRoot.getError().add(requestErrors.getError()); - } else {*/ - oaipmhRoot.setListRecords(listRecords); - //} + /* + * if (this.recordListDC.getResultSize() == 0) { requestErrors.setError("RecordMatchError", + * "The combination of the values of the from, until, set and metadataPrefix arguments results in an empty list." + * ); oaipmhRoot.getError().add(requestErrors.getError()); } else { + */ + oaipmhRoot.setListRecords(listRecords); + // } } } @@ -553,19 +554,19 @@ public class OAIPMHImpl implements OAIPMHProducer { VerbType verbParam = null; - if (verb!=null && verb.equals("Identify")) { + if (verb != null && verb.equals("Identify")) { verbParam = VerbType.IDENTIFY; - } else if (verb!=null && verb.equals("ListMetadataFormats")) { + } else if (verb != null && verb.equals("ListMetadataFormats")) { verbParam = VerbType.LIST_METADATA_FORMATS; - } else if (verb!=null && verb.equals("ListSets")) { + } else if (verb != null && verb.equals("ListSets")) { verbParam = VerbType.LIST_SETS; - } else if (verb!=null && verb.equals("ListIdentifiers")) { + } else if (verb != null && verb.equals("ListIdentifiers")) { verbParam = VerbType.LIST_IDENTIFIERS; - } else if (verb!=null && verb.equals("ListRecords")) { + } else if (verb != null && verb.equals("ListRecords")) { verbParam = VerbType.LIST_RECORDS; - } else if (verb!=null && verb.equals("GetRecord")) { + } else if (verb != null && verb.equals("GetRecord")) { verbParam = VerbType.GET_RECORD; - }else if (verb!=null && verb.length()>0){ + } else if (verb != null && verb.length() > 0) { this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); } @@ -679,10 +680,11 @@ public class OAIPMHImpl implements OAIPMHProducer { * @param resumptionToken * @return * @throws ParseException + * @throws IOException */ private JAXBElement<OAIPMHtype> handleRequest(String verb, String identifier, String metadataPrefix, String set, String from, String until, String resumptionToken) - throws ParseException { + throws ParseException, IOException { JAXBElement<OAIPMHtype> result; @@ -732,16 +734,17 @@ public class OAIPMHImpl implements OAIPMHProducer { } else if (verbParam.value().equals("ListRecords")) { response = listRecordsRequest(response, request); } - } else { - if(this.error.getError().getValue()!=null && this.error.getError().getValue().equals("Illegal OAI verb")){ - this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); - response.getError().add(this.error.getError()); - }else { - this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); - response.getError().add(this.error.getError()); - } + } else { + if (this.error.getError().getValue() != null + && this.error.getError().getValue().equals("Illegal OAI verb")) { + this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + } else { + this.error.setError(TGConstants.OAI_VERB_ERROR, "Illegal OAI verb"); + response.getError().add(this.error.getError()); + } } - + response.setRequest(request); result = obf.createOAIPMH(response); @@ -767,7 +770,7 @@ public class OAIPMHImpl implements OAIPMHProducer { String schemaLocations = OAIPMHUtilities.OAIPMH_NAMESPACE + " " + OAIPMHUtilities.OAIPMH_SCHEMA_LOCATION; // Add OAI_DC and DC schema location if needed. - if (theVerb!=null && (theVerb.equals("GetRecord") || theVerb.endsWith("ListRecords"))) { + if (theVerb != null && (theVerb.equals("GetRecord") || theVerb.endsWith("ListRecords"))) { schemaLocations += OAIPMHUtilities.OAIDC_NAMESPACE + " " + OAIPMHUtilities.OAIDC_SCHEMA_LOCATION + " " + OAIPMHUtilities.DC_NAMESPACE + " " + OAIPMHUtilities.DC_SCHEMA_LOCATION; @@ -798,4 +801,4 @@ public class OAIPMHImpl implements OAIPMHProducer { return result; } -} \ No newline at end of file +} 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 ec8064c850509e7ced4a3f2e32bc7b5fdc56b354..3db63f06952687fe2aec68bfd27eb90e36636065 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHUtilities.java @@ -17,7 +17,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; import java.util.TimeZone; - import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; @@ -29,7 +28,6 @@ import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; - import org.apache.commons.io.IOUtils; import org.apache.commons.logging.LogFactory; import org.elasticsearch.action.get.GetRequest; @@ -47,7 +45,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.json.JSONException; import org.json.JSONObject; - import info.textgrid.clients.AuthClient; import info.textgrid.clients.tgauth.AuthClientException; import info.textgrid.middleware.oaipmh.GetRecordType; @@ -70,7 +67,7 @@ import info.textgrid.middleware.common.TextGridMimetypes; * </p> * * @author Maximilian Brodhun, SUB Göttingen - * @version 2019-10-29 + * @version 2021-05-20 * @since 2014-01-29 */ public class OAIPMHUtilities { @@ -91,10 +88,15 @@ public class OAIPMHUtilities { "https://dublincore.org/schemas/xmls/simpledc20021212.xsd"; public static final String METS_NAMESPACE = "http://www.loc.gov/METS/"; public static final String METS_SCHEMA_LOCATION = "http://www.loc.gov/standards/mets/mets.xsd"; - - public static final String OPEN_AIRE_SCHEMA_LOCATION = "https://www.openaire.eu/schema/1.0/oaf-1.0.xsd"; - public static final String OPEN_AIRE_NAMESPACE ="oai_datacite"; - + + public static final String OPEN_AIRE_SCHEMA_LOCATION = + "https://www.openaire.eu/schema/1.0/oaf-1.0.xsd"; + public static final String OPEN_AIRE_NAMESPACE = "oai_datacite"; + + // ** + // CLASS + // ** + private String rangeField; private long resultSize; private boolean foundItems; @@ -102,8 +104,11 @@ public class OAIPMHUtilities { private ResumptionTokenType resTokenForResponse; private String formatToFilter; private int searchResponseSize; - - + + // ** + // STATICS + // ** + protected static Map<String, Integer> cursorCollector = new Hashtable<String, Integer>(); // ** @@ -112,13 +117,15 @@ public class OAIPMHUtilities { private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); - - public static boolean isOAIPMH_RequestArgument(String verb){ - String allowedArgument= "^[identifier,from,until,set,resumptionToken,metadataPrefix]*$"; - return verb.matches(allowedArgument); + /** + * @param verb + * @return + */ + public static boolean isOAIPMH_RequestArgument(String verb) { + String allowedArgument = "^[identifier,from,until,set,resumptionToken,metadataPrefix]*$"; + return verb.matches(allowedArgument); } - - + /** * <p> * Since TextGrid just supports DC the only returned MetadataFormat is DublinCore. @@ -136,20 +143,29 @@ public class OAIPMHUtilities { return tgDublinCore; } + /** + * @return + * @throws AuthClientException + */ public static List<ProjectInfo> getProjectList() throws AuthClientException { - AuthClient auth = new AuthClient(); - List<ProjectInfo> projectInfos =auth.getAllProjects(); - auth.getAllProjects(); - - return projectInfos; + + AuthClient auth = new AuthClient(); + List<ProjectInfo> projectInfos = auth.getAllProjects(); + auth.getAllProjects(); + + return projectInfos; } - + + /** + * @param projectID + * @return + * @throws AuthClientException + */ public static String getProjectName(String projectID) throws AuthClientException { - - AuthClient auth = new AuthClient(); - return auth.getProjectInfo(projectID).getName(); + AuthClient auth = new AuthClient(); + return auth.getProjectInfo(projectID).getName(); } - + /** * <p> * Producing the list of all metadata formats. @@ -204,7 +220,7 @@ public class OAIPMHUtilities { outFormatter.setTimeZone(TimeZone.getTimeZone("UTC")); String output2 = outFormatter.format(date); XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(output2); - + return xmlCal; } @@ -245,66 +261,69 @@ public class OAIPMHUtilities { * @return A resumption token if applicable, null otherwise. */ public static ResumptionTokenType getResumptionToken(final long completeListSize, -//<<<<<<< HEAD -// final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, -// final int searchResponseSize, final int i) { -// -// log.info("Creating a ResumptionToken:\n " + -// "CompleteListSize: " + completeListSize + "\n" + -// "ResumptionToken: " + resumptionToken + "\n" + -// "CursorCollector: " + cursorCollector + "\n" + -// "ScrollID: " + scrollID + "\n" + -// "SearchResponseSize: " + scrollID + "\n" + -// "IterationStep: " + i); -// -// int cursor; -// -// // Three cases here: -// // 1. Complete list size is > searchResponseSize and a token already is existing: we need to -// // check hash map! -// // 2. Complete list size is > searchResponseSize and we have no token: we do need one! -// // 3. Complete list size is <= searchResponseSize (we do not need a token! do nothing!) -// -// if (completeListSize > searchResponseSize) { -// ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); -// -// if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { -// cursor = cursorCollector.get(resumptionToken).intValue() + i; -// if(cursor-searchResponseSize == 0) { -// cursor *= 2; -// } -// resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); -// cursorCollector.put(scrollID, cursor); -// } else { -// resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); -// cursorCollector.put(scrollID, searchResponseSize); -// cursor = searchResponseSize; -// resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); -// -// } -// -// // Set resumption token string if cursor is less then complete list size: More objects can be -// // delivered! -// if (cursor < completeListSize) { -// resTokenForResponse.setValue(scrollID); -// } -// -// // Remove resumption token string if cursor is bigger then or equal complete list size: This -// // is the last response, no more objects are available! -// if (cursor >= completeListSize) { -// //cursor =; -// resTokenForResponse.setValue(""); -// } -// -// // Set complete list size. -// resTokenForResponse.setCompleteListSize(BigInteger.valueOf(completeListSize)); -// -// return resTokenForResponse; -// } -// -// return null; -// } -//======= + // <<<<<<< HEAD + // final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, + // final int searchResponseSize, final int i) { + // + // log.info("Creating a ResumptionToken:\n " + + // "CompleteListSize: " + completeListSize + "\n" + + // "ResumptionToken: " + resumptionToken + "\n" + + // "CursorCollector: " + cursorCollector + "\n" + + // "ScrollID: " + scrollID + "\n" + + // "SearchResponseSize: " + scrollID + "\n" + + // "IterationStep: " + i); + // + // int cursor; + // + // // Three cases here: + // // 1. Complete list size is > searchResponseSize and a token already is existing: we need + // to + // // check hash map! + // // 2. Complete list size is > searchResponseSize and we have no token: we do need one! + // // 3. Complete list size is <= searchResponseSize (we do not need a token! do nothing!) + // + // if (completeListSize > searchResponseSize) { + // ResumptionTokenType resTokenForResponse = new ResumptionTokenType(); + // + // if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { + // cursor = cursorCollector.get(resumptionToken).intValue() + i; + // if(cursor-searchResponseSize == 0) { + // cursor *= 2; + // } + // resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + // cursorCollector.put(scrollID, cursor); + // } else { + // resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); + // cursorCollector.put(scrollID, searchResponseSize); + // cursor = searchResponseSize; + // resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); + // + // } + // + // // Set resumption token string if cursor is less then complete list size: More objects can + // be + // // delivered! + // if (cursor < completeListSize) { + // resTokenForResponse.setValue(scrollID); + // } + // + // // Remove resumption token string if cursor is bigger then or equal complete list size: + // This + // // is the last response, no more objects are available! + // if (cursor >= completeListSize) { + // //cursor =; + // resTokenForResponse.setValue(""); + // } + // + // // Set complete list size. + // resTokenForResponse.setCompleteListSize(BigInteger.valueOf(completeListSize)); + // + // return resTokenForResponse; + // } + // + // return null; + // } + // ======= final String resumptionToken, Map<String, Integer> cursorCollector, final String scrollID, final int searchResponseSize, final int i) { @@ -329,22 +348,22 @@ public class OAIPMHUtilities { if (resumptionToken != null && cursorCollector.containsKey(resumptionToken)) { cursor = cursorCollector.get(resumptionToken).intValue() + i; - if(cursor == 100) { - cursor = 200; + if (cursor == 100) { + cursor = 200; } resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); cursorCollector.put(scrollID, cursor); } else { resTokenForResponse.setCursor(BigInteger.valueOf(searchResponseSize)); - cursorCollector.put(scrollID, searchResponseSize); + cursorCollector.put(scrollID, searchResponseSize); cursor = 100; resTokenForResponse.setCursor(BigInteger.valueOf((long) cursor)); - + } // Set resumption token string if cursor is less then complete list size: More objects can be // delivered! - if (cursor < completeListSize) { + if (cursor < completeListSize) { resTokenForResponse.setValue(scrollID); } @@ -362,364 +381,400 @@ public class OAIPMHUtilities { return null; } - - public static boolean isThisDateValid(String dateToValidate){ - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); - - dateFormat.setLenient(false); - try { - dateFormat.parse(dateToValidate.trim()); - } catch (ParseException pe) { - return false; - } - return true; - } - - public static boolean isThisDateValidToOtherTimeStamp(String dateToValidate){ - - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); - - dateFormat.setLenient(false); - dateFormat.setLenient(false); - try { - dateFormat.parse(dateToValidate.trim()); - } catch (ParseException pe) { - return false; - } - return true; - } - - - private static final String[] formats = { - "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ssZ", - "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", - "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss", - "MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'", - "MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS", - "MM/dd/yyyy'T'HH:mm:ssZ", "MM/dd/yyyy'T'HH:mm:ss", - "yyyy:MM:dd HH:mm:ss", "yyyyMMdd", }; - - - public static String getFormatOfDate(String d) { - if (d != null) { - for (String parse : formats) { - SimpleDateFormat sdf = new SimpleDateFormat(parse); - try { - sdf.parse(d); - return parse; - } catch (ParseException e) { - - } - } - } - return d; - } -//>>>>>>> feature/elastic6 - - - public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields){ - - List<String> fieldResulsts = new ArrayList<String>(); - - for(String field : fields) { - String[] fieldPathForESIndex = field.split("\\."); - JSONObject singlePath=resultFromGetRequestInES; - for(int i=0; i<fieldPathForESIndex.length;i++) { - if(i<fieldPathForESIndex.length-1) { - try { - singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); - }catch(JSONException notFound) { - return null; - } - }else if(fieldPathForESIndex.length == 1){ - fieldResulsts.add(resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString()); - }else { - fieldResulsts.add(singlePath.get(fieldPathForESIndex[i]).toString()); - } - } - } - - return fieldResulsts; + + /** + * @param dateToValidate + * @return + */ + public static boolean isThisDateValid(String dateToValidate) { + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S"); + + dateFormat.setLenient(false); + try { + dateFormat.parse(dateToValidate.trim()); + } catch (ParseException pe) { + return false; } - - public static String fieldLoader(JSONObject resultFromGetRequestInES, String field){ - - String fieldResulst = ""; - - String[] fieldPathForESIndex = field.split("\\."); - JSONObject singlePath=resultFromGetRequestInES; - for(int i=0; i<fieldPathForESIndex.length;i++) { - - if(i<fieldPathForESIndex.length-1) { - try { - singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); - }catch(JSONException notFound) { - return null; - } - }else if(fieldPathForESIndex.length == 1){ - //System.out.println(fieldPathForESIndex[i]); - fieldResulst = resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString(); - }else { - try { - fieldResulst = singlePath.get(fieldPathForESIndex[i]).toString(); - }catch(JSONException notFound) { - return null; - } - } - } - - - return fieldResulst; + return true; + } + + /** + * @param dateToValidate + * @return + */ + public static boolean isThisDateValidToOtherTimeStamp(String dateToValidate) { + + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); + + dateFormat.setLenient(false); + dateFormat.setLenient(false); + try { + dateFormat.parse(dateToValidate.trim()); + } catch (ParseException pe) { + return false; } - - /** - * - * @param idInElasticSearchIndex - * @param includes including the fields to fetch from the elastic search index - * @param excludes excluding the fields to fetch from the elastic search index - * @return - */ - public static GetResponse getRcordByIDFromElasticSearch(String idInElasticSearchIndex, String[] includes, String[] excludes) { - //Including and excluding the fields to fetch from the elastic search index - - //Setting the source context for fetching the fields from the elastic search index - FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); - //System.out.println("INDEX: " + OAI_ESClient.getEsIndex()); - //Building the getRequest against the elastic search index - GetRequest getRequest = - new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), idInElasticSearchIndex) - .fetchSourceContext(fetchSourceContext); - - //Declaration of the result from the get-reuest - GetResponse esResultObject = null; - - try { - esResultObject = - OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); - - } catch (IOException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - log.error("Could not fetch the result of ElasticSearch"); - } - //System.out.println("STRANGE: "); - //System.out.println(esResultObject.getSourceAsString()); - return esResultObject; + return true; + } + + /** + * + */ + private static final String[] formats = { + "yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ssZ", + "yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", + "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss", + "MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'", + "MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS", + "MM/dd/yyyy'T'HH:mm:ssZ", "MM/dd/yyyy'T'HH:mm:ss", + "yyyy:MM:dd HH:mm:ss", "yyyyMMdd",}; + + /** + * @param d + * @return + */ + public static String getFormatOfDate(String d) { + if (d != null) { + for (String parse : formats) { + SimpleDateFormat sdf = new SimpleDateFormat(parse); + try { + sdf.parse(d); + return parse; + } catch (ParseException e) { + + } + } } - - public static void marshal(Resource resource) throws JAXBException { - JAXBContext jc = JAXBContext.newInstance(Resource.class); - Marshaller marshaller = jc.createMarshaller(); - StringWriter stringWriter = new StringWriter(); - marshaller.marshal(resource, stringWriter ); - marshaller.marshal(resource, System.out); + return d; + } + // >>>>>>> feature/elastic6 + + /** + * @param resultFromGetRequestInES + * @param fields + * @return + */ + public static List<String> fieldLoader(JSONObject resultFromGetRequestInES, String[] fields) { + + List<String> fieldResulsts = new ArrayList<String>(); + + for (String field : fields) { + String[] fieldPathForESIndex = field.split("\\."); + JSONObject singlePath = resultFromGetRequestInES; + for (int i = 0; i < fieldPathForESIndex.length; i++) { + if (i < fieldPathForESIndex.length - 1) { + try { + singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); + } catch (JSONException notFound) { + return null; + } + } else if (fieldPathForESIndex.length == 1) { + fieldResulsts.add(resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString()); + } else { + fieldResulsts.add(singlePath.get(fieldPathForESIndex[i]).toString()); + } + } } - - - public static GetRecordType getRecordType(Object metadata, HeaderType header) { - - MetadataType metadataType = new MetadataType(); - RecordType recordType = new RecordType(); - GetRecordType getRecordType = new GetRecordType(); - - metadataType.setAny(metadata); - recordType.setMetadata(metadataType); - recordType.setHeader(header); - getRecordType.setRecord(recordType); - - return getRecordType; + + return fieldResulsts; + } + + /** + * @param resultFromGetRequestInES + * @param field + * @return + */ + public static String fieldLoader(JSONObject resultFromGetRequestInES, String field) { + + String fieldResulst = ""; + + String[] fieldPathForESIndex = field.split("\\."); + JSONObject singlePath = resultFromGetRequestInES; + for (int i = 0; i < fieldPathForESIndex.length; i++) { + + if (i < fieldPathForESIndex.length - 1) { + try { + singlePath = singlePath.getJSONObject(fieldPathForESIndex[i]); + } catch (JSONException notFound) { + return null; + } + } else if (fieldPathForESIndex.length == 1) { + // System.out.println(fieldPathForESIndex[i]); + fieldResulst = resultFromGetRequestInES.get(fieldPathForESIndex[i]).toString(); + } else { + try { + fieldResulst = singlePath.get(fieldPathForESIndex[i]).toString(); + } catch (JSONException notFound) { + return null; + } + } } - - public static String[][] fetchArrayFromPropFile(String propertyName, Properties propFile) { - //get array split up by the semicolin - String[] a = propFile.getProperty(propertyName).split(";"); + return fieldResulst; + } + + /** + * @param idInElasticSearchIndex The ID to get the ES record from. + * @param includes Including the fields to fetch from the elastic search index. + * @param excludes Excluding the fields to fetch from the elastic search index. + * @return + * @throws IOException + */ + protected static GetResponse getRcordByIDFromElasticSearch(String idInElasticSearchIndex, + String[] includes, String[] excludes) throws IOException { + + // Setting the source context for fetching the fields from the elastic search index + FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + + // Building the getRequest against the elastic search index + GetRequest getRequest = + new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), idInElasticSearchIndex) + .fetchSourceContext(fetchSourceContext); + + // Declaration of the result from the get-reuest + GetResponse esResultObject = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + + return esResultObject; + } + + /** + * @param resource + * @throws JAXBException + */ + public static void marshal(Resource resource) throws JAXBException { + JAXBContext jc = JAXBContext.newInstance(Resource.class); + Marshaller marshaller = jc.createMarshaller(); + StringWriter stringWriter = new StringWriter(); + marshaller.marshal(resource, stringWriter); + marshaller.marshal(resource, System.out); + } + + /** + * @param metadata + * @param header + * @return + */ + public static GetRecordType getRecordType(Object metadata, HeaderType header) { + + MetadataType metadataType = new MetadataType(); + RecordType recordType = new RecordType(); + GetRecordType getRecordType = new GetRecordType(); + + metadataType.setAny(metadata); + recordType.setMetadata(metadataType); + recordType.setHeader(header); + getRecordType.setRecord(recordType); + + return getRecordType; + } + + /** + * @param propertyName + * @param propFile + * @return + */ + public static String[][] fetchArrayFromPropFile(String propertyName, Properties propFile) { + + // Get array split up by the semicolon. + String[] a = propFile.getProperty(propertyName).split(";"); - //create the two dimensional array with correct size - String[][] array = new String[a.length][a.length]; + // Create the two dimensional array with correct size. + String[][] array = new String[a.length][a.length]; - //combine the arrays split by semicolin and comma - for(int i = 0;i < a.length;i++) { - array[i] = a[i].split(","); - } - - return array; + // Combine the arrays split by semicolon and comma. + for (int i = 0; i < a.length; i++) { + array[i] = a[i].split(","); } - - /*public List<String> getUriListOfAllEditions(String from, String to, String set, String resumptionToken) throws IOException { - - InputStream input = null; - try { - input = new FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Properties prop = new Properties(); - prop.load(input); - - QueryBuilder query; - - QueryBuilder rangeQuery = QueryBuilders.rangeQuery(prop.getProperty("rangeField")).from("1900").to("2020"); - - if(set!=null) { - String[] setParts = set.split(":"); - - String queryField = ""; - String valueField = ""; - - if (setParts[0].equals(TGConstants.SET_FIELD_FOR_TEXTGRID)) { - queryField = TGConstants.PROJECT_ID_FOR_TEXTGRID; - valueField = setParts[1]; - } - - QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); - QueryBuilder boolQuery = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); - - query = boolQuery; - }else { - query = rangeQuery; - } - - return getConentFromESIndex(query, resumptionToken, set); - } - - private List<String> getConentFromESIndex(QueryBuilder query, String resumptionToken, - String set) throws IOException { - - List<String> uriList = new ArrayList<String>(); - QueryBuilder recordFilter = QueryBuilders.boolQuery().must(query) - .must(QueryBuilders.matchPhraseQuery(TGConstants.FORMAT, TextGridMimetypes.EDITION)); - - SearchRequest searchRequest = new SearchRequest(OAI_ESClient.getEsIndex()); - SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); - - InputStream input = null; - try { - input = new FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - Properties prop = new Properties(); - prop.load(input); - - searchSourceBuilder.query(recordFilter); - searchSourceBuilder.size(Integer.parseInt(prop.getProperty("searchResponseSize"))); - searchRequest.source(searchSourceBuilder); - - SearchResponse scrollResp = new SearchResponse(); - - if (resumptionToken != null) { - - SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); - scrollRequest.scroll(TimeValue.timeValueSeconds(Integer.parseInt(prop.getProperty("lifetimeForResumptionToken")))); - - try { - scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else { - searchRequest.source(searchSourceBuilder); - searchRequest.scroll(TimeValue.timeValueMinutes(600)); - try { - scrollResp = OAI_ESClient.getEsClient().search(searchRequest,RequestOptions.DEFAULT); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - String scrollID = scrollResp.getScrollId(); - long completeListSize = scrollResp.getHits().totalHits; - setResultSize(completeListSize); - - if (completeListSize > 0) { - - setFoundItems(true); - int i=0; - - for (SearchHit hit : scrollResp.getHits().getHits()) { - i++; - if (hit != null && hit.getFields() != null) { - uriList.add(hit.getSourceAsMap().get(TGConstants.URI).toString()); - } - } - - this.setResTokenForResponse(OAIPMHUtilities.getResumptionToken( - completeListSize, resumptionToken, cursorCollector, scrollID, Integer.parseInt(prop.getProperty("searchResponseSize")), i)); - - }else { - setFoundItems(false); - } - - - return uriList; - - }*/ - - - - public String getRangeField() { - return rangeField; - } - - public void setRangeField(String rangeField) { - this.rangeField = rangeField; - } - - public long getResultSize() { - return resultSize; - } - - public void setResultSize(long resultSize) { - this.resultSize = resultSize; - } - - public boolean isFoundItems() { - return foundItems; - } - - public void setFoundItems(boolean foundItems) { - this.foundItems = foundItems; - } - - public ResumptionTokenType getResTokenForResponse() { - return resTokenForResponse; - } - - public void setResTokenForResponse(ResumptionTokenType resTokenForResponse) { - this.resTokenForResponse = resTokenForResponse; - } - - - public String setFormatField() { - return formatField; - } - - public void setFormatField(String formatField) { - this.formatField = formatField; - } - - public String getFormatToFilter() { - return formatToFilter; - } - - public void setFormatToFilter(String formatToFilter) { - this.formatToFilter = formatToFilter; - } - - public int getSearchResponseSize() { - return searchResponseSize; - } - - public void setSearchResponseSize(int searchResponseSize) { - this.searchResponseSize = searchResponseSize; - } - + + return array; + } + + /* + * public List<String> getUriListOfAllEditions(String from, String to, String set, String + * resumptionToken) throws IOException { + * + * InputStream input = null; try { input = new + * FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); } catch (FileNotFoundException e) { // + * TODO Auto-generated catch block e.printStackTrace(); } + * + * Properties prop = new Properties(); prop.load(input); + * + * QueryBuilder query; + * + * QueryBuilder rangeQuery = + * QueryBuilders.rangeQuery(prop.getProperty("rangeField")).from("1900").to("2020"); + * + * if(set!=null) { String[] setParts = set.split(":"); + * + * String queryField = ""; String valueField = ""; + * + * if (setParts[0].equals(TGConstants.SET_FIELD_FOR_TEXTGRID)) { queryField = + * TGConstants.PROJECT_ID_FOR_TEXTGRID; valueField = setParts[1]; } + * + * QueryBuilder matchQuery = QueryBuilders.matchPhraseQuery(queryField, valueField); QueryBuilder + * boolQuery = QueryBuilders.boolQuery().must(rangeQuery).must(matchQuery); + * + * query = boolQuery; }else { query = rangeQuery; } + * + * return getConentFromESIndex(query, resumptionToken, set); } + * + * private List<String> getConentFromESIndex(QueryBuilder query, String resumptionToken, String + * set) throws IOException { + * + * List<String> uriList = new ArrayList<String>(); QueryBuilder recordFilter = + * QueryBuilders.boolQuery().must(query) .must(QueryBuilders.matchPhraseQuery(TGConstants.FORMAT, + * TextGridMimetypes.EDITION)); + * + * SearchRequest searchRequest = new SearchRequest(OAI_ESClient.getEsIndex()); SearchSourceBuilder + * searchSourceBuilder = new SearchSourceBuilder(); + * + * InputStream input = null; try { input = new + * FileInputStream("/etc/dhrep/oaipmh/oaipmh.properties"); } catch (FileNotFoundException e) { // + * TODO Auto-generated catch block e.printStackTrace(); } + * + * Properties prop = new Properties(); prop.load(input); + * + * searchSourceBuilder.query(recordFilter); + * searchSourceBuilder.size(Integer.parseInt(prop.getProperty("searchResponseSize"))); + * searchRequest.source(searchSourceBuilder); + * + * SearchResponse scrollResp = new SearchResponse(); + * + * if (resumptionToken != null) { + * + * SearchScrollRequest scrollRequest = new SearchScrollRequest(resumptionToken); + * scrollRequest.scroll(TimeValue.timeValueSeconds(Integer.parseInt(prop.getProperty( + * "lifetimeForResumptionToken")))); + * + * try { scrollResp = OAI_ESClient.getEsClient().scroll(scrollRequest, RequestOptions.DEFAULT); } + * catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { + * searchRequest.source(searchSourceBuilder); + * searchRequest.scroll(TimeValue.timeValueMinutes(600)); try { scrollResp = + * OAI_ESClient.getEsClient().search(searchRequest,RequestOptions.DEFAULT); } catch (IOException + * e) { // TODO Auto-generated catch block e.printStackTrace(); } } + * + * String scrollID = scrollResp.getScrollId(); long completeListSize = + * scrollResp.getHits().totalHits; setResultSize(completeListSize); + * + * if (completeListSize > 0) { + * + * setFoundItems(true); int i=0; + * + * for (SearchHit hit : scrollResp.getHits().getHits()) { i++; if (hit != null && hit.getFields() + * != null) { uriList.add(hit.getSourceAsMap().get(TGConstants.URI).toString()); } } + * + * this.setResTokenForResponse(OAIPMHUtilities.getResumptionToken( completeListSize, + * resumptionToken, cursorCollector, scrollID, + * Integer.parseInt(prop.getProperty("searchResponseSize")), i)); + * + * }else { setFoundItems(false); } + * + * + * return uriList; + * + * } + */ + + // ** + // GETTERS & SETTERS + // ** + + /** + * @return + */ + public String getRangeField() { + return this.rangeField; + } + + /** + * @param rangeField + */ + public void setRangeField(String rangeField) { + this.rangeField = rangeField; + } + + /** + * @return + */ + public long getResultSize() { + return this.resultSize; + } + + /** + * @param resultSize + */ + public void setResultSize(long resultSize) { + this.resultSize = resultSize; + } + + /** + * @return + */ + public boolean isFoundItems() { + return this.foundItems; + } + + /** + * @param foundItems + */ + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } + + /** + * @return + */ + public ResumptionTokenType getResTokenForResponse() { + return this.resTokenForResponse; + } + + /** + * @param resTokenForResponse + */ + public void setResTokenForResponse(ResumptionTokenType resTokenForResponse) { + this.resTokenForResponse = resTokenForResponse; + } + + /** + * @return + */ + public String setFormatField() { + return this.formatField; + } + + /** + * @param formatField + */ + public void setFormatField(String formatField) { + this.formatField = formatField; + } + + /** + * @return + */ + public String getFormatToFilter() { + return this.formatToFilter; + } + + /** + * @param formatToFilter + */ + public void setFormatToFilter(String formatToFilter) { + this.formatToFilter = formatToFilter; + } + + /** + * @return + */ + public int getSearchResponseSize() { + return this.searchResponseSize; + } + + /** + * @param searchResponseSize + */ + public void setSearchResponseSize(int searchResponseSize) { + this.searchResponseSize = searchResponseSize; + } + } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OpenAireRecord.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OpenAireRecord.java index e01921d9b7cf956023ab2cd4c928356c00367ff4..c510f393e810a3fbfc1c228383a519da6d89de8a 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OpenAireRecord.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OpenAireRecord.java @@ -148,8 +148,9 @@ public class OpenAireRecord extends RecordDelivererAbstract { /** * building the record XML object for the OAI-PMH response * @throws ParseException + * @throws IOException */ - public GetRecordType getRecordById(String idInElasticSearchIndex) throws ParseException, DatatypeConfigurationException { + public GetRecordType getRecordById(String idInElasticSearchIndex) throws ParseException, DatatypeConfigurationException, IOException { jsonObj = new JSONObject(OAIPMHUtilities.getRcordByIDFromElasticSearch(idInElasticSearchIndex.replace("textgrid:", ""), this.fields, Strings.EMPTY_ARRAY).getSource()); HeaderType header = new HeaderType(); @@ -173,8 +174,9 @@ public class OpenAireRecord extends RecordDelivererAbstract { * @throws ParseException * @throws JAXBException * @throws DatatypeConfigurationException + * @throws IOException */ - public JAXBElement<OAIPMHtype> getRecord(String idInElasticSearchIndex) throws ParseException, JAXBException, DatatypeConfigurationException { + public JAXBElement<OAIPMHtype> getRecord(String idInElasticSearchIndex) throws ParseException, JAXBException, DatatypeConfigurationException, IOException { ObjectFactory obf = new ObjectFactory(); JAXBElement<OAIPMHtype> oaijaxb; OAIPMHtype oai = new OAIPMHtype(); @@ -206,8 +208,9 @@ public class OpenAireRecord extends RecordDelivererAbstract { * @return * @throws ParseException * @throws DatatypeConfigurationException + * @throws IOException */ - private Resource setOpenAireRecord() throws ParseException, DatatypeConfigurationException { + private Resource setOpenAireRecord() throws ParseException, DatatypeConfigurationException, IOException { resource.setTitles(this.addTitles()); resource.setPublisher(this.addPublisher()); @@ -292,7 +295,7 @@ public class OpenAireRecord extends RecordDelivererAbstract { //return geoLocations; } - private RelatedIdentifiers addRelatedIdentifiers() { + private RelatedIdentifiers addRelatedIdentifiers() throws IOException { RelatedIdentifiers relatedIdentifiers = new RelatedIdentifiers(); for (String relatedIdentifierField: relatedIdentifierFields) { @@ -312,7 +315,7 @@ public class OpenAireRecord extends RecordDelivererAbstract { return relatedIdentifiers; } - private Descriptions addDescriptions() { + private Descriptions addDescriptions() throws IOException { Descriptions descriptions = new Descriptions(); for (String descriptionField: descriptionFields) { 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 a6bf031e08280dbe5410ed8eff619126579766dd..41c1d293047f069c745996bffa75b8572e4610c4 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererDC.java @@ -4,13 +4,9 @@ import java.io.IOException; import java.text.ParseException; import javax.xml.datatype.DatatypeConfigurationException; import org.apache.commons.logging.LogFactory; -import org.elasticsearch.action.get.GetRequest; import org.elasticsearch.action.get.GetResponse; -import org.elasticsearch.client.RequestOptions; import org.elasticsearch.common.Strings; -import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import org.springframework.stereotype.Component; - import info.textgrid.middleware.oaipmh.GetRecordType; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.RecordType; @@ -18,9 +14,12 @@ import info.textgrid.middleware.oaipmh.RecordType; /** * FIXME Was magst Du denn hier fixen, Herr Max? * + * FIXME Habe hier mal die Methode aus OAIPMHUtilities genutzt: getRcordByIDFromElasticSearch(), + * sollten wir auch in anderen Klassen so machen! Der Umbau auf ES6 ist so einfacher, no? + * * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2019-10-30 + * @version 2021-05-20 * @since 2014-02-17 */ @@ -59,7 +58,6 @@ public class RecordDelivererDC extends RecordDelivererAbstract { private String[] titleList; private String[] typeList; - private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDelivererDC.class); private OAI_ESClient oaiEsClient; @@ -76,29 +74,26 @@ public class RecordDelivererDC extends RecordDelivererAbstract { * * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) */ - public GetRecordType getRecordById(String id) throws ParseException, DatatypeConfigurationException { - - String[] includes = this.fields; - String[] excludes = Strings.EMPTY_ARRAY; - FetchSourceContext fetchSourceContext = new FetchSourceContext(true, includes, excludes); + public GetRecordType getRecordById(String id) + throws ParseException, DatatypeConfigurationException { GetRecordType getRecordType = new GetRecordType(); RecordType record = new RecordType(); - String changedId = id; DublinCoreBuilder dublinCoreBuilder; + String changedId = id; if (id.startsWith(this.repositoryObjectURIPrefix)) { + // FIXME Why do we need changeID? Where is it used? changedId = changedId.replace(this.repositoryObjectURIPrefix, ""); } - GetRequest getRequest = - new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id) - .fetchSourceContext(fetchSourceContext); + // Get ES response, get record for given ID. GetResponse esResultObject = null; - try { - esResultObject = - OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + String[] includes = this.fields; + String[] excludes = Strings.EMPTY_ARRAY; + + esResultObject = OAIPMHUtilities.getRcordByIDFromElasticSearch(id, includes, excludes); } catch (IOException e1) { // TODO Auto-generated catch block @@ -107,7 +102,6 @@ public class RecordDelivererDC extends RecordDelivererAbstract { } if (esResultObject.isExists()) { - String identifier; if (this.dariah == true) { @@ -130,15 +124,16 @@ public class RecordDelivererDC extends RecordDelivererAbstract { } record.setMetadata(dublinCoreBuilder.getDC()); } - String setSpec = DublinCoreFieldLoader.fillList(esResultObject, DARIAHConstants.IDENTIFIER_LIST).get(0); + String setSpec = + DublinCoreFieldLoader.fillList(esResultObject, DARIAHConstants.IDENTIFIER_LIST).get(0); setRecordHeader(OAIPMHUtilities - .convertDateFormat(dateOfCreation).toString(), identifier, record, dublinCoreBuilder, setSpec); + .convertDateFormat(dateOfCreation).toString(), identifier, record, dublinCoreBuilder, + setSpec); } if (this.textgrid == true && esResultObject.getSourceAsMap().get(this.formatField).equals(this.formatToFilter)) { - String workUri = DublinCoreFieldLoader .fillList(esResultObject, new String[] {this.relationToFurtherMetadataObject}).get(0); workUri = workUri.substring(this.repositoryObjectURIPrefix.length()); @@ -146,11 +141,13 @@ public class RecordDelivererDC extends RecordDelivererAbstract { identifier = esResultObject.getSourceAsMap().get(this.identifierField).toString(); String dateOfCreation = esResultObject.getSourceAsMap().get(this.dateOfObjectCreation).toString(); - - String setSpec = "project:" + DublinCoreFieldLoader.fillList(esResultObject, TGConstants.RELATIONS_LIST).get(0); - - setRecordHeader(OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, record, dublinCoreBuilder, setSpec); - + + String setSpec = "project:" + + DublinCoreFieldLoader.fillList(esResultObject, TGConstants.RELATIONS_LIST).get(0); + + setRecordHeader(OAIPMHUtilities.convertDateFormat(dateOfCreation).toString(), identifier, + record, dublinCoreBuilder, setSpec); + record.setMetadata(dublinCoreBuilder.getDC()); } @@ -180,12 +177,12 @@ public class RecordDelivererDC extends RecordDelivererAbstract { RecordType record, DublinCoreBuilder dbc, String setSpec) { HeaderType recordHeader = new HeaderType(); - + recordHeader.setIdentifier(identifier); recordHeader.setDatestamp(dateOfCreation); recordHeader.getSetSpec().add(setSpec); - // FIXME Do add set spec here! + // FIXME Do add set spec here if set existing! // if (set != null) { // recordHeader.getSetSpec().add(set); // } @@ -202,21 +199,17 @@ public class RecordDelivererDC extends RecordDelivererAbstract { */ private GetResponse furtherDCElements(String id) { - String[] includes = this.workFields; - String[] excludes = Strings.EMPTY_ARRAY; - FetchSourceContext fetchSourceContext = - new FetchSourceContext(true, includes, excludes); - if (!id.endsWith(".0")) { id = id.concat(".0"); } - GetRequest getRequest = new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), id) - .fetchSourceContext(fetchSourceContext); GetResponse responseWorkValues = null; - try { - responseWorkValues = OAI_ESClient.getEsClient().get(getRequest, RequestOptions.DEFAULT); + String[] includes = this.workFields; + String[] excludes = Strings.EMPTY_ARRAY; + + responseWorkValues = OAIPMHUtilities.getRcordByIDFromElasticSearch(id, includes, excludes); + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -231,8 +224,8 @@ public class RecordDelivererDC extends RecordDelivererAbstract { * * @param responseWorkValues contains the edition object * @param relatedWorkObject contains the work object related to edition object - * @throws DatatypeConfigurationException - * @throws ParseException + * @throws DatatypeConfigurationException + * @throws ParseException */ private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues, GetResponse relatedWorkObject) throws ParseException, DatatypeConfigurationException { @@ -244,7 +237,7 @@ public class RecordDelivererDC extends RecordDelivererAbstract { DublinCoreFieldLoader.fillList(responseWorkValues, this.contributorList)); result.setCoverage(DublinCoreFieldLoader.fillList(responseWorkValues, this.coverageList)); result.setCreator(DublinCoreFieldLoader.fillList(relatedWorkObject, this.creatorList)); - result.setDate(DublinCoreFieldLoader.fillList(relatedWorkObject, this.dateList)); + result.setDate(DublinCoreFieldLoader.fillList(relatedWorkObject, this.dateList)); result.setDescription( DublinCoreFieldLoader.fillList(relatedWorkObject, this.descriptionList)); result.setFormat(DublinCoreFieldLoader.fillList(responseWorkValues, this.formatList)); @@ -267,10 +260,11 @@ public class RecordDelivererDC extends RecordDelivererAbstract { * This function with just one object as parameter is for DARIAH * * @param responseWorkValues - * @throws DatatypeConfigurationException - * @throws ParseException + * @throws DatatypeConfigurationException + * @throws ParseException */ - private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues) throws ParseException, DatatypeConfigurationException { + private DublinCoreBuilder putContentIntoDCFieldLists(GetResponse responseWorkValues) + throws ParseException, DatatypeConfigurationException { DublinCoreBuilder result = new DublinCoreBuilder(); 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 4ec901147058b80c3f23c6d78f478bff7e4e5ab8..b7df75d7430e51a25b0eeddb3b7c2f737e98a123 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererIDIOM.java @@ -20,12 +20,11 @@ import info.textgrid.middleware.oaipmh.GetRecordType; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.RecordType; -import info.textgrid.middleware.oaipmh.StatusType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @since 2019-10-28 + * @since 2020-05-20 * @version 2019-03-12 */ @@ -36,9 +35,8 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { private String dateOfLastOblectModification; private OAI_ESClient oaiEsClient; - RecordType record = new RecordType(); - //ClassicMayanMetsMods metsmods; + ClassicMayanMetsMods metsmods; private static org.apache.commons.logging.Log log = LogFactory.getLog(RecordDelivererIDIOM.class); @@ -50,12 +48,6 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { super(textgrid, dariah); } - /* - * (non-Javadoc) - * - * @see info.textgrid.middleware.RecordDelivererInterface#getRecordById(java.lang.String) - */ - /** * <p> * ElasticSearch request in non-public index to get the datestamps for the object creation and @@ -63,9 +55,10 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { * </p> * * @param idInDatabase - * @throws ParseException + * @throws ParseException + * @throws IOException */ - public void setDatestamps(String idInDatabase) throws ParseException { + public void setDatestamps(String idInDatabase) throws ParseException, IOException { String changedId = idInDatabase; @@ -78,31 +71,30 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { } if (!idInDatabase.contains(".0")) { - - //changedId = changedId.substring(0,changedId.length() - 1) + "0"; + // changedId = changedId.substring(0,changedId.length() - 1) + "0"; changedId = changedId + ".0"; - - } - if(changedId.contains(".1")) { - changedId = changedId.replace(".1", ""); } -<<<<<<< HEAD - - System.out.println("id in elasticsearch is: " + changedId); - GetRequestBuilder recordById = OAI_ESClient.getOaiESClient() - .prepareGet() - .setIndex("textgrid-nonpublic") - .setType(OAI_ESClient.getEsType()) - .setFields(TGConstants.CREATED, TGConstants.MODIFIED_FIELD) - .setId(changedId); - - GetResponse objectInDatabase = recordById.execute().actionGet(); - - - this.dateOfObjectCreation = - objectInDatabase.getField(TGConstants.CREATED).getValue().toString(); -======= + if (changedId.contains(".1")) { + changedId = changedId.replace(".1", ""); + } + // <<<<<<< HEAD + // + // + // System.out.println("id in elasticsearch is: " + changedId); + // GetRequestBuilder recordById = OAI_ESClient.getOaiESClient() + // .prepareGet() + // .setIndex("textgrid-nonpublic") + // .setType(OAI_ESClient.getEsType()) + // .setFields(TGConstants.CREATED, TGConstants.MODIFIED_FIELD) + // .setId(changedId); + // + // GetResponse objectInDatabase = recordById.execute().actionGet(); + // + // + // this.dateOfObjectCreation = + // objectInDatabase.getField(TGConstants.CREATED).getValue().toString(); + // ======= GetRequest getRequest = new GetRequest(OAI_ESClient.getEsIndex(), OAI_ESClient.getEsType(), changedId) @@ -116,31 +108,37 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { e.printStackTrace(); } JSONObject json = new JSONObject(); - String[] fields = {TGConstants.CREATED,TGConstants.MODIFIED_FIELD}; - json = new JSONObject(OAIPMHUtilities.getRcordByIDFromElasticSearch(changedId, fields, Strings.EMPTY_ARRAY).getSource()); - - System.out.println("id in elasticsearch is: " + OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED))); + String[] fields = {TGConstants.CREATED, TGConstants.MODIFIED_FIELD}; + json = new JSONObject(OAIPMHUtilities + .getRcordByIDFromElasticSearch(changedId, fields, Strings.EMPTY_ARRAY).getSource()); + + System.out.println("id in elasticsearch is: " + OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED))); System.out.println(json); - this.dateOfObjectCreation = OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED)); - //objectInDatabase.getField(TGConstants.CREATED).getValue().toString(); ->>>>>>> feature/elastic6 - - this.dateOfLastOblectModification = OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.MODIFIED_FIELD)); - // objectInDatabase.getField(TGConstants.MODIFIED_FIELD).getValue().toString(); + this.dateOfObjectCreation = + OAIPMHUtilities.datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.CREATED)); + // objectInDatabase.getField(TGConstants.CREATED).getValue().toString(); + // >>>>>>> feature/elastic6 + + this.dateOfLastOblectModification = OAIPMHUtilities + .datestampAsString(OAIPMHUtilities.fieldLoader(json, TGConstants.MODIFIED_FIELD)); + // objectInDatabase.getField(TGConstants.MODIFIED_FIELD).getValue().toString(); } /** * building the record XML object for the OAI-PMH response - * @throws ParseException + * + * @throws ParseException + * @throws IOException */ -<<<<<<< HEAD - - public GetRecordType getRecordById(String id) { - ClassicMayanMetsMods metsmods; -======= - public GetRecordType getRecordById(String id) throws ParseException { - ->>>>>>> feature/elastic6 + // <<<<<<< HEAD + // + // public GetRecordType getRecordById(String id) { + // ClassicMayanMetsMods metsmods; + // ======= + public GetRecordType getRecordById(String id) throws ParseException, IOException { + + // >>>>>>> feature/elastic6 GetRecordType grt = new GetRecordType(); setDatestamps(id); @@ -155,7 +153,8 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { textgridBaseURI_FromID, this.dateOfObjectCreation, this.dateOfLastOblectModification); - this.record.setMetadata(idiomMets(metsmods)); + // this.record.setMetadata(idiomMets(metsmods)); + this.record.setMetadata(idiomMets()); try { if (!id.startsWith("textgrid:")) { setRecordHeader(this.dateOfObjectCreation, "textgrid:" + id); @@ -184,14 +183,14 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { * * @return */ -<<<<<<< HEAD - - private MetadataType idiomMets(ClassicMayanMetsMods metsmods) { -======= + // <<<<<<< HEAD + // + // private MetadataType idiomMets(ClassicMayanMetsMods metsmods) { + // ======= private MetadataType idiomMets() { ->>>>>>> feature/elastic6 + // >>>>>>> feature/elastic6 - MetadataType metadataMets = new MetadataType(); + MetadataType metadataMets = new MetadataType(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; @@ -217,8 +216,8 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract { recordHeader.setIdentifier(identifier); recordHeader.setDatestamp(OAIPMHUtilities.datestampAsString(dateOfCreation)); this.record.setHeader(recordHeader); - - //recordHeader.setStatus(StatusType.DELETED); + + // recordHeader.setStatus(StatusType.DELETED); // return recordHeader; } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java index c4b353b0a34e26d235d8630f3183247c14924cc2..e50e1124d45823ec01e82b2a0909923c680e9232 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordDelivererInterface.java @@ -1,15 +1,14 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; - import javax.xml.datatype.DatatypeConfigurationException; - import info.textgrid.middleware.oaipmh.GetRecordType; /** * @author Maximilian Brodhun, SUB Göttingen * @author Stefan E. Funk, SUB Göttingen - * @version 2019-03-07 + * @version 2021-05-20 * @since 2019-03-07 */ @@ -22,9 +21,11 @@ public interface RecordDelivererInterface { * * @param id identifier within database * @return Get the GetRecord response for the request - * @throws DatatypeConfigurationException - * @throws ParseException + * @throws DatatypeConfigurationException + * @throws ParseException + * @throws IOException */ - GetRecordType getRecordById(String id) throws ParseException, DatatypeConfigurationException; + GetRecordType getRecordById(String id) + throws ParseException, DatatypeConfigurationException, IOException; } 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 9f1c478c27bdd43de3daea11bc4bcb6eea6e9123..92e14734c3e18211ca26bb3eb986e7f2e0291159 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -1,15 +1,13 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; import java.util.Hashtable; +import java.util.List; import java.util.Map; +import java.util.UUID; import org.apache.commons.logging.LogFactory; -import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.index.query.QueryBuilders; -import org.elasticsearch.search.SearchHit; - +import org.classicmayan.tools.Queries; import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListRecordsType; import info.textgrid.middleware.oaipmh.MetadataType; @@ -32,7 +30,7 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { * @param dariah */ public RecordListDelivererIDIOM(boolean textgrid, boolean dariah) { - + super(textgrid, dariah); } @@ -62,71 +60,73 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { @Override public ListRecordsType getRecords(final String from, final String to, final String set, -<<<<<<< HEAD - final String resumptionToken) { - System.out.println("BUFF"); - ListRecordsType recordList = new ListRecordsType(); - - QueryBuilder recordFilterForClassicMayan; - QueryBuilder rangeQuery; - //Queries queries = new Queries(); - //List<String> artefactURIs = queries.getArtefactList(); - - 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")); - - SearchResponse scrollResp; - - if (resumptionToken == null) { - - 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(); - }else { - scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) - .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); - } - - String scrollID = scrollResp.getScrollId(); - - long completeListSize = scrollResp.getHits().totalHits(); - //long completeListSize = 45; - //System.out.println(completeListSize); - //System.out.println(completeListSize + " || " + artefactURIs.size()); - if (completeListSize > 0) { - setFoundItems(true); - int i = 0; - //System.out.println("inside "); - 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! - ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( - completeListSize, resumptionToken, cursorCollector, scrollID, 30, i); - if (resTokenForResponse != null) { - recordList.setResumptionToken(resTokenForResponse); - } - }else { - setFoundItems(false); - } - - return recordList; -======= - final String resumptionToken) throws ParseException { + // <<<<<<< HEAD + // final String resumptionToken) { + // System.out.println("BUFF"); + // ListRecordsType recordList = new ListRecordsType(); + // + // QueryBuilder recordFilterForClassicMayan; + // QueryBuilder rangeQuery; + // //Queries queries = new Queries(); + // //List<String> artefactURIs = queries.getArtefactList(); + // + // 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")); + // + // SearchResponse scrollResp; + // + // if (resumptionToken == null) { + // + // 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(); + // }else { + // scrollResp = OAI_ESClient.getOaiESClient().prepareSearchScroll(resumptionToken) + // .setScroll(TimeValue.timeValueHours(24L)).execute().actionGet(); + // } + // + // String scrollID = scrollResp.getScrollId(); + // + // long completeListSize = scrollResp.getHits().totalHits(); + // //long completeListSize = 45; + // //System.out.println(completeListSize); + // //System.out.println(completeListSize + " || " + artefactURIs.size()); + // if (completeListSize > 0) { + // setFoundItems(true); + // int i = 0; + // //System.out.println("inside "); + // 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! + // ResumptionTokenType resTokenForResponse = OAIPMHUtilities.getResumptionToken( + // completeListSize, resumptionToken, cursorCollector, scrollID, 30, i); + // if (resTokenForResponse != null) { + // recordList.setResumptionToken(resTokenForResponse); + // } + // }else { + // setFoundItems(false); + // } + // + // return recordList; + // ======= + final String resumptionToken) throws ParseException, IOException { String resTokenValue = resumptionToken; @@ -164,9 +164,9 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { } return recordList; ->>>>>>> feature/elastic6 + // >>>>>>> feature/elastic6 } - + /* * (non-Javadoc) * @@ -178,26 +178,42 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract { return null; } - /** - * @return + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.RecordListDelivererAbstract#getOaiEsClient() */ public OAI_ESClient getOaiEsClient() { return this.oaiEsClient; } - /** - * @param oaiEsClient + /* + * (non-Javadoc) + * + * @see + * info.textgrid.middleware.RecordListDelivererAbstract#setOaiEsClient(info.textgrid.middleware. + * OAI_ESClient) */ public void setOaiEsClient(OAI_ESClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } -public boolean isFoundItems() { - return foundItems; -} + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.RecordListDelivererAbstract#isFoundItems() + */ + public boolean isFoundItems() { + return this.foundItems; + } -public void setFoundItems(boolean foundItems) { - this.foundItems = foundItems; -} + /* + * (non-Javadoc) + * + * @see info.textgrid.middleware.RecordListDelivererAbstract#setFoundItems(boolean) + */ + public void setFoundItems(boolean foundItems) { + this.foundItems = foundItems; + } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java index e3ce3a67c3e116295365ff05ba201c382d7af6cc..8e00da405ac9181caac8247d59388e26eb57dbe0 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererInterface.java @@ -1,7 +1,7 @@ package info.textgrid.middleware; +import java.io.IOException; import java.text.ParseException; - import info.textgrid.middleware.oaipmh.HeaderType; import info.textgrid.middleware.oaipmh.ListRecordsType; @@ -10,16 +10,18 @@ import info.textgrid.middleware.oaipmh.ListRecordsType; */ public interface RecordListDelivererInterface { - + /** * @param from * @param to * @param set * @param resumptionToken * @return - * @throws ParseException + * @throws ParseException + * @throws IOException */ - public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) throws ParseException; + public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) + throws ParseException, IOException; /** * @param set