Browse Source

Modified BatchIngest to allow collections without metadata to be batch ingested

pull/42/head
Alan Stanley 13 years ago
parent
commit
7b550d7346
  1. 49
      BatchIngest.inc
  2. 1
      CollectionClass.inc
  3. 5
      xsl/sparql_to_html.xsl

49
BatchIngest.inc

@ -1,13 +1,12 @@
<?php
/**
* batch creation form submit
* @global type $user
* @param array $form
* @param array $form_state
* @param array $content_models
*/
*/
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');
@ -35,13 +34,6 @@ function batch_creation_form(&$form_state, $collection_pid, $content_models) {
'#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',
@ -70,8 +62,7 @@ function batch_creation_form(&$form_state, $collection_pid, $content_models) {
/**
* @param array $form
* @param array $form_state
*/
*/
function batch_creation_form_validate($form, &$form_state) {
$fieldName = 'file-location';
@ -155,9 +146,7 @@ function batch_creation_form_submit($form, &$form_state) {
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('create_batch_objects', array($label, $content_model, $object_files, $collection_pid, $namespace, $metadata));
}
$batch['operations'][] = array('recursive_directory_delete', array($tmpDir));
batch_set($batch);
@ -173,28 +162,33 @@ function batch_creation_form_submit($form, &$form_state) {
* @param <string> $namespace
* @param <string> $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');
module_load_include('inc', 'fedora_reppository', 'api/fedora_item');
$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);
if ($object_files['xml']) {
$data = file_get_contents($object_files['xml']);
$xml = simplexml_load_string($data);
$identifier = $xml->getName();
if ($identifier == 'dc') {
$item->modify_datastream_by_value($data, 'DC', "Dublin Core", 'text/xml');
}
if ($identifier == 'mods') {
$item->add_datastream_from_string($mods_xml, 'MODS');
$dc_xml = batch_create_dc_from_mods($mods_xml);
$item->modify_datastream_by_value($dc_xml, 'DC', "Dublin Core", 'text/xml');
}
}
unset($object_files['xml']);
$use_primary = TRUE;
foreach ($object_files as $ext => $filename) {
@ -206,7 +200,7 @@ function create_batch_objects($label, $content_model, $object_files, $collection
$item->purge("$pid $label not ingested. $file_mimetype not permitted in objects associated with $content_model");
continue;
}
$ds_label = $use_primary ? $cm->getDatastreamNameDSID():$ext;
$ds_label = $use_primary ? $cm->getDatastreamNameDSID() : $ext;
$item->add_datastream_from_file($filename, $ds_label);
$use_primary = FALSE;
@ -223,9 +217,6 @@ function create_batch_objects($label, $content_model, $object_files, $collection
* @param <string> $mods_xml
* @return <string>
*/
function batch_create_dc_from_mods($mods_xml) {
$path = drupal_get_path('module', 'fedora_repository');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');

1
CollectionClass.inc

@ -623,6 +623,7 @@ class CollectionClass {
$collectionName = $collection;
if (!$pageNumber) {
$pageNumber = 1;
}

5
xsl/sparql_to_html.xsl

@ -8,7 +8,7 @@
<xsl:value-of select="$path"/>
</xsl:variable>
<xsl:variable name="thisPid" select="$collectionPid"/>
<xsl:variable name="thisTitle" select="$collectionTitle"/>
<xsl:variable name="thisTitle" select="Collection"/>
<xsl:variable name="size" select="20"/>
<xsl:variable name="page" select="$hitPage"/>
<xsl:variable name="start" select="((number($page) - 1) * number($size)) + 1"/>
@ -161,6 +161,7 @@
<xsl:with-param name="from" select="'_'"/>
<xsl:with-param name="to" select="' '"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cleanTitle">
<xsl:value-of select="php:functionString('fedora_repository_urlencode_string', $newTitle)"/>
@ -168,7 +169,7 @@
<xsl:variable name="linkUrl">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="$cleanTitle"/>
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/-/<xsl:value-of select="'collection'"/>
</xsl:when>
<xsl:otherwise>
<!--the below is an example of going straight to a datastream instead of the details page.

Loading…
Cancel
Save