Changeset 16715


Ignore:
Timestamp:
2008-08-12T12:25:09+12:00 (16 years ago)
Author:
mdewsnip
Message:

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

File:
1 edited

Legend:

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

    r15428 r16715  
    3030bool recordaction::validateAction(recptproto *protocol, oaiargs &params)
    3131{
    32   int params_size = params.getSize();
    33 
    34   // Remove any parameters that aren't valid for this action
     32  // ----------------------------------------------------------------------------
     33  //  1. Check for invalid arguments
     34  // ----------------------------------------------------------------------------
     35  bool invalid_argument_supplied = false;
    3536  text_tmap::const_iterator param_iterator = params.begin();
    3637  while (param_iterator != params.end())
    3738  {
     39    // Check for arguments that aren't valid for this action
    3840    if (param_iterator->first != "verb" &&
    3941    param_iterator->first != "identifier" &&
    4042    param_iterator->first != "metadataPrefix")
    4143    {
     44      // We've found an invalid argument
     45      invalid_argument_supplied = true;
     46
     47      // Delete the invalid argument from the list so it doesn't end up in the <request> tag that is returned
    4248      params.erase(param_iterator->first);
    4349    }
     
    4652  }
    4753
    48   text_t meta = params["metadataPrefix"];
    49   text_t gsdlId = params["identifier"];
    50   text_t gsdlCollect;
    51   text_t language = "";
    52   int oaiVersion = this->configuration->getOAIVersion();
    53 
    54   // The identifier and metadataPrefix args MUST be supplied, and are the only
    55   // args allowed (excluding verb arg). If we don't have them, throw an error.
    56   if(gsdlId == "" || meta == "" || params_size != 3){
     54  // If we found an invalid argument it's an error, so don't go any further
     55  if (invalid_argument_supplied)
     56  {
    5757    this->errorType = "badArgument";
    5858    return false;
    5959  }
    6060
    61   // Check to see if the metadataPrefix supplied is supported
    62   if(this->formatNotSupported(meta)) {
     61  // ----------------------------------------------------------------------------
     62  //  2. Handle any exclusive arguments
     63  // ----------------------------------------------------------------------------
     64
     65  // None!
     66
     67  // ----------------------------------------------------------------------------
     68  //  3. Handle any required arguments
     69  // ----------------------------------------------------------------------------
     70
     71  // The "metadataPrefix" argument is required
     72  text_t metadataPrefix = params["metadataPrefix"];
     73
     74  // Check that the metadataPrefix argument exists
     75  if (metadataPrefix == "")
     76  {
     77    this->errorType = "badArgument";
     78    return false;
     79  }
     80  // Check that the metadataPrefix is a format we support
     81  if (this->formatNotSupported(metadataPrefix))
     82  {
    6383    this->errorType = "cannotDisseminateFormat";
    64     if(oaiVersion == 200)
    65       return false;
    66   }
    67 
    68   // convert record identifier into GSDL format from OAI
    69   oaiclassifier::toGSDL(gsdlCollect, gsdlId);
    70  
    71   // get the document information
    72   text_tset        metadata;
    73   if (!get_info(gsdlId, gsdlCollect, language, metadata, false, protocol, this->gsdlResponse, *logout)) {
     84    return false;
     85  }
     86
     87  // The "identifier" argument is required
     88  text_t identifier = params["identifier"];
     89
     90  // Extract the collection name from the identifier specification
     91  text_t collection = "";
     92  oaiclassifier::toGSDL(collection, identifier);
     93 
     94  // Check a document with the specified identifier exists
     95  text_tset metadata;
     96  if (!get_info(identifier, collection, "", metadata, false, protocol, this->gsdlResponse, *logout))
     97  {
    7498    this->errorType = "idDoesNotExist";
    75     if(oaiVersion == 200)
    76       return false;
    77   }
    78 
     99    return false;
     100  }
     101
     102  // ----------------------------------------------------------------------------
     103  // 4. Check any remaining arguments
     104  // ----------------------------------------------------------------------------
     105
     106  // None!
     107
     108  // If we've reached here everything must be fine
     109  this->errorType = "";
    79110  return true;
    80111}
Note: See TracChangeset for help on using the changeset viewer.