Changeset 30034

Show
Ignore:
Timestamp:
16.07.2015 18:42:45 (4 years ago)
Author:
ak19
Message:

The OAI Validator has added more tests, one of them had failed: when the until date is provided in a request, either on its own or with a from date, the until date should not precede the earliestDatestamp. (Not sure if there are constraints on the from date not exceeding the current time, so I've left that out for now.) Further, the test on until coming on or after earliestDatestamp should be performed after checking that from and until dates' granularities match. Not sure how to make the tests sequence independent when the tests are conducted in sequence.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java

    r29270 r30034  
    490490 
    491491      //if there are any date params, check they're of the right format 
     492      Date from_date = null; 
     493      Date until_date = null; 
     494 
    492495      from = param_map.get(OAIXML.FROM); 
    493496      if(from != null) {     
    494     Date from_date = OAIXML.getDate(from); 
     497    from_date = OAIXML.getDate(from); 
    495498    if(from_date == null) { 
    496499      logger.error("invalid date: " + from); 
     
    500503      until = param_map.get(OAIXML.UNTIL); 
    501504      if(until != null) {    
    502     Date until_date = OAIXML.getDate(until); 
     505    until_date = OAIXML.getDate(until); 
    503506    if(until_date == null) { 
    504507      logger.error("invalid date: " + until); 
     
    506509    }  
    507510      }     
     511 
    508512      if(from != null && until != null) { // check they are of the same date-time format (granularity) 
    509513    if(from.length() != until.length()) { 
     
    511515      return OAIXML.createErrorMessage(OAIXML.BAD_ARGUMENT, "The request has different granularities (date-time formats) for the From and Until date parameters."); 
    512516    } 
    513       } 
     517 
     518    if(from_date.compareTo(until_date) > 0) { // from date can't be later than until date 
     519        return OAIXML.createErrorMessage(OAIXML.NO_RECORDS_MATCH, ""); 
     520    } 
     521      } 
     522       
     523      if(until_date != null) { 
     524       
     525      // Also call until_date.compareTo(earliestdatestamp) as the until date can't precede the earliest timestamp 
     526      // Unfortunately, this test has to be done after the granularity test 
     527      // compareTo() returns the value 0 if the argument Date is equal to this Date; a value less than 0 if this Date is before  
     528      // the Date argument; and a value greater than 0 if this Date is after the Date argument.     
     529      long earliestDatestamp = getEarliestDateStamp(collection_list); 
     530      String earliestDatestamp_str = OAIXML.getTime(earliestDatestamp); 
     531      Date earliestDatestamp_date = OAIXML.getDate(earliestDatestamp_str); 
     532       
     533      if(until_date.compareTo(earliestDatestamp_date) < 0) { 
     534          return OAIXML.createErrorMessage(OAIXML.NO_RECORDS_MATCH, ""); 
     535      } 
     536      } 
     537       
    514538   
    515539      // check the set arg is a set we know about