From cfe5efd06b33eb35296a67f072c2a195be1d6cdd Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:09:34 -0300 Subject: [PATCH 1/5] added checks to get_datastream and get_datastream_dissemination to filter for missing datastreams, also updated add_datastream_from_* and purge_datastrea to resync the datastream list so the checks are consistent --- api/fedora_item.inc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index d9a1202d..f051c38a 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -10,9 +10,9 @@ define("ISLANDORA_PAGE_URI", 'info:islandora/islandora-system:def/pageinfo#'); define("ISLANDORA_RELS_EXT_URI", 'http://islandora.ca/ontology/relsext#'); define("ISLANDORA_RELS_INT_URI", "http://islandora.ca/ontology/relsint#"); -define("RELS_TYPE_URI", 0); -define("RELS_TYPE_PLAIN_LITERAL", 1); -define("RELS_TYPE_STRING", 2); +define("RELS_TYPE_URI", 0); +define("RELS_TYPE_PLAIN_LITERAL", 1); +define("RELS_TYPE_STRING", 2); define("RELS_TYPE_INT", 3); define("RELS_TYPE_DATETIME", 4); @@ -130,6 +130,7 @@ class Fedora_Item { $datastream_url = drupal_urlencode($datastream_file); $url = file_create_url($datastream_url); + // add_datastream_from_url forces a re-sync of the datastream list $return_value = $this->add_datastream_from_url($url, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage); if ($original_path != $datastream_file) { @@ -177,8 +178,10 @@ class Fedora_Item { 'logMessage' => ($logMessage != NULL) ? $logMessage : 'Ingested object ' . $datastream_id ); - - return $this->soap_call('addDataStream', $params); + $soap_result = $this->soap_call('addDataStream', $params); + // make sure to refresh the datastream list after adding so this item stays in sync with the repository + $this->datastreams = $this->get_datastreams_list_as_array(); + return $soap_result; } /** @@ -197,6 +200,7 @@ class Fedora_Item { $tmpfile = fopen($tmpfilename, 'w'); fwrite($tmpfile, $str, strlen($str)); fclose($tmpfile); + // add_datastream_from_file forces a re-sync of the datastream list $returnvalue = $this->add_datastream_from_file($tmpfilename, $datastream_id, $datastream_label, $datastream_mimetype, $controlGroup, $logMessage); unlink($tmpfilename); return $returnvalue; @@ -513,6 +517,12 @@ RDF; * @return null */ function get_datastream_dissemination($dsid, $as_of_date_time = "", $quiet=TRUE) { + if (!array_key_exists($dsid, $this->datastreams)) { + watchdog('fedora_repository', 'Requested invalid datastream dissemination @dsid on object @pid', + array('@dsid' => $dsid, '@pid' => $pid)); + return NULL; + } + $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -538,6 +548,9 @@ RDF; * @return type */ function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) { + if (!array_key_exists($dsid, datastreams)) { + return NULL; + } $params = array( 'pid' => $this->pid, 'dsID' => $dsid, @@ -859,7 +872,10 @@ RDF; 'logMessage' => $log_message, 'force' => $force, ); - return $this->soap_call('purgeDatastream', $params); + $soap_result = $this->soap_call('purgeDatastream', $params); + // make sure to refresh the datastream list after adding so this item stays in sync with the repository + $this->datastreams = $this->get_datastreams_list_as_array(); + return $soap_result; } /** From b345b01a2072c09148f7845d8ecac8535fbc4202 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:10:18 -0300 Subject: [PATCH 2/5] updated createDQCEditForm to use fedora_item instead of calling __soap:getDatastreamDissemination directly, now the request is error filtered --- formClass.inc | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/formClass.inc b/formClass.inc index fc3b1748..06d840de 100644 --- a/formClass.inc +++ b/formClass.inc @@ -817,15 +817,12 @@ class formClass { * @return string */ function createQDCEditForm($pid, $dsid, $client, &$form_state) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $dsid = empty($dsid) ? 'QDC' : $dsid; - try { - $params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => ""); - $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params)); - } catch (Exception $e) { - return array(); - } - $content = $object->dissemination->stream; - $content = trim($content); + + $item = new fedora_item($pid); + $content = trim($item->get_datastream_dissemination($dsid)); + $doc = new DOMDocument(); if (!$doc->loadXML($content)) { echo "error loading xml"; From 4e0d243a79c410547ea34d3d73b5a83ac71cabf8 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:10:57 -0300 Subject: [PATCH 3/5] removed old commented out code this is now wrong and would cause errors if someone used it again --- api/fedora_export.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/api/fedora_export.inc b/api/fedora_export.inc index f3c82160..32d7b49d 100644 --- a/api/fedora_export.inc +++ b/api/fedora_export.inc @@ -57,7 +57,6 @@ function export_objects_for_pid($pid, $dir, &$log) { $file = $dir . '/' . $ds->label . '.' . get_file_extension($ds->MIMEType); $paths[$ds->ID] = $file; - //$content = $ob_helper->getDatastreamDissemination($pid, $ds->ID); if ($content = $ob_helper->getStream($pid, $ds->ID, FALSE)) { if (!$fp = @fopen($file, 'w')) { $log[] = log_line(t("Failed to open file %file to write datastream %dsid for pid %pid", array('%file' => $file, '%dsid' => $ds->ID, '%pid' => $pid)), 'error'); From 13781d24f764bd5035e2d20f4af79a3adca44843 Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:11:43 -0300 Subject: [PATCH 4/5] updated getStream function to use fedora_item to retrieve the datastream dissemination instead of calling soap directly, the result error filtering on the output --- ObjectHelper.inc | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e9bebdfb..12f8dd9b 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -233,8 +233,8 @@ class ObjectHelper { elseif ((isset($user) && $user->uid != 0) || $forceSoap || isset($_SERVER['HTTPS'])) { //If not anonymous, soap is force or we're using HTTPS //Have the webserver mediate the transfer (download and restream) - if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) { - header("Content-Length: $contentSize"); + if (($contentSize = self::getDatastreamSize($pid, $dsID, TRUE)) > 0) { + header("Content-Length: $contentSize"); } $opts = array( @@ -624,30 +624,9 @@ class ObjectHelper { * */ function getStream($pid, $dsid, $showError = FALSE) { - module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); - $soapHelper = new ConnectionHelper(); - try { - $client = $soapHelper->getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); - $params = array( - 'pid' => "$pid", - 'dsID' => "$dsid", - 'asOfDateTime' => "" - ); - - if (!isset($client)) { - drupal_set_message(t('Error connection to Fedora using soap client.')); - return NULL; - } - $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params)); - } catch (Exception $e) { - if ($showError) { - drupal_set_message(t('Error getting Datastream for %pid and %datastream
', array('%pid' => $pid, '%datastream' => $dsid)), 'error'); - } - return NULL; - } - $content = $object->dissemination->stream; - $content = trim($content); - return $content; + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $item = new fedora_item($pid); + return $item->get_datastream_dissemination($dsid); } /** From c781b4e78d0ccdc2a9080b0766756c830d904bbc Mon Sep 17 00:00:00 2001 From: Jason MacWilliams Date: Fri, 8 Jun 2012 17:14:14 -0300 Subject: [PATCH 5/5] fixed error trap in get_datastream to log it in the watchdog - also fixed a syntax bug --- api/fedora_item.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/fedora_item.inc b/api/fedora_item.inc index f051c38a..93e2b65e 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -548,7 +548,9 @@ RDF; * @return type */ function get_datastream($dsid, $as_of_date_time = '', $quiet = TRUE) { - if (!array_key_exists($dsid, datastreams)) { + if (!array_key_exists($dsid, $this->datastreams)) { + watchdog('fedora_repository', 'Requested invalid datastream dissemination @dsid on object @pid', + array('@dsid' => $dsid, '@pid' => $pid)); return NULL; } $params = array(