This repository was archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathApiComponent.php
More file actions
1243 lines (1124 loc) · 45.9 KB
/
Copy pathApiComponent.php
File metadata and controls
1243 lines (1124 loc) · 45.9 KB
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*=========================================================================
Midas Server
Copyright Kitware SAS, 26 rue Louis Guérin, 69100 Villeurbanne, France.
All rights reserved.
For more information visit http://www.kitware.com/.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
/** These are the implementations of the core web api methods */
class Api_ApiComponent extends AppComponent
{
public $controller;
public $apiSetup;
public $userSession;
/**
* This should be called before _getUser to define what policy scopes (see module.php constants)
* are required for the current API endpoint. If this is not called and _getUser is called,
* the default behavior is to require PERMISSION_SCOPE_ALL.
*
* @param scopes A list of scope constants that are required for the operation
*/
private function _requirePolicyScopes($scopes)
{
Zend_Registry::get('notifier')->callback('CALLBACK_API_REQUIRE_PERMISSIONS', array('scopes' => $scopes));
}
/**
* Pass the args and a list of required parameters.
* Will throw an exception if a required one is missing.
*/
private function _validateParams($args, $requiredList)
{
foreach ($requiredList as $param) {
if (!array_key_exists($param, $args)) {
throw new Exception('Parameter '.$param.' is not defined', MIDAS_INVALID_PARAMETER);
}
}
}
/** Return the user dao */
private function _getUser($args)
{
/** @var AuthenticationComponent $authComponent */
$authComponent = MidasLoader::loadComponent('Authentication');
return $authComponent->getUser($args, $this->userSession->Dao);
}
/** Return the user dao */
private function _callCoreApiMethod($args, $coreApiMethod, $resource = null, $hasReturn = true)
{
$ApiComponent = MidasLoader::loadComponent('Api'.$resource);
$rtn = $ApiComponent->$coreApiMethod($args);
if ($hasReturn) {
return $rtn;
}
return;
}
/**
* Get the server version.
*
* @return Server version in the form <major>.<minor>.<patch>
*/
public function version($args)
{
return $this->_callCoreApiMethod($args, 'version', 'system');
}
/**
* Get the enabled modules on the server.
*
* @return List of enabled modules on the server
*/
public function modulesList($args)
{
return $this->_callCoreApiMethod($args, 'modulesList', 'system');
}
/**
* List all available web api methods on the server.
*
* @return List of api method names and their corresponding documentation
*/
public function methodsList($args)
{
$data = array();
$data['methods'] = array();
$apiMethods = Zend_Registry::get('notifier')->callback('CALLBACK_API_HELP', array());
foreach ($apiMethods as $module => $methods) {
foreach ($methods as $method) {
$apiMethodName = $module != 'api' ? $module.'.' : '';
$apiMethodName .= $method['name'];
$data['methods'][] = array('name' => $apiMethodName, 'help' => $method['help']);
}
}
return $data;
}
/**
* Get the server information including version, modules enabled,
* and available web api methods (names do not include the global prefix).
*
* @return Server information
*/
public function info($args)
{
return $this->_callCoreApiMethod($args, 'info', 'system');
}
/**
* Login as a user using a web api key.
*
* @param appname The application name
* @param email The user email
* @param apikey The api key corresponding to the given application name
* @return A web api token that will be valid for a set duration
*/
public function login($args)
{
return $this->_callCoreApiMethod($args, 'login', 'system');
}
/**
* Get a resource by its UUID.
*
* @param uuid Universal identifier for the resource
* @param folder (Optional) If set, will return the folder instead of the community record
* @return The resource's dao
*/
public function resourceGet($args)
{
$this->_validateParams($args, array('uuid'));
$uuid = $args['uuid'];
/** @var UuidComponent $uuidComponent */
$uuidComponent = MidasLoader::loadComponent('Uuid');
$resource = $uuidComponent->getByUid($uuid);
if ($resource == false) {
throw new Exception('No resource for the given UUID.', MIDAS_INVALID_PARAMETER);
}
if ($resource->resourceType == MIDAS_RESOURCE_COMMUNITY && array_key_exists('folder', $args)
) {
return array('type' => MIDAS_RESOURCE_FOLDER, 'id' => $resource->getFolderId());
}
return array('type' => $resource->resourceType, 'id' => $resource->getKey());
}
/**
* Returns a path of uuids from the root folder to the given node.
*
* @param uuid Unique identifier of the resource
* @return An ordered list of uuids representing a path from the root node
*/
public function pathFromRoot($args)
{
return array_reverse($this->pathToRoot($args));
}
/**
* Returns a path of uuids from the given node to the root node.
*
* @param uuid Unique identifier of the resource
* @return An ordered list of uuids representing a path to the root node
*/
public function pathToRoot($args)
{
$this->_validateParams($args, array('uuid'));
/** @var UuidComponent $uuidComponent */
$uuidComponent = MidasLoader::loadComponent('Uuid');
$element = $uuidComponent->getByUid($args['uuid']);
$return = array();
$return[] = $element->toArray();
if ($element == false) {
throw new Exception('No resource for the given UUID.', MIDAS_INVALID_PARAMETER);
}
if ($element instanceof FolderDao) {
$parent = $element->getParent();
while ($parent !== false) {
$return[] = $parent->toArray();
$parent = $parent->getParent();
}
} elseif ($element instanceof ItemDao) {
$owningFolders = $element->getFolders();
// randomly pick one parent folder
$parent = $owningFolders[0];
while ($parent !== false) {
$return[] = $parent->toArray();
$parent = $parent->getParent();
}
} elseif (!$element instanceof CommunityDao) {
// community element itself is the root
throw new Exception('Should be a folder, an item or a community.', MIDAS_INVALID_PARAMETER);
}
return $return;
}
/**
* Search items for the given words.
*
* @param token (Optional) Authentication token
* @param search The search query
* @param folder Parent uuid folder
* @return An array of matching resources
*/
public function itemSearch($args)
{
$this->_validateParams($args, array('search'));
$this->_requirePolicyScopes(array(MIDAS_API_PERMISSION_SCOPE_READ_DATA));
$userDao = $this->_getUser($args);
$order = 'view';
if (isset($args['order'])) {
$order = $args['order'];
}
$folder = false;
if (isset($args['folder'])) {
$folder = $args['folder'];
}
/** @var SearchComponent $searchComponent */
$searchComponent = MidasLoader::loadComponent('Search');
return $searchComponent->searchItems($userDao, $args['search'], $folder, $order);
}
/**
* Search resources for the given words.
*
* @param token (Optional) Authentication token
* @param search The search query
* @return An array of matching resources
*/
public function resourceSearch($args)
{
$this->_validateParams($args, array('search'));
$this->_requirePolicyScopes(array(MIDAS_API_PERMISSION_SCOPE_READ_DATA));
$userDao = $this->_getUser($args);
$order = 'view';
if (isset($args['order'])) {
$order = $args['order'];
}
/** @var SearchComponent $searchComponent */
$searchComponent = MidasLoader::loadComponent('Search');
return $searchComponent->searchAll($userDao, $args['search'], $order);
}
/**
* Create a link bitstream.
*
* @param token Authentication token.
* @param folderid The id of the folder in which to create a new item that
* will contain the link. The new item will have the same name as
* <b>url</b> unless <b>itemname</b> is supplied.
* @param url The URL of the link you will create, will be used as the name
* of the bitstream and of the item (unless <b>itemname</b> is
* supplied).
* @param itemname (Optional)
* The name of the newly created item, if not supplied, the item will
* have the same name as <b>url</b>.
* @param length (Optional)
* The length in bytes of the file to which the link points.
* @param checksum (Optional)
* The md5 checksum of the file to which the link points.
* @return The item information of the item created.
*/
public function linkCreate($args)
{
return $this->_callCoreApiMethod($args, 'linkCreate', 'system');
}
/**
* Generate a unique upload token. Either <b>itemid</b> or <b>folderid</b> is required,
* but both are not allowed.
*
* @param token Authentication token.
* @param itemid
The id of the item to upload into.
* @param folderid
The id of the folder to create a new item in and then upload to.
* The new item will have the same name as <b>filename</b> unless <b>itemname</b>
* is supplied.
* @param filename The filename of the file you will upload, will be used as the
* bitstream's name and the item's name (unless <b>itemname</b> is supplied).
* @param itemdescription (Optional)
* When passing the <b>folderid</b> param, the description of the item,
* if not supplied the item's description will be blank.
* @param itemname (Optional)
* When passing the <b>folderid</b> param, the name of the newly created item,
* if not supplied, the item will have the same name as <b>filename</b>.
* @param checksum (Optional) The md5 checksum of the file to be uploaded.
* @param create_additional_revision (Optional) When a <b>checksum</b> is passed and
* the server already has the file, by default a reference to the existing
* bitstream will be added to the latest revision. By setting
* <b>create_additional_revision</b> to true, a new revision will be created.
* @return An upload token that can be used to upload a file.
* If <b>folderid</b> is passed instead of <b>itemid</b>, a new item will be created
* in that folder, but the id of the newly created item will not be
* returned. If the id of the newly created item is needed,
* then call the <b>midas.item.create</b> method instead.
* If <b>checksum</b> is passed and the token returned is blank, the
* server already has this file and there is no need to follow this
* call with a call to <b>midas.upload.perform</b>, as the passed in
* file will have been added as a bitstream to the item's latest
* revision, creating a new revision if one doesn't exist.
*/
public function uploadGeneratetoken($args)
{
return $this->_callCoreApiMethod($args, 'uploadGeneratetoken', 'system');
}
/**
* Get the size of a partially completed upload.
*
* @param uploadtoken The upload token for the file
* @return [offset] The size of the file currently on the server
*/
public function uploadGetoffset($args)
{
return $this->_callCoreApiMethod($args, 'uploadGetoffset', 'system');
}
/**
* Upload a file to the server. PUT or POST is required.
* Will add the file as a bitstream to the item that was specified when
* generating the upload token in a new revision to that item, unless
* <b>revision</b> param is set.
*
* @param uploadtoken The upload token (see <b>midas.upload.generatetoken</b>).
* @param filename The name of the bitstream that will be added to the item.
* @param length The length in bytes of the file being uploaded.
* @param mode (Optional) Stream or multipart. Default is stream.
* @param revision (Optional)
* If set, will add a new file into the existing passed in revision number.
* If set to "head", will add a new file into the most recent revision,
* and will create a new revision in this case if none exists.
* @param changes (Optional)
* The changes field on the affected item revision,
* e.g. for recording what has changed since the previous revision.
* @param license (Optional) The license for the revision.
* @return The item information of the item created or changed.
*/
public function uploadPerform($args)
{
return $this->_callCoreApiMethod($args, 'uploadPerform', 'system');
}
/**
* Create a new community or update an existing one using the uuid.
*
* @param token Authentication token
* @param name The community name
* @param description (Optional) The community description
* @param uuid (Optional) Uuid of the community. If none is passed, will generate one.
* @param privacy (Optional) Default 'Public', possible values [Public|Private].
* @param canjoin (Optional) Default 'Everyone', possible values [Everyone|Invitation].
* @return The community dao that was created
*/
public function communityCreate($args)
{
return $this->_callCoreApiMethod($args, 'communityCreate', 'community');
}
/**
* Get a community's information based on the id OR name.
*
* @param token (Optional) Authentication token
* @param id The id of the community
* @param name the name of the community
* @return The community information
*/
public function communityGet($args)
{
return $this->_callCoreApiMethod($args, 'communityGet', 'community');
}
/**
* Get the immediate children of a community (non-recursive).
*
* @param token (Optional) Authentication token
* @param id The id of the community
* @return The folders in the community
*/
public function communityChildren($args)
{
return $this->_callCoreApiMethod($args, 'communityChildren', 'community');
}
/**
* Return a list of all communities visible to a user.
*
* @param token (Optional) Authentication token
* @return A list of all communities
*/
public function communityList($args)
{
return $this->_callCoreApiMethod($args, 'communityList', 'community');
}
/**
* Delete a community. Requires admin privileges on the community.
*
* @param token Authentication token
* @param id The id of the community
*/
public function communityDelete($args)
{
$this->_callCoreApiMethod($args, 'communityDelete', 'community', false);
}
/**
* Create a folder or update an existing one if one exists by the uuid passed.
* If a folder is requested to be created with the same parentid and name as
* an existing folder, an exception will be thrown and no new folder will
* be created.
*
* @param token Authentication token
* @param name The name of the folder to create
* @param description (Optional) The description of the folder
* @param uuid (Optional) Uuid of the folder. If none is passed, will generate one.
* @param privacy (Optional) Possible values [Public|Private]. Default behavior is to inherit from parent folder.
* @param reuseExisting (Optional) If this parameter is set, will just return the existing folder if there is one with the name provided
* @param parentid The id of the parent folder. Set this to -1 to create a top level user folder.
* @return The folder object that was created
*/
public function folderCreate($args)
{
return $this->_callCoreApiMethod($args, 'folderCreate', 'folder');
}
/**
* Get information about the folder.
*
* @param token (Optional) Authentication token
* @param id The id of the folder
* @return The folder object, including its parent object
*/
public function folderGet($args)
{
return $this->_callCoreApiMethod($args, 'folderGet', 'folder');
}
/**
* Get the immediate children of a folder (non-recursive).
*
* @param token (Optional) Authentication token
* @param id The id of the folder
* @return The items and folders in the given folder
*/
public function folderChildren($args)
{
return $this->_callCoreApiMethod($args, 'folderChildren', 'folder');
}
/**
* Delete a folder. Requires admin privileges on the folder.
*
* @param token Authentication token
* @param id The id of the folder
*/
public function folderDelete($args)
{
$this->_callCoreApiMethod($args, 'folderDelete', 'folder', false);
}
/**
* Download a folder.
*
* @param token (Optional) Authentication token
* @param id The id of the folder
* @return A zip archive of the folder's contents
*/
public function folderDownload($args)
{
return $this->_callCoreApiMethod($args, 'folderDownload', 'folder');
}
/**
* Move a folder to the destination folder.
*
* @param token Authentication token
* @param id The id of the folder
* @param dstfolderid The id of destination folder (new parent folder) where the folder is moved to
* @return The folder object
*/
public function folderMove($args)
{
return $this->_callCoreApiMethod($args, 'folderMove', 'folder');
}
/**
* List the permissions on a folder, requires Admin access to the folder.
*
* @param folder_id The id of the folder
* @return A list with three keys: privacy, user, group; privacy will be the
* folder's privacy string [Public|Private]; user will be a list of
* (user_id, policy, email); group will be a list of (group_id, policy, name).
* policy for user and group will be a policy string [Admin|Write|Read].
*/
public function folderListPermissions($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderListPermissions', 'folder');
}
/**
* Set the privacy status on a folder, and push this value down recursively
* to all children folders and items, requires Admin access to the folder.
*
* @param folder_id The id of the folder.
* @param privacy Desired privacy status, one of [Public|Private].
* @return An array with keys 'success' and 'failure' indicating a count
* of children resources that succeeded or failed the permission change.
*/
public function folderSetPrivacyRecursive($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderSetPrivacyRecursive', 'folder');
}
/**
* Add a folderpolicygroup to a folder with the passed in group and policy;
* if a folderpolicygroup exists for that group and folder, it will be replaced
* with the passed in policy.
*
* @param folder_id The id of the folder.
* @param group_id The id of the group.
* @param policy Desired policy status, one of [Admin|Write|Read].
* @param recursive If included will push all policies from
* the passed in folder down to its child folders and items, default is non-recursive.
* @return An array with keys 'success' and 'failure' indicating a count of
* resources affected by the addition.
*/
public function folderAddPolicygroup($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderAddPolicygroup', 'folder');
}
/**
* Remove a folderpolicygroup from a folder with the passed in group if the
* folderpolicygroup exists.
*
* @param folder_id The id of the folder.
* @param group_id The id of the group.
* @param recursive If included will push all policies after the removal from
* the passed in folder down to its child folders and items, default is non-recursive.
* @return An array with keys 'success' and 'failure' indicating a count of
* resources affected by the removal.
*/
public function folderRemovePolicygroup($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderRemovePolicygroup', 'folder');
}
/**
* Add a folderpolicyuser to a folder with the passed in user and policy;
* if a folderpolicyuser exists for that user and folder, it will be replaced
* with the passed in policy.
*
* @param folder_id The id of the folder.
* @param user_id The id of the targeted user to create the policy for.
* @param policy Desired policy status, one of [Admin|Write|Read].
* @param recursive If included will push all policies from
* the passed in folder down to its child folders and items, default is non-recursive.
* @return An array with keys 'success' and 'failure' indicating a count of
* resources affected by the addition.
*/
public function folderAddPolicyuser($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderAddPolicyuser', 'folder');
}
/**
* Remove a folderpolicyuser from a folder with the passed in user if the
* folderpolicyuser exists.
*
* @param folder_id The id of the folder.
* @param user_id The id of the target user.
* @param recursive If included will push all policies after the removal from
* the passed in folder down to its child folders and items, default is non-recursive.
* @return An array with keys 'success' and 'failure' indicating a count of
* resources affected by the removal.
*/
public function folderRemovePolicyuser($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'folder_id', 'id');
return $this->_callCoreApiMethod($args, 'folderRemovePolicyuser', 'folder');
}
/**
* Check whether an item with the given name exists in the given folder.
*
* @param parentid The id of the parent folder
* @param name The name of the item
* @return array('exists' => bool)
*/
public function itemExists($args)
{
return $this->_callCoreApiMethod($args, 'itemExists', 'item');
}
/**
* Create an item or update an existing one if one exists by the uuid passed.
* Note: In the case of an already existing item, any parameters passed whose name
* begins with an underscore are assumed to be metadata fields to set on the item.
*
* @param token Authentication token
* @param parentid The id of the parent folder. Only required for creating a new item.
* @param name The name of the item to create
* @param description (Optional) The description of the item
* @param uuid (Optional) Uuid of the item. If none is passed, will generate one.
* @param privacy (Optional) [Public|Private], default will inherit from parent folder
* @param updatebitstream (Optional) If set, the bitstream's name will be updated
* simultaneously with the item's name if and only if the item has already
* existed and its latest revision contains only one bitstream.
* @return The item object that was created
*/
public function itemCreate($args)
{
return $this->_callCoreApiMethod($args, 'itemCreate', 'item');
}
/**
* Get an item's information.
*
* @param token (Optional) Authentication token
* @param id The item id
* @param head (Optional) only list the most recent revision
* @return The item object
*/
public function itemGet($args)
{
return $this->_callCoreApiMethod($args, 'itemGet', 'item');
}
/**
* Download an item.
*
* @param token (Optional) Authentication token
* @param id The id of the item
* @param revision (Optional) Revision to download. Defaults to latest revision
* @return The bitstream(s) in the item
*/
public function itemDownload($args)
{
return $this->_callCoreApiMethod($args, 'itemDownload', 'item');
}
/**
* Delete an item.
*
* @param token Authentication token
* @param id The id of the item
*/
public function itemDelete($args)
{
$this->_callCoreApiMethod($args, 'itemDelete', 'item', false);
}
/**
* Get the item's metadata.
*
* @param token (Optional) Authentication token
* @param id The id of the item
* @param revision (Optional) Revision of the item. Defaults to latest revision
* @return the sought metadata array on success,
* will fail if there are no revisions or the specified revision is not found.
*/
public function itemGetmetadata($args)
{
return $this->_callCoreApiMethod($args, 'itemGetmetadata', 'item');
}
/**
* Set a metadata field on an item.
*
* @param token Authentication token
* @param itemId The id of the item
* @param element The metadata element
* @param value The metadata value for the field
* @param qualifier (Optional) The metadata qualifier. Defaults to empty string.
* @param type (Optional) The metadata type (integer constant). Defaults to MIDAS_METADATA_TEXT type (0).
* @param revision (Optional) Revision of the item. Defaults to latest revision.
* @return true on success,
* will fail if there are no revisions or the specified revision is not found.
*/
public function itemSetmetadata($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'itemId', 'id');
return $this->_callCoreApiMethod($args, 'itemSetmetadata', 'item');
}
/**
* Set multiple metadata fields on an item, requires specifying the number of
* metadata tuples to add.
*
* @param token Authentication token
* @param itemid The id of the item
* @param revision (Optional) Item Revision number to set metadata on, defaults to latest revision.
* @param count The number of metadata tuples that will be set. For every one
* of these metadata tuples there will be the following set of params with counters
* at the end of each param name, from 1..<b>count</b>, following the example
* using the value <b>i</b> (i.e., replace <b>i</b> with values 1..<b>count</b>)
* (<b>element_i</b>, <b>value_i</b>, <b>qualifier_i</b>, <b>type_i</b>).
*
* @param element_i metadata element for tuple i
* @param value_i metadata value for the field, for tuple i
* @param qualifier_i (Optional) metadata qualifier for tuple i. Defaults to empty string.
* @param type_i (Optional) metadata type (integer constant). Defaults to MIDAS_METADATA_TEXT type (0).
* @return true on success,
* will fail if there are no revisions or the specified revision is not found.
*/
public function itemSetmultiplemetadata($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'itemid', 'id');
return $this->_callCoreApiMethod($args, 'itemSetmultiplemetadata', 'item');
}
/**
* Delete a metadata tuple (element, qualifier, type) from a specific item revision,
* defaults to the latest revision of the item.
*
* @param token Authentication token
* @param itemid The id of the item
* @param element The metadata element
* @param qualifier (Optional) The metadata qualifier. Defaults to empty string.
* @param type (Optional) metadata type (integer constant).
* Defaults to MIDAS_METADATA_TEXT (0).
* @param revision (Optional) Revision of the item. Defaults to latest revision.
* @return true on success,
* false if the metadata was not found on the item revision,
* will fail if there are no revisions or the specified revision is not found.
*/
public function itemDeletemetadata($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'itemid', 'id');
return $this->_callCoreApiMethod($args, 'itemDeletemetadata', 'item');
}
/**
* Deletes all metadata associated with a specific item revision;
* defaults to the latest revision of the item;
* pass <b>revision</b>=<b>all</b> to delete all metadata from all revisions.
*
* @param token Authentication token
* @param itemid The id of the item
* @param revision (Optional)
* Revision of the item. Defaults to latest revision; pass <b>all</b> to delete all metadata from all revisions.
* @return true on success,
* will fail if there are no revisions or the specified revision is not found.
*/
public function itemDeletemetadataAll($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'itemid', 'id');
return $this->_callCoreApiMethod($args, 'itemDeletemetadataAll', 'item');
}
/**
* Duplicate an item to the destination folder.
*
* @param token Authentication token
* @param id The id of the item
* @param dstfolderid The id of destination folder where the item is duplicated to
* @return The item object that was created
*/
public function itemDuplicate($args)
{
return $this->_callCoreApiMethod($args, 'itemDuplicate', 'item');
}
/**
* Share an item to the destination folder.
*
* @param token Authentication token
* @param id The id of the item
* @param dstfolderid The id of destination folder where the item is shared to
* @return The item object
*/
public function itemShare($args)
{
return $this->_callCoreApiMethod($args, 'itemShare', 'item');
}
/**
* List the permissions on an item, requires Admin access to the item.
*
* @param item_id The id of the item
* @return A list with three keys: privacy, user, group; privacy will be the
* item's privacy string [Public|Private]; user will be a list of
* (user_id, policy, email); group will be a list of (group_id, policy, name).
* policy for user and group will be a policy string [Admin|Write|Read].
*/
public function itemListPermissions($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'item_id', 'id');
return $this->_callCoreApiMethod($args, 'itemListPermissions', 'item');
}
/**
* Move an item from the source folder to the desination folder.
*
* @param token Authentication token
* @param id The id of the item
* @param srcfolderid The id of source folder where the item is located
* @param dstfolderid The id of destination folder where the item is moved to
* @return The item object
*/
public function itemMove($args)
{
return $this->_callCoreApiMethod($args, 'itemMove', 'item');
}
/**
* Return all items.
*
* @param token (Optional) Authentication token
* @param name The name of the item to search by
* @return A list of all items with the given name
*/
public function itemSearchbyname($args)
{
return $this->_callCoreApiMethod($args, 'itemSearch', 'item');
}
/**
* Return all items with a given name and parent folder id.
*
* @param token (Optional) Authentication token
* @param name The name of the item to search by
* @param folderId The id of the parent folder to search by
* @return A list of all items with the given name and parent folder id
*/
public function itemSearchbynameandfolder($args)
{
return $this->_callCoreApiMethod($args, 'itemSearch', 'item');
}
/**
* Return all items with a given name and parent folder name.
*
* @param token (Optional) Authentication token
* @param name The name of the item to search by
* @param folderName The name of the parent folder to search by
* @return A list of all items with the given name and parent folder name
*/
public function itemSearchbynameandfoldername($args)
{
return $this->_callCoreApiMethod($args, 'itemSearch', 'item');
}
/**
* Add an itempolicygroup to an item with the passed in group and policy;
* if an itempolicygroup exists for that group and item, it will be replaced
* with the passed in policy.
*
* @param item_id The id of the item.
* @param group_id The id of the group.
* @param policy Desired policy status, one of [Admin|Write|Read].
* @return success = true on success.
*/
public function itemAddPolicygroup($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'item_id', 'id');
return $this->_callCoreApiMethod($args, 'itemAddPolicygroup', 'item');
}
/**
* Remove a itempolicygroup from a item with the passed in group if the
* itempolicygroup exists.
*
* @param item_id The id of the item.
* @param group_id The id of the group.
* @return success = true on success.
*/
public function itemRemovePolicygroup($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'item_id', 'id');
return $this->_callCoreApiMethod($args, 'itemRemovePolicygroup', 'item');
}
/**
* Add a itempolicyuser to an item with the passed in user and policy;
* if an itempolicyuser exists for that user and item, it will be replaced
* with the passed in policy.
*
* @param item_id The id of the item.
* @param user_id The id of the targeted user to create the policy for.
* @param policy Desired policy status, one of [Admin|Write|Read].
* @return success = true on success.
*/
public function itemAddPolicyuser($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'item_id', 'id');
return $this->_callCoreApiMethod($args, 'itemAddPolicyuser', 'item');
}
/**
* Remove an itempolicyuser from an item with the passed in user if the
* itempolicyuser exists.
*
* @param item_id The id of the item.
* @param user_id The id of the target user.
* @return success = true on success.
*/
public function itemRemovePolicyuser($args)
{
/** @var ApihelperComponent $ApihelperComponent */
$ApihelperComponent = MidasLoader::loadComponent('Apihelper');
$ApihelperComponent->renameParamKey($args, 'item_id', 'id');
return $this->_callCoreApiMethod($args, 'itemRemovePolicyuser', 'item');
}
/**
* Return a list of top level folders belonging to the user.
*
* @param token Authentication token
* @return List of the user's top level folders
*/
public function userFolders($args)
{
return $this->_callCoreApiMethod($args, 'userFolders', 'user');
}
/**
* Returns the user's default API key given their username and password.
* POST method required.