Browse Source

ISLANDORA-171 Resolve merge conflict with master.

pull/105/head
Alexander O'Neill 14 years ago
parent
commit
f23c78c6d6
  1. 2
      CollectionPolicy.inc
  2. 10
      ConnectionHelper.inc
  3. 3
      MimeClass.inc
  4. 12
      ObjectHelper.inc
  5. 10
      XMLDatastream.inc
  6. 2
      api/fedora_item.inc
  7. 7
      api/fedora_utils.inc
  8. 80
      fedora_repository.module
  9. 33
      ilives/fedora_ilives.test
  10. 1
      plugins/ShowStreamsInFieldSets.inc
  11. 4
      plugins/slide_viewer.inc
  12. 52
      tests/fedora_repository.test
  13. 70
      tests/test_files/jabberwocky.pdf

2
CollectionPolicy.inc

@ -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');

10
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) {
@ -41,9 +36,10 @@ class ConnectionHelper {
}
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

3
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 )

12
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 (<info:fedora/' . $pid . '> <dc:title> $title
and $parentObject <fedora-model:hasModel> $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
<a href=http://www.kakadusoftware.com/index.php?option=com_content&task=view&id=27&Itemid=23>Here</a>',

10
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();
$this->xml->loadXML($xmlStr);
}
}
}

2
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) {

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() {
$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);
}
/**

80
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'], '.'));
$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');
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
* TODO: need a better way to get mimetypes
*/
$mimetype = new MimeClass();
$dformat = $mimetype->getType($file->filepath);
$item = new Fedora_Item($pid);
$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;
}
$item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat);
drupal_goto('fedora/repository/' . $pid . '/-/' . $dsId);
$form_state['redirect'] = 'fedora/repository/' . $pid;
}
function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) {

33
ilives/fedora_ilives.test

@ -1,33 +0,0 @@
<?php
class fedoraBookTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => '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'));
}
}

1
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(

4
plugins/slide_viewer.inc

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

52
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)) {

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