-
Notifications
You must be signed in to change notification settings - Fork 118
Build, Access, Modify and Delete Fedora objects with the Tuque interface
This document has been deprecated in favor of Working With Fedora Objects Programmatically Via Tuque
It is inadvisable to rely on functionality available in lower level API objects due to the possibility of these interfaces not being present on all repository implementations in the future.
$connection = new RepositoryConnection($fedoraUrl, $username, $password); $connection->reuseConnection = TRUE; $repository = new FedoraRepository( new FedoraApi($connection), new SimpleCache());
D6 module_load_include('inc', 'fedora_repository', 'api/tuque'); No module_load_include is required for Drupal 7 installations. The IslandoraTuque class is found in includes/tuque.inc and is automatically loaded by the islandora.info file $my_islandora_tuque = new IslandoraTuque(); $repository = $my_islandora_tuque->repository;
or
$my_islandora_tuque = islandora_get_tuque_connection() $repository = $my_islandora_tuque->repository;
All interaction with Fedora can now take place through the $repository object. D7 There is a wrapper object that handles some errors and fires some hooks in includes/tuque.inc. More error handling is available if one uses the wrapper functions in islandora.module.
Create array of ContentModels for the object. This will normally be a single element array:
$content_models = array(array('pid' => 'islandora:collectionCModel'));
Identify the namespace for the new pid, and identify the collection the object is to be a member of. Tuque will retrieve the next available PID in that namespace.¶ ↑
$namespace = 'test'; $collection_pid = 'islandora:root';
$fedora_object = $repository->constructObject($namespace); // allow fedora to generate a PID
or with a specified PID:
$fedora_object = $repository->constructObject($pid); // create an object with the given PID
$fedora_object->models = array('islandora:collectionCModel');
$fedora_object->label = “my new object”;
$fedora_object->owner = $username;
$datastream_id = “TN”; $new_datastream = $fedora_object->constructDatastream($datastream_id);
or
$datastream_id = "MODS"; $controlGroup = "X"; $new_datastream = $fedora_object->constructDatastream($datastream_id, $controlGroup);
$new_datastream->label = 'MYDSID'; $new_datastream->mimetype = 'something/something'; $new_datastream->setContentFromUrl(URL_TO_CONTENT);
or
$new_datastream->setContentFromFile(PATH_TO_CONTENT);
or
$new_datastream->setContentFromString(“content”);
$new_datastream->url = 'some redirect URL';
$fedora_object->ingestDatastream($new_datastream);
$fedora_object->relationships->remove(FEDORA_MODEL_URI, 'hasModel', 'islandora:collectionCModel'); $fedora_object->relationships->add(FEDORA_MODEL_URI, 'hasModel', 'islandora:imageCModel');
$fedora_object['your dsid']->relationships->remove(ISLANDORA_SCHOLAR_EMBARGO_RELS_URI, 'embargo-until'); $fedora_object['your dsid']->relationships->add(ISLANDORA_SCHOLAR_EMBARGO_RELS_URI, 'embargo-until', 'some date', RELS_TYPE_DATETIME);
$new_fedora_object = islandora_add_object($fedora_object);
or ingest with existing repository object
$repository->ingestObject($fedora_object);
$pid = “test:1”; $fedora_object = islandora_object_load($pid);
or
$fedora_object = $repository->getObject($pid);
if (!$fedora_object) { drupal_set_message("Fedora Object isn't in the repo!"); }
print_r($fedora_object['models']);
unset($fedora_object['models']['islandora:collectionCModel']);
in_array('islandora:collectionCModel', $fedora_object->models);
$fedora_object->repository->purgeObject($pid);
or
$repository->purgeObject($pid);
$fedora_object->delete()
$pid = $fedoraObject->id;
$rels = $fedora_object->relationships->get()
[0] = Array ( [predicate] => Array ( [value] => hasModel [alias] => fedora-model [namespace] => info:fedora/fedora-system:def/model# ) [object] => Array ( [literal] => [value] => islandora:collectionCModel ) ) [1] => Array......
$rels = $fedora_object->relationships->get('info:fedora/fedora-system:def/model#', 'hasModel' );
$datastream = $fedora_object['dsid'];
$dsid = $datastream->id;
label controlGroup versionable state mimetype format size checksum checksumType createdDate content url location logMessage
foreach($fedora_object as $datastream){ // access individual datastreams. }
$old_mime = $datastream->mimeType; $datastream->mimeType = “new/mimetype”; $datastream->content = file_get_contents('http://myexample.com/sample.jpg'));
// Create DS or grab it. if (!isset($fedora_object["JP2"])) { $jp2_ds = $fedora_object->constructDatastream('JP2', 'M'); } else { $jp2_ds = $fedora_object["JP2"]; } $jp2_ds->label = 'Derived display JP2.'; $jp2_ds->mimeType = 'image/jp2'; // Don't copy the file. $jp2_ds->setContentFromFile($jp2_file, FALSE); // May not need to be called if the DS already existed $fedora_object->ingestDatastream($jp2_ds);
See wiki.duraspace.org/display/FEDORA35/REST+API#RESTAPI-export for possible values of the ‘format’, context’, and ‘encoding’ parameters in the call to the Tuque API’s ‘export’ method.
// $foxml is a string containing the requested XML. $foxml = $repository->api->m->export($pid, array('format' => 'info:fedora/fedora-system:FOXML-1.1', 'context' => 'migrate', 'encoding' => 'UTF-8') );
$objects = $fedora_object->repository->ri->itqlQuery($query, 'unlimited'); // for itql $objects = $fedora_object->repository->ri->sparqlQuery($query); // for SparQL queries
You may be looking for the islandora-community wiki · new to islandora? · community calendar · interest groups