Ignore:
Timestamp:
2011-05-09T14:37:04+12:00 (13 years ago)
Author:
sjm84
Message:

Updating this branch to match the latest Greenstone3 changes

Location:
main/branches/64_bit_Greenstone/greenstone3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/branches/64_bit_Greenstone/greenstone3

  • main/branches/64_bit_Greenstone/greenstone3/src/java/org/greenstone/gsdl3/core/OAIReceptionist.java

    r16688 r24007  
    296296       *  Use the time value plus the current system time to get the expiration date string.
    297297       */
    298       String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration());
     298    String expiration_date = OAIXML.getTime(System.currentTimeMillis() + OAIXML.getTokenExpiration()); // in milliseconds
    299299      token.setAttribute(OAIXML.EXPIRATION_DATE, expiration_date);
    300300    }
     
    339339   
    340340    HashMap param_map = OAIXML.getParamMap(params);   
    341     if (!isValidParam(param_map, valid_strs) ||
    342         !param_map.containsKey(OAIXML.METADATA_PREFIX)) {
    343       logger.error("contains invalid params or no metadataPrefix");
    344       return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     341    if (!isValidParam(param_map, valid_strs)) {
     342    logger.error("One of the params is invalid");
     343    return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
    345344    }
     345    // param keys are valid, but if there are any date params, check they're of the right format
     346    String from = (String)param_map.get(OAIXML.FROM);
     347    if(from != null) { 
     348    Date from_date = OAIXML.getDate(from);
     349    if(from_date == null) {
     350        logger.error("invalid date: " + from);
     351        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     352    }
     353    }
     354    String until = (String)param_map.get(OAIXML.UNTIL);
     355    if(until != null) {
     356    Date until_date = OAIXML.getDate(until);
     357    if(until_date == null) {
     358        logger.error("invalid date: " + until);
     359        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     360    }
     361    }   
     362    if(from != null && until != null) { // check they are of the same date-time format (granularity)
     363    if(from.length() != until.length()) {
     364        logger.error("The request has different granularities (date-time formats) for the From and Until date parameters.");
     365        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     366    }
     367    }
     368
    346369    //ask the message router for a list of oai collections
    347370    NodeList oai_coll = getOAICollectionList();
     
    350373      logger.info("returned oai collection list is empty");
    351374      return getMessage(OAIXML.createErrorElement(OAIXML.NO_RECORDS_MATCH, ""));
    352     }
    353     //Now that we got a prefix, check and see if it's supported by this repository
    354     String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);
    355     if (containsMetadataPrefix(prefix_value) == false) {
    356       logger.error("requested prefix is not found in OAIConfig.xml");
    357       return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
    358375    }
    359376   
     
    390407    }
    391408   
     409    // Custom test that expects a metadataPrefix comes here at end so that the official params can
     410    // be tested first for errors and their error responses sent off. Required for OAI validation
     411    if (!param_map.containsKey(OAIXML.METADATA_PREFIX)) {
     412      logger.error("contains invalid params or no metadataPrefix");
     413      return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     414    }   
     415   
     416    //Now that we got a prefix, check and see if it's supported by this repository
     417    String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);
     418    if (containsMetadataPrefix(prefix_value) == false) {
     419      logger.error("requested prefix is not found in OAIConfig.xml");
     420      return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
     421    }
     422
    392423    //Now that all validation has been done, I hope, we can send request to the message router
    393424    Element result = null;
     
    519550   
    520551    HashMap param_map = OAIXML.getParamMap(params);   
    521     if (!isValidParam(param_map, valid_strs) ||
    522         !param_map.containsKey(OAIXML.METADATA_PREFIX)) {
    523       // it must have a metadataPrefix
    524       /** Here I disagree with the OAI specification: even if a resumptionToken is
    525        *  included in the request, the metadataPrefix is a must argument. Otherwise
    526        *  how would we know what metadataPrefix the harvester requested in his last request?
    527        */
    528       logger.error("no metadataPrefix");
    529       return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
    530     }
     552    if (!isValidParam(param_map, valid_strs)) {
     553    logger.error("One of the params is invalid");
     554    return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     555    }
     556    // param keys are valid, but if there are any date params, check they're of the right format
     557    String from = (String)param_map.get(OAIXML.FROM);
     558    if(from != null) { 
     559    Date from_date = OAIXML.getDate(from);
     560    if(from_date == null) {
     561        logger.error("invalid date: " + from);
     562        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     563    }
     564    }
     565    String until = (String)param_map.get(OAIXML.UNTIL);
     566    Date until_date = null;
     567    if(until != null) {
     568    until_date = OAIXML.getDate(until);
     569    if(until_date == null) {
     570        logger.error("invalid date: " + until);
     571        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     572    }
     573    }
     574    if(from != null && until != null) { // check they are of the same date-time format (granularity)
     575    if(from.length() != until.length()) {
     576        logger.error("The request has different granularities (date-time formats) for the From and Until date parameters.");
     577        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     578    }
     579    }
    531580   
    532581    //ask the message router for a list of oai collections
     
    536585      logger.info("returned oai collection list is empty");
    537586      return getMessage(OAIXML.createErrorElement(OAIXML.NO_RECORDS_MATCH, ""));
    538     }
    539    
    540     //Now that we got a prefix, check and see if it's supported by this repository
    541     String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);
    542     if (containsMetadataPrefix(prefix_value) == false) {
    543       logger.error("requested prefix is not found in OAIConfig.xml");
    544       return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
    545587    }
    546588   
     
    585627      }
    586628    }
     629
     630    // Moved the additional custom test that mandates the metadataPrefix here, since official
     631    // errors should be caught first, so that their error responses can be sent off first
     632    // such that GS2's oaiserver will validate properly.
     633    if (!param_map.containsKey(OAIXML.METADATA_PREFIX)) {
     634      // it must have a metadataPrefix
     635      /** Here I disagree with the OAI specification: even if a resumptionToken is
     636       *  included in the request, the metadataPrefix is a must argument. Otherwise
     637       *  how would we know what metadataPrefix the harvester requested in his last request?
     638       */
     639      logger.error("no metadataPrefix");
     640      return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, ""));
     641    }
     642       
     643    //Now that we got a prefix, check and see if it's supported by this repository
     644    String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX);
     645    if (containsMetadataPrefix(prefix_value) == false) {
     646      logger.error("requested prefix is not found in OAIConfig.xml");
     647      return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, ""));
     648    }
     649
    587650    //Now that all validation has been done, I hope, we can send request to the message router
    588651    Element result = null;
     
    704767    }
    705768    Element res_in_result = (Element)GSXML.getChildByTagName(result, OAIXML.RESPONSE);
     769    if(res_in_result == null) { // return the results of all other collections accumulated so far
     770    return msg;
     771    }
    706772    Element verb_elem = (Element)GSXML.getChildByTagName(res_in_result, verb);
    707773    if(msg == null) {
     
    787853        // get the names
    788854        strs = splitNames(identifier);
     855    if(strs == null || strs.length < 3) {
     856        logger.error("identifier is not in the form site:coll:id" + identifier);
     857        return getMessage(OAIXML.createErrorElement(OAIXML.ID_DOES_NOT_EXIST, ""));
     858    }
    789859        String name_of_site = strs[0];
    790860        String coll_name = strs[1];
     
    831901    //do the protocol version
    832902    copyElement(identify, OAIXML.PROTOCOL_VERSION);
    833     //do the deletedRecord
    834     copyElement(identify, OAIXML.DELETED_RECORD);
    835     //do the granularity
    836     copyElement(identify, OAIXML.GRANULARITY);
    837    
     903       
    838904    //There can be more than one admin email according to the OAI specification
    839905    NodeList admin_emails = GSXML.getChildrenByTagName(oai_config, OAIXML.ADMIN_EMAIL);
     
    848914
    849915    //do the earliestDatestamp
    850     long lastmodified = System.currentTimeMillis();
    851916    //send request to mr to search through the earliest datestamp amongst all oai collections in the repository.
    852917    //ask the message router for a list of oai collections
    853918    NodeList oai_coll = getOAICollectionList();
    854     int oai_coll_size = oai_coll.getLength();
    855     if (oai_coll_size == 0) {
    856       logger.info("returned oai collection list is empty. Set repository earliestDatestamp to be 1970-01-01.");
    857       lastmodified = 0;
    858     }
    859     //the collection build time is determined by the last modified time of the buildConfig.xml file
    860     for(int i=0; i<oai_coll_size; i++) {
    861       long coll_build_time = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.LASTMODIFIED));
    862       lastmodified = (lastmodified > coll_build_time)? coll_build_time : lastmodified;
    863     }
    864     String earliestDatestamp_str = OAIXML.getTime(lastmodified);
     919    long earliestDatestamp = getEarliestDateStamp(oai_coll);
     920    String earliestDatestamp_str = OAIXML.getTime(earliestDatestamp);
    865921    Element earliestDatestamp_elem = OAIXML.createElement(OAIXML.EARLIEST_DATESTAMP);
    866922    GSXML.setNodeText(earliestDatestamp_elem, earliestDatestamp_str);
    867923    identify.appendChild(earliestDatestamp_elem);
     924
     925    //do the deletedRecord
     926    copyElement(identify, OAIXML.DELETED_RECORD);
     927    //do the granularity
     928    copyElement(identify, OAIXML.GRANULARITY);
    868929       
    869930    return getMessage(identify);
     
    886947    String [] strs = new String[3];
    887948    int first_colon = identifier.indexOf(":");
     949    if(first_colon == -1) {
     950    return null;
     951    }
    888952    strs[0] = identifier.substring(0, first_colon);
    889953
     
    9681032    return converter.nodeToElement(result_node);
    9691033  }
     1034
     1035    // See OAIConfig.xml
     1036    // dynamically works out what the earliestDateStamp is, since it varies by collection
     1037    // returns this time in *milliseconds*.
     1038    protected long getEarliestDateStamp(NodeList oai_coll) {
     1039    //do the earliestDatestamp
     1040    long earliestDatestamp = System.currentTimeMillis();   
     1041    int oai_coll_size = oai_coll.getLength();
     1042    if (oai_coll_size == 0) {
     1043        logger.info("returned oai collection list is empty. Setting repository earliestDatestamp to be 1970-01-01.");
     1044        earliestDatestamp = 0;
     1045    }
     1046    // the earliestDatestamp is now stored as a metadata element in the collection's buildConfig.xml file
     1047    // we get the earliestDatestamp among the collections
     1048    for(int i=0; i<oai_coll_size; i++) {
     1049        long coll_earliestDatestamp = Long.parseLong(((Element)oai_coll.item(i)).getAttribute(OAIXML.EARLIEST_DATESTAMP));
     1050        earliestDatestamp = (earliestDatestamp > coll_earliestDatestamp)? coll_earliestDatestamp : earliestDatestamp;
     1051    }
     1052
     1053    return earliestDatestamp*1000; // converting from seconds to milliseconds
     1054    }
    9701055}
Note: See TracChangeset for help on using the changeset viewer.