From 6d78e5f1616db76e0dc2db44d4aea12306171b93 Mon Sep 17 00:00:00 2001 From: ppound Date: Wed, 9 Feb 2011 11:07:01 -0400 Subject: [PATCH 01/24] added a check to verify strrpos actually returned something useful before trying to call substr --- fedora_repository.module | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index 818fc4ac..62cc48a7 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -522,10 +522,13 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $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'], '.')); + $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'); From 15815187c2f10c6c2bb611b2203a226408ae3905 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 11 Feb 2011 17:44:37 -0400 Subject: [PATCH 02/24] ISLANDORA-190 Remove link ot FULL_JPG in slideCModel. --- plugins/slide_viewer.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/slide_viewer.inc b/plugins/slide_viewer.inc index 7b14073d..39a950c3 100644 --- a/plugins/slide_viewer.inc +++ b/plugins/slide_viewer.inc @@ -44,8 +44,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) . '

', ); $ssifs = new ShowStreamsInFieldSets($this->pid); From f6058113e37736240e217d8e1642d66cf77b6bed Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 11 Feb 2011 18:18:22 -0400 Subject: [PATCH 03/24] ISLANDORA-191 Change availability check to look at HTTP status of /fedora/describe --- api/fedora_utils.inc | 7 ++----- fedora_repository.module | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) 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 818fc4ac..0df5b660 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1245,10 +1245,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 { From 51f477b6479820467c59ebdd4d6b7e4447cd9bb1 Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Sun, 13 Feb 2011 13:55:21 -0400 Subject: [PATCH 04/24] ISLANDORA-193: The code now creates a DOMDocument and calls loadXML() on that instance to prevent the warning. --- XMLDatastream.inc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/XMLDatastream.inc b/XMLDatastream.inc index 3998582d..9f1ea251 100644 --- a/XMLDatastream.inc +++ b/XMLDatastream.inc @@ -96,7 +96,13 @@ abstract class XMLDatastream { $this->dsid = $dsid; if ($xmlStr !== NULL) { - $this->xml = (is_object($xmlStr) && get_class($xmlStr) == DOMDocument) ? $xmlStr : DOMDocument::loadXML($xmlStr); + if(is_object($xmlStr) && get_class($xmlStr) == DOMDocument) { + $this->xml = $xmlStr; + } + else { + $this->xml = new DOMDocument(); + $this->xml->loadXML($xmlStr); + } } } From ac7f71d04572a31d69fb0cb0e2b0fcf283aa6b57 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 14 Feb 2011 10:47:59 -0400 Subject: [PATCH 05/24] ISLANDORA-194 Add permission check to purge object form. --- fedora_repository.module | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fedora_repository.module b/fedora_repository.module index 818fc4ac..623217ef 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -236,7 +236,12 @@ function fedora_repository_ingest_form(&$form_state, $collection_pid, $collectio function fedora_repository_purge_object_form(&$form_state, $pid, $referrer = NULL) { global $base_url; - // $form['#redirect'] = "fedora/repository/$collectionPid/"; + if (!user_access('purge objects and datastreams')) { + return NULL; + } + if ($pid == NULL) { + return NULL; + } $form['pid'] = array( '#type' => 'hidden', '#value' => "$pid" From 33c06067c14691750aa9a02267614294e6e617e0 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 14 Feb 2011 16:14:24 -0400 Subject: [PATCH 06/24] ISLANDORA-195 Breadcrumb breaks on top-level collection Test results for FALSE and not NULL after doing a preg match --- ObjectHelper.inc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 9b24f088..ea75d332 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -998,7 +998,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 @@ -1015,11 +1016,14 @@ 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); } From 9f897f805c5aa7e4bdf21c4cf2c9c293a99b8ad9 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 14 Feb 2011 16:38:53 -0400 Subject: [PATCH 07/24] ISLANDORA-195 Add test for breadcrumb trail. --- tests/fedora_repository.test | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/fedora_repository.test b/tests/fedora_repository.test index 3eb6226e..58cc887b 100644 --- a/tests/fedora_repository.test +++ b/tests/fedora_repository.test @@ -71,7 +71,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 +80,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 From c300933192558d35fdf888853e953231d637cf75 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 16 Feb 2011 11:15:53 -0400 Subject: [PATCH 08/24] Changed in response to ISLANDORA-200 --- CollectionPolicy.inc | 4 ++-- XMLDatastream.inc | 10 ++++++++-- ilives/fedora_ilives.test | 33 --------------------------------- 3 files changed, 10 insertions(+), 37 deletions(-) delete mode 100644 ilives/fedora_ilives.test 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/XMLDatastream.inc b/XMLDatastream.inc index 3998582d..5bb149c9 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(is_object($xmlStr) && get_class($xmlStr) == 'DOMDocument'){ + $this->xml = $xmlStr; + }else{ + $this->xml = new DOMDocument('1.0', 'iso-8859-1'); + $this->xml->loadXML($xmlStr); + } + } } 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 From ef9a30b54caa995e81ad1f099f1c5f3e5484c9aa Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 16 Feb 2011 15:47:32 -0400 Subject: [PATCH 09/24] ISLANDORA-204: Strict warning is no longer issued. --- MimeClass.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ) From c0a5a02c8280901d7c91e660648f1c10de869fbc Mon Sep 17 00:00:00 2001 From: Nigel Banks Date: Wed, 16 Feb 2011 15:58:50 -0400 Subject: [PATCH 10/24] ISLANDORA-206 Fixed strict warning by declaring a function static. --- ObjectHelper.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 9b24f088..62956809 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -1026,7 +1026,7 @@ class ObjectHelper { } } - function warnIfMisconfigured($app) { + public static function warnIfMisconfigured($app) { $messMap = array( 'Kakadu' => 'Full installation instructions for Kakadu can be found Here', From 2ba465b33ff0f475bec376719283d2d2da132039 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Thu, 17 Feb 2011 15:33:22 -0400 Subject: [PATCH 11/24] ISLANDORA-158 Fix for non-alphanumeric filenames --- api/fedora_item.inc | 2 +- fedora_repository.module | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) 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/fedora_repository.module b/fedora_repository.module index 62cc48a7..a5b1274f 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -307,8 +307,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 @@ -518,7 +519,7 @@ 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']; @@ -526,21 +527,29 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { // Remove the original file extension from the label and add the new one $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.; + $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'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + + - $streamUrl = file_create_url($file->filepath); + $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 */ $mimetype = new MimeClass(); $dformat = $mimetype->getType($file->filepath); - + $item = new Fedora_Item($pid); + //$item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); + /* $controlGroup = "M"; $function = 'modifyDatastreamByReference'; $params = array( @@ -587,7 +596,7 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { drupal_set_message(t($e->getMessage()), 'error'); return; } - +*/ drupal_goto('fedora/repository/' . $pid . '/-/' . $dsId); } From 6d009901360aeeb5f1e2de144fd3f8d1ebf47694 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 22 Feb 2011 09:25:55 -0400 Subject: [PATCH 12/24] Add ISLANDORACM to DualResImageCollection. --- fedora_repository.module | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fedora_repository.module b/fedora_repository.module index 623217ef..e04e6dca 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -1397,9 +1397,16 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) { $smiley_stuff->add_relationship('isMemberOfCollection', 'info:fedora/islandora:demos'); $tn = $smiley_stuff->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/images/smileytn.png', 'TN', 'Thumbnail.png', 'image/png', 'M'); $cp = $smiley_stuff->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/collection_policies/JPG-COLLECTION POLICY.xml', 'COLLECTION_POLICY', 'Collection Policy.xml', 'application/xml', 'X'); + $cm = new Fedora_Item('demo:DualResImage'); try { $cmstream = $cm->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/STANDARD JPG.xml', 'ISLANDORACM', 'Content Model.xml', 'application/xml', 'X'); + } catch (exception $e) { + + } + $dual_res_image_collection_cmodel = new Fedora_Item('demo:DualResImageCollection'); + try { + $cmstream = $dual_res_image_collection_cmodel->add_datastream_from_file(drupal_get_path('module', 'fedora_repository') . '/content_models/COLLECTIONCM.xml', 'ISLANDORACM', 'Islandora Content Model.xml', 'application/xml', 'X'); drupal_set_message("Successfully installed demo:SmileyStuff collection view.", 'message'); } catch (exception $e) { From e56fd1a2e8c4ac8a4e1935c3e41d44b1b606f719 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 22 Feb 2011 14:32:38 -0400 Subject: [PATCH 13/24] ISLANDORA-158 Fix warnings and remove commented-out code. --- fedora_repository.module | 66 +++------------------------------------- 1 file changed, 5 insertions(+), 61 deletions(-) diff --git a/fedora_repository.module b/fedora_repository.module index a5b1274f..468aaf1a 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -333,14 +333,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); } @@ -405,7 +401,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 @@ -479,7 +474,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; } @@ -531,73 +526,22 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) { $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'); 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); $item = new Fedora_Item($pid); - //$item->add_datastream_from_url($streamUrl, $dsid, $dsLabel, $dformat, $controlGroup); + $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat); - /* - $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); + + $form_state['redirect'] = 'fedora/repository/' . $pid; } function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { From ddf9d821c3d2289edb90c48f558e90beb64ac990 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Wed, 23 Feb 2011 16:38:23 -0400 Subject: [PATCH 14/24] Added test for add datastream form. --- ConnectionHelper.inc | 12 ++++------- plugins/ShowStreamsInFieldSets.inc | 1 - tests/fedora_repository.test | 34 +++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 12 deletions(-) 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/plugins/ShowStreamsInFieldSets.inc b/plugins/ShowStreamsInFieldSets.inc index ad3f2829..d0cae02d 100644 --- a/plugins/ShowStreamsInFieldSets.inc +++ b/plugins/ShowStreamsInFieldSets.inc @@ -57,7 +57,6 @@ class ShowStreamsInFieldSets { */ function showPDFPreview() { global $base_url; - $tabset = array(); $tabset['my_tabset'] = array( diff --git a/tests/fedora_repository.test b/tests/fedora_repository.test index 3eb6226e..52a79b03 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,41 @@ 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; + $this->drupalPost('fedora/repository/' . $pdf_item->pid, $add_stream_form, 'Add Datastream'); + $this->outputScreenContents(); + // Test replace datastream form + + } + /** * 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 @@ -115,7 +143,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)) { From 7b573225de268ad4cb6da00fc38de62a42f2fbbf Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 25 Feb 2011 10:19:57 -0400 Subject: [PATCH 15/24] ISLANDORA-158 Test of replace datastream form. --- tests/fedora_repository.test | 12 +++++- tests/test_files/jabberwocky.pdf | 70 ++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/test_files/jabberwocky.pdf diff --git a/tests/fedora_repository.test b/tests/fedora_repository.test index 52a79b03..93f86c00 100644 --- a/tests/fedora_repository.test +++ b/tests/fedora_repository.test @@ -55,10 +55,20 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase { $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'); - $this->outputScreenContents(); + // 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(); } /** 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 From 4f92799fcee81e3bb45fc290d4015677ccd38908 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 25 Feb 2011 10:56:47 -0400 Subject: [PATCH 16/24] ISLANDORA-138 Change default ForceSoap to TRUE. --- ObjectHelper.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ObjectHelper.inc b/ObjectHelper.inc index c6a2ad1e..e0d0395c 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -39,7 +39,7 @@ class ObjectHelper { * @param $pid String * @param $dsID String */ - function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = FALSE) { + function makeObject($pid, $dsID, $asAttachment = FALSE, $label = NULL, $filePath=FALSE, $version=NULL, $forceSoap = TRUE) { global $user; module_load_include('inc','fedora_repository','ContentModel'); if ($pid == NULL || $dsID == NULL) { From cf37e9bc2cd4652f6bd44bf218435fc0fda703a0 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Fri, 25 Feb 2011 08:26:36 -0800 Subject: [PATCH 17/24] Add reference to DuraSpace JIRA to README --- README | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README b/README index 45f1df77..71ece32c 100644 --- a/README +++ b/README @@ -7,3 +7,7 @@ https://wiki.duraspace.org/display/ISLANDORA/Islandora Specifically the Islandora Guide: https://wiki.duraspace.org/display/ISLANDORA/Islandora+Guide + +All bugs, feature requests and improvement suggestions are tracked at the DuraSpace JIRA: + +https://jira.duraspace.org/browse/ISLANDORA \ No newline at end of file From 8731684b778d00f99e351ad7b6aa8fcc2f56b4ee Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 7 Mar 2011 16:41:41 -0400 Subject: [PATCH 18/24] ISLANDORA-227 MODS fixes - still in progress --- ilives/book.inc | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/ilives/book.inc b/ilives/book.inc index c7ec2eec..30aa06aa 100644 --- a/ilives/book.inc +++ b/ilives/book.inc @@ -58,8 +58,12 @@ class IslandoraBook { '#type' => 'textarea', '#title' => 'MODS Record to Import', '#rows' => 20, - '#value' => (!empty($mods_save) ? $mods_save['mods']['mods_record'] : ''), + ); + + if (!empty($mods_save)) { + $form['mods']['mods_record']['#value'] = $mods_save['mods']['mods_record']; + } return $form; } @@ -101,7 +105,7 @@ class IslandoraBook { return TRUE; } - public function handleIngestForm($form_values) { + public function handleIngestForm($form_values, &$form_state) { /* * process the metadata form * Create fedora object @@ -113,33 +117,38 @@ class IslandoraBook { return; } - $mods_simple = simplexml_load_string($form_values['mods']['mods_record']); $title = ''; - foreach ($mods_simple->children('http://www.loc.gov/mods/v3')->mods[0]->titleInfo[0]->children() as $child) { - if ($child->getName() == 'subTitle') { - // We don't care about subtitles for creating the item label. - continue; - } - $title .= $child; - } - + + $mods_simple->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); + $mods_records = $mods_simple->xpath('//mods:mods'); + $mods_record = $mods_records[0]; + $titles = $mods_simple->xpath('//mods:title'); + $title = (string) $titles[0]; + $mods_dom = dom_import_simplexml($mods_record); + $mods_dom->name = 'mods'; + $mods_text = $mods_dom->ownerDocument->saveXML(); + $mods_doc = new DOMDocument(); + $new_node = $mods_doc->importNode($mods_dom, TRUE); + $mods_doc->documentElement->appendChild($new_node); + $mods_text = $mods_doc->saveXML(); global $user; $mimetype = new MimeClass(); $new_item = Fedora_Item::ingest_new_item(!empty($form_values['custom_pid']) ? $form_values['custom_pid'] : $form_values['pid'], 'A', $title, $user->name); - $new_item->add_datastream_from_string($form_values['mods']['mods_record'], 'MODS', + $new_item->add_datastream_from_string($mods_text, 'MODS', 'MODS Metadata', 'text/xml', 'X'); - $dc = transform_mods_to_dc($form_values['mods']['mods_record']); + $dc = transform_mods_to_dc($mods_text); if ($dc) { // Add the PID to a dc:identifier field. - $dc_doc = simplexml_load_string($dc); - $dc_item = $dc_doc->xpath('/srw_dc:dcCollection/srw_dc:dc[1]'); + $dc_doc = simplexml_load_string($dc); + $dc_doc->registerXPathNamespace('oai_dc', 'http://www.openarchives.org/OAI/2.0/oai_dc/'); + $dc_item = $dc_doc->xpath('//oai_dc:dc'); foreach($dc_item as $node) { - $node->addChild('identifier', $new_item->pid, 'http://purl.org/dc/elements/1.1/'); + $node->addChild('dc:identifier', $new_item->pid, 'http://purl.org/dc/elements/1.1/'); } $new_item->modify_datastream_by_value($dc_doc->saveXML(), 'DC', 'Dublin Core XML Metadata', 'text/xml'); } @@ -291,4 +300,4 @@ function transform_mods_to_dc($mods) { else { return FALSE; } -} \ No newline at end of file +} From cbba26b0f3c241bb5a871a58d6c0dc3073c1e4bc Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 7 Mar 2011 20:54:41 -0400 Subject: [PATCH 19/24] ISLANDORA-227 Switched from SimpleXML to Dom because of namespace issues in SimpleXML. --- ilives/book.inc | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/ilives/book.inc b/ilives/book.inc index 30aa06aa..9a44958c 100644 --- a/ilives/book.inc +++ b/ilives/book.inc @@ -117,21 +117,13 @@ class IslandoraBook { return; } - $mods_simple = simplexml_load_string($form_values['mods']['mods_record']); - $title = ''; - - $mods_simple->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3'); - $mods_records = $mods_simple->xpath('//mods:mods'); - $mods_record = $mods_records[0]; - $titles = $mods_simple->xpath('//mods:title'); - $title = (string) $titles[0]; - $mods_dom = dom_import_simplexml($mods_record); - $mods_dom->name = 'mods'; - $mods_text = $mods_dom->ownerDocument->saveXML(); - $mods_doc = new DOMDocument(); - $new_node = $mods_doc->importNode($mods_dom, TRUE); - $mods_doc->documentElement->appendChild($new_node); - $mods_text = $mods_doc->saveXML(); + $mods_list_doc = new DomDocument(); + $mods_list_doc->loadXML($form_values['mods']['mods_record']); + $mods_item_doc = new DomDocument(); + $mods_item = $mods_list_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3', 'mods')->item(0); + $new_mods_item = $mods_item_doc->importNode($mods_item, TRUE); + $mods_item_doc->appendChild($new_mods_item); + $mods_text = $mods_item_doc->saveXML(); global $user; $mimetype = new MimeClass(); From 53af2c7f32dd813ceb2e4743890463274b5492eb Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 7 Mar 2011 22:39:10 -0400 Subject: [PATCH 20/24] ISLANDORA-227 Add title to object label. --- ilives/book.inc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ilives/book.inc b/ilives/book.inc index 9a44958c..76bbe836 100644 --- a/ilives/book.inc +++ b/ilives/book.inc @@ -123,6 +123,13 @@ class IslandoraBook { $mods_item = $mods_list_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3', 'mods')->item(0); $new_mods_item = $mods_item_doc->importNode($mods_item, TRUE); $mods_item_doc->appendChild($new_mods_item); + + $title_info = $mods_item_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3', 'titleInfo')->item(0); + $title = ''; + foreach(array('nonSort', 'title') as $title_field) { + $title .= $title_info->getElementsByTagNameNS('http://www.loc.gov/mods/v3', $title_field)->item(0)->nodeValue; + } + $mods_text = $mods_item_doc->saveXML(); global $user; $mimetype = new MimeClass(); From b06b893048c2967b70c3735e95f0d1ccb46a850f Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 8 Mar 2011 10:03:44 -0400 Subject: [PATCH 21/24] ISLANDORA-227 book content model now displays 'created successfully' message. --- ilives/book.inc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ilives/book.inc b/ilives/book.inc index 76bbe836..f44bacd5 100644 --- a/ilives/book.inc +++ b/ilives/book.inc @@ -136,7 +136,7 @@ class IslandoraBook { $new_item = Fedora_Item::ingest_new_item(!empty($form_values['custom_pid']) ? $form_values['custom_pid'] : $form_values['pid'], 'A', $title, $user->name); - + $new_item->add_datastream_from_string($mods_text, 'MODS', 'MODS Metadata', 'text/xml', 'X'); @@ -153,8 +153,11 @@ class IslandoraBook { } $new_item->add_relationship('hasModel', $form_values['content_model_pid'], FEDORA_MODEL_URI); $new_item->add_relationship(!empty($form_values['relationship']) ? $form_values['relationship'] : 'isMemberOfCollection', $form_values['collection_pid']); + drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($new_item->pid, 'fedora/repository/'. $new_item->pid))), "status"); + } + public function buildAddPagesForm($form = array()) { } From c5969925f684a57a968b4021dd6d82ea4e7e38d8 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 8 Mar 2011 10:04:22 -0400 Subject: [PATCH 22/24] ISLANDORA-227 Add book collection policy. --- ilives/xml/book_collection_policy.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ilives/xml/book_collection_policy.xml diff --git a/ilives/xml/book_collection_policy.xml b/ilives/xml/book_collection_policy.xml new file mode 100644 index 00000000..8c4639f5 --- /dev/null +++ b/ilives/xml/book_collection_policy.xml @@ -0,0 +1,22 @@ + + + + + + + dc.title + dc.creator + dc.description + dc.date + dc.identifier + dc.language + dc.publisher + dc.rights + dc.subject + dc.relation + dcterms.temporal + dcterms.spatial + Full Text + + isMemberOfCollection + \ No newline at end of file From 7ee6cb716b76831fa5a3e23215f7259a92f1cfa3 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Tue, 8 Mar 2011 10:45:34 -0400 Subject: [PATCH 23/24] ISLANDORA-227 Tests for book module. --- ilives/tests/fedora_ilives.test | 132 ++++++++++++++++++++++++ ilives/tests/test_files/mods_record.xml | 83 +++++++++++++++ 2 files changed, 215 insertions(+) create mode 100644 ilives/tests/fedora_ilives.test create mode 100644 ilives/tests/test_files/mods_record.xml diff --git a/ilives/tests/fedora_ilives.test b/ilives/tests/fedora_ilives.test new file mode 100644 index 00000000..be8c0ffd --- /dev/null +++ b/ilives/tests/fedora_ilives.test @@ -0,0 +1,132 @@ + 'Fedora Book', + 'description' => t('The Fedora repository book content model.'), + 'group' => t('fedora repository'), + ); + } + + function setUp() { + parent::setUp('fedora_repository', 'fedora_ilives', 'tabs'); + + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + + // Create and login user. + $repository_user = $this->drupalCreateFedoraUser(array('add fedora datastreams', + 'edit fedora meta data', + 'edit tags datastream', + 'ingest new fedora objects', + 'purge objects and datastreams', + 'view fedora collection', + 'view detailed list of content')); + + + $this->drupalLogin($repository_user); + + } + + public function testBookCModel() { + // First add a book collection + + $pid_list = array(); + // Create a collection for ingesting book content model objects. + + $ingest_form = array(); + $ingest_form['models'] = 'islandora:collectionCModel/ISLANDORACM'; + + $this->drupalPost('fedora/ingestObject/islandora:top/Islandora%20Top-Level%20Collection', $ingest_form, 'Next'); + + $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_ilives') . '/xml/book_collection_policy.xml'); + $this->drupalPost(NULL, $ingest_form_step_2, 'Ingest'); + $this->assertPattern('/Item .* created successfully./', "Verified item created."); + + $pid = $this->getIngestedPid(); + $this->drupalGet("fedora/repository/$pid"); + $pid_list[] = $pid; + + // Now add a book into the new collection + $this->pass("Create book collection $pid below top-level collection.", 'fedora book'); + $ingest_book_form = array(); + $ingest_book_form['models'] = 'ilives:bookCModel/ISLANDORACM'; + $this->drupalPost("fedora/ingestObject/$pid/", $ingest_book_form, 'Next'); + $ingest_book_form_step_2 = array(); + + $ingest_book_form_step_2['mods[mods_record]'] = file_get_contents(drupal_get_path('module', 'fedora_ilives') . '/tests/test_files/mods_record.xml'); + $this->outputScreenContents(); + $this->drupalPost(NULL, $ingest_book_form_step_2, 'Ingest'); + $this->outputScreenContents(); + $book_pid = $this->getIngestedPid(); + $pid_list[] = $book_pid; + if (!empty($book_pid)) { + $this->pass("Successfully ingested book object $book_pid."); + } + $this->cleanUpRepository($pid_list); + + } + + private function cleanUpRepository($pid_list = array()) { + $this->pass("This is the PID list to purge: ". implode(", ", $pid_list) ); + foreach ($pid_list as $pid) { + $this->drupalPost("fedora/repository/purgeObject/$pid", array(), 'Purge'); + $this->drupalPost(NULL, array(), 'Delete'); + } + } + + private function getIngestedPid() { + $subject = $this->drupalGetContent(); + $pattern = '/">(.*)<\/a> created successfully./'; + $matches = array(); + $res = preg_match($pattern, $subject, $matches); + return $matches[1]; + } + + 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)) { + mkdir($file_dir, 0777, TRUE); + } + $output_path = "$file_dir/$basename.". $this->randomName(10) . '.html'; + $rv = file_put_contents($output_path, $this->drupalGetContent()); + $this->pass("$description: Contents of result page are ". l('here', $output_path)); + } + + protected function drupalCreateFedoraUser($permissions = array('access comments', 'access content', 'post comments', 'post comments without approval')) { + // Create a role with the given permission set. + if (!($rid = $this->drupalCreateRole($permissions))) { + return FALSE; + } + + // Create a user assigned to that role. + $edit = array(); + $edit['name'] = 'simpletestuser'; + $edit['mail'] = $edit['name'] . '@example.com'; + $edit['roles'] = array($rid => $rid); + $edit['pass'] = 'simpletestpass'; + $edit['status'] = 1; + + $account = user_save('', $edit); + + $this->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array('%name' => $edit['name'], '%pass' => $edit['pass'])), t('User login')); + if (empty($account->uid)) { + return FALSE; + } + + // Add the raw password so that we can log in as this user. + $account->pass_raw = $edit['pass']; + return $account; + } + +} \ No newline at end of file diff --git a/ilives/tests/test_files/mods_record.xml b/ilives/tests/test_files/mods_record.xml new file mode 100644 index 00000000..6ec2a1d2 --- /dev/null +++ b/ilives/tests/test_files/mods_record.xml @@ -0,0 +1,83 @@ + + + + + The + amazing Maurice and his educated rodents + + + Pratchett, Terry. + + creator + + + text + novel + + + enk + + + London + + Corgi Books + 2002 + 2001 + monographic + + + eng + + +
print
+ 269 p. ; 22 cm. +
+ A talking cat, intelligent rats, and a strange boy cooperate in a Pied Piper scam until they try to con the wrong town and are confronted by a deadly evil rat king. + juvenile + Terry Pratchett. + Carnegie Medal winner. + + Discworld (Imaginary place) + Fiction + + + Discworld (Imaginary place) + Fiction + + + Rats + Fiction + + + Cats + Fiction + + + Fantasy fiction + + + Humorous stories + + PZ7.P8865 Am 2002 + + + Discworld series + + + Pratchett, Terry. + + + 006001234X (library binding) + 0385601239 + 0552546933 (pbk.) + + CaNWHRN + 010730 + 20020314 .0 + + eng + + +
+
+ From d1591695160a149af67db2b18a95c044f4ea5ff8 Mon Sep 17 00:00:00 2001 From: Alexander O'Neill Date: Mon, 14 Mar 2011 17:03:32 -0700 Subject: [PATCH 24/24] Use do_curl instead of drupal_http_request for availability check. --- ConnectionHelper.inc | 4 ++-- api/fedora_utils.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ConnectionHelper.inc b/ConnectionHelper.inc index 712eec18..68ed4124 100644 --- a/ConnectionHelper.inc +++ b/ConnectionHelper.inc @@ -21,10 +21,10 @@ class ConnectionHelper { $creds = urlencode($_name) . ':'. urlencode($_pass); - if (strpos($url, 'http://') == 0) { + if (strpos($url, 'http://') === 0) { $new_url = 'http://'. $creds . '@'. substr($url, 7); } - elseif (strpos($url, 'https://') == 0) { + elseif (strpos($url, 'https://') === 0) { $new_url = 'https://'. $creds . '@'. substr($url, 8); } else { diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index f286806c..b3628e24 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -66,8 +66,8 @@ function do_curl($url, $return_to_variable = 1, $number_of_post_vars = 0, $post } function fedora_available() { - $response = drupal_http_request(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe'); - return ($response->code == 200); + $response = do_curl(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe'); + return strstr($response, 'Repository Information HTML Presentation') !== FALSE; } /**