[8182] | 1 | #include "metaformatsaction.h"
|
---|
| 2 | #include "metaformat.h"
|
---|
[15428] | 3 | #include "recptprototools.h"
|
---|
[8182] | 4 | #include "oaitools.h"
|
---|
| 5 |
|
---|
| 6 | bool metaformatsaction::validateAction(recptproto *protocol, oaiargs ¶ms)
|
---|
| 7 | {
|
---|
[16716] | 8 | // ----------------------------------------------------------------------------
|
---|
| 9 | // 1. Check for invalid arguments
|
---|
| 10 | // ----------------------------------------------------------------------------
|
---|
| 11 | bool invalid_argument_supplied = false;
|
---|
[15198] | 12 | text_tmap::const_iterator param_iterator = params.begin();
|
---|
| 13 | while (param_iterator != params.end())
|
---|
| 14 | {
|
---|
[16716] | 15 | // Check for arguments that aren't valid for this action
|
---|
[15198] | 16 | if (param_iterator->first != "verb" &&
|
---|
| 17 | param_iterator->first != "identifier")
|
---|
| 18 | {
|
---|
[16716] | 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
|
---|
[15198] | 23 | params.erase(param_iterator->first);
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | param_iterator++;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[16716] | 29 | // If we found an invalid argument it's an error, so don't go any further
|
---|
| 30 | if (invalid_argument_supplied)
|
---|
| 31 | {
|
---|
[8182] | 32 | this->errorType = "badArgument";
|
---|
| 33 | return false;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[16716] | 36 | // ----------------------------------------------------------------------------
|
---|
| 37 | // 2. Handle any exclusive arguments
|
---|
| 38 | // ----------------------------------------------------------------------------
|
---|
[8182] | 39 |
|
---|
[16716] | 40 | // None!
|
---|
[8182] | 41 |
|
---|
[16716] | 42 | // ----------------------------------------------------------------------------
|
---|
| 43 | // 3. Handle any required arguments
|
---|
| 44 | // ----------------------------------------------------------------------------
|
---|
[8182] | 45 |
|
---|
[16716] | 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 | {
|
---|
[8182] | 65 | this->errorType = "idDoesNotExist";
|
---|
[16716] | 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 | {
|
---|
[8182] | 73 | return false;
|
---|
| 74 | }
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
[16716] | 77 |
|
---|
| 78 | // If we've reached here everything must be fine
|
---|
| 79 | this->errorType = "";
|
---|
[8182] | 80 | return true;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | bool metaformatsaction::output_content(ostream &output, recptproto *protocol, oaiargs ¶ms)
|
---|
| 84 | {
|
---|
| 85 | // if an identifier parameter is being used, then respond to it - currently we reject anything other
|
---|
| 86 | // than dublin core (unqualified)
|
---|
| 87 | //
|
---|
| 88 | // TODO: only return the selected identifier (if given) and don't validate the entry; just
|
---|
| 89 | // return nothing if an invalid or unknown metadata format is given
|
---|
| 90 |
|
---|
| 91 | // give the required xml response
|
---|
| 92 |
|
---|
| 93 | text_t gsdlId = params["identifier"];
|
---|
| 94 | text_t gsdlCollect;
|
---|
| 95 |
|
---|
| 96 | // convert record identifier into GSDL format from OAI
|
---|
| 97 | if (gsdlId != "") {
|
---|
| 98 | oaiclassifier::toGSDL(gsdlCollect, gsdlId);
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | metaformat_map::iterator here = this->formats->begin();
|
---|
| 102 | metaformat_map::iterator end = this->formats->end();
|
---|
| 103 |
|
---|
| 104 | // v1.1 should check that the id - if supplied - didn't cause an error. If it did,
|
---|
| 105 | // don't output the metadataFormat tags. OAI v2.0 should already have bailed.
|
---|
| 106 | if(this->errorType != "idDoesNotExist"){
|
---|
| 107 | while (here != end) { // Loop through the repository's supported metadata formats
|
---|
| 108 | bool doOutput = true;
|
---|
| 109 |
|
---|
| 110 | // if we were given an identifier, then check if it supports the metadata format in question
|
---|
| 111 | if (gsdlId != "") {
|
---|
| 112 | doOutput = here->second.get_class()->is_available(gsdlCollect, this->gsdlResponse.docInfo[0]);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | if (doOutput) {
|
---|
| 116 | output << " <metadataFormat>" << endl;
|
---|
| 117 | here->second.get_class()->output_formatdata(output);
|
---|
| 118 | output << " </metadataFormat>\n";
|
---|
| 119 | }
|
---|
[9608] | 120 | ++here;
|
---|
[8182] | 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | return true;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | void metaformatsaction::setConfiguration(oaiconfig *configuration)
|
---|
| 128 | {
|
---|
| 129 | this->configuration = configuration;
|
---|
| 130 |
|
---|
| 131 | metaformat_map::iterator here = this->formats->begin();
|
---|
| 132 | metaformat_map::iterator end = this->formats->end();
|
---|
| 133 | while (here != end) {
|
---|
| 134 | here->second.set_configuration((oaiconfig *) configuration);
|
---|
[9608] | 135 | ++here;
|
---|
[8182] | 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|