From 41b005ae1a634d9e388752269a7cfd2da92a78fe Mon Sep 17 00:00:00 2001 From: Daniel Neis Date: Sat, 11 May 2013 22:00:10 +0000 Subject: [PATCH] successfully harvested metadata from dspace --- ands_rifcs.php | 1 - identify.php | 9 ++++----- listrecords.php | 4 +--- oai2.php | 10 +++++----- oaidp-config.php | 2 +- oaidp-util.php | 24 ++++++++---------------- record_dc.php | 28 +++++++++++++++++++++++++--- record_rif.php | 2 -- 8 files changed, 44 insertions(+), 36 deletions(-) diff --git a/ands_rifcs.php b/ands_rifcs.php index 1f8ba64..1182480 100644 --- a/ands_rifcs.php +++ b/ands_rifcs.php @@ -3,7 +3,6 @@ * \file * \brief classes related to generating RIF-CS XML response file for ANDS. * - * * Generate RIF-CS set records of Activity, Collection, Party. * - They are closely bounded to ANDS requirements, need to know the database for getting information. */ diff --git a/identify.php b/identify.php index ea064f8..53acdea 100644 --- a/identify.php +++ b/identify.php @@ -1,7 +1,6 @@ 10) { - $des = $outputObj->doc->createDocumentFragment(); - $des->appendXML($output); - $outputObj->verbNode->appendChild($des); + $des = $outputObj->doc->createDocumentFragment(); + $des->appendXML($output); + $outputObj->verbNode->appendChild($des); } diff --git a/listrecords.php b/listrecords.php index 442070a..21a6942 100644 --- a/listrecords.php +++ b/listrecords.php @@ -113,14 +113,12 @@ if ($num_rows - $deliveredrecords > $maxItems) { $cursor = (int)$deliveredrecords + $maxItems; $restoken = createResumToken($cursor, $extquery, $metadataPrefix); $expirationdatetime = gmstrftime('%Y-%m-%dT%TZ', time()+TOKEN_VALID); -} +} elseif (isset($args['resumptionToken'])) { // Last delivery, return empty ResumptionToken -elseif (isset($args['resumptionToken'])) { $restoken = $args['resumptionToken']; // just used as an indicator unset($expirationdatetime); } - if (isset($args['resumptionToken'])) { debug_message("Try to resume because a resumptionToken supplied.") ; $record = $res->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, $deliveredrecords); diff --git a/oai2.php b/oai2.php index c345074..4c69af9 100644 --- a/oai2.php +++ b/oai2.php @@ -1,7 +1,5 @@ $val) { $errors[] = oai_error('badArgument', $checking); } else {$args[$key] = $checking; } } -if (!empty($errors)) { oai_exit(); } +if (!empty($errors)) { + oai_exit(); +} foreach($attribs as $val) { unset($$val); @@ -96,7 +96,7 @@ if (isset($args['verb'])) { case 'Identify': // we never use compression in Identify $compress = FALSE; - if(count($args)>1) { + if (count($args)>1) { foreach($args as $key => $val) { if(strcmp($key,"verb")!=0) { $errors[] = oai_error('badArgument', $key, $val); @@ -113,7 +113,7 @@ if (isset($args['verb'])) { break; case 'ListSets': - if(isset($args['resumptionToken']) && count($args) > 2) { + if (isset($args['resumptionToken']) && count($args) > 2) { $errors[] = oai_error('exclusiveArgument'); } $checkList = array("ops"=>array("resumptionToken")); diff --git a/oaidp-config.php b/oaidp-config.php index 0f75525..51f2ada 100644 --- a/oaidp-config.php +++ b/oaidp-config.php @@ -54,7 +54,7 @@ $identifyResponse = array(); // MUST (only one) // please adjust -$identifyResponse["repositoryName"] = 'Moodle Dev2'; +$identifyResponse["repositoryName"] = 'Moodle Neis'; // For ANDS to harvest of RIF-CS, originatingSource is plantaccelerator.org.au // $dataSource = "plantaccelerator.org.au"; diff --git a/oaidp-util.php b/oaidp-util.php index d6bb3d4..4d881eb 100644 --- a/oaidp-util.php +++ b/oaidp-util.php @@ -54,30 +54,24 @@ function debug_message($msg) { * is needed. */ function checkArgs($args, $checkList) { - // global $errors, $TOKEN_VALID, $METADATAFORMATS; global $errors, $METADATAFORMATS; - // $verb = $args['verb']; - unset($args["verb"]); - - debug_print_r('checkList',$checkList); - debug_print_r('args',$args); // "verb" has been checked before, no further check is needed + unset($args["verb"]); + if(isset($checkList['required'])) { for($i = 0; $i < count($checkList["required"]); $i++) { - debug_message("Checking: par$i: ". $checkList['required'][$i] . " in "); - debug_var_dump("isset(\$args[\$checkList['required'][\$i]])",isset($args[$checkList['required'][$i]])); - // echo "key exists". array_key_exists($checkList["required"][$i],$args)."\n"; + if(isset($args[$checkList['required'][$i]])==false) { - // echo "caught\n"; $errors[] = oai_error('missingArgument', $checkList["required"][$i]); } else { // if metadataPrefix is set, it is in required section if(isset($args['metadataPrefix'])) { $metadataPrefix = $args['metadataPrefix']; // Check if the format is supported, it has enough infor (an array), last if a handle has been defined. - if (!array_key_exists ($metadataPrefix, $METADATAFORMATS) || !(is_array($METADATAFORMATS[$metadataPrefix]) - || !isset($METADATAFORMATS[$metadataPrefix]['myhandler']))) { + if (!array_key_exists($metadataPrefix, $METADATAFORMATS) || + !(is_array($METADATAFORMATS[$metadataPrefix]) || + !isset($METADATAFORMATS[$metadataPrefix]['myhandler']))) { $errors[] = oai_error('cannotDisseminateFormat', 'metadataPrefix', $metadataPrefix); } } @@ -85,15 +79,13 @@ function checkArgs($args, $checkList) { } } } - debug_message('Before return'); - debug_print_r('errors',$errors); + if (!empty($errors)) return; // check to see if there is unwanted foreach($args as $key => $val) { - debug_message("checkArgs: $key"); + if(!in_array($key, $checkList["ops"])) { - debug_message("Wrong\n".print_r($checkList['ops'],true)); $errors[] = oai_error('badArgument', $key, $val); } switch ($key) { diff --git a/record_dc.php b/record_dc.php index 57be707..a61ac7a 100644 --- a/record_dc.php +++ b/record_dc.php @@ -6,9 +6,31 @@ * to demonstrate how a new metadata can be supported. For a working * example, please see record_rif.php. * - * \sa oaidp-config.php - */ + */ function create_metadata($outputObj, $cur_record, $identifier, $setspec, $db) { - $metadata_node = $outputObj->create_metadata($cur_record); + + $sql = "SELECT dc_title, dc_creator, dc_subject, dc_description, dc_contributor, dc_publisher, + dc_date , dc_type , dc_format , dc_identifier , dc_source , dc_language, + dc_relation , dc_coverage , dc_rights + FROM oai_records + WHERE oai_set = '{$setspec}' + AND oai_identifier = '{$identifier}'"; + + $res = exec_pdo_query($db,$sql); + $record = $res->fetch(PDO::FETCH_ASSOC); + + $meta_node = $outputObj->addChild($cur_record ,"metadata"); + + $schema_node = $outputObj->addChild($meta_node, 'oai_dc:dc'); + $schema_node->setAttribute('xmlns:oai_dc', "http://www.openarchives.org/OAI/2.0/oai_dc/"); + $schema_node->setAttribute('xmlns:dc',"http://purl.org/dc/elements/1.1/"); + $schema_node->setAttribute('xmlns:xsi',"http://www.w3.org/2001/XMLSchema-instance"); + $schema_node->setAttribute('xsi:schemaLocation', + 'http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd'); + foreach ($record as $r => $v) { + if (!empty($v)) { + $outputObj->addChild($schema_node, str_replace('_', ':', $r), $v); + } + } } diff --git a/record_rif.php b/record_rif.php index 1530844..37d29da 100644 --- a/record_rif.php +++ b/record_rif.php @@ -20,9 +20,7 @@ // Create a metadata object and a registryObjects, and its only child registryObject function create_metadata($outputObj, $cur_record, $identifier, $setspec, $db) { - // debug_message('In '.__FILE__.' function '.__FUNCTION__.' was called.'); - // debug_var_dump('metadata_node',$metadata_node); $metadata_node = $outputObj->create_metadata($cur_record); $obj_node = new ANDS_TPA($outputObj, $metadata_node, $db); try {