From ebd8a5096b18dcc1dc529905c57ea0816e542e44 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Wed, 28 Sep 2011 09:21:04 -0300 Subject: [PATCH 1/4] Added management tab to collections --- CollectionClass.inc | 297 +++++++++++++++++++++++---------------- CollectionManagement.inc | 276 ++++++++++++++++++++++++++++++++++++ ObjectHelper.inc | 22 +-- api/fedora_item.inc | 8 +- fedora_repository.module | 2 + 5 files changed, 474 insertions(+), 131 deletions(-) create mode 100644 CollectionManagement.inc diff --git a/CollectionClass.inc b/CollectionClass.inc index f9d906e8..f40aff4d 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -498,6 +498,7 @@ class CollectionClass { */ function showFieldSets($page_number) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'CollectionManagement'); global $base_url; $tabset = array(); global $user; @@ -514,10 +515,15 @@ class CollectionClass { // Check the form post to see if we are in the middle of an ingest operation. $show_ingest_tab = (!empty($_POST['form_id']) && $_POST['form_id'] == 'fedora_repository_ingest_form'); $add_to_collection = $this->getIngestInterface(); + $show_batch_tab = TRUE; + $policy = CollectionPolicy::loadFromCollection($this->pid, TRUE); + $content_models = $policy->getContentModels(); + if (count($content_models) == 1 && $content_models[0]->pid == "islandora:collectionCModel") { + $show_batch_tab = FALSE; + } if (!$show_ingest_tab) { $view_selected = true; } - drupal_set_message(); $tabset['view_tab'] = array( @@ -534,14 +540,24 @@ class CollectionClass { // This will be the content of the tab. '#content' => $add_to_collection, ); - - $tabset['add_collection_tab'] = array( - // #type and #title are the minimum requirements. - '#type' => 'tabpage', - '#title' => t('Add Child Collection'), - // This will be the content of the tab. - '#content' => drupal_get_form('collection_creation_form', $this->pid), - ); + if (user_access('manage collections')) { + $tabset['add_collection_tab'] = array( + // #type and #title are the minimum requirements. + '#type' => 'tabpage', + '#title' => t('Manage This Collection'), + // This will be the content of the tab. + '#content' => drupal_get_form('collection_management_form', $this->pid, $content_models), + ); + } + if ($show_batch_tab) { + $tabset['batch_ingest_tab'] = array( + // #type and #title are the minimum requirements. + '#type' => 'tabpage', + '#title' => t('Batch Ingest'), + // This will be the content of the tab. + '#content' => drupal_get_form('batch_creation_form', $this->pid, $content_models), + ); + } return $tabset; } @@ -651,74 +667,55 @@ class CollectionClass { } -/** - * collection creation form ? - * @param type $form_state - * @param type $parent_collection_pid - * @return type - */ -function collection_creation_form(&$form_state, $parent_collection_pid) { +function batch_creation_form(&$form_state, $collection_pid, $content_models) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - $restricted = FALSE; - if (variable_get('fedora_namespace_restriction_enforced', true)) { - $restricted = true; - $allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); - $namespaces = explode(':', $allowed_string); - foreach ($namespaces as $namespace) { - if ($namespace) { - $allowed[trim($namespace)] = trim($namespace); - } + module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); + $cm_options = array(); + $name_mappings = array(); + foreach ($content_models as $content_model) { + if ($content_model->pid != "islandora:collectionCModel") { + $cm_options[$content_model->pid] = $content_model->name; + $name_mappings[] = $content_model->pid . '^' . $content_model->pid_namespace; } } + $mappings = implode('~~~', $name_mappings); + $form['#attributes']['enctype'] = 'multipart/form-data'; - $content_models = get_content_models_as_option_array(); $form['titlebox'] = array( '#type' => 'item', - '#value' => t("Create New Child Collection within $collection_pid"), + '#value' => t("Batch ingest into $collection_pid"), ); - $form['collection_name'] = array( - '#title' => "Collection Name", - '#type' => 'textfield', - '#description' => t("Human readable name for this collection"), - ); - $form['collection_pid'] = array( - '#title' => "Collection PID", - '#type' => 'textfield', - '#size' => 15, - '#description' => t("Unique PID for this collection.
Pids take the general form of namespace:collection eg islandora:pamphlets"), - ); - if (!$restricted) { - $form['collection_namespace'] = array( - '#title' => "Collection Namespace", - '#type' => 'textfield', - '#size' => 15, - '#default_value' => 'default', - '#description' => t("Namespace for objects in this collection."), - ); - } - else { - $form['collection_namespace'] = array( - '#title' => "Collection Namespace", - '#type' => 'select', - '#options' => $allowed, - '#default_value' => 'default', - '#description' => t("Namespace for objects in this collection."), - ); - } $form['parent_collection'] = array( '#type' => 'hidden', - '#value' => $parent_collection_pid, + '#value' => $collection_pid, ); - - $form['content_models'] = array( - '#title' => "Choose allowable content models for this collection", - '#type' => 'checkboxes', - '#options' => $content_models, + $form['namespace_mappings'] = array( + '#type' => 'hidden', + '#value' => $mappings, + ); + $form['metadata_type'] = array( + '#title' => "Choose Metadata Type", + '#type' => 'radios', + '#options' => array('MODS' => 'MODS', "DC" => "DUBLIN CORE"), + '#required' => true, + '#description' => t("Select primary metadata schema"), + ); + $form['content_model'] = array( + '#title' => "Choose content model to be associated with objects ingested", + '#type' => 'select', + '#options' => $cm_options, '#required' => true, '#description' => t("Content models describe the behaviours of objects with which they are associated."), ); - + $form['indicator']['file-location'] = array( + '#type' => 'file', + '#title' => t('Upload zipped folder'), + '#size' => 48, + '#description' => t('The zipped folder should contain all files necessary to build objects.
+ Related files must have the same filename, but with diffening extensions to indicate mimetypes.
+ ie. myFile.xml and myFile.jpg'), + ); $form['submit'] = array( '#type' => 'submit', @@ -729,68 +726,130 @@ function collection_creation_form(&$form_state, $parent_collection_pid) { return($form); } -/** - * collection creation form validate ? - * @param type $form - * @param type $form_state - * @return type - */ -function collection_creation_form_validate($form, &$form_state) { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - $pid = $form_state['values']['collection_pid']; - $item = new fedora_item($pid); - if ($item->exists()) { - form_set_error('', t("$pid already exists within your repository. the PID must be unique")); - return; +function batch_creation_form_validate($form, &$form_state) { + + $fieldName = 'file-location'; + if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$fieldName])) { + $file = file_save_upload($fieldName); + if ($file->filemime != 'application/zip') { + form_set_error($fieldName, 'Input file must be a .zip file'); + return; + } + if (!$file) { + form_set_error($fieldName, 'Error uploading file.'); + return; + } + $form_state['values']['file'] = $file; } - if (!valid_pid($pid)){ - form_set_error('', t("$pid is not a valid identifier")); - return; + else { + // set error + form_set_error($fieldName, 'Error uploading file.'); + return; } } -/** - * collection creation form submit - * @global type $user - * @param type $form - * @param type $form_state - */ -function collection_creation_form_submit($form, &$form_state) { +function batch_creation_form_submit($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'ContentModel'); global $user; + $namespace_mappings = array(); + $content_model = $form_state['values']['content_model']; + $metadata = $form_state['values']['meta_data_type']; + $namespace_process = explode('~~~', $form_state['values']['namespace_mappings']); + foreach ($namespace_process as $line) { + $line_parts = explode('^', $line); + $namespace_mappings[$line_parts[0]] = $line_parts[1]; + } + $namespace = $namespace_mappings[$content_model]; + $dirName = "temp" . $user->uid; + $tmpDir = file_directory_path() . '/' . $dirName . '/'; + mkdir($tmpDir); + $file = $form_state['values']['file']; + $fileName = $file->filepath; + $file_list = array(); + $cmdString = "unzip -q -o -d $tmpDir \"$fileName\""; + system($cmdString, $retVal); + $dirs = array(); + $doNotAdd = array('.', '..', '__MACOSX'); + array_push($dirs, $tmpDir); + $files = scandir($tmpDir); + foreach ($files as $file) { + if (is_dir("$tmpDir/$file") & !in_array($file, $doNotAdd)) { + array_push($dirs, $tmpDir . $file); + } + } + + foreach ($dirs as $directory) { + if ($inputs = opendir($directory)) { + while (FALSE !== ($file_name = readdir($inputs))) { + if (!in_array($file_name, $doNotAdd)) { + $ext = strrchr($file_name, '.'); + $base = preg_replace("/$ext$/", '', $file_name); + $ext = substr($ext, 1); + $file_list[$base][$ext] = "$directory" . $file_name; + } + } + closedir($inputs); + } + } + + /** + * use the content model class to construct a class representing the selected content model + * call execIngestmethods on each mimetype passed in + */ + create_fedora_batch($file_list, $content_model, $metadata, $namespace); +} + +function create_fedora_batch($file_list, $content_model, $metadata, $namespace) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - module_load_include('inc', 'fedora_repository', 'api/dublin_core'); - $module_path = drupal_get_path('module', 'fedora_repository'); - $thumbnail = drupal_get_path('module', 'Fedora_Repository') . '/images/Crystal_Clear_filesystem_folder_grey.png'; - $collection_pid = $form_state['values']['collection_pid']; - $new_collection_label = $form_state['values']['collection_name']; - $parent_collection = $form_state['values']['parent_collection']; - $pid_namespace = $form_state['values']['collection_namespace']; - $all_cModels = get_content_models_as_option_array(); - $collection_policy = ' - - - - - - - isMemberOfCollection -'; - $content_models = $form_state['values']['content_models']; - $collection_policy_xml = simplexml_load_string($collection_policy); - foreach ($content_models as $content_model) { - if ($content_model) { - $node = $collection_policy_xml->content_models->addChild('content_model'); - $node->addAttribute('dsid', 'ISLANDORACM'); - $node->addAttribute('name', $all_cModels[$content_model]); - $node->addAttribute('namespace', $pid_namespace . ':1'); - $node->addAttribute('pid', $content_model); + if (($cm = ContentModel::loadFromModel($content_model, 'ISLANDORACM')) !== FALSE) { + $allowedMimeTypes = $cm->getMimetypes(); + + if (!in_array($dformat, $allowedMimeTypes)) { + form_set_error('ingest-file-location', t('The uploaded file\'s mimetype (' . $dformat . ') is not associated with this Content Model. The allowed types are ' . + implode(' ', $allowedMimeTypes))); + return; } + elseif (!$cm->execIngestRules($file, $dformat)) { + drupal_set_message(t('Error following Content Model Rules'), 'error'); + foreach (ContentModel::$errors as $err) { + drupal_set_message($err, 'error'); + } + } + } + + $batch = array( + 'title' => 'Ingesting Objects', + 'operations' => array(), + 'file' => drupal_get_path('module', 'fedora_repository') . '/CollectionClass.inc', + ); + + + foreach ($file_list as $label => $object_files) { + + $batch['operations'][] = array('create_fedora_objects', array($label, $content_model, $object_files, $collection_pid, $metadata)); } - $item = fedora_item::ingest_new_item($collection_pid, 'A', $new_collection_label, $user->name); - $item->add_relationship('isMemberOfCollection', $parent_collection, RELS_EXT_URI); - $item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); - $item->add_datastream_from_string($collection_policy_xml->saveXML(), 'COLLECTION_POLICY'); - $item->add_datastream_from_file($thumbnail, 'TN'); - drupal_goto("/fedora/repository/$collection_pid"); + + batch_set($batch); } + +function create_fedora_objects($lable, $content_model, $object_files, $collection_pid, $namespace, $metadata, $content_model) { + $namespace = preg_replace('/:.*/', '', $namespace); + $pid = fedora_item::get_next_PID_in_namespace($namespace); + module_load_include('inc', 'fedora_reppository', 'api/fedora_item'); + $item = Fedora_item::ingest_new_item($pid, 'A', $label, $owner); + $item->add_relationship('hasModel', $content_model, FEDORA_MODEL_URI); + if ($metadata == 'DC') { + $dc_xml = file_get_contents($object_files['xml']); + $object_files['xml'] = null; + $item->modify_datastream_by_value($dc_xml, 'DC', "Dublin Core", 'tex/xml'); + } + if ($metadata == 'MODS') { + $item->add_datastream_from_file($object_files['xml'], 'MODS'); + //add crosswalk to dc logic + } + + foreach ($object_files as $file) { + + } +} + diff --git a/CollectionManagement.inc b/CollectionManagement.inc new file mode 100644 index 00000000..aac1fc69 --- /dev/null +++ b/CollectionManagement.inc @@ -0,0 +1,276 @@ +objectProfile->objLabel; + $new_content_models = get_content_models_as_option_array(); + $cm_options = array(); + $name_mappings = array(); + foreach ($content_models as $content_model) { + if ($content_model->pid != "islandora:collectionCModel") { + $cm_options[$content_model->pid] = $content_model->name; + } + } + + $content_models = get_content_models_as_option_array(); + $form['child_creation'] = array( + '#title' => "Create Child Collection", + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['child_creation']['titlebox'] = array( + '#type' => 'item', + '#value' => t("Create New Child Collection within $parent_collection_pid"), + ); + + $form['child_creation']['collection_name'] = array( + '#title' => "Collection Name", + '#type' => 'textfield', + '#description' => t("Human readable name for this collection"), + ); + $form['child_creation']['new_collection_pid'] = array( + '#title' => "Collection PID", + '#type' => 'textfield', + '#size' => 15, + '#description' => t("Unique PID for this collection.
Pids take the general form of namespace:collection eg islandora:pamphlets"), + ); + if (!$restricted) { + $form['child_creation']['collection_namespace'] = array( + '#title' => "Collection Namespace", + '#type' => 'textfield', + '#size' => 15, + '#default_value' => 'default', + '#description' => t("Namespace for objects in this collection."), + ); + } + else { + $form['child_creation']['collection_namespace'] = array( + '#title' => "Collection Namespace", + '#type' => 'select', + '#options' => $allowed, + '#default_value' => 'default', + '#description' => t("Namespace for objects in this collection."), + ); + } + $form['child_creation']['parent_collection'] = array( + '#type' => 'hidden', + '#value' => $parent_collection_pid, + ); + + $form['child_creation']['content_models'] = array( + '#title' => "Choose allowable content models for this collection", + '#type' => 'checkboxes', + '#options' => $content_models, + '#description' => t("Content models describe the behaviours of objects with which they are associated."), + ); + + + $form['child_creation']['submit'] = array( + '#type' => 'submit', + '#value' => t('Create Collection'), + '#id' => 'create_class' + ); + $form['change_cmodel'] = array( + '#title' => "Change Content Models", + '#type' => 'fieldset', + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['change_cmodel']['titlebox'] = array( + '#type' => 'item', + '#value' => t("Change Content Models within $parent_collection_pid"), + ); + + $form['change_cmodel']['current_content_model'] = array( + '#title' => "Choose content model to be changed", + '#type' => 'select', + '#options' => $cm_options, + '#description' => t("All objects in this collection with the selected content model will be changed."), + ); + $form['change_cmodel']['new_content_model'] = array( + '#title' => "Choose new content model", + '#type' => 'select', + '#options' => $new_content_models, + '#description' => t("The new content model to be assigned to selected objects."), + ); + $form['change_cmodel']['collection_pid'] = array( + '#type' => 'hidden', + '#value' => $parent_collection_pid, + ); + $form['change_cmodel']['submit'] = array( + '#type' => 'submit', + '#value' => t('Change Content Model Associations'), + '#id' => 'change_model', + ); + if (user_access('delete entire collections')) { + $form['delete_collection'] = array( + '#title' => "Permanently Delete $collection_name", + '#type' => 'fieldset', + '#description' => t("Clicking this button will delete $collection_name and all objects within.
This action cannot be undone."), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + $form['delete_collection']['confirm'] = array( + '#title' => "Are you sure?", + '#type' => 'fieldset', + '#description' => t('Clicking the delete button will permanantly remove all objects from this collection.
This action cannot be undone. '), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + + $form['delete_collection']['confirm']['submit'] = array( + '#type' => 'submit', + '#value' => t('Delete this collection'), + '#id' => 'delete_collection', + ); + } + return($form); +} + +/** + * collection creation form validate + * @param array $form + * @param array $form_state + */ +function collection_management_form_validate($form, &$form_state) { + if ($form_state['clicked_button']['#id'] == 'create_class') { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); + $pid = $form_state['values']['new_collection_pid']; + $item = new fedora_item($pid); + if ($item->exists()) { + form_set_error('', t("$pid already exists within your repository. the PID must be unique")); + return; + } + if (!valid_pid($pid)) { + form_set_error('', t("$pid is not a valid identifier")); + return; + } + } +} + +/** + * collection creation form submit + * @global type $user + * @param type $form + * @param type $form_state + */ +function collection_management_form_submit($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'api/fedora_collection'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + module_load_include('inc', 'fedora_repository', 'api/dublin_core'); + global $user; + $collection_pid = $form_state['values']['parent_collection']; + if ($form_state['clicked_button']['#id'] == 'create_class') { + $module_path = drupal_get_path('module', 'fedora_repository'); + $thumbnail = drupal_get_path('module', 'Fedora_Repository') . '/images/Crystal_Clear_filesystem_folder_grey.png'; + $new_collection_pid = $form_state['values']['new_collection_pid']; + $new_collection_label = $form_state['values']['collection_name']; + $pid_namespace = $form_state['values']['collection_namespace']; + $all_cModels = get_content_models_as_option_array(); + $collection_policy = ' + + + + + + + isMemberOfCollection +'; + $content_models = $form_state['values']['content_models']; + $collection_policy_xml = simplexml_load_string($collection_policy); + foreach ($content_models as $content_model) { + if ($content_model) { + $node = $collection_policy_xml->content_models->addChild('content_model'); + $node->addAttribute('dsid', 'ISLANDORACM'); + $node->addAttribute('name', $all_cModels[$content_model]); + $node->addAttribute('namespace', $pid_namespace . ':1'); + $node->addAttribute('pid', $content_model); + } + } + $item = fedora_item::ingest_new_item($new_collection_pid, 'A', $new_collection_label, $user->name); + $item->add_relationship('isMemberOfCollection', $collection_pid, RELS_EXT_URI); + $item->add_relationship('hasModel', 'islandora:collectionCModel', FEDORA_MODEL_URI); + $item->add_datastream_from_string($collection_policy_xml->saveXML(), 'COLLECTION_POLICY'); + $item->add_datastream_from_file($thumbnail, 'TN'); + drupal_goto("/fedora/repository/$new_collection_pid"); + } + + if ($form_state['clicked_button']['#id'] == 'change_model') { + $current_content_model = $form_state['values']['current_content_model']; + $new_content_model = $form_state['values']['new_content_model']; + $policy = CollectionPolicy::loadFromCollection($collection_pid, TRUE); + $add_to_policy = TRUE; + $policy_cms = $policy->getContentModels(); + foreach ($policy_cms as $policy_cm) { + if ($policy_cm->pid == $current_content_model) { + $namespace = $policy_cm->pid_namespace; + } + if ($policy_cm->pid == $new_content_model) { + $add_to_policy = FALSE; + } + } + if ($add_to_policy) { + $policy->addModel(ContentModel::loadFromModel($new_content_model), $namespace); + $policy->saveToFedora(); + } + $query = "select \$object from <#ri> + where (\$object + and \$object + and \$object )"; + $query = htmlentities(urlencode($query)); + $content = ''; + + $url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch'); + $url .= "?type=tuples&flush=TRUE&format=csv&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query; + $content .= do_curl($url); + $results = explode("\n", $content); + $object_pids = preg_replace('/^info:fedora\/|"object"/', '', $results); + $count = 0; + foreach ($object_pids as $object_pid) { + if (!$object_pid) { + continue; + } + $item = new fedora_item($object_pid); + $item->purge_relationship('hasModel', $current_content_model); + $item->add_relationship('hasModel', $new_content_model, FEDORA_MODEL_URI); + $count++; + } + drupal_set_message("$current_content_model changed to $new_content_model on $count objects"); + } + + if ($form_state['clicked_button']['#id'] == 'delete_collection') { + $name = $user->name; + $objects = get_related_items_as_array($collection_pid, $relationship); + $objects[] = $collection_pid; + foreach ($objects as $object) { + $item_to_delete = new Fedora_Item($object); + $item_to_delete->purge("$object purged by $name"); + } + drupal_goto('fedora/repository'); + } +} + diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e575fb7d..eb7ccecf 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -19,6 +19,8 @@ class ObjectHelper { public static $INGEST_FEDORA_OBJECTS = 'ingest new fedora objects'; public static $EDIT_TAGS_DATASTREAM = 'edit tags datastream'; public static $VIEW_DETAILED_CONTENT_LIST = 'view detailed list of content'; + public static $MANAGE_COLLECTIONS = 'manage collections'; + public static $DELETE_ENTIRE_COLLECTIONS = 'delete entire collections'; public static $DISPLAY_ALWAYS = 0; public static $DISPLAY_NEVER = 1; public static $DISPLAY_NO_MODEL_OUTPUT = 2; @@ -160,7 +162,7 @@ class ObjectHelper { if ($asAttachment) { $suggestedFileName = "$label"; $pos = strpos($suggestedFileName, '.'); - + /* * Here we used to take an object of, say, type application/pdf with label, say, "My Document" * and we assemble the output filename extension based on the post-slash portion of the mimetype. @@ -300,8 +302,8 @@ class ObjectHelper { } if ($allow) { $purgeImage = 'purge datastream'; + $pid . '/' . $dataStreamValue->ID . '/' . $dataStreamValue->label . '">purge datastream'; } } else { @@ -329,7 +331,7 @@ class ObjectHelper { $mimeType = $dataStreamValue->MIMEType; $view = '' . t('View') . ''; + '" target="_blank" >' . t('View') . ''; $action = "$base_url/fedora/repository/object_download/" . drupal_urlencode($pid) . '/' . $id . '/' . drupal_urlencode(preg_replace('/\//i', '${1}_', $label)); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $downloadVersion = '
'; if (user_access(ObjectHelper :: $EDIT_FEDORA_METADATA)) { @@ -416,7 +418,7 @@ class ObjectHelper { if ($allow) { $output .= '
' . t('Edit Meta Data') . ''; + $dsid . '">' . t('Edit Meta Data') . ''; } } return $output; @@ -673,8 +675,8 @@ class ObjectHelper { if ($allow) { // $ingestObject = ' $collectionName, '!collection_pid' => $collection_pid)) . '" href="' . base_path() . - 'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '">' . t('Add a New Object') . ' ' . t('Add to this Collection'); + 'fedora/ingestObject/' . $collection_pid . '/' . $collectionName . '">' . t('Add a New Object') . ' ' . t('Add to this Collection'); } } } @@ -855,10 +857,10 @@ class ObjectHelper { // Get pid, title and description for children of object $pid $query_string = 'select $o $title from <#ri> ' . // $query_string = 'select $o $title $desc from <#ri> '. - 'where $s $o ' . - 'and $o $title ' . + 'where $s $o ' . + 'and $o $title ' . // 'and $o $desc '. - 'and ( '; + 'and ( '; foreach ($pids as $pid) { $query_string .= '$s or '; diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 13f126aa..2625568b 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -76,10 +76,9 @@ class Fedora_Item { */ function add_datastream_from_file($datastream_file, $datastream_id, $datastream_label = NULL, $datastream_mimetype = '', $controlGroup = 'M', $logMessage = NULL) { module_load_include('inc', 'fedora_repository', 'MimeClass'); - if (!is_file($datastream_file)){ + if (!is_file($datastream_file)) { drupal_set_message("$datastream_file not found
", 'warning'); return; - } if (empty($datastream_mimetype)) { // Get mime type from the file extension. @@ -233,6 +232,11 @@ class Fedora_Item { $relationship = "isPartOf"; $namespaceURI = 'info:fedora/fedora-system:def/relations-external#'; break; + case "rel:hasModel": + case "hasModel": + $relationship = "hasModel"; + $namespaceURI = FEDORA_MODEL_URI; + break; } if (substr($object, 0, 12) != 'info:fedora/') { diff --git a/fedora_repository.module b/fedora_repository.module index 3ffb32ac..3f46f4b8 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -830,6 +830,8 @@ function fedora_repository_perm() { OBJECTHELPER::$INGEST_FEDORA_OBJECTS, OBJECTHELPER::$EDIT_TAGS_DATASTREAM, OBJECTHELPER::$VIEW_DETAILED_CONTENT_LIST, + OBJECTHELPER::$MANAGE_COLLECTIONS, + OBJECTHELPER::$DELETE_ENTIRE_COLLECTIONS, ); } From 351d44ed4dc95b04d7ec3f00d01cf7e76315cd08 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 29 Sep 2011 14:05:19 -0300 Subject: [PATCH 2/4] Added management and batch capabilites to Collections --- BatchIngest.inc | 241 ++++++++++++++++++++++ CollectionClass.inc | 203 +----------------- CollectionManagement.inc | 55 +++-- ContentModel.inc | 48 +++-- ObjectHelper.inc | 1 + api/fedora_item.inc | 35 +++- fedora_repository.module | 11 + xsl/mods_to_dc.xsl | 436 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 799 insertions(+), 231 deletions(-) create mode 100644 BatchIngest.inc create mode 100644 xsl/mods_to_dc.xsl diff --git a/BatchIngest.inc b/BatchIngest.inc new file mode 100644 index 00000000..2f3f6e57 --- /dev/null +++ b/BatchIngest.inc @@ -0,0 +1,241 @@ +pid != "islandora:collectionCModel") { + $cm_options[$content_model->pid] = $content_model->name; + $name_mappings[] = $content_model->pid . '^' . $content_model->pid_namespace; + } + } + $mappings = implode('~~~', $name_mappings); + $form['#attributes']['enctype'] = 'multipart/form-data'; + + $form['titlebox'] = array( + '#type' => 'item', + '#value' => t("Batch ingest into $collection_pid"), + ); + + $form['collection_pid'] = array( + '#type' => 'hidden', + '#value' => $collection_pid, + ); + $form['namespace_mappings'] = array( + '#type' => 'hidden', + '#value' => $mappings, + ); + $form['metadata_type'] = array( + '#title' => "Choose Metadata Type", + '#type' => 'radios', + '#options' => array('MODS' => 'MODS', "DC" => "DUBLIN CORE"), + '#required' => true, + '#description' => t("Select primary metadata schema"), + ); + $form['content_model'] = array( + '#title' => "Choose content model to be associated with objects ingested", + '#type' => 'select', + '#options' => $cm_options, + '#required' => true, + '#description' => t("Content models describe the behaviours of objects with which they are associated."), + ); + $form['indicator']['file-location'] = array( + '#type' => 'file', + '#title' => t('Upload zipped folder'), + '#size' => 48, + '#description' => t('The zipped folder should contain all files necessary to build objects.
+ Related files must have the same filename, but with differing extensions to indicate mimetypes.
+ ie. myFile.xml and myFile.jpg'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Create Objects ') + ); + + + return($form); +} + +function batch_creation_form_validate($form, &$form_state) { + + $fieldName = 'file-location'; + if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$fieldName])) { + $file = file_save_upload($fieldName); + if ($file->filemime != 'application/zip') { + form_set_error($fieldName, 'Input file must be a .zip file'); + return; + } + if (!$file) { + form_set_error($fieldName, 'Error uploading file.'); + return; + } + $form_state['values']['file'] = $file; + } + else { + // set error + form_set_error($fieldName, 'Error uploading file.'); + return; + } +} + +function batch_creation_form_submit($form, &$form_state) { + module_load_include('inc', 'fedora_repository', 'ContentModel'); + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + global $user; + $namespace_mappings = array(); + $content_model = $form_state['values']['content_model']; + $metadata = $form_state['values']['metadata_type']; + $collection_pid = $form_state['values']['collection_pid']; + $namespace_process = explode('~~~', $form_state['values']['namespace_mappings']); + foreach ($namespace_process as $line) { + $line_parts = explode('^', $line); + $namespace_mappings[$line_parts[0]] = $line_parts[1]; + } + $namespace = $namespace_mappings[$content_model]; + $namespace = preg_replace('/:.*/', '', $namespace); + $dirName = "temp" . $user->uid; + $tmpDir = file_directory_path() . '/' . $dirName . '/'; + mkdir($tmpDir); + $file = $form_state['values']['file']; + $fileName = $file->filepath; + $file_list = array(); + $cmdString = "unzip -q -o -d $tmpDir \"$fileName\""; + system($cmdString, $retVal); + $dirs = array(); + $doNotAdd = array('.', '..', '__MACOSX'); + array_push($dirs, $tmpDir); + $files = scandir($tmpDir); + foreach ($files as $file) { + if (is_dir("$tmpDir/$file") & !in_array($file, $doNotAdd)) { + array_push($dirs, $tmpDir . $file); + } + } + foreach ($dirs as $directory) { + if ($inputs = opendir($directory)) { + while (FALSE !== ($file_name = readdir($inputs))) { + if (!in_array($file_name, $doNotAdd) && is_dir($file_name) == FALSE) { + $ext = strrchr($file_name, '.'); + $base = preg_replace("/$ext$/", '', $file_name); + $ext = substr($ext, 1); + if ($ext) { + $file_list[$base][$ext] = "$directory/" . $file_name; + } + } + } + closedir($inputs); + } + } + + /** + * use the content model class to construct a class representing the selected content model + * call execIngestmethods on each mimetype passed in + */ + if (($cm = ContentModel::loadFromModel($content_model, 'ISLANDORACM')) === FALSE) { + drupal_set_message("$content_model not found", "error"); + return; + } + + $batch = array( + 'title' => 'Ingesting Objects', + 'operations' => array(), + 'file' => drupal_get_path('module', 'fedora_repository') . '/BatchIngest.inc', + ); + + + foreach ($file_list as $label => $object_files) { + if ($object_files['xml']) { + $batch['operations'][] = array('create_batch_objects', array($label, $content_model, $object_files, $collection_pid, $namespace, $metadata)); + } + } + $batch['operations'][] = array('recursive_directory_delete', array($tmpDir)); + batch_set($batch); + batch_process(); +} + +function create_batch_objects($label, $content_model, $object_files, $collection_pid, $namespace, $metadata) { + module_load_include('inc', 'fedora_repository', 'ContentModel'); + module_load_include('inc', 'fedora_repository', 'MimeClass'); + $cm = ContentModel::loadFromModel($content_model, 'ISLANDORACM'); + $allowedMimeTypes = $cm->getMimetypes(); + $mime_helper = new MimeClass(); + $pid = fedora_item::get_next_PID_in_namespace($namespace); + module_load_include('inc', 'fedora_reppository', 'api/fedora_item'); + $item = Fedora_item::ingest_new_item($pid, 'A', $label, $owner); + $item->add_relationship('hasModel', $content_model, FEDORA_MODEL_URI); + $item->add_relationship('isMemberOfCollection', $collection_pid); + if ($metadata == 'DC') { + $dc_xml = file_get_contents($object_files['xml']); + $item->modify_datastream_by_value($dc_xml, 'DC', "Dublin Core", 'text/xml'); + } + if ($metadata == 'MODS') { + $mods_xml = file_get_contents($object_files['xml']); + $item->add_datastream_from_string($mods_xml, 'MODS'); + $dc_xml = batch_create_dc_from_mods($mods_xml); + } + unset($object_files['xml']); + $use_primary = TRUE; + foreach ($object_files as $ext => $filename) { + $file_mimetype = $mime_helper->get_mimetype($filename); + if (in_array($file_mimetype, $allowedMimeTypes)) { + $added = $cm->execIngestRules($filename, $file_mimetype); + } + else { + $item->purge("$pid $label not ingested. $file_mimetype not permitted in objects associated with $content_model"); + continue; + } + $ds_label = $use_primary ? $cm->getDatastreamNameDSID():$ext; + $item->add_datastream_from_file($filename, $ds_label); + $use_primary = FALSE; + + if (!empty($_SESSION['fedora_ingest_files'])) { + foreach ($_SESSION['fedora_ingest_files'] as $dsid => $datastream_file) { + $item->add_datastream_from_file($datastream_file, $dsid); + } + } + } +} + +function batch_create_dc_from_mods($mods_xml) { + $path = drupal_get_path('module', 'fedora_repository'); + module_load_include('inc', 'fedora_repository', 'ObjectHelper'); + module_load_include('inc', 'fedora_repository', 'CollectionClass'); + + if ($xmlstr == NULL || strlen($xmlstr) < 5) { + return " "; + } + + try { + $proc = new XsltProcessor(); + } catch (Exception $e) { + drupal_set_message(t("!e", array('!e' => $e->getMessage())), 'error'); + return " "; + } + + $xsl = new DomDocument(); + $xsl->load($path . '/xsl/mods_to_dc.xsl'); + $input = new DomDocument(); + $input->loadXML(trim($xmlstr)); + $xsl = $proc->importStylesheet($xsl); + $newdom = $proc->transformToDoc($input); + $dc_xml = $newdom->saveXML(); + + return $dc_xml; +} + + +function recursive_directory_delete($dir) { + if (!file_exists($dir)) + return true; + if (!is_dir($dir)) + return unlink($dir); + foreach (scandir($dir) as $item) { + if ($item == '.' || $item == '..') + continue; + if (!recursive_directory_delete($dir . DIRECTORY_SEPARATOR . $item)) + return false; + } + return rmdir($dir); +} \ No newline at end of file diff --git a/CollectionClass.inc b/CollectionClass.inc index f537a3cc..4251eea4 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -499,6 +499,7 @@ class CollectionClass { function showFieldSets($page_number) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'CollectionManagement'); + module_load_include('inc', 'fedora_repository', 'BatchIngest'); global $base_url; $tabset = array(); global $user; @@ -525,23 +526,24 @@ class CollectionClass { if (!$show_ingest_tab) { $view_selected = true; } - + if(!$collection_items){ + $view_selected = false; + $add_selected = true; + } $view_selected = !$show_ingest_tab; - drupal_set_message(); - $tabset['view_tab'] = array( '#type' => 'tabpage', '#title' => 'View', '#selected' => $view_selected, - '#content' => $collection_items + '#content' => $collection_items, + ); $tabset['add_tab'] = array( - // #type and #title are the minimum requirements. '#type' => 'tabpage', '#title' => t('Add'), - '#selected' => $show_ingest_tab, + '#selected' => $add_selected, // This will be the content of the tab. '#content' => $add_to_collection, ); @@ -552,9 +554,10 @@ class CollectionClass { '#title' => t('Manage This Collection'), // This will be the content of the tab. '#content' => drupal_get_form('collection_management_form', $this->pid, $content_models), + '#selected' => false, ); } - if ($show_batch_tab) { + if ($show_batch_tab && user_access('create batch process')) { $tabset['batch_ingest_tab'] = array( // #type and #title are the minimum requirements. '#type' => 'tabpage', @@ -672,189 +675,3 @@ class CollectionClass { } -function batch_creation_form(&$form_state, $collection_pid, $content_models) { - module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); - module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); - $cm_options = array(); - $name_mappings = array(); - foreach ($content_models as $content_model) { - if ($content_model->pid != "islandora:collectionCModel") { - $cm_options[$content_model->pid] = $content_model->name; - $name_mappings[] = $content_model->pid . '^' . $content_model->pid_namespace; - } - } - $mappings = implode('~~~', $name_mappings); - $form['#attributes']['enctype'] = 'multipart/form-data'; - - $form['titlebox'] = array( - '#type' => 'item', - '#value' => t("Batch ingest into $collection_pid"), - ); - - $form['parent_collection'] = array( - '#type' => 'hidden', - '#value' => $collection_pid, - ); - $form['namespace_mappings'] = array( - '#type' => 'hidden', - '#value' => $mappings, - ); - $form['metadata_type'] = array( - '#title' => "Choose Metadata Type", - '#type' => 'radios', - '#options' => array('MODS' => 'MODS', "DC" => "DUBLIN CORE"), - '#required' => true, - '#description' => t("Select primary metadata schema"), - ); - $form['content_model'] = array( - '#title' => "Choose content model to be associated with objects ingested", - '#type' => 'select', - '#options' => $cm_options, - '#required' => true, - '#description' => t("Content models describe the behaviours of objects with which they are associated."), - ); - $form['indicator']['file-location'] = array( - '#type' => 'file', - '#title' => t('Upload zipped folder'), - '#size' => 48, - '#description' => t('The zipped folder should contain all files necessary to build objects.
- Related files must have the same filename, but with diffening extensions to indicate mimetypes.
- ie. myFile.xml and myFile.jpg'), - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - - return($form); -} - -function batch_creation_form_validate($form, &$form_state) { - - $fieldName = 'file-location'; - if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$fieldName])) { - $file = file_save_upload($fieldName); - if ($file->filemime != 'application/zip') { - form_set_error($fieldName, 'Input file must be a .zip file'); - return; - } - if (!$file) { - form_set_error($fieldName, 'Error uploading file.'); - return; - } - $form_state['values']['file'] = $file; - } - else { - // set error - form_set_error($fieldName, 'Error uploading file.'); - return; - } -} - -function batch_creation_form_submit($form, &$form_state) { - module_load_include('inc', 'fedora_repository', 'ContentModel'); - global $user; - $namespace_mappings = array(); - $content_model = $form_state['values']['content_model']; - $metadata = $form_state['values']['meta_data_type']; - $namespace_process = explode('~~~', $form_state['values']['namespace_mappings']); - foreach ($namespace_process as $line) { - $line_parts = explode('^', $line); - $namespace_mappings[$line_parts[0]] = $line_parts[1]; - } - $namespace = $namespace_mappings[$content_model]; - $dirName = "temp" . $user->uid; - $tmpDir = file_directory_path() . '/' . $dirName . '/'; - mkdir($tmpDir); - $file = $form_state['values']['file']; - $fileName = $file->filepath; - $file_list = array(); - $cmdString = "unzip -q -o -d $tmpDir \"$fileName\""; - system($cmdString, $retVal); - $dirs = array(); - $doNotAdd = array('.', '..', '__MACOSX'); - array_push($dirs, $tmpDir); - $files = scandir($tmpDir); - foreach ($files as $file) { - if (is_dir("$tmpDir/$file") & !in_array($file, $doNotAdd)) { - array_push($dirs, $tmpDir . $file); - } - } - - foreach ($dirs as $directory) { - if ($inputs = opendir($directory)) { - while (FALSE !== ($file_name = readdir($inputs))) { - if (!in_array($file_name, $doNotAdd)) { - $ext = strrchr($file_name, '.'); - $base = preg_replace("/$ext$/", '', $file_name); - $ext = substr($ext, 1); - $file_list[$base][$ext] = "$directory" . $file_name; - } - } - closedir($inputs); - } - } - - /** - * use the content model class to construct a class representing the selected content model - * call execIngestmethods on each mimetype passed in - */ - create_fedora_batch($file_list, $content_model, $metadata, $namespace); -} - -function create_fedora_batch($file_list, $content_model, $metadata, $namespace) { - module_load_include('inc', 'fedora_repository', 'api/fedora_item'); - if (($cm = ContentModel::loadFromModel($content_model, 'ISLANDORACM')) !== FALSE) { - $allowedMimeTypes = $cm->getMimetypes(); - - if (!in_array($dformat, $allowedMimeTypes)) { - form_set_error('ingest-file-location', t('The uploaded file\'s mimetype (' . $dformat . ') is not associated with this Content Model. The allowed types are ' . - implode(' ', $allowedMimeTypes))); - return; - } - elseif (!$cm->execIngestRules($file, $dformat)) { - drupal_set_message(t('Error following Content Model Rules'), 'error'); - foreach (ContentModel::$errors as $err) { - drupal_set_message($err, 'error'); - } - } - } - - $batch = array( - 'title' => 'Ingesting Objects', - 'operations' => array(), - 'file' => drupal_get_path('module', 'fedora_repository') . '/CollectionClass.inc', - ); - - - foreach ($file_list as $label => $object_files) { - - $batch['operations'][] = array('create_fedora_objects', array($label, $content_model, $object_files, $collection_pid, $metadata)); - } - - batch_set($batch); -} - -function create_fedora_objects($lable, $content_model, $object_files, $collection_pid, $namespace, $metadata, $content_model) { - $namespace = preg_replace('/:.*/', '', $namespace); - $pid = fedora_item::get_next_PID_in_namespace($namespace); - module_load_include('inc', 'fedora_reppository', 'api/fedora_item'); - $item = Fedora_item::ingest_new_item($pid, 'A', $label, $owner); - $item->add_relationship('hasModel', $content_model, FEDORA_MODEL_URI); - if ($metadata == 'DC') { - $dc_xml = file_get_contents($object_files['xml']); - $object_files['xml'] = null; - $item->modify_datastream_by_value($dc_xml, 'DC', "Dublin Core", 'tex/xml'); - } - if ($metadata == 'MODS') { - $item->add_datastream_from_file($object_files['xml'], 'MODS'); - //add crosswalk to dc logic - } - - foreach ($object_files as $file) { - - } -} - diff --git a/CollectionManagement.inc b/CollectionManagement.inc index aac1fc69..8b2c04d1 100644 --- a/CollectionManagement.inc +++ b/CollectionManagement.inc @@ -7,7 +7,7 @@ * @param string $content_models * @return array */ -function collection_management_form(&$form_state, $parent_collection_pid, $content_models) { +function collection_management_form(&$form_state, $this_collection_pid, $content_models) { module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); $restricted = FALSE; if (variable_get('fedora_namespace_restriction_enforced', true)) { @@ -22,7 +22,7 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte } module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'fedora_repository', 'CollectionPolicy'); - $item = new Fedora_Item($parent_collection_pid); + $item = new Fedora_Item($this_collection_pid); $collection_name = $item->objectProfile->objLabel; $new_content_models = get_content_models_as_option_array(); $cm_options = array(); @@ -43,7 +43,7 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte $form['child_creation']['titlebox'] = array( '#type' => 'item', - '#value' => t("Create New Child Collection within $parent_collection_pid"), + '#value' => t("Create New Child Collection within $this_collection_pid"), ); $form['child_creation']['collection_name'] = array( @@ -75,11 +75,14 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte '#description' => t("Namespace for objects in this collection."), ); } - $form['child_creation']['parent_collection'] = array( + $form['parent_collection'] = array( '#type' => 'hidden', - '#value' => $parent_collection_pid, + '#value' => $this_collection_pid, + ); + $form['collection_pid'] = array( + '#type' => 'hidden', + '#value' => $this_collection_pid, ); - $form['child_creation']['content_models'] = array( '#title' => "Choose allowable content models for this collection", '#type' => 'checkboxes', @@ -101,7 +104,7 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte ); $form['change_cmodel']['titlebox'] = array( '#type' => 'item', - '#value' => t("Change Content Models within $parent_collection_pid"), + '#value' => t("Change Content Models within $this_collection_pid"), ); $form['change_cmodel']['current_content_model'] = array( @@ -118,7 +121,7 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte ); $form['change_cmodel']['collection_pid'] = array( '#type' => 'hidden', - '#value' => $parent_collection_pid, + '#value' => $this_collection_pid, ); $form['change_cmodel']['submit'] = array( '#type' => 'submit', @@ -129,7 +132,7 @@ function collection_management_form(&$form_state, $parent_collection_pid, $conte $form['delete_collection'] = array( '#title' => "Permanently Delete $collection_name", '#type' => 'fieldset', - '#description' => t("Clicking this button will delete $collection_name and all objects within.
This action cannot be undone."), + '#description' => t("Clicking this button will delete all objects within $collection_name.
This action cannot be undone."), '#collapsible' => TRUE, '#collapsed' => TRUE, ); @@ -263,14 +266,34 @@ function collection_management_form_submit($form, &$form_state) { } if ($form_state['clicked_button']['#id'] == 'delete_collection') { - $name = $user->name; - $objects = get_related_items_as_array($collection_pid, $relationship); - $objects[] = $collection_pid; - foreach ($objects as $object) { - $item_to_delete = new Fedora_Item($object); - $item_to_delete->purge("$object purged by $name"); + $collection_name = $form_state['values']['collection_name']; + $pids = get_related_items_as_array($collection_pid, 'isMemberOfCollection'); + + $batch = array( + 'title' => "Deleting Objects from $name", + 'operations' => array(), + 'file' => drupal_get_path('module', 'fedora_repository') . '/CollectionManagement.inc', + ); + + + foreach ($pids as $pid) { + + $batch['operations'][] = array('delete_objects_as_batch', array($pid)); } - drupal_goto('fedora/repository'); + + batch_set($batch); + batch_process('/fedora/repository'); } } +function delete_objects_as_batch($pid) { + module_load_include('inc', 'fedora_repository', 'api/fedora_item'); + $name = $user->name; + $item_to_delete = new Fedora_Item($pid); + $models = $item_to_delete->get_models(); + foreach ($models as $model) { + if ($model['object'] != 'islandora:collectionCModel') { + $item_to_delete->purge("$object purged by $name"); + } + } +} \ No newline at end of file diff --git a/ContentModel.inc b/ContentModel.inc index 64b71980..ccc0fb82 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -4,7 +4,6 @@ * @file * */ - /** * @file * Content Model Class @@ -396,12 +395,12 @@ class ContentModel extends XMLDatastream { $rootEl->appendChild($ingest_formEl); if (isset($sXml->edit_metadata) && - trim($sXml->edit_metadata->build_form_method->module) != '' && - trim($sXml->edit_metadata->build_form_method->file) != '' && - trim($sXml->edit_metadata->build_form_method->class_name) != '' && - trim($sXml->edit_metadata->build_form_method->method_name) != '' && - trim($sXml->edit_metadata->submit_form_method->method_name) != '' && - trim($sXml->edit_metadata->build_form_method['dsid']) != '' + trim($sXml->edit_metadata->build_form_method->module) != '' && + trim($sXml->edit_metadata->build_form_method->file) != '' && + trim($sXml->edit_metadata->build_form_method->class_name) != '' && + trim($sXml->edit_metadata->build_form_method->method_name) != '' && + trim($sXml->edit_metadata->submit_form_method->method_name) != '' && + trim($sXml->edit_metadata->build_form_method['dsid']) != '' ) { $edit_metadata_methodEl = $newDom->createElement('edit_metadata_method'); $edit_metadata_methodEl->setAttribute('module', $sXml->edit_metadata->build_form_method->module); @@ -491,6 +490,23 @@ class ContentModel extends XMLDatastream { return $ret; } + /** + * Gets the DSID of the default datastream + * from the element of the schema. + * Returns FALSE on failure. + * + * @return String + */ + + public function getDatastreamNameDSID() { + $datastreams = $this->xml->getElementsByTagName('datastreams'); + $datastream = $datastreams->item(0); + if ($datastreams->length > 0) { + $datastream = $datastreams->item(0)->getElementsByTagName('datastream'); + return $datastream->item(0)->getAttribute('dsid'); + } + } + /** * Gets an array of form elements to use in the ingest form. The results of this array are passed * to the specified ingest form builder. The form builder can optionally not use the elements as defined @@ -1677,9 +1693,9 @@ class ContentModel extends XMLDatastream { $dispMethods = $ds->getElementsByTagName('display_method'); for ($i = 0; !$found && $i < $dispMethods->length; $i++) { if ($module == ($dispMethods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $dispMethods->item($i)->getAttribute('module')) && - $file == $dispMethods->item($i)->getAttribute('file') && - $class == $dispMethods->item($i)->getAttribute('class') && - $method == $dispMethods->item($i)->getAttribute('method')) { + $file == $dispMethods->item($i)->getAttribute('file') && + $class == $dispMethods->item($i)->getAttribute('class') && + $method == $dispMethods->item($i)->getAttribute('method')) { $found = $dispMethods->item($i); } } @@ -1715,9 +1731,9 @@ class ContentModel extends XMLDatastream { $dispMethods = $ds->getElementsByTagName('display_method'); for ($i = 0; !$found && $i < $dispMethods->length; $i++) { if ($module == ($dispMethods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $dispMethods->item($i)->getAttribute('module') == '') && - $file == $dispMethods->item($i)->getAttribute('file') && - $class == $dispMethods->item($i)->getAttribute('class') && - $method == $dispMethods->item($i)->getAttribute('method')) { + $file == $dispMethods->item($i)->getAttribute('file') && + $class == $dispMethods->item($i)->getAttribute('class') && + $method == $dispMethods->item($i)->getAttribute('method')) { $found = $dispMethods->item($i); } } @@ -1919,9 +1935,9 @@ class ContentModel extends XMLDatastream { $found = FALSE; for ($i = 0; $found === FALSE && $i < $methods->length; $i++) { if (($methods->item($i)->getAttribute('module') == '' ? 'fedora_repository' : $methods->item($i)->getAttribute('module')) == $module && - $methods->item($i)->getAttribute('file') == $file && - $methods->item($i)->getAttribute('class') == $class && - $methods->item($i)->getAttribute('method') == $method) { + $methods->item($i)->getAttribute('file') == $file && + $methods->item($i)->getAttribute('class') == $class && + $methods->item($i)->getAttribute('method') == $method) { $found = $methods->item($i); } } diff --git a/ObjectHelper.inc b/ObjectHelper.inc index e6e0bb69..9e9995b7 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -21,6 +21,7 @@ class ObjectHelper { public static $VIEW_DETAILED_CONTENT_LIST = 'view detailed list of content'; public static $MANAGE_COLLECTIONS = 'manage collections'; public static $DELETE_ENTIRE_COLLECTIONS = 'delete entire collections'; + public static $CREATE_BATCH_PROCESS = 'create batch process'; public static $DISPLAY_ALWAYS = 0; public static $DISPLAY_NEVER = 1; public static $DISPLAY_NO_MODEL_OUTPUT = 2; diff --git a/api/fedora_item.inc b/api/fedora_item.inc index 4c78ce97..4dacca8c 100644 --- a/api/fedora_item.inc +++ b/api/fedora_item.inc @@ -562,7 +562,6 @@ class Fedora_Item { $relsextxml->loadXML($relsext); $relsextxml->normalizeDocument(); $rels = $relsextxml->getElementsByTagNameNS('info:fedora/fedora-system:def/relations-external#', '*'); - foreach ($rels as $child) { if (empty($relationship) || preg_match("/$relationship/", $child->tagName)) { $relationships[] = array( @@ -572,12 +571,36 @@ class Fedora_Item { ); } } + + return $relationships; + } + + + function get_models() { + $relationships = array(); + try { + $relsext = $this->get_datastream_dissemination('RELS-EXT'); + } catch (exception $e) { + drupal_set_message(t("Error retrieving RELS-EXT of object $pid"), 'error'); + return $relationships; + } + + // Parse the RELS-EXT into an associative array. + $relsextxml = new DOMDocument(); + $relsextxml->loadXML($relsext); + $relsextxml->normalizeDocument(); + $mods = $relsextxml->getElementsByTagNameNS(FEDORA_MODEL_URI, '*'); + foreach ($mods as $child) { + if (empty($relationship) || preg_match("/$relationship/", $child->tagName)) { + $relationships[] = array( + 'subject' => $this->pid, + 'predicate' => $child->tagName, + 'object' => substr($child->getAttributeNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'resource'), 12), + ); + } + } + return $relationships; - //$children = $relsextxml->RDF->description; - //$children = $relsextxml->RDF->description; - //$params = array( 'pid' => $this->pid, - // 'relationship' => 'NULL' ); - //return $this->soap_call( 'getRelationships', $params ); } /** diff --git a/fedora_repository.module b/fedora_repository.module index 06c2d6d4..ea1c15c5 100644 --- a/fedora_repository.module +++ b/fedora_repository.module @@ -832,6 +832,7 @@ function fedora_repository_perm() { OBJECTHELPER::$VIEW_DETAILED_CONTENT_LIST, OBJECTHELPER::$MANAGE_COLLECTIONS, OBJECTHELPER::$DELETE_ENTIRE_COLLECTIONS, + OBJECTHELPER::$CREATE_BATCH_PROCESS, ); } @@ -989,7 +990,17 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU // Add a 'manage object' tab for all objects, where detailed list of content is shown. $obj = new FedoraObjectDetailedContent($pid); $object_details = $obj->showFieldSets(); + if ($object_details['fedora_object_details']['#selected'] == true){ + foreach($cmodels_tabs as $cmodel_tab){ + if (is_array($cmodel_tab)){ + $cmodel_tab['#selected'] = FALSE; + } + + } + } $cmodels_tabs = array_merge($cmodels_tabs, $object_details); + + return tabs_render($cmodels_tabs); } diff --git a/xsl/mods_to_dc.xsl b/xsl/mods_to_dc.xsl new file mode 100644 index 00000000..4c007469 --- /dev/null +++ b/xsl/mods_to_dc.xsl @@ -0,0 +1,436 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + . + + + + . + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- + + + + + -- + + + + + + + + + + + + + + + + + + + + + + + + + + -- + + + + + + + + + + + + + + + + - + + + + + + + + + + -- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Collection + + + DataSet + + + Service + + + + Software + + + Image + + + + InteractiveResource + + + MovingImage + + + PhysicalObject + + + + Sound + + + StillImage + + + + Text + + + Text + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- + + + + + + + + + + + + + -- + + + + + + + + + + + + + + + + + + + + + + + + , + + + + + , + + + + + ( + + + ) + + + ( + + ) + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + From 24f7bfb1e9dc8c4685e2fc1fe652ca76ae62db32 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 30 Sep 2011 08:12:38 -0300 Subject: [PATCH 3/4] Changed the way ContentModel assigned names to objects --- ContentModel.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ContentModel.inc b/ContentModel.inc index ccc0fb82..b1f28074 100644 --- a/ContentModel.inc +++ b/ContentModel.inc @@ -203,6 +203,9 @@ class ContentModel extends XMLDatastream { try { if (self::valid_pid($pid)) { $fedoraItem = new Fedora_Item($pid); + if (!$name) { + $name = $fedoraItem->objectProfile->objLabel; + } $dsid = ($dsid != NULL && self::valid_dsid($dsid)) ? $dsid : ContentModel::getDefaultDSID(); $ds = $fedoraItem->get_datastream_dissemination($dsid); if (!empty($ds)) { @@ -497,7 +500,6 @@ class ContentModel extends XMLDatastream { * * @return String */ - public function getDatastreamNameDSID() { $datastreams = $this->xml->getElementsByTagName('datastreams'); $datastream = $datastreams->item(0); From 3b3891ebd7fbc692282deba92eee4f2c40f98569 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Fri, 30 Sep 2011 09:53:26 -0300 Subject: [PATCH 4/4] Added documentation --- BatchIngest.inc | 42 +++++++++++++++++++++++++++++++++++----- CollectionManagement.inc | 9 +++++++-- api/fedora_utils.inc | 2 +- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/BatchIngest.inc b/BatchIngest.inc index 2f3f6e57..31daa608 100644 --- a/BatchIngest.inc +++ b/BatchIngest.inc @@ -1,5 +1,13 @@ $label + * @param $content_model + * @param $object_files + * @param $collection_pid + * @param $namespace + * @param $metadata + */ + + function create_batch_objects($label, $content_model, $object_files, $collection_pid, $namespace, $metadata) { module_load_include('inc', 'fedora_repository', 'ContentModel'); module_load_include('inc', 'fedora_repository', 'MimeClass'); @@ -198,6 +218,14 @@ function create_batch_objects($label, $content_model, $object_files, $collection } } +/** + * transforms mods to dc + * @param $mods_xml + * @return + */ + + + function batch_create_dc_from_mods($mods_xml) { $path = drupal_get_path('module', 'fedora_repository'); module_load_include('inc', 'fedora_repository', 'ObjectHelper'); @@ -225,7 +253,11 @@ function batch_create_dc_from_mods($mods_xml) { return $dc_xml; } - +/** + * + * @param $dir + * @return + */ function recursive_directory_delete($dir) { if (!file_exists($dir)) return true; diff --git a/CollectionManagement.inc b/CollectionManagement.inc index 8b2c04d1..148fab84 100644 --- a/CollectionManagement.inc +++ b/CollectionManagement.inc @@ -29,7 +29,9 @@ function collection_management_form(&$form_state, $this_collection_pid, $content $name_mappings = array(); foreach ($content_models as $content_model) { if ($content_model->pid != "islandora:collectionCModel") { - $cm_options[$content_model->pid] = $content_model->name; + $item = new fedora_item($content_model->pid); + $cm_name = $item->objectProfile->objLabel; + $cm_options[$content_model->pid] = $cm_name; } } @@ -285,7 +287,10 @@ function collection_management_form_submit($form, &$form_state) { batch_process('/fedora/repository'); } } - +/** + * deletes PID if pid is not collection + * @param $pid + */ function delete_objects_as_batch($pid) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $name = $user->name; diff --git a/api/fedora_utils.inc b/api/fedora_utils.inc index c430d37d..c8ce7d0e 100644 --- a/api/fedora_utils.inc +++ b/api/fedora_utils.inc @@ -299,7 +299,7 @@ function get_content_models_as_option_array() { $nameparts = explode(':', $parts[0]); if (!$restricted || in_array($nameparts[0], $allowed)) if ($item->get_datastream_dissemination('ISLANDORACM')) { - $options[$parts[0]] = $parts[1]; + $options[$parts[0]] = $parts[1]. ' ~ ' . $parts[0] ; } } }