Changeset 16716

Show
Ignore:
Timestamp:
12.08.2008 12:31:48 (11 years ago)
Author:
mdewsnip
Message:

Tidied up the validateAction() function to be consistently structured.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/runtime-src/src/oaiservr/metaformatsaction.cpp

    r15428 r16716  
    66bool metaformatsaction::validateAction(recptproto *protocol, oaiargs &params) 
    77{  
    8   int params_size = params.getSize(); 
    9  
    10   // Remove any parameters that aren't valid for this action 
     8  // ---------------------------------------------------------------------------- 
     9  //  1. Check for invalid arguments 
     10  // ---------------------------------------------------------------------------- 
     11  bool invalid_argument_supplied = false; 
    1112  text_tmap::const_iterator param_iterator = params.begin(); 
    1213  while (param_iterator != params.end()) 
    1314  { 
     15    // Check for arguments that aren't valid for this action 
    1416    if (param_iterator->first != "verb" && 
    1517    param_iterator->first != "identifier") 
    1618    { 
     19      // We've found an invalid argument 
     20      invalid_argument_supplied = true; 
     21 
     22      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned 
    1723      params.erase(param_iterator->first); 
    1824    } 
     
    2127  } 
    2228 
    23   int numArgs = 1; // the number of expected arguments 
    24    
    25   // increase the number of expected arguments if the optional 'identifier' argument 
    26   // is given  
    27   if (params["identifier"] != "") { 
    28     ++numArgs; 
    29   } 
    30  
    31   // If the total number of params isn't equal to the number of valid 
    32   // args (i.e. we have an arg but it isn't the identifier), throw an error   
    33   if((params_size != numArgs)){ 
     29  // If we found an invalid argument it's an error, so don't go any further  
     30  if (invalid_argument_supplied) 
     31  { 
    3432    this->errorType = "badArgument"; 
    3533    return false; 
    3634  } 
    3735 
    38   // Variables to hold identifier in Greenstone format 
    39   text_t docID = params["identifier"];  
    40   text_t collection = ""; 
     36  // ---------------------------------------------------------------------------- 
     37  //  2. Handle any exclusive arguments 
     38  // ---------------------------------------------------------------------------- 
    4139 
    42   // The following two variables are used solely by the get_info() function call to test if 
    43   // the identifier supplied is an actual document. If it isn't, we need to throw an exception. 
    44   const text_tset metadata; 
     40  // None! 
    4541 
    46   // Check for the existence, etc. of the record if an identifier is given. 
    47   if (docID != "") { 
    48     oaiclassifier::toGSDL(collection, docID); 
    49      
    50     // Only throw an error if we're using v2.0.  
    51     // v1.1 should simply return a response without a metadataFormat container. 1.1 
    52     // should still set the errorType so we know that the error was encountered 
     42  // ---------------------------------------------------------------------------- 
     43  //  3. Handle any required arguments 
     44  // ---------------------------------------------------------------------------- 
    5345 
    54     // the information retrieved here is retained for the output_content function below 
    55     if (!get_info(docID, collection, "", metadata, false, protocol, this->gsdlResponse, cerr)){ 
     46  // None! 
     47 
     48  // ---------------------------------------------------------------------------- 
     49  // 4. Check any remaining arguments 
     50  // ---------------------------------------------------------------------------- 
     51 
     52  // Check "identifier" argument 
     53  if (params["identifier"] != "") 
     54  { 
     55    text_t identifier = params["identifier"]; 
     56 
     57    // Extract the collection name from the identifier specification 
     58    text_t collection = ""; 
     59    oaiclassifier::toGSDL(collection, identifier); 
     60   
     61    // Check a document with the specified identifier exists 
     62    text_tset metadata; 
     63    if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout)) 
     64    { 
    5665      this->errorType = "idDoesNotExist"; 
    57       if(this->configuration->getOAIVersion() >= 200) { 
     66 
     67      // Only throw an error if we're using v2.0.  
     68      // v1.1 should simply return a response without a metadataFormat container. 1.1 
     69      // should still set the errorType so we know that the error was encountered 
     70      // the information retrieved here is retained for the output_content function below 
     71      if (this->configuration->getOAIVersion() >= 200) 
     72      { 
    5873    return false; 
    5974      } 
    6075    } 
    6176  } 
     77 
     78  // If we've reached here everything must be fine 
     79  this->errorType = ""; 
    6280  return true; 
    6381}