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); } /** 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'); diff --git a/api/fedora_item.inc b/api/fedora_item.inc index d9a1202d..93e2b65e 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,11 @@ RDF; * @return type */ function get_datastream($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, @@ -859,7 +874,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; } /** 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";