Browse Source

Merge branch 'master' of github.com:Islandora/islandora

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
19750f1293
  1. 12
      ConnectionHelper.inc
  2. 2
      ObjectHelper.inc
  3. 4
      README
  4. 2
      api/fedora_item.inc
  5. 7
      api/fedora_utils.inc
  6. 96
      fedora_repository.module
  7. 1
      plugins/ShowStreamsInFieldSets.inc
  8. 4
      plugins/slide_viewer.inc
  9. 44
      tests/fedora_repository.test
  10. 70
      tests/test_files/jabberwocky.pdf

12
ConnectionHelper.inc

@ -15,15 +15,10 @@ class ConnectionHelper {
} }
function _fixURL($url, $_name, $_pass) { function _fixURL($url, $_name, $_pass) {
if ($url == NULL) { if (empty($url)) {
$url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'); $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); $creds = urlencode($_name) . ':'. urlencode($_pass);
if (strpos($url, 'http://') == 0) { if (strpos($url, 'http://') == 0) {
@ -36,14 +31,15 @@ class ConnectionHelper {
drupal_set_message(t('Invalid URL: !url', array('!url' => $url))); drupal_set_message(t('Invalid URL: !url', array('!url' => $url)));
return NULL; return NULL;
} }
return $new_url; return $new_url;
} }
function getSoapClient($url = NULL, $exceptions = TRUE) { 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'); $url=variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl');
} }
global $user; global $user;
if ($user->uid == 0) { if ($user->uid == 0) {
//anonymous user. We will need an entry in the fedora users.xml file //anonymous user. We will need an entry in the fedora users.xml file

2
ObjectHelper.inc

@ -39,7 +39,7 @@ class ObjectHelper {
* @param $pid String * @param $pid String
* @param $dsID 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; global $user;
module_load_include('inc','fedora_repository','ContentModel'); module_load_include('inc','fedora_repository','ContentModel');
if ($pid == NULL || $dsID == NULL) { if ($pid == NULL || $dsID == NULL) {

4
README

@ -7,3 +7,7 @@ https://wiki.duraspace.org/display/ISLANDORA/Islandora
Specifically the Islandora Guide: Specifically the Islandora Guide:
https://wiki.duraspace.org/display/ISLANDORA/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

2
api/fedora_item.inc

@ -96,7 +96,7 @@ class Fedora_Item {
'logMessage' => ($logMessage != null)?$logMessage: 'Ingested object '. $datastream_id '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) { function add_datastream_from_string($str, $datastream_id, $datastream_label = NULL, $datastream_mimetype = 'text/xml', $controlGroup = 'M',$logMessage = null) {

7
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() { function fedora_available() {
$response = drupal_http_request(variable_get('fedora_base_url', 'http://localhost:8080/fedora').'/describe');
$ret = do_curl(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/management?wsdl'), 1); return ($response->code == 200);
// 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);
} }
/** /**

96
fedora_repository.module

@ -312,8 +312,9 @@ function add_stream_form_submit($form, &$form_state) {
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$dsid = $form_state['values']['stream_id']; $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.; $dsLabel = $form_state['values']['stream_label'] . substr($file, strrpos($file, '.')); // Add the file extention to the end of the label.;
$file_basename = basename($file);
$streamUrl = $base_url . '/' . drupal_urlencode($file); $file_directory = dirname($file);
$streamUrl = $base_url . '/' . $file_directory . '/' . urlencode($file_basename);
/* ----------------------------------------------------------------- /* -----------------------------------------------------------------
* need a better way to get mimetypes * need a better way to get mimetypes
@ -337,14 +338,10 @@ function add_stream_form_submit($form, &$form_state) {
return; return;
} }
$form_state['rebuild'] = TRUE; $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) { 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'); 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(); $addDataStreamForm = new formClass();
return $addDataStreamForm->createAddDataStreamForm($pid, $form_state); 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) { function fedora_repository_purge_object_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); 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']; $pid = $form_state['values']['pid'];
if (!isset($form_state['storage']['confirm'])) { 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 $form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form
@ -483,7 +479,7 @@ function fedora_repository_replace_stream($pid, $dsId, $dsLabel, $collectionName
drupal_set_message(t('You must specify an pid and dsId to replace.'), 'error'); drupal_set_message(t('You must specify an pid and dsId to replace.'), 'error');
return ''; 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; return $output;
} }
@ -523,74 +519,34 @@ function fedora_repository_replace_stream_form_validate($form, &$form_state) {
} }
function fedora_repository_replace_stream_form_submit($form, &$form_state) { function fedora_repository_replace_stream_form_submit($form, &$form_state) {
global $base_url;
$file = $form_state['values']['file']; $file = $form_state['values']['file'];
$pid = $form_state['values']['pid']; $pid = $form_state['values']['pid'];
$dsid = $form_state['values']['dsId']; $dsid = $form_state['values']['dsId'];
$dsLabel = $form_state['values']['dsLabel'];
// Remove the original file extension from the label and add the new one // 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
$dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.; 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', 'MimeClass');
module_load_include('inc', 'Fedora_Repository', 'ObjectHelper'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'Fedora_Repository', 'ConnectionHelper');
$file_basename = basename($file->filepath);
$streamUrl = file_create_url($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(); $mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath); $dformat = $mimetype->getType($file->filepath);
$item = new Fedora_Item($pid);
$controlGroup = "M";
$function = 'modifyDatastreamByReference'; $item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat);
$params = array(
'pid' => $pid, $form_state['redirect'] = 'fedora/repository/' . $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);
} }
function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) { function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) {
@ -1250,10 +1206,10 @@ function fedora_repository_demo_objects_form() {
); );
foreach (array( foreach (array(
'islandora:collectionCModel' => 'Islandora default content models', 'islandora:collectionCModel' => 'Islandora default content models',
'islandora:top' => 'Islandora top-level collection', 'islandora:top' => 'Islandora top-level collection',
'islandora:demos' => 'Islandora demos collection', 'islandora:demos' => 'Islandora demos collection',
'islandora:largeimages' => 'Sample large image content model (requires <a href="http://sourceforge.net/projects/djatoka/">Djatoka</a> and <a href="http://www.kakadusoftware.com/index.php?option=com_content&task=view&id=26&Itemid=22">Kakadu</a>.)', 'islandora:largeimages' => 'Sample large image content model (requires <a href="http://sourceforge.net/projects/djatoka/">Djatoka</a> and <a href="http://www.kakadusoftware.com/index.php?option=com_content&task=view&id=26&Itemid=22">Kakadu</a>.)',
) )
as $available_demo => $available_demo_desc) { as $available_demo => $available_demo_desc) {
try { try {

1
plugins/ShowStreamsInFieldSets.inc

@ -57,7 +57,6 @@ class ShowStreamsInFieldSets {
*/ */
function showPDFPreview() { function showPDFPreview() {
global $base_url; global $base_url;
$tabset = array(); $tabset = array();
$tabset['my_tabset'] = array( $tabset['my_tabset'] = array(

4
plugins/slide_viewer.inc

@ -44,8 +44,8 @@ class ShowSlideStreamsInFieldSets {
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('View'), '#title' => t('View'),
// This will be the content of the tab. // This will be the content of the tab.
'#content' => '<a href="'. $base_url . '/fedora/repository/'. $this->pid . '/FULL_JPG/"><img src="'. $base_url . '#content' => '<img src="'. $base_url .
'/fedora/imageapi/'. $this->pid . '/JPG/JPG.jpg'. '" /></a>'. '<p>'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>', '/fedora/imageapi/'. $this->pid . '/JPG/JPG.jpg'. '" />'. '<p>'. drupal_get_form('fedora_repository_image_tagging_form', $this->pid) . '</p>',
); );
$ssifs = new ShowStreamsInFieldSets($this->pid); $ssifs = new ShowStreamsInFieldSets($this->pid);

44
tests/fedora_repository.test

@ -16,7 +16,7 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
} }
function setUp() { function setUp() {
parent::setUp('fedora_repository'); parent::setUp('fedora_repository', 'tabs');
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
@ -26,13 +26,51 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
'edit tags datastream', 'edit tags datastream',
'ingest new fedora objects', 'ingest new fedora objects',
'purge objects and datastreams', 'purge objects and datastreams',
'view fedora collection')); 'view fedora collection',
'view detailed list of content'));
$this->drupalLogin($repository_user); $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 * 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 * will be populated with the default content models and collections that are
@ -121,7 +159,7 @@ class FedoraRepositoryTestCase extends DrupalWebTestCase {
return $matches[1]; 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. // This is a hack to get a directory that won't be cleaned up by SimpleTest.
$file_dir = file_directory_path() . '../simpletest_output_pages'; $file_dir = file_directory_path() . '../simpletest_output_pages';
if (!is_dir($file_dir)) { if (!is_dir($file_dir)) {

70
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^<nr7-Z)qT,-O)'$i?Bc^9'YCg:,Z[O>+",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:*<pMV6@OWWM)C=i$@6J"?0e!u]d4Y,i2c2Td>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
Loading…
Cancel
Save