Skip to content

Instantly share code, notes, and snippets.

@mjordan
mjordan / gist:99fac083970ea43528c6
Created July 19, 2015 14:49
Islandora Dev 101 Exercise 1: Sample implementation
/**
* Implements hook_islandora_object_modified().
*/
function islandora_dev101_islandora_object_modified(AbstractObject $islandora_object) {
drupal_set_message("Owner: " . $islandora_object->owner);
// Bonus answer.
// $message = variable_get('islandora_dev101_message', 'This just happened: ');
// drupal_set_message($message . ': ' . $islandora_object->owner);
}
@mjordan
mjordan / gist:4ae7724d5b3ffe38207f
Created July 19, 2015 14:39
Islandora Dev 101 Exercise 3: Two sample implementations
/**
* Implements hook_islandora_datastream_access().
*/
function islandora_dev101_islandora_datastream_access($op, $object, $user) {
if ($op == 'view fedora repository objects') {
foreach ($object as $ds) {
if ($ds->id == 'DC') {
// file_put_contents('/tmp/myfile.txt', $ds->content);
dd($ds->content);
}
@mjordan
mjordan / foxml_migrate.xml
Created July 11, 2015 23:27
FOXML export in migrate format for the standard Islandora Basic Image Collection
<?xml version="1.0" encoding="UTF-8"?>
<foxml:digitalObject VERSION="1.1" PID="islandora:sp_basic_image_collection"
xmlns:foxml="info:fedora/fedora-system:def/foxml#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
<foxml:objectProperties>
<foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="Active"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="Basic Image Collection"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#ownerId" VALUE="fedoraAdmin"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#createdDate" VALUE="2015-06-30T22:02:43.975Z"/>
@mjordan
mjordan / foxml_archive.xml
Last active August 29, 2015 14:24
FOXML export in archive format for the standard Islandora Basic Image Collection
<?xml version="1.0" encoding="UTF-8"?>
<foxml:digitalObject VERSION="1.1" PID="islandora:sp_basic_image_collection"
xmlns:foxml="info:fedora/fedora-system:def/foxml#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="info:fedora/fedora-system:def/foxml# http://www.fedora.info/definitions/1/0/foxml1-1.xsd">
<foxml:objectProperties>
<foxml:property NAME="info:fedora/fedora-system:def/model#state" VALUE="Active"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#label" VALUE="Basic Image Collection"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#ownerId" VALUE="fedoraAdmin"/>
<foxml:property NAME="info:fedora/fedora-system:def/model#createdDate" VALUE="2015-06-30T22:02:43.975Z"/>
@mjordan
mjordan / gist:92e9eb263ee1071d8a23
Created March 26, 2015 22:42
Islandora content model to OBJ file extension map
$content_model_to_extension_map = array(
"islandora:sp-audioCModel" => array("mp3", "mp4a", "m4a", "oga", "ogg", "flac", "wav"),
"islandora:sp_basic_image" => array("jpeg", "jpe", "jpeg", "gif", "png"),
"islandora:sp_large_image_cmodel" => array("tiff", "tif", "jp2"),
"islandora:sp_pdf" => array("pdf"),
"islandora:sp_videoCModel" => array("mp4", "m4v", "mkv", "mpeg", "mpe","mpg", "qt", "mov", "ogv"),
"islandora:sp_web_archive" => array("warc"),
);
<html>
<body>
<head><title>The document’s title</title>
</head>
<h1>A heading</h1>
<table>
<tr><td>120</td><td>389</td></tr>
</table>
<p>Some text</p>
</body>
@mjordan
mjordan / gist:4513687555ac54ee4b10
Last active August 29, 2015 14:07
Walks a directory and generates checksums
import os
# Supports md5, sha1, sha256, and sha512
import hashlib
start_dir = '/home/mark/Pictures'
def generate_checksum_for_file(source_file_path, algorithm='md5'):
"""Generate and return a checksum for the file at source_file_path
using the specified algorithm.
"""
@mjordan
mjordan / gist:9575829
Last active August 29, 2015 13:57
Number of items in FedoraCommons with average time to download a datastream, calculcated by downloading 100 random datastreams from all objects
Number of objects,average time to download datastream
9879,0.22425223655914
45096,0.079587544444444
77467,0.13624490322581
108640,0.088355711340206
133895,0.10383455102041
159749,0.091124947368421
185478,0.15220051546392
211806,0.14662007368421
235972,0.15356125773196
@mjordan
mjordan / transferAPI
Created March 12, 2014 02:34
Archivematica REST transer API test
#!/bin/sh
source_directory=$1
transfer_directory='/var/archivematica/sharedDirectory/watchedDirectories/activeTransfers/standardTransfer'
cp -rp $source_directory $transfer_directory
if [ $? -eq 0 ]; then
echo "Files in $source_directory copied to $transfer_directory, firing API call."
message=(curl --data="username=rick&api_key=74e506e5a206c99a95c8c514300fd27fec939f69&type=standard&directory=$transfer_directory" http://127.0.0.1/api/transfer/approve)
@mjordan
mjordan / gist:8672407
Created January 28, 2014 17:41
PREMIS with FITS in <objectCharacteristicsExtension>
<?xml version="1.0" encoding="utf-8"?>
<premis xmlns="info:lc/xmlns/premis-v2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:oai_dc="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="info:lc/xmlns/premis-v2 http://www.loc.gov/standards/premis/v2/premis.xsd" version="2.2">
<!--PREMIS data for Islandora object islandora:220. Contains object entries for each datastream
in an Islandora object, and event entries documenting all fixity checks performed on
versions of those datastreams. Note that a datastream version that has never had a fixity
check performed on it will not be linked to any fixity check events.-->
<!--'Internal' eventIdentifierType values are comprised of Fedora datasteam ID plus ':' plus Fedora Audit Record ID.-->
<object xsi:type="file">
<objectIdentifier>
<objectIdentifierType>Fedora Commons datastreamVersion ID</objectIdentifierType>