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;
}
/**
diff --git a/fedora_repository.module b/fedora_repository.module
index 8db073eb..6a2cfc72 100644
--- a/fedora_repository.module
+++ b/fedora_repository.module
@@ -1353,9 +1353,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) {
diff --git a/ilives/book.inc b/ilives/book.inc
index c7ec2eec..f44bacd5 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,40 +117,47 @@ class IslandoraBook {
return;
}
-
- $mods_simple = simplexml_load_string($form_values['mods']['mods_record']);
+ $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);
+
+ $title_info = $mods_item_doc->getElementsByTagNameNS('http://www.loc.gov/mods/v3', 'titleInfo')->item(0);
$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;
+ 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();
$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');
}
$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()) {
}
@@ -291,4 +302,4 @@ function transform_mods_to_dc($mods) {
else {
return FALSE;
}
-}
\ No newline at end of file
+}
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
+
+
+
+ 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
+
+
+
+
+
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