-
Notifications
You must be signed in to change notification settings - Fork 15
/
islandora_rest.module
171 lines (162 loc) · 6.37 KB
/
islandora_rest.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
<?php
/**
* @file
* Defines all the hooks this module implements.
*/
define('ISLANDORA_REST_VERSION', 'v1');
define('ISLANDORA_REST_URL_PREFIX', 'islandora/rest/' . ISLANDORA_REST_VERSION);
define('ISLANDORA_REST_OBJECT_MENU', ISLANDORA_REST_URL_PREFIX . '/object');
define('ISLANDORA_REST_DATASTREAM_MENU', ISLANDORA_REST_OBJECT_MENU . '/%/datastream');
define('ISLANDORA_REST_RELATIONSHIP_MENU', ISLANDORA_REST_OBJECT_MENU . '/%/relationship');
define('ISLANDORA_REST_SOLR_MENU', ISLANDORA_REST_URL_PREFIX . '/solr');
define('ISLANDORA_REST_OBJECT_GET_PERM', 'view objects');
define('ISLANDORA_REST_OBJECT_POST_PERM', 'create objects');
define('ISLANDORA_REST_OBJECT_PUT_PERM', 'modify object properties');
define('ISLANDORA_REST_OBJECT_DELETE_PERM', 'delete objects');
define('ISLANDORA_REST_DATASTREAM_GET_PERM', 'view datastreams');
define('ISLANDORA_REST_DATASTREAM_POST_PERM', 'create datastreams');
define('ISLANDORA_REST_DATASTREAM_PUT_PERM', 'modify datastreams');
define('ISLANDORA_REST_DATASTREAM_DELETE_PERM', 'delete datastreams');
define('ISLANDORA_REST_RELATIONSHIP_GET_PERM', 'list relationships');
define('ISLANDORA_REST_RELATIONSHIP_POST_PERM', 'create relationships');
define('ISLANDORA_REST_RELATIONSHIP_DELETE_PERM', 'delete relationships');
// @codingStandardsIgnoreStart
// XXX: This should be removed at some point in the future.
define('MENU_ISLANDORA_REST_OBJECT', ISLANDORA_REST_OBJECT_MENU);
define('MENU_ISLANDORA_REST_DATASTREAM', ISLANDORA_REST_DATASTREAM_MENU);
define('MENU_ISLANDORA_REST_RELATIONSHIP', ISLANDORA_REST_RELATIONSHIP_MENU);
define('MENU_ISLANDORA_REST_SOLR', ISLANDORA_REST_SOLR_MENU);
define('PERM_OBJECT_GET', ISLANDORA_REST_OBJECT_GET_PERM);
define('PERM_OBJECT_POST', ISLANDORA_REST_OBJECT_POST_PERM);
define('PERM_OBJECT_PUT', ISLANDORA_REST_OBJECT_PUT_PERM);
define('PERM_OBJECT_DELETE', ISLANDORA_REST_OBJECT_DELETE_PERM);
define('PERM_DATASTREAM_GET', ISLANDORA_REST_DATASTREAM_GET_PERM);
define('PERM_DATASTREAM_POST', ISLANDORA_REST_DATASTREAM_POST_PERM);
define('PERM_DATASTREAM_PUT', ISLANDORA_REST_DATASTREAM_PUT_PERM);
define('PERM_DATASTREAM_DELETE', ISLANDORA_REST_DATASTREAM_DELETE_PERM);
define('PERM_RELATIONSHIP_GET', ISLANDORA_REST_RELATIONSHIP_GET_PERM);
define('PERM_RELATIONSHIP_POST', ISLANDORA_REST_RELATIONSHIP_POST_PERM);
define('PERM_RELATIONSHIP_DELETE', ISLANDORA_REST_RELATIONSHIP_DELETE_PERM);
// @codingStandardsIgnoreEnd
/**
* Implements hook_menu().
*/
function islandora_rest_menu() {
// We don't use the access callback for any of the REST end-poinst as we can't
// reliably return JSON from that point.
return array(
ISLANDORA_REST_OBJECT_MENU => array(
'page callback' => 'islandora_rest_object',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_DATASTREAM_MENU => array(
'page callback' => 'islandora_rest_datastream',
'page arguments' => array(4, 6),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_RELATIONSHIP_MENU => array(
'page callback' => 'islandora_rest_relationship',
'page arguments' => array(4),
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
ISLANDORA_REST_SOLR_MENU => array(
'page callback' => 'islandora_rest_solr',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
),
);
}
/**
* Implements hook_permission().
*/
function islandora_rest_permission() {
return array(
ISLANDORA_REST_OBJECT_GET_PERM => array(
'title' => t('View objects'),
'description' => t('Allows users to fetch an objects properties and list its datastreams.'),
),
ISLANDORA_REST_OBJECT_POST_PERM => array(
'title' => t('Create objects'),
'description' => t('Allows users to create objects.'),
),
ISLANDORA_REST_OBJECT_PUT_PERM => array(
'title' => t('Modify object properties'),
'description' => t('Allows users to modify an objects properites.'),
),
ISLANDORA_REST_OBJECT_DELETE_PERM => array(
'title' => t('Delete objects'),
'description' => t('Allows users to delete objects.'),
),
ISLANDORA_REST_DATASTREAM_GET_PERM => array(
'title' => t('View datastreams'),
'description' => t('Allows users to get a given datastream content and properties.'),
),
ISLANDORA_REST_DATASTREAM_POST_PERM => array(
'title' => t('Create datastreams'),
'description' => t('Allows users to create datastreams.'),
),
ISLANDORA_REST_DATASTREAM_PUT_PERM => array(
'title' => t('Modify datastreams'),
'description' => t('Allows users to modify existing datastreams and their properties.'),
),
ISLANDORA_REST_DATASTREAM_DELETE_PERM => array(
'title' => t('Delete datastreams'),
'description' => t('Allows users to delete datastreams.'),
),
ISLANDORA_REST_RELATIONSHIP_GET_PERM => array(
'title' => t('List relationships'),
'description' => t('Allows users to list an objects relationships.'),
),
ISLANDORA_REST_RELATIONSHIP_POST_PERM => array(
'title' => t('Create relationships'),
'description' => t('Allows users to create new relationships.'),
),
ISLANDORA_REST_RELATIONSHIP_DELETE_PERM => array(
'title' => t('Delete relationships'),
'description' => t('Allows users to delete existing relationships'),
),
);
}
/**
* Rest end-point for objects.
*
* @note This function exits.
*/
function islandora_rest_object($pid = NULL) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('object', array('pid' => $pid));
exit();
}
/**
* Rest end-point for datastreams.
*
* @note This function exits.
*/
function islandora_rest_datastream($pid, $dsid = NULL) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('datastream', array('pid' => $pid, 'dsid' => $dsid));
exit();
}
/**
* Rest end-point for relationships.
*
* @note This function exits.
*/
function islandora_rest_relationship($pid) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('relationship', array('pid' => $pid));
exit();
}
/**
* Rest end-point for making SOLR queries.
*
* @note This function exits.
*/
function islandora_rest_solr($query = NULL) {
module_load_include('inc', 'islandora_rest', 'includes/utilities');
print islandora_rest_get_response('solr', array('query' => $query));
exit();
}