diff --git a/CollectionPolicy.inc b/CollectionPolicy.inc index 15a0392c..8997b42e 100644 --- a/CollectionPolicy.inc +++ b/CollectionPolicy.inc @@ -33,7 +33,7 @@ class CollectionPolicy extends XMLDatastream { static function loadFromCollection($pid, $preFetch=TRUE) { $ret = FALSE; module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - + try { if (self::validPid($pid)) { $dsid=CollectionPolicy::getDefaultDSID(); @@ -133,7 +133,7 @@ class CollectionPolicy extends XMLDatastream { */ public static function ingestBlankPolicy($pid, $name, $policyDsid, $model_pid, $model_namespace, $relationship, $searchField, $searchValue) { $ret = FALSE; - if (($cp = self::loadFromCollection($pid, $modelDsid)) === FALSE) { + if (($cp = self::loadFromCollection($pid )) === FALSE) { //removed second, non-existant variable module_load_include('inc', 'fedora_repository', 'ContentModel'); if (($cm = ContentModel::loadFromModel($model_pid)) !== FALSE && $cm->validate()) { $newDom = new DOMDocument('1.0', 'utf-8'); diff --git a/ConnectionHelper.inc b/ConnectionHelper.inc index f464ab91..712eec18 100644 --- a/ConnectionHelper.inc +++ b/ConnectionHelper.inc @@ -15,15 +15,10 @@ class ConnectionHelper { } function _fixURL($url, $_name, $_pass) { - if ($url == NULL) { + if (empty($url)) { $url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); } - if ($_name == '' || $_pass == '') { - drupal_set_message(t('No credentials provided.')); - return NULL; - } - $creds = urlencode($_name) . ':'. urlencode($_pass); if (strpos($url, 'http://') == 0) { @@ -36,14 +31,15 @@ class ConnectionHelper { drupal_set_message(t('Invalid URL: !url', array('!url' => $url))); return NULL; } - + return $new_url; } function getSoapClient($url = NULL, $exceptions = TRUE) { - if ($url == NULL) { + if (empty($url)) { $url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); } + global $user; if ($user->uid == 0) { //anonymous user. We will need an entry in the fedora users.xml file diff --git a/MimeClass.inc b/MimeClass.inc index 652f3cc3..f1c5cb16 100644 --- a/MimeClass.inc +++ b/MimeClass.inc @@ -223,7 +223,8 @@ class MimeClass { */ public function get_mimetype( $filename, $debug = FALSE ) { - $ext = strtolower( array_pop( explode( '.', $filename ) ) ); + $file_name_and_extension = explode( '.', $filename ); + $ext = strtolower( array_pop( $file_name_and_extension ) ); if ( ! empty( $this->private_mime_types[$ext] ) ) { if ( TRUE === $debug ) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index c008ac69..381ab39c 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -876,7 +876,8 @@ class ObjectHelper { */ function getBreadcrumbs($pid, &$breadcrumbs, $level=10) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - + // Before executing the query, we hve a base case of accessing the top-level collection + global $base_url; $query_string = 'select $parentObject $title $content from <#ri> where ( $title and $parentObject $content @@ -893,18 +894,21 @@ class ObjectHelper { $result = preg_split('/[\r\n]+/',do_curl($url)); array_shift($result); // throw away first line $matches =str_getcsv(join("\n",$result)); - if ($matches !== NULL) { + if ($matches !== FALSE) { $parent = preg_replace('/^info:fedora\//','',$matches[0]); $breadcrumbs[] = l($matches[1], 'fedora/repository/' . $pid); if ($parent == variable_get('fedora_repository_pid', 'islandora:top')) { - $breadcrumbs[] = l(t('Home'), ''); // l(t('Digital repository'), 'fedora/repository'); + $breadcrumbs[] = l(t('Digital repository'), 'fedora/repository'); + $breadcrumbs[] = l(t('Home'), $base_url); + + } elseif ($level > 0) { $this->getBreadcrumbs($parent, $breadcrumbs, $level - 1); } } } - function warnIfMisconfigured($app) { + public static function warnIfMisconfigured($app) { $messMap = array( 'Kakadu' => 'Full installation instructions for Kakadu can be found Here', diff --git a/XMLDatastream.inc b/XMLDatastream.inc index 3998582d..f5efa4d2 100644 --- a/XMLDatastream.inc +++ b/XMLDatastream.inc @@ -92,11 +92,17 @@ abstract class XMLDatastream { */ public function __construct($xmlStr, $pid = NULL, $dsid = NULL) { libxml_use_internal_errors(true); + $this->pid = $pid; $this->dsid = $dsid; - - if ($xmlStr !== NULL) { - $this->xml = (is_object($xmlStr) && get_class($xmlStr) == DOMDocument) ? $xmlStr : DOMDocument::loadXML($xmlStr); + if ($xmlStr !== NULL) { + if(is_object($xmlStr) && get_class($xmlStr) == DOMDocument) { + $this->xml = $xmlStr; + } + else { + $this->xml = new DOMDocument(); + $this->xml->loadXML($xmlStr); + } } } diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 463ba6df..59bc1275 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -96,7 +96,7 @@ class Fedora_Item { 'logMessage' => ($logMessage != null)?$logMessage: 'Ingested object '. $datastream_id ); - return $this->soap_call( 'addDataStream', $params )->datastreamID; + return $this->soap_call( 'addDataStream', $params ); } function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M',$logMessage = null) { diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index 97612595..f286806c 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -66,11 +66,8 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post } function fedora_available() { - - $ret = do_curl(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/management?wsdl'), 1); - // A bit of a hack but the SOAP parser will cause a fatal error if you give it the wrong URL. - // PHP SOAP is now an installation requirement so this check is all we need to do. - return (strpos($ret, 'wsdl:definitions') != FALSE); + $response = drupal_http_request(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe'); + return ($response->code == 200); } /** diff --git a/fedora_repository.module b/fedora_repository.module index 21f33217..797f29be 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -312,8 +312,9 @@ function add_stream_form_submit($form, &$form_state) { $pid = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.; - - $streamUrl = $base_url . '/' . drupal_urlencode($file); + $file_basename = basename($file); + $file_directory = dirname($file); + $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); /* ----------------------------------------------------------------- * need a better way to get mimetypes @@ -337,14 +338,10 @@ function add_stream_form_submit($form, &$form_state) { return; } $form_state['rebuild'] = TRUE; - //$form_state['redirect'] = $base_url."/fedora/repository/$pid"; - // drupal_goto("http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); } function add_stream_form(&$form_state, $pid) { - //module_load_module_load_include('hp', ''Fedora_Repository'', 'config', 'fedora_repository', ''); module_load_include('inc', 'fedora_repository', 'formClass'); - //$client = getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); $addDataStreamForm = new formClass(); return $addDataStreamForm->createAddDataStreamForm($pid, $form_state); } @@ -409,7 +406,6 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL) function fedora_repository_purge_object_form_submit($form, &$form_state) { module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); - //$client = getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); $pid = $form_state['values']['pid']; if (!isset($form_state['storage']['confirm'])) { $form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form @@ -486,7 +482,7 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel, $collectionName drupal_set_message(t('You must specify an pid and dsId to replace.'), 'error'); return ''; } - $output .= drupal_get_form('fedora_repository_replace_stream_form', $pid, $dsId, $dsLabel); + $output = drupal_get_form('fedora_repository_replace_stream_form', $pid, $dsId, $dsLabel); return $output; } @@ -526,74 +522,34 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) { } function fedora_repository_replace_stream_form_submit($form, &$form_state) { - + global $base_url; $file = $form_state['values']['file']; $pid = $form_state['values']['pid']; $dsid = $form_state['values']['dsId']; - + $dsLabel = $form_state['values']['dsLabel']; // Remove the original file extension from the label and add the new one - $dsLabel = substr($form_state['values']['dsLabel'], 0, strrpos($form_state['values']['dsLabel'], '.')); - $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; + $indexOfDot = strrpos($dsLabel,'.');//use strrpos to get the last dot + if($indexOfDot !== FALSE){ + $dsLabel = substr($dsLabel, 0, $indexOfDot); + $dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; + } module_load_include('inc', 'Fedora_Repository', 'MimeClass'); - module_load_include('inc', 'Fedora_Repository', 'ObjectHelper'); - module_load_include('inc', 'Fedora_Repository', 'ConnectionHelper'); - - $streamUrl = file_create_url($file->filepath); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + + $file_basename = basename($file->filepath); + $file_directory = dirname($file->filepath); + $streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename); /* ----------------------------------------------------------------- - * need a better way to get mimetypes + * TODO: need a better way to get mimetypes */ $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - - $controlGroup = "M"; - $function = 'modifyDatastreamByReference'; - $params = array( - 'pid' => $pid, - 'dsID' => $dsid, - 'altIDs' => "", - 'dsLabel' => $dsLabel, - 'MIMEType' => $dformat, - 'formatURI' => "URL", - 'dsLocation' => $streamUrl, - 'controlGroup' => "$controlGroup", - 'dsState' => "A", - 'checksumType' => "DISABLED", - 'checksum' => "none", - 'logMessage' => "datastream replaced", - 'force' => FALSE, - ); - - if ($dformat == 'text/xml') { - $doc = new DOMDocument(); - $doc->load($file->filepath); - $controlGroup = 'X'; - $function = 'modifyDatastreamByValue'; - $params['dsContent'] = $doc->saveXML(); - unset($params['dsLocation']); - } - - try { - $soapHelper = new ConnectionHelper(); - $client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl')); - - if ($client == NULL) { - drupal_set_message(t('Error Getting Soap Client.'), 'error'); - return; - } - $object = $client->__soapCall($function, array('parameters' => $params)); - - // Apply the add datastream rules. - $object_helper = new ObjectHelper(); - $object_helper->get_and_do_datastream_rules($pid, $dsid, $file->filepath); - - file_delete($file->filepath); - } catch (exception $e) { - drupal_set_message(t($e->getMessage()), 'error'); - return; - } - - drupal_goto('fedora/repository/' . $pid . '/-/' . $dsId); + $item = new Fedora_Item($pid); + + $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); + + $form_state['redirect'] = 'fedora/repository/' . $pid; } function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { @@ -1281,10 +1237,10 @@ function fedora_repository_demo_objects_form() { ); foreach (array( -'islandora:collectionCModel' => 'Islandora default content models', - 'islandora:top' => 'Islandora top-level collection', - 'islandora:demos' => 'Islandora demos collection', - 'islandora:largeimages' => 'Sample large image content model (requires Djatoka and Kakadu.)', + 'islandora:collectionCModel' => 'Islandora default content models', + 'islandora:top' => 'Islandora top-level collection', + 'islandora:demos' => 'Islandora demos collection', + 'islandora:largeimages' => 'Sample large image content model (requires Djatoka and Kakadu.)', ) as $available_demo => $available_demo_desc) { try { diff --git a/ilives/fedora_ilives.test b/ilives/fedora_ilives.test deleted file mode 100644 index 1923d45c..00000000 --- a/ilives/fedora_ilives.test +++ /dev/null @@ -1,33 +0,0 @@ - 'Fedora Ilives', - 'description' => t('The Fedora repository book module.'), - 'group' => t('fedora repository'), - ); - } - - protected function setUp() { - parent::setUp('fedora_ilives', 'fedora_repository'); - - - // Create and login user. - $drupal_user = $this->drupalCreateUser(array('add fedora datastreams', - 'edit fedora meta data', - 'edit tags datastream', - 'ingest new fedora objects', - 'purge objects and datastreams', - 'view fedora collection')); - - - $this->drupalLogin($drupal_user); - } - - public function testFedoraIlives() { - // Initially we are just testing that the module installs successfully from a clean Drupal. ISLANDORA-165. - $this->pass(drupal_get_path('module', 'fedora_ilives')); - - } -} \ No newline at end of file diff --git a/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index 730372e4..1ba95545 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -60,6 +60,7 @@ class ShowStreamsInFieldSets { global $base_path; global $user; module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $tabset = array(); $tabset['first_tab'] = array( diff --git a/plugins/slide_viewer.inc b/plugins/slide_viewer.inc index 00e650e6..30d2eb01 100644 --- a/plugins/slide_viewer.inc +++ b/plugins/slide_viewer.inc @@ -38,8 +38,8 @@ class ShowSlideStreamsInFieldSets { '#type' => 'tabpage', '#title' => t('View'), // This will be the content of the tab. - '#content' => ''. '

'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', + '#content' => ''. '

'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '

', ); return $tabset; diff --git a/tests/fedora_repository.test b/tests/fedora_repository.test index 3eb6226e..f7801e14 100644 --- a/tests/fedora_repository.test +++ b/tests/fedora_repository.test @@ -16,7 +16,7 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { } function setUp() { - parent::setUp('fedora_repository'); + parent::setUp('fedora_repository', 'tabs'); module_load_include('inc', 'fedora_repository', 'api/fedora_item'); @@ -26,13 +26,51 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { 'edit tags datastream', 'ingest new fedora objects', 'purge objects and datastreams', - 'view fedora collection')); + 'view fedora collection', + 'view detailed list of content')); $this->drupalLogin($repository_user); } + public function testDatastreams() { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $pid_list = array(); + + // Test Add datastream form + $cm_item = fedora_item::ingest_new_item(); + $cm_item->add_relationship('hasModel', 'fedora-system:ContentModel-3.0', FEDORA_MODEL_URI); + $cm_item->add_datastream_from_file(drupal_get_path('module', 'fedora_repository').'/content_models/STRICT_PDFCM.xml', 'ISLANDORACM'); + $pids_list[] = $cm_item->pid; + + // Ingest a new PDF object + $pdf_item = fedora_item::ingest_new_item(); + $pdf_item->add_relationship('hasModel', $cm_item->pid, FEDORA_MODEL_URI); + $pids_list[] = $pdf_item->pid; + + // Submit the add datastream form. + $add_stream_form = array(); + $add_stream_form['pid'] = $pdf_item->pid; + $add_stream_form['stream_label'] = $this->randomName(20); + $rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/lorem_ipsum.pdf'); + $add_stream_form['files[add-stream-file-location]'] = $rpath; + $add_stream_form['stream_id'] = 'OBJ'; + $this->drupalPost('fedora/repository/' . $pdf_item->pid, $add_stream_form, 'Add Datastream'); + + // Test replace datastream form + $this->assertText('The datastream has been uploaded', "Add initial datastream.", 'fedora datastreams'); + $this->drupalGet('fedora/repository/'.$pdf_item->pid); + $this->assertText($add_stream_form['stream_label'], 'Datastream appears in DS list.', 'fedora datastreams'); + $replace_stream_edit = array(); + $replace_stream_rpath = realpath(drupal_get_path('module', 'fedora_repository') . '/tests/test_files/jabberwocky.pdf'); + $replace_stream_edit['files[file]'] = $replace_stream_rpath; + + $this->drupalPost("fedora/repository/replaceStream/$pdf_item->pid/OBJ/NewLabel", $replace_stream_edit , 'Replace Datastream' ); + $this->assertText('NewLabel', "Replacement datastream appears in DS list.", 'fedora datastreams'); + $this->outputScreenContents(); + } + /** * Add an item based on a content model. Initially we will assume that the repository * will be populated with the default content models and collections that are @@ -71,7 +109,8 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { $this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next'); // Required fields are file location, dc:title and dc:description $ingest_form_step_2 = array(); - $ingest_form_step_2['dc:title'] = $this->randomName(32); + $ingest_title = $this->randomName(32); + $ingest_form_step_2['dc:title'] = $ingest_title; $ingest_form_step_2['dc:description'] = $this->randomName(256); $ingest_form_step_2['files[ingest-file-location]'] = realpath(drupal_get_path('module', 'fedora_repository') . '/collection_policies/PDF-COLLECTION POLICY.xml'); $this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); @@ -79,6 +118,11 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { $this->assertPattern('/Item .* created successfully./', "Verified item created."); $pid = $this->getIngestedPid(); + $this->drupalGet("fedora/repository/$pid"); + $this->assertLink('Home'); + $this->assertLink('Digital Repository'); + $this->assertLink($ingest_title); + $pid_list[] = $pid; $this->pass('Now attempting to ingest a PDF into the new collection.'); // Now try ingesting a PDF @@ -115,7 +159,7 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { return $matches[1]; } - private function outputScreenContents($description, $basename) { + private function outputScreenContents($description = '', $basename = '') { // This is a hack to get a directory that won't be cleaned up by SimpleTest. $file_dir = file_directory_path() . '../simpletest_output_pages'; if (!is_dir($file_dir)) { diff --git a/tests/test_files/jabberwocky.pdf b/tests/test_files/jabberwocky.pdf new file mode 100644 index 00000000..5aedeb27 --- /dev/null +++ b/tests/test_files/jabberwocky.pdf @@ -0,0 +1,70 @@ +%PDF-1.3 +%ª«¬­ +4 0 obj +<< /Type /Info +/Producer (FOP 0.20.4) >> +endobj +5 0 obj +<< /Length 1072 /Filter [ /ASCII85Decode /FlateDecode ] + >> +stream +GauHJ9lHOU&A@P9+Ls=kZBT8uH`3C?<>7mEU"lXh$lJId`fU_(r;/e^nT\OkBiS.`mB/18H#MhjAhMNVqer1i"h%p;ji3^+",Ygb:k#?^)p.QT2p8$=c"\RZ*GD[][0DY/+O<7ns>P!GTc"qg3V`Elf8[ucC3n;8GLDbS'3NT:1+<%oP!8j3ZqfTj.pB[FXE`R[ZHEM`c<4@d[aPPJ*R]Z_sXd35cB^\jP4oZa'T+V>E'UA>ZQMi%G2r.!R?3Nr))oAp?cPdqg"4KHA3%^!;$:Z(f05.Z]&m)bllAbT#,#1m-;\03Q`aPEO7^jC6/bQG86_ufm60&D^VT\isRuBf8rXnJ`K]o?Ej,on&nG$?;bHX[iumsA;WDZ0[eo96Q#@uR1JFnAWbRK>`LK!oIL+PpHI@))$Ind..P7gba5:*E+"ZS1D[5Z+XDmn@md9I^`JbRMH"cJ-`e@on;L\hL?)04l*?N!XK'[79UD5^D','$nRX+_>:2"[Tbm!hig+ucG0V"U;M]A@Q#-FT(]PW.G3\ulS!,5`_o=LV%lr$_%I270peU>CAQ]MT6m42[>O[2hHjQT7+@"cf0Wo%mL31Cd>qe:YOpAV0J&5T#9_q:_tm>aHoHj"K'Pq0'\4R^.[d#6QA_Mm.$CY,,?o"s]=t6uXP.:;5pR2AA2`cLe5ZiC*gAEJZ+g/2SgS)jgHpDm4-HW\[LP@:!GS@ceKJoV6V3_>"KW&8K*mtHg]FLM-2AVRX_:SGf5pZ2?%&,UE!\(Xk;k1K.SNd[TZE(6+;OQk9TLG/V66t[S1<%\oWD6EPtgoCpXBRVWL)Y!KT`,LM%1kdol(s=`o1IAASXrnJ'nGg,H7Y8V5AF/+MtRH3#.1.Smb%=<5;\#Z-eY>c]LQ*Kq/Za4/K7uBEUB16qt!cA+d[XoVT@cGtt:S;dM9:.CW5i@V]f^E-?'IB6=,Jrm@hE[NX7^6E-[Y397[B$\'nlrkW^BqLR)7hDj?*37`OQ2noBVcONh~> +endstream +endobj +6 0 obj +<< /Type /Page +/Parent 1 0 R +/MediaBox [ 0 0 576 792 ] +/Resources 3 0 R +/Contents 5 0 R +>> +endobj +7 0 obj +<< /Type /Font +/Subtype /Type1 +/Name /F6 +/BaseFont /Times-Italic +/Encoding /WinAnsiEncoding >> +endobj +8 0 obj +<< /Type /Font +/Subtype /Type1 +/Name /F5 +/BaseFont /Times-Roman +/Encoding /WinAnsiEncoding >> +endobj +1 0 obj +<< /Type /Pages +/Count 1 +/Kids [6 0 R ] >> +endobj +2 0 obj +<< /Type /Catalog +/Pages 1 0 R + >> +endobj +3 0 obj +<< +/Font << /F6 7 0 R /F5 8 0 R >> +/ProcSet [ /PDF /ImageC /Text ] >> +endobj +xref +0 9 +0000000000 65535 f +0000001560 00000 n +0000001618 00000 n +0000001668 00000 n +0000000015 00000 n +0000000071 00000 n +0000001235 00000 n +0000001341 00000 n +0000001451 00000 n +trailer +<< +/Size 9 +/Root 2 0 R +/Info 4 0 R +>> +startxref +1756 +%%EOF