forked from axfelix/sfudora
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathislandora_pydio_bridge.module
410 lines (391 loc) · 16.2 KB
/
islandora_pydio_bridge.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
<?php
/**
* @file
* Module used to integrate Pydio and Islandora.
*/
define('ISLANDORA_PYDIO_BRIDGE_INGEST_PATH', 'islandora_pydio_bridge/ingest');
define('ISLANDORA_PYDIO_BRIDGE_XACML_FOLDER', '/xacml');
define('ISLANDORA_PYDIO_BRIDGE_PYDIO_URI', 'http://pyd.io#');
define('ISLANDORA_PYDIO_BRIDGE_PYDIO_FRAME', 'pydio_bridge/pydio');
/**
* Implements hook_menu().
*/
function islandora_pydio_bridge_menu() {
$items = array();
$items[ISLANDORA_PYDIO_BRIDGE_INGEST_PATH] = array(
'title' => 'Ingest',
'access callback' => 'islandora_pydio_bridge_access_callback',
'page callback' => 'islandora_pydio_bridge_ingest',
'file' => 'includes/pydio_ingest.inc',
'type' => MENU_CALLBACK,
);
$items[ISLANDORA_PYDIO_BRIDGE_PYDIO_FRAME] = array(
'title' => 'Islandora Pydio Bridge',
'access callback' => 'islandora_pydio_bridge_access_callback',
'page callback' => 'drupal_goto',
'page arguments' => array(variable_get("islandora_pydio_bridge_pydio_path", 'pydio')),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/islandora/islandora_pydio_bridge'] = array(
'title' => 'Islandora Pydio Bridge Settings',
'description' => 'Configure settings for the Islandora Pydio Bridge module.',
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_pydio_bridge_admin_form'),
'access arguments' => array('administer site configuration'),
'file' => 'includes/admin.form.inc',
);
$items['islandora/object/%islandora_object/ds_versions'] = array(
'title' => 'Versions and Events',
'type' => MENU_LOCAL_TASK,
'file' => 'theme/theme.inc',
'page callback' => 'islandora_pydio_bridge_versions',
'page arguments' => array(2),
'access callback' => 'islandora_pydio_bridge_versions_tab_access_callback',
'access arguments' => array(ISLANDORA_VIEW_OBJECTS, 2),
);
return $items;
}
/**
* Implements hook_theme().
*/
function islandora_pydio_bridge_theme() {
return array(
'islandora_pydio_bridge_versions' => array(
'variables' => array('object' => NULL),
'file' => 'theme/theme.inc',
'template' => 'theme/islandora-pydio-bridge-versions',
),
);
}
/**
* Implements hook_islandora_ingested().
*/
function islandora_pydio_bridge_islandora_object_ingested(AbstractObject $object) {
global $user;
module_load_include('inc', 'islandora', 'includes/utilities');
$restrictions = 'Archive';
$ddi = $object['DDI']->content;
if(!empty($ddi)) {
$status = islandora_pydio_bridge_get_ddi_status($ddi);
$restrictions = isset($status) ? $status : 'Archive';
}
islandora_pydio_bridge_ingest_set_xacml($object, $restrictions);
islandora_pydio_bridge_ingest_create_doi($object, $restrictions);
}
/**
* Implements hook_islandora_datastream_alter
*/
function islandora_pydio_bridge_islandora_datastream_alter(AbstractObject $object, AbstractDatastream $datastream, array &$context) {
module_load_include('inc', 'islandora_pydio_bridge', 'includes/utilities');
if ($datastream->id != 'DDI' || $context['action'] != 'modify' || empty($context['params']['dsString'])) {
return;
}
$same_license = islandora_pydio_bridge_compare_license($datastream->content, $context['params']['dsString']);
if (!$same_license) {
$context['params']['dsString'] = islandora_pydio_bridge_add_ddi_event($datastream, 'MetadataEditing', 'The license (Copyright information) has changed', FALSE, $context['params']['dsString']);
}
$context['params']['dsString'] = islandora_pydio_bridge_add_ddi_event($datastream, 'MetadataEditing', 'Updating the metadata', FALSE, $context['params']['dsString']);
// check for status changes here and update the xacml if needed. we could do this in the modified hook but we would have know way to know if it was an actual change
$status1 = islandora_pydio_bridge_get_ddi_status($datastream->content);
$status2 = islandora_pydio_bridge_get_ddi_status($context['params']['dsString']);
if ($status1 !== $status2) {
if ($status1 === 'Embargoed') {
// Was embargoed but isn't now so lift the embargo
$ds_array = islandora_pydio_bridge_get_datastream_array($object);
islandora_scholar_embargo_lift_embargo($object, $ds_array);
}
if ($status1 === 'Archive' && module_exists('islandora_datacite_doi')) {
// Changing from a state that has no DOI to one that has a DOI
// Add a DOI to the DDI
try {
$context['params']['dsString'] = islandora_datacite_doi_mint($object, $datastream->id, $context['params']['dsString'], FALSE);
$context['params']['dsString'] = islandora_pydio_bridge_add_ddi_event($datastream, 'Other', 'minted a DOI and updated the DDI with the DOI', FALSE, $context['params']['dsString']);
}
catch (Exception $e) {
drupal_set_message(t('There was an error registering or minting the Datacite DOI for @object - @dsid, @msg', array(
'@object' => $object->id,
'@dsid' => $datastream->id,
'@msg' => $e->getMessage())), 'error');
}
}
if ($status2 === 'Archive' && module_exists('islandora_datacite_doi')) {
// Changing from a state that had a DOI to one that has no DOI so attempt to set the DOI inactive
try {
islandora_datacite_doi_delete($object->id);
} catch (Exception $e) {
drupal_set_message(t('There was an error setting the Datacite DOI to inactive for @object - @dsid, @msg', array(
'@object' => $object->id,
'@dsid' => $datastream->id,
'@msg' => $e->getMessage())), 'warning');
}
}
// Status is not the same update the xacml and add A DDI event
islandora_pydio_bridge_ingest_set_xacml($object, $status2);
$context['params']['dsString'] = islandora_pydio_bridge_add_ddi_event($datastream, 'Other', "The security policy has been modified.", FALSE, $context['params']['dsString']);
$context['params']['dsString'] = islandora_pydio_bridge_add_ddi_event($datastream, 'MetadataEditing', "The AccessCondition (status) has been changed from $status1 to $status2", FALSE, $context['params']['dsString']);
}
}
/**
* Implements hook_islandora_required_objects().
*/
function islandora_pydio_bridge_islandora_required_objects(IslandoraTuque $connection) {
$module_path = drupal_get_path('module', 'islandora');
// Root Collection.
$pydio_data_collection = $connection->repository->constructObject('islandora:pydio_data_top');
$pydio_data_collection->owner = 'fedoraAdmin';
$pydio_data_collection->label = 'Research Data Collections';
$pydio_data_collection->models = 'islandora:collectionCModel';
// Collection Policy Datastream.
$datastream = $pydio_data_collection->constructDatastream('COLLECTION_POLICY', 'X');
$datastream->label = 'Collection policy';
$datastream->mimetype = 'text/xml';
$datastream->setContentFromFile("$module_path/xml/islandora_collection_policy.xml", FALSE);
$pydio_data_collection->ingestDatastream($datastream);
// Add to root collection
$pydio_data_collection->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', 'islandora:root');
// TN Datastream.
$datastream = $pydio_data_collection->constructDatastream('TN', 'M');
$datastream->label = 'Thumbnail';
$datastream->mimetype = 'image/png';
$datastream->setContentFromFile("$module_path/images/folder.png", FALSE);
$pydio_data_collection->ingestDatastream($datastream);
return array(
'islandora_pydio_bridge' => array(
'title' => 'Islandora Pydio Bridge Data Collection',
'objects' => array($pydio_data_collection),
),
);
}
/**
* Implements hook_user_view()
*/
function islandora_pydio_bridge_user_view($account, $view_mode) {
$collection_pid = empty($account->data['islandora_pydio_bridge_person_data_collection']) ? NULL :
$account->data['islandora_pydio_bridge_person_data_collection'];
if (!empty($collection_pid)) {
$collection_link = l($collection_pid, "islandora/object/$collection_pid");
$account->content['islandora_pydio_bridge_user_collection'] = array(
'#type' => 'user_profile_category',
'#title' => 'Personal Research Data Collection',
'research_data_collection' => array(
'#markup' => t("Your Personal Data Collection ID is !collection_pid.", array('!collection_pid' => $collection_link)),
'#type' => 'user_profile_item',
'#title' => 'Personal Collection ID',
),
'#weight' => 10,
);
}
$entity_pid = empty($account->data['islandora_pydio_bridge_person_entity']) ? NULL :
$account->data['islandora_pydio_bridge_person_entity'];
if (!empty($entity_pid)) {
$entity_link = l($entity_pid, "islandora/object/$entity_pid");
$account->content['islandora_pydio_bridge_person_entity'] = array(
'#type' => 'user_profile_category',
'#title' => 'Personal Entity Object',
'entity_data_object' => array(
'#markup' => t("Your Entity Object ID is !entity_pid.", array('!entity_pid' => $entity_link)),
'#type' => 'user_profile_item',
'#title' => 'Personal Entity ID',
),
'#weight' => 10,
);
}
}
/**
* Implements hook_user_login().
*
* If you user logs in and does not have a corresponding Islandora personCModel
* object we will create one.
*
* TODO on user deletion should we remove the users fedora data?
*
* @param array $edit
* The array of form values submitted by the user
* @param object $account
* the users object
*/
function islandora_pydio_bridge_user_login(&$edit, $account) {
module_load_include('inc', 'islandora_pydio_bridge', 'includes/person');
islandora_pydio_bridge_create_user_collection($account);
islandora_pydio_bridge_create_user_entity($account);
islandora_pydio_bridge_verify_user_objects($account);
}
/**
* Menu access callback.
*/
function islandora_pydio_bridge_access_callback() {
global $user;
// TODO update or remove this so it gets the correct collection object from the drupal db (we now store each users own collection object
// in their drupal user object
// This is used for the pydio frame callback that we probably don't want
$object = islandora_object_load(variable_get('islandora_pydio_bridge_repository_pid', 'islandora:pydio_data_top'));
return in_array('authenticated user', $user->roles) && islandora_object_access(ISLANDORA_INGEST, $object, $user);
}
/**
* Menu access callback.
*
* We only want to show the versions tab if the object has a DDI datastream.
*
* @param string $permission
* An Islandora permission
* @param AbstractObject $object
* An Islandora object
* @return boolean
* TRUE if a user should see the versions tab FALSE otherwise.
*/
function islandora_pydio_bridge_versions_tab_access_callback($permission, $object) {
if (!isset($object['DDI'])) {
return FALSE;
}
return islandora_object_access_callback($permission, $object);
}
/**
* Implements hook_islandora_xml_form_builder_forms().
*/
function islandora_pydio_bridge_islandora_xml_form_builder_forms() {
$module_path = drupal_get_path('module', 'islandora_pydio_bridge');
return array(
'Islandora Pydio Bridge DDI form' => array(
'form_file' => "$module_path/xml/Simplified-DDI-3.2-Lifecycle-Form.xml",
),
);
}
/**
* Implements hook_islandora_content_model_forms_form_associations().
*/
function islandora_pydio_bridge_islandora_content_model_forms_form_associations() {
return array(
'islandora_pydio_bridge_generic_form' => array(
'content_model' => 'islandora:binaryObjectCModel',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_basic_image_form' => array(
'content_model' => 'islandora:sp_basic_image',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_large_image_form' => array(
'content_model' => 'islandora:sp_large_image_cmodel',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_pdf_form' => array(
'content_model' => 'islandora:sp_pdf',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_video_form' => array(
'content_model' => 'islandora:sp_videoCModel',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_audio_form' => array(
'content_model' => 'islandora:sp-audioCModel',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
'islandora_pydio_bridge_data_form' => array(
'content_model' => 'islandora:sp_data',
'form_name' => 'Islandora Pydio Bridge DDI form',
'dsid' => 'DDI',
'title_field' => array('Citation', 'Title', 'Title-String'),
'transform' => 'ddi_to_dc.xsl',
//'self_transform' => 'cleanup_ddi.xsl',
'template' => FALSE,
),
);
}
/**
* Implements hook_islandora_xml_form_builder_get_transforms().
*/
function islandora_pydio_bridge_xml_form_builder_get_transforms() {
$module_path = drupal_get_path('module', 'islandora_pydio_bridge');
return array(
'ddi_to_dc.xsl' => "$module_path/xml/ddi_to_dc.xsl",
);
}
/**
* Implements hook_xml_form_builder_get_self_transforms().
*/
function islandora_pydio_bridge_xml_form_builder_get_self_transforms() {
$module_path = drupal_get_path('module', 'islandora_pydio_bridge');
return array(
'cleanup_ddi.xsl' => "$module_path/xml/cleanup_ddi.xsl",
);
}
/**
* Implements hook_islandora_datastream_modified().
*
* We need to update datacite if the DDI is modified.
*/
function islandora_pydio_bridge_islandora_datastream_modified($object, $datastream) {
module_load_include('inc', 'islandora_pydio_bridge', 'includes/utilities');
if ($datastream->id != 'DDI') {
return;
}
$xml = new DOMDocument();
$xml->loadXML($datastream->content);
$query = "//r:Citation/r:InternationalIdentifier[r:ManagingAgency/text() = 'Datacite']/r:IdentifierContent";
$xpath = new DOMXPath($xml);
$xpath->registerNamespace('r', 'ddi:reusable:3_2');
$results = $xpath->query($query);
$status = islandora_pydio_bridge_get_ddi_status($datastream->content);
if ($results->length > 0 && $status !== 'Archive') {
$identifier = $results->item(0)->nodeValue;
if (!empty($identifier) && module_exists('islandora_datacite_doi')) {
$updated = islandora_datacite_doi_update_doi($object, $datastream->id);
if ($updated < 0) {
drupal_set_message(t('There was an error updating the Datacite metadata for @object - @dsid,'
. ' check the watchdog logs for more information', array(
'@object' => $object->id,
'@dsid' => $datastream->id
)));
}
}
}
}
/**
* Implements hook_islandora_object_purged().
*
* We need to update datacite if the object is purged
*/
function islandora_pydio_bridge_islandora_object_purged($pid) {
module_load_include('inc', 'islandora_pydio_bridge', 'includes/pydio_ingest');
// Attempt to mark the doi as inactive, at this point we don't know for sure if the
// object had a doi or not.
// TODO check for a doi before attempting to remove it
if(module_exists('islandora_datacite_doi')) {
try {
islandora_datacite_doi_delete($pid);
}
catch (Exception $e) {
drupal_set_message(t('There was an error deleting Datacite doi for @object, '
. ' check the watchdog logs for more information', array('@object' => $object->id)));
}
}
}