Annotation of nsdl/lib/perl/Apache/NSDL/ToTheGateway.pm, revision 1.6
1.1 harris41 1: # Apache::NSDL::ToTheGateway
2: #
3: # ToTheGateway.pm
4: # API for passing information from NSDL to the Gateway Server
5: #
6: # For more documentation, read the POD documentation
7: # of this module with the perldoc command:
8: #
9: # perldoc ./ToTheGateway.pm
10: #
11: # Brief description
12: # =================
13: #
14: # This module contains functionality for
15: # transferring information from NSDL to the Gateway Server.
16: #
17: # In terms of the overall data flow, the
18: # '=====>' below indicates the role of this
19: # module.
20: #
21: # NSDL =========> Gateway --------> LON-CAPA
22: # LON-CAPA -----> Gateway --------> NSDL
23: #
24: # SUBROUTINES:
25: # NSDL->answer_list_records_request
26: # NSDL->answer_search_request
27: # NSDL->answer_metadata_record_request
28: # NSDL->answer_resource_request
29:
30: # Year 2002
31: # Scott Harrison
32: # February-May
33: #
34: ###
35:
36: package Apache::NSDL::ToTheGateway;
37:
38: # ================================================================ DEPENDENCIES
39: use strict; # enforce handling of variables, references and subroutines
1.3 harris41 40: use Apache::Constants qw(:common);
1.4 harris41 41: use Apache::GATEWAY::Common;
42: use Apache::NSDL::FromTheGateway;
1.1 harris41 43:
44: # ============================================================ MODULE VARIABLES
1.6 ! harris41 45: my $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
! 46: my $hostname='nsdl.lon-capa.org';
1.1 harris41 47:
48: # ================================================================= SUBROUTINES
1.3 harris41 49:
50: # ----------------------------- Handling routine called via Apache and mod_perl
51: sub handler {
52: my $r = shift;
1.4 harris41 53: Apache::GATEWAY::Common::readCGI($r);
54: my $output;
55: if ($ENV{'form.verb'} eq 'GetRecord') {
1.6 ! harris41 56: # arguments: identifier, metadataPrefix
! 57: if(!defined($ENV{'form.identifier'})) {
! 58: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 59: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 60: $output=(<<END);
! 61: <?xml version="1.0" encoding="UTF-8"?>
! 62: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 63: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 64: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 65: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 66: <responseDate>$responseDate</responseDate>
! 67: <request>$requestURL</request>
! 68: <error code="badArgument">Missing identifier argument</error>
! 69: </OAI-PMH>
! 70: END
! 71: }
! 72: elsif(!defined($ENV{'form.metadataPrefix'})) {
! 73: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 74: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 75: $output=(<<END);
! 76: <?xml version="1.0" encoding="UTF-8"?>
! 77: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 78: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 79: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 80: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 81: <responseDate>$responseDate</responseDate>
! 82: <request>$requestURL</request>
! 83: <error code="badArgument">Missing metadataPrefix argument</error>
! 84: </OAI-PMH>
! 85: END
! 86: }
! 87: elsif ($ENV{'form.metadataPrefix'} ne 'oai_dc' and
! 88: $ENV{'form.metadataPrefix'} ne 'loncapa_ieeelom') {
! 89: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 90: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 91: $output=(<<END);
! 92: <?xml version="1.0" encoding="UTF-8"?>
! 93: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 94: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 95: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 96: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 97: <responseDate>$responseDate</responseDate>
! 98: <request>$requestURL</request>
! 99: <error code="cannotDisseminateFormat">Cannot disseminate the requested
! 100: metadata format</error>
! 101: </OAI-PMH>
! 102: END
! 103: }
! 104: else {
! 105: my $status;
! 106: ($status,$output)=
1.4 harris41 107: Apache::NSDL::FromTheGateway::view_LONCAPAgateway_metadata_record(\%ENV);
1.6 ! harris41 108: }
1.4 harris41 109: }
110: elsif ($ENV{'form.verb'} eq 'Identify') {
1.6 ! harris41 111: # arguments: none
1.5 harris41 112: my $responseDate=Apache::GATEWAY::Common::responseDate();
1.6 ! harris41 113: my $requestURL=Apache::GATEWAY::Common::requestURL();
1.4 harris41 114: $output=(<<END);
115: <?xml version="1.0" encoding="UTF-8"?>
1.6 ! harris41 116: <OAI-PMH
! 117: xmlns="http://www.openarchives.org/OAI/2.0/"
1.4 harris41 118: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1.6 ! harris41 119: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 120: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
1.5 harris41 121: <responseDate>$responseDate</responseDate>
1.6 ! harris41 122: <requestURL>$requestURL</requestURL>
! 123: <Identify >
1.4 harris41 124: <repositoryName>The LearningOnline Network with CAPA</repositoryName>
1.6 ! harris41 125: <baseURL>http://$hostname/OAI-script</baseURL>
1.4 harris41 126: <protocolVersion>1.1</protocolVersion>
1.6 ! harris41 127: <adminEmail>mailto:korte\@lite.msu.edu</adminEmail>
1.4 harris41 128: <description>
1.6 ! harris41 129: <oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier"
1.4 harris41 130: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1.6 ! harris41 131: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai-identifier
! 132: http://www.openarchives.org/OAI/2.0/oai-identifier.xsd">
1.4 harris41 133: <scheme>oai</scheme>
134: <repositoryIdentifier>loncapa</repositoryIdentifier>
135: <delimiter>:</delimiter>
136: <sampleIdentifier>oai:loncapa:harrison2002-1</sampleIdentifier>
137: </oai-identifier>
138: </description>
139: <description>
1.6 ! harris41 140: <eprints xmlns="http://www.openarchives.org/OAI/2.0/eprints"
1.4 harris41 141: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1.6 ! harris41 142: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/eprints
! 143: http://www.openarchives.org/OAI/2.0/eprints.xsd">
1.4 harris41 144: <content>
1.6 ! harris41 145: <URL>http://$hostname/info/content.html</URL>
! 146: <text>Educational materials from the LearningOnline Network</text>
1.4 harris41 147: </content>
148: <metadataPolicy>
149: <text>Metadata can be used by authorized users</text>
150: </metadataPolicy>
151: <dataPolicy>
152: <text>Full content, i.e. preprints may not be harvested by robots</text>
153: </dataPolicy>
154: <submissionPolicy>
1.6 ! harris41 155: <text>Submissions can be made by institutions with installed
! 156: LON-CAPA servers.</text>
1.4 harris41 157: </submissionPolicy>
158: </eprints>
159: </description>
160: </Identify>
1.6 ! harris41 161: </OAI-PMH>
1.4 harris41 162: END
163: }
1.5 harris41 164: elsif ($ENV{'form.verb'} eq 'ListIdentifiers') {
1.6 ! harris41 165: # arguments: until, from, set, resumptionToken
! 166: # $output=
! 167: # Apache::NSDL::FromTheGateway::search_against_LONCAPAgateway(\%ENV);
! 168: # no full implementation scheme yet so...
! 169: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 170: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 171: $output=(<<END);
! 172: <?xml version="1.0" encoding="UTF-8"?>
! 173: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 174: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 175: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 176: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 177: <responseDate>$responseDate</responseDate>
! 178: <request>$requestURL</request>
! 179: <error code="noSetHierarchy">No set hierarchy available yet for this
! 180: gateway.</error>
! 181: </OAI-PMH>
! 182: END
1.5 harris41 183: }
184: elsif ($ENV{'form.verb'} eq 'ListMetadataFormats') {
1.6 ! harris41 185: # arguments: identifier
! 186: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 187: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 188: $output=(<<END);
! 189: <?xml version="1.0" encoding="UTF-8"?>
! 190: <ListMetadataFormats
! 191: xmlns="http://www.openarchives.org/OAI/1.1/OAI_ListMetadataFormats"
! 192: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 193: xsi:schemaLocation="http://www.openarchives.org/OAI/1.1/OAI_ListMetadataFormats
! 194: http://www.openarchives.org/OAI/1.1/OAI_ListMetadataFormats.xsd">
! 195: <responseDate>$responseDate</responseDate>
! 196: <requestURL>$requestURL</requestURL>
! 197: <metadataFormat>
! 198: <metadataPrefix>oai_dc</metadataPrefix>
! 199: <schema>http://www.openarchives.org/OAI/1.1/dc.xsd</schema>
! 200: <metadataNamespace>http://purl.org/dc/elements/1.1/</metadataNamespace>
! 201: </metadataFormat>
! 202: <metadataFormat>
! 203: <metadataPrefix>loncapa_ieeelom</metadataPrefix>
! 204: <schema>http://nsdl.lon-capa.org/lom/6.4/ieeelom.xsd</schema>
! 205: <metadataNamespace>http://nsdl.lon-capa.org/lom/6.4/</metadataNamespace>
! 206: </metadataFormat>
! 207: </ListMetadataFormats>
! 208: END
1.5 harris41 209: }
210: elsif ($ENV{'form.verb'} eq 'ListRecords') {
1.6 ! harris41 211: # arguments: until, from, set, resumptionToken
! 212: # $output=
! 213: # Apache::NSDL::FromTheGateway::search_against_LONCAPAgateway(\%ENV);
! 214: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 215: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 216: $output=(<<END);
! 217: <?xml version="1.0" encoding="UTF-8"?>
! 218: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 219: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 220: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 221: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 222: <responseDate>$responseDate</responseDate>
! 223: <request>$requestURL</request>
! 224: <error code="noSetHierarchy">No set hierarchy available yet for this
! 225: gateway.</error>
! 226: </OAI-PMH>
! 227: END
1.5 harris41 228: }
229: elsif ($ENV{'form.verb'} eq 'ListSets') {
1.6 ! harris41 230: # arguments: resumptionToken
! 231: # $output='not yet implemented';
! 232: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 233: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 234: $output=(<<END);
! 235: <?xml version="1.0" encoding="UTF-8"?>
! 236: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 237: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 238: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 239: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 240: <responseDate>$responseDate</responseDate>
! 241: <request>$requestURL</request>
! 242: <error code="noSetHierarchy">No set hierarchy available yet for this
! 243: gateway.</error>
! 244: </OAI-PMH>
! 245: END
1.5 harris41 246: }
1.6 ! harris41 247: else {
! 248: my $responseDate=Apache::GATEWAY::Common::responseDate();
! 249: my $requestURL=Apache::GATEWAY::Common::requestURL();
! 250: $output=(<<END);
! 251: <?xml version="1.0" encoding="UTF-8"?>
! 252: <OAI-PMH xmlns="http://www.openarchives.org/OAI/2.0/"
! 253: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
! 254: xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/
! 255: http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd">
! 256: <responseDate>$responseDate</responseDate>
! 257: <request>$requestURL</request>
! 258: <error code="badVerb">Illegal OAI verb</error>
! 259: </OAI-PMH>
! 260: END
1.4 harris41 261: }
1.6 ! harris41 262: $r->content_type('text/xml');
1.3 harris41 263: $r->send_http_header;
264: return(OK) if $r->header_only;
265: $r->print(<<END);
1.4 harris41 266: $output
1.6 ! harris41 267: END
! 268:
! 269: # $output=~s/\>/\>/g;
! 270: # $output=~s/\</\</g;
! 271: # my $cgi;
! 272: # foreach my $key (keys %ENV) {
! 273: # if ($key=~/^form\./) {
! 274: # $cgi.="$key: $ENV{$key}\n";
! 275: # }
! 276: # }
! 277: # $r->content_type('text/html');
! 278: # $r->send_http_header;
! 279: # return(OK) if $r->header_only;
! 280: # $r->print(<<END);
! 281: #<html>
! 282: #<head><title>Test Output</title></head>
! 283: #<body>
! 284: #<h1>Apache::NSDL::ToTheGateway</h1>
! 285: #<h2>Input</h2>
! 286: #<pre>
! 287: #$cgi
! 288: #</pre>
! 289: #<h2>Output</h2>
! 290: #<pre>
! 291: #$output
! 292: #</pre>
! 293: #</body>
! 294: #</html>
1.3 harris41 295: END
296: return(OK);
297: }
1.1 harris41 298:
299: # ------------------------------------------- NSDL->answer_list_records_request
300: sub answer_list_records_request {
301: # Not yet implemented
302: # Need to specifically characterize INPUT arguments and OUTPUT data
303: }
304:
305: # ------------------------------------------------- NSDL->answer_search_request
306: sub answer_search_request {
1.4 harris41 307: my ($url)=@_;
308: return "will have http querying strategy against NSDL servers\n";
1.1 harris41 309: }
310:
311: # ---------------------------------------- NSDL->answer_metadata_record_request
312: sub answer_metadata_record_request {
1.4 harris41 313: my ($eref)=@_;
314: return Apache::NSDL::FromTheGateway($eref);
1.1 harris41 315: }
316:
317: # ----------------------------------------------- NSDL->answer_resource_request
318: sub answer_resource_request {
1.6 ! harris41 319: my ($eref)=@_;
! 320: return Apache::NSDL::FromTheGateway($eref);
1.1 harris41 321: }
322:
323: 1;
324:
325: __END__
326:
327: =pod
328:
329: =head1 NAME
330:
331: B<Apache::NSDL::ToTheGateway> - API for passing information from NSDL to the Gateway Server
332:
333: =head1 SYNOPSIS
334:
335: use Apache::NSDL::ToTheGateway;
336:
337: my $arrayref=
338: Apache::NSDL::ToTheGateway::answer_list_records_request
339: ($OAI_protocol_request);
340:
341: =head1 DESCRIPTION
342:
343: This module contains functionality for
344: transferring information from NSDL to the Gateway Server.
345:
346: In terms of the overall data flow, the
347: '=====>' below indicates the role of this
348: module.
349:
350: B<NSDL =========E<gt> Gateway> --------E<gt> LON-CAPA
351:
352: LON-CAPA -----E<gt> Gateway --------E<gt> NSDL
353:
354: =head2 EXIT CODES
355:
356: The subroutines of this module all output an exit code which
357: describes the status of function completion. The exit code
358: may be followed by a more descriptive message such as:
359:
360: FORMATERROR:Sun May 5 20:15:16 GMT 2002:missing 'protocol://' pattern
361:
362: =over 4
363:
364: =item *
365:
366: B<'SUCCESS'>, information was found and is being returned
367:
368: =item *
369:
370: B<'EMPTY'>, everything functioned properly, but no information was present
371:
372: =item *
373:
374: B<'BADEMPTY'>, everything appeared to function properly, but no information
375: was present (which defies expectation); this is useful for detecting phantom
376: cases of connectivity when verifying test cases of vertical software partitions
377:
378: =item *
379:
380: B<'TIMEOUT'>, the request is taking WAY too long
381:
382: =item *
383:
384: B<'FORMATERROR'>, the input argument is not formatted correctly in a way that
385: can be processed by the NSDL server
386:
387: =item *
388:
389: B<'CONNECTIONFAILURE'>, the NSDL server cannot be contacted
390:
391: =back
392:
393: =head2 SUBROUTINES
394:
395: Note that the subroutines all output an exit code which
396: describes the status of function completion.
397:
398: In the case of failed function completion, the other
399: output argument(s) will typically only be 'NULL' values.
400:
401: =over 4
402:
403: =item B<Apache::NSDL::answer_list_records_request>
404:
405: =over 4
406:
407: =item B<Input> - Scalar string
408:
409: Take in an OAI-format request for a specific NSDL server.
410:
411: =item B<Output> - Scalar string, Scalar array reference
412:
413: An exit code is returned as a scalar string.
414:
415: A list of records returned via an array reference.
416:
417: =item B<Description>
418:
419: This lists the records matching a given request.
420: The request comes from the Gateway Server, B<and the information
421: passes from NSDL I<to the> GATEWAY>.
422:
1.2 harris41 423: =item B<Status of Implementation>
424:
425: n/a
426:
1.1 harris41 427: =back
428:
429: =item B<Apache::NSDL::answer_search_request>
430:
431: =over 4
432:
433: =item B<Input> - Scalar string
434:
435: Take in an OAI-format request for a specific NSDL server (a search expression
436: is passed).
437:
438: =item B<Output> - Scalar string, Scalar array reference
439:
440: An exit code is returned as a scalar string.
441:
442: A list of relevant records (matching the search request) returned via an
443: array reference.
444:
445: =item B<Description>
446:
447: This lists the records matching a given search request.
448: The request comes from the Gateway Server, B<and the information
449: passes from NSDL I<to the> GATEWAY>.
450:
1.2 harris41 451: =item B<Status of Implementation>
452:
453: n/a
454:
1.1 harris41 455: =back
456:
457: =item B<Apache::NSDL::answer_metadata_record_request>
458:
459: =over 4
460:
461: =item B<Input> - Scalar string
462:
463: Take in an OAI-format request for a specific NSDL server resource's
464: metadata.
465:
466: =item B<Output> - Scalar string, Scalar string reference
467:
468: An exit code is returned as a scalar string.
469:
470: The metadata entries for the resource; returned via a scalar reference.
471:
472: =item B<Description>
473:
474: This lists the records matching a given request.
475: The request comes from the Gateway Server, B<and the information
476: passes from NSDL I<to the> GATEWAY>.
477:
1.2 harris41 478: =item B<Status of Implementation>
479:
480: n/a
481:
1.1 harris41 482: =back
483:
484: =item B<Apache::NSDL::answer_resource_request>
485:
486: =over 4
487:
488: =item B<Input> - Scalar string
489:
490: Take in an OAI-format request for a specific NSDL server's
491: resource content.
492:
493: =item B<Output> - Scalar string, Scalar string reference
494:
495: An exit code is returned as a scalar string.
496:
497: A reference to the resource content (now physically present in computer
498: memory).
499:
500: =item B<Description>
501:
502: This provides the content of the resource matching a given request.
503: The request comes from the Gateway Server, B<and the information
504: passes from NSDL I<to the> GATEWAY>.
1.2 harris41 505:
506: =item B<Status of Implementation>
507:
508: n/a
1.1 harris41 509:
510: =back
511:
512: =back
513:
514: =head1 README
515:
516: B<Apache::NSDL::ToTheGateway>
517: is part of the NSDL-LONCAPA Gateway Server system.
518: Please see http://nsdl.lon-capa.org/ for more information.
519:
520: =head1 AUTHOR
521:
522: Scott Harrison, 2002
523:
524: =head1 PREREQUISITES
525:
526: This module requires the C<strict> module.
527:
528: =head1 COREQUISITES
529:
530: Apache::NSDL::FromTheGateway
531: Apache::GATEWAY::ToNSDL
532: Apache::GATEWAY::FromNSDL
533: Apache::GATEWAY::ToLONCAPA
534: Apache::GATEWAY::FromLONCAPA
535: Apache::LONCAPA::FromTheGateway
536: Apache::LONCAPA::ToTheGateway
537:
538: =head1 SEE ALSO
539:
540: http://www.lon-capa.org/
541:
542: http://www.smete.org/
543:
544: Also visit the other Apache::NSDL::*, Apache::LONCAPA::*,
545: and Apache::GATEWAY::* manpages.
546:
547: =head1 OSNAMES
548:
549: linux
550:
551: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>