Changeset 24440

Show
Ignore:
Timestamp:
20.08.2011 21:42:11 (8 years ago)
Author:
ak19
Message:

GS2 failed new OAI validation test at openarchives.org The code failed on a listRecords request with a resumptiontoken: since no metadata_prefix was specified, the code was set to fail. Now, the metadata_prefix is appended to the end of the resumptiontoken so that a follow-up request to listrecords can work out what the metadata-prefix was from the resumptiontoken.

Files:
1 modified

Legend:

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

    r23944 r24440  
    287287    return getMessage(list_sets_elem); 
    288288  }   
    289   private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration) { 
     289    private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration, String metadata_prefix) { 
    290290    Element token = OAIXML.createElement(OAIXML.RESUMPTION_TOKEN); 
    291291    token.setAttribute(OAIXML.COMPLETE_LIST_SIZE, "" + total_size); 
     
    305305      //data provider has to offer 
    306306      //Here, we make use of the uniqueness of the system time 
    307       GSXML.setNodeText(token, OAIXML.GS3OAI + System.currentTimeMillis() + ":" + so_far_sent); 
     307    String tokenValue = OAIXML.GS3OAI + System.currentTimeMillis() + ":" + so_far_sent;  
     308    if(!metadata_prefix.equals("")) { 
     309        tokenValue = tokenValue + ":" + metadata_prefix; 
     310    } 
     311    GSXML.setNodeText(token, tokenValue); 
    308312    } 
    309313    return token; 
    310314  } 
     315     
     316    private Element createResumptionTokenElement(int total_size, int cursor, int so_far_sent, boolean set_expiration) { 
     317    return createResumptionTokenElement(total_size, cursor, so_far_sent, set_expiration, ""); // empty metadata_prefix 
     318    } 
     319 
    311320  /** if the param_map contains strings other than those in valid_strs, return false; 
    312321   *  otherwise true. 
     
    622631        //}       
    623632      token = (String)param_map.get(OAIXML.RESUMPTION_TOKEN); 
    624       logger.info("has resumptionToken" + token); 
     633      logger.info("has resumptionToken: " + token); 
    625634      if(OAIXML.containsToken(token) == false) { 
    626635        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_RESUMPTION_TOKEN, "")); 
     
    632641    // such that GS2's oaiserver will validate properly. 
    633642    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    if(!token.equals("")) { // resumptiontoken 
     644        int lastIndex = token.lastIndexOf(":"); 
     645        if(lastIndex != token.indexOf(":")) { // if a meta_prefix is suffixed to the usual token, 
     646        // put that in the map and remove it from the end of the stored token 
     647        String meta_prefix = token.substring(lastIndex+1); 
     648        param_map.put(OAIXML.METADATA_PREFIX, meta_prefix); 
     649        token = token.substring(0, lastIndex); 
     650        param_map.put(OAIXML.RESUMPTION_TOKEN, token); 
     651 
     652        // Add to request <param name="metadataPrefix" value="oai_dc"/> 
     653        // need to add metaprefix as param to request, else a request  
     654        // for subsequent records when working with resumption tokens will fail 
     655        Element paramEl = req.getOwnerDocument().createElement(OAIXML.PARAM); 
     656        paramEl.setAttribute(OAIXML.NAME, OAIXML.METADATA_PREFIX); 
     657        paramEl.setAttribute(OAIXML.VALUE, meta_prefix); 
     658        req.appendChild(paramEl); 
     659        } 
     660    } else { // no metadata_prefix 
     661 
     662        // it must have a metadataPrefix 
     663        /** Here I disagree with the OAI specification: even if a resumptionToken is  
     664         *  included in the request, the metadataPrefix is a must argument. Otherwise 
     665         *  how would we know what metadataPrefix the harvester requested in his last request? 
     666         */ 
     667        logger.error("no metadataPrefix"); 
     668        return getMessage(OAIXML.createErrorElement(OAIXML.BAD_ARGUMENT, "")); 
     669    } 
     670    } 
     671     
    643672    //Now that we got a prefix, check and see if it's supported by this repository 
    644673    String prefix_value = (String)param_map.get(OAIXML.METADATA_PREFIX); 
    645674    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     } 
     675    logger.error("requested prefix is not found in OAIConfig.xml"); 
     676    return getMessage(OAIXML.createErrorElement(OAIXML.CANNOT_DISSEMINATE_FORMAT, "")); 
     677    } 
     678     
    649679 
    650680    //Now that all validation has been done, I hope, we can send request to the message router 
     
    678708    Element e = converter.nodeToElement(n); 
    679709        result = collectAll(result, e, verb, OAIXML.RECORD); 
    680          
     710 
    681711        //clear the content of the old request element 
    682712        msg.removeChild(req); 
     
    717747      getRecords(list_records, record_list, 0, resume_after); 
    718748      //An incomplete list is sent; append a resumptionToken element 
    719       Element token_elem = createResumptionTokenElement(num_records, 0, resume_after, true); 
     749      Element token_elem = createResumptionTokenElement(num_records, 0, resume_after, true, (String)param_map.get(OAIXML.METADATA_PREFIX)); 
    720750      //store this token 
    721751      OAIXML.addToken(token_elem); 
     
    738768        getRecords(list_records, record_list, cursor, num_records); 
    739769        //An incomplete list is sent; append a resumptionToken element 
    740         token_elem = createResumptionTokenElement(num_records, cursor, -1, false); 
    741         list_records.appendChild(token_elem); 
     770    token_elem = createResumptionTokenElement(num_records, cursor, -1, false, (String)param_map.get(OAIXML.METADATA_PREFIX)); 
     771    list_records.appendChild(token_elem); 
     772 
    742773      } else { 
    743774        //No, we are not. 
    744775        //append required records to list_records (list is incomplete) 
    745776        getRecords(list_records, record_list, cursor, cursor + resume_after); 
    746         token_elem = createResumptionTokenElement(num_records, cursor, cursor + resume_after, true); 
     777        token_elem = createResumptionTokenElement(num_records, cursor, cursor + resume_after, true, (String)param_map.get(OAIXML.METADATA_PREFIX)); 
    747778        //store this token 
    748779        OAIXML.addToken(token_elem);