diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java index 95755cf72b3ea543fa6ffa5c00d47f24ed89fcc3..e54a87cd9a069730296598dd7bd378926b5902f0 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererAbstract.java @@ -2,100 +2,121 @@ package info.textgrid.middleware; import java.util.ArrayList; import java.util.List; - import info.textgrid.middleware.oaipmh.RequestType; -public abstract class RecordListDelivererAbstract implements RecordListDelivererInterface{ - - protected boolean textgrid; - protected boolean dariah; - private static boolean idiomMets; - private static boolean dublinCore; - /** - * @param textgrid - * @param dariah - */ - - public RecordListDelivererAbstract(boolean textgrid, boolean dariah) { - this.textgrid = textgrid; - this.dariah = dariah; - } - - public static ErrorHandler requestChecker(RequestType request) { - - ErrorHandler result = new ErrorHandler(); - - // Check if metadata prefix is existing and valid. - if (request.getMetadataPrefix() != null - && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) - && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - result.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()); - } - // Check if resumptioToken is valid - if(request.getResumptionToken() != null) { - - if(RecordListDelivererAbstract.isIdiomMets() && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken())) { - RecordListDelivererAbstract.setIdiomMets(true); - RecordListDelivererAbstract.setDublinCore(false); - }else if(RecordListDelivererAbstract.isDublinCore() && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken())){ - RecordListDelivererAbstract.setDublinCore(true); - RecordListDelivererAbstract.setIdiomMets(false); - }else { - result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, - "The value of the " + request.getResumptionToken() + " argument is invalid or expired."); - } - } - - if (request.getResumptionToken() == null && request.getMetadataPrefix() != null) { - if(request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { - RecordListDelivererAbstract.setIdiomMets(true); - RecordListDelivererAbstract.setDublinCore(false); - } - if(request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { - RecordListDelivererAbstract.setDublinCore(true); - RecordListDelivererAbstract.setIdiomMets(false); - } - } - - // Check if other params are existing, they shouldn't! - else { - List<String> errorValues = new ArrayList<String>(); - - if (request.getResumptionToken() != null && request.getMetadataPrefix() !=null) { - errorValues.add("metadataPrefix"); - } - if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { - errorValues.add("metadataPrefix"); - } - if (request.getIdentifier() != null) { - errorValues.add("identifier"); - } - if(errorValues.size()>0) { - result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " - + "or is missing required arguments: " + errorValues); - } - - } - - return result; - } - - public static boolean isIdiomMets() { - return idiomMets; - } - - public static void setIdiomMets(boolean idiomMets) { - RecordListDelivererAbstract.idiomMets = idiomMets; - } - - public static boolean isDublinCore() { - return dublinCore; - } - - public static void setDublinCore(boolean dublinCore) { - RecordListDelivererAbstract.dublinCore = dublinCore; - } +/** + * + */ +public abstract class RecordListDelivererAbstract implements RecordListDelivererInterface { + + protected boolean textgrid; + protected boolean dariah; + private static boolean idiomMets; + private static boolean dublinCore; + + /** + * @param textgrid + * @param dariah + */ + public RecordListDelivererAbstract(boolean textgrid, boolean dariah) { + this.textgrid = textgrid; + this.dariah = dariah; + } + + /** + * @param request + * @return + */ + public static ErrorHandler requestChecker(RequestType request) { + + ErrorHandler result = new ErrorHandler(); + + // Check if metadata prefix is existing and valid. + if (request.getMetadataPrefix() != null + && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX) + && !request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { + result.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()); + } + // Check if resumptioToken is valid + if (request.getResumptionToken() != null) { + + if (RecordListDelivererAbstract.isIdiomMets() + && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken())) { + RecordListDelivererAbstract.setIdiomMets(true); + RecordListDelivererAbstract.setDublinCore(false); + } else if (RecordListDelivererAbstract.isDublinCore() + && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken())) { + RecordListDelivererAbstract.setDublinCore(true); + RecordListDelivererAbstract.setIdiomMets(false); + } else { + result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, + "The value of the " + request.getResumptionToken() + + " argument is invalid or expired."); + } + } + + if (request.getResumptionToken() == null && request.getMetadataPrefix() != null) { + if (request.getMetadataPrefix().equals(TGConstants.METADATA_IDIOM_PREFIX)) { + RecordListDelivererAbstract.setIdiomMets(true); + RecordListDelivererAbstract.setDublinCore(false); + } + if (request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { + RecordListDelivererAbstract.setDublinCore(true); + RecordListDelivererAbstract.setIdiomMets(false); + } + } + + // Check if other params are existing, they shouldn't! + else { + List<String> errorValues = new ArrayList<String>(); + + if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) { + errorValues.add("metadataPrefix"); + } + if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { + errorValues.add("metadataPrefix"); + } + if (request.getIdentifier() != null) { + errorValues.add("identifier"); + } + if (errorValues.size() > 0) { + result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " + + "or is missing required arguments: " + errorValues); + } + + } + + return result; + } + + /** + * @return + */ + public static boolean isIdiomMets() { + return idiomMets; + } + + /** + * @param idiomMets + */ + public static void setIdiomMets(boolean idiomMets) { + RecordListDelivererAbstract.idiomMets = idiomMets; + } + + /** + * @return + */ + public static boolean isDublinCore() { + return dublinCore; + } + + /** + * @param dublinCore + */ + public static void setDublinCore(boolean dublinCore) { + RecordListDelivererAbstract.dublinCore = dublinCore; + } } diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java index 71d32bab460a3271fae5ca174e7b2d7bc15ad1d4..431cc958bb97ae36323f5c95ab708ff179e07ecd 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererDC.java @@ -29,7 +29,6 @@ import info.textgrid.middleware.oaipmh.ResumptionTokenType; * FIXME Care about all repeatable fields as done in TITLE! */ public class RecordListDelivererDC extends RecordListDelivererAbstract{ - // ** // STATICS // ** @@ -157,7 +156,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ recordFilter = query; } else { recordFilter = QueryBuilders.boolQuery().must(query) - .must(QueryBuilders.matchPhraseQuery(formatField, formatToFilter)); + .must(QueryBuilders.matchPhraseQuery(this.formatField, this.formatToFilter)); } if (resumptionToken == null) { @@ -168,7 +167,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ .setTypes(OAI_ESClient.getEsType()) .addFields(this.fields) .setQuery(recordFilter) - .setSize(searchResponseSize) + .setSize(this.searchResponseSize) .execute() .actionGet(); } else { @@ -176,7 +175,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ .setScroll(new TimeValue(lifeTimeResToken)).execute().actionGet(); } - log.info("Quried fields: " + fields.toString()); + log.info("Queried fields: " + this.fields.toString()); log.info("Life time for resumption token is set to: " + lifeTimeResToken); scrollID = scrollResp.getScrollId(); @@ -204,13 +203,13 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ } catch (DatatypeConfigurationException e1) { log.debug(e1); } - modifiedValue = hit.getFields().get(this.modifiedField).getValue().toString(); + this.modifiedValue = hit.getFields().get(this.modifiedField).getValue().toString(); // TextGrid search! String workUri = ""; - if (this.textgrid == true && hit.getFields().get(formatField).values().get(0).toString() - .equals(formatToFilter)) { + if (this.textgrid == true && hit.getFields().get(this.formatField).values().get(0).toString() + .equals(this.formatToFilter)) { if (hit.getFields().get(this.relationToFurtherMetadataObject) != null) { workUri = hit.getFields().get(this.relationToFurtherMetadataObject).values().get(0) .toString().substring(this.repositoryObjectURIPrefix.length()); @@ -240,7 +239,7 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ // Check the need for a resumption token! ResumptionTokenType resTokenForResponse = OAIPMHUtillities.getResumptionToken( - completeListSize, resumptionToken, cursorCollector, scrollID, searchResponseSize, i); + completeListSize, resumptionToken, cursorCollector, scrollID, this.searchResponseSize, i); if (resTokenForResponse != null) { recordList.setResumptionToken(resTokenForResponse); } @@ -662,32 +661,53 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ this.foundItems = foundItems; } + /** + * @return + */ public String getModifiedField() { - return modifiedField; + return this.modifiedField; } + /** + * @param modifiedField + */ public void setModifiedField(String modifiedField) { this.modifiedField = modifiedField; } + /** + * @return + */ public String getIdentifierField() { - return identifierField; + return this.identifierField; } + /** + * @param identifierField + */ public void setIdentifierField(String identifierField) { this.identifierField = identifierField; } + /** + * @return + */ public int getSearchResponseSize() { - return searchResponseSize; + return this.searchResponseSize; } + /** + * @param searchResponseSize + */ public void setSearchResponseSize(String searchResponseSize) { this.searchResponseSize = Integer.parseInt(searchResponseSize); } + /** + * @return + */ public boolean getTextGrid() { - return textgrid; + return this.textgrid; } // public String getCollectionTitle() { @@ -711,10 +731,16 @@ public class RecordListDelivererDC extends RecordListDelivererAbstract{ this.workFields = workFields; } + /** + * @param fields + */ public void setFields(String[] fields) { this.fields = fields; } + /** + * @return + */ public String[] getFields() { return this.fields; } 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 c7378b2cd65265fb4ba77bee6cbf8711cfd660d8..e8d9a1189e07db66c6d59f9d9fa330ddaab319fe 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/RecordListDelivererIDIOM.java @@ -1,6 +1,5 @@ package info.textgrid.middleware; - import java.util.Hashtable; import java.util.List; import java.util.Map; @@ -15,6 +14,9 @@ import info.textgrid.middleware.oaipmh.MetadataType; import info.textgrid.middleware.oaipmh.RecordType; import info.textgrid.middleware.oaipmh.ResumptionTokenType; +/** + * + */ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract{ private static org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); @@ -22,11 +24,18 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract{ private OAI_ESClient oaiEsClient; + /** + * @param textgrid + * @param dariah + */ public RecordListDelivererIDIOM(boolean textgrid, boolean dariah) { super(textgrid, dariah); // TODO Auto-generated constructor stub } + /* (non-Javadoc) + * @see info.textgrid.middleware.RecordListDelivererInterface#buildRecord(info.textgrid.middleware.oaipmh.ListRecordsType, java.lang.String, java.lang.String) + */ @Override public RecordType buildRecord(ListRecordsType recordList, String set, String headerIdentifier) { @@ -39,6 +48,9 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract{ return null; } + /* (non-Javadoc) + * @see info.textgrid.middleware.RecordListDelivererInterface#getRecords(java.lang.String, java.lang.String, java.lang.String, java.lang.String) + */ @Override public ListRecordsType getRecords(String from, String to, String set, String resumptionToken) { @@ -50,7 +62,8 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract{ if(resumptionToken==null) { artefactURIs = queries.getArtefactList(0); - }else { + } else { + // FIXME @Max: Hier gibt's eine NPE, wenn ein resumptionToken für oai_dc existiert. Komisch? artefactURIs = queries.getArtefactList(cursorCollector.get(resumptionToken)); } @@ -78,16 +91,25 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract{ return recordList; } + /* (non-Javadoc) + * @see info.textgrid.middleware.RecordListDelivererInterface#setHeader(java.lang.String, java.lang.String) + */ @Override public HeaderType setHeader(String set, String headerIdentifier) { // TODO Auto-generated method stub return null; } + /** + * @return + */ public OAI_ESClient getOaiEsClient() { return oaiEsClient; } + /** + * @param oaiEsClient + */ public void setOaiEsClient(OAI_ESClient oaiEsClient) { this.oaiEsClient = oaiEsClient; } diff --git a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java index 4faea6163b101675ef4364d44e089cce080f53fc..d3f55ff947d4b9b162898a7700557b0951b0cf91 100644 --- a/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java +++ b/oaipmh-core/src/test/java/info/textgrid/middleware/OaiPmhTextgridOnlineTests.java @@ -23,8 +23,8 @@ import info.textgrid.utils.httpclient.TGHttpResponse; public class OaiPmhTextgridOnlineTests { // The OAIPMH host to be tested. - private static String host = "http://textgrid-esx1.gwdg.de/1.0/tgoaipmh/"; - // private static String host = "https://textgridlab.org/1.0/tgoaipmh/"; + // private static String host = "http://textgrid-esx1.gwdg.de/1.0/tgoaipmh/"; + private static String host = "http://textgridlab.org/1.0/tgoaipmh/"; // Some output finals. private static final String ERROR = ">>> ERROR"; @@ -81,7 +81,7 @@ public class OaiPmhTextgridOnlineTests { TGHttpResponse httpResponse = getHttpResponse(host + "oai/version"); int status = httpResponse.getStatusCode(); - + String response = IOUtils.readStringFromStream(httpResponse.getInputstream()); if (status != HttpStatus.SC_OK || !response.startsWith(shouldStartWith)) {