@@ -94,62 +94,6 @@ function login($args)
94
94
return $ data ;
95
95
}
96
96
97
- /**
98
- * Get the UUID of a resource
99
- * @param id The id of the resource (numeric)
100
- * @param type The type of the resource (numeric)
101
- * @return Universal identifier
102
- */
103
- public function uuidGet ($ args )
104
- {
105
- $ this ->_validateParams ($ args , array ('id ' , 'type ' ));
106
-
107
- $ id = $ args ['id ' ];
108
- $ type = $ args ['type ' ];
109
- $ modelLoad = new MIDAS_ModelLoader ();
110
- switch ($ type )
111
- {
112
- case MIDAS_RESOURCE_ASSETSTORE :
113
- $ model = $ modelLoad ->loadModel ('Assetstore ' );
114
- break ;
115
- case MIDAS_RESOURCE_BITSTREAM :
116
- $ model = $ modelLoad ->loadModel ('Bitstream ' );
117
- break ;
118
- case MIDAS_RESOURCE_ITEM :
119
- $ model = $ modelLoad ->loadModel ('Item ' );
120
- break ;
121
- case MIDAS_RESOURCE_COMMUNITY :
122
- $ model = $ modelLoad ->loadModel ('Community ' );
123
- break ;
124
- case MIDAS_RESOURCE_REVISION :
125
- $ model = $ modelLoad ->loadModel ('ItemRevision ' );
126
- break ;
127
- case MIDAS_RESOURCE_FOLDER :
128
- $ model = $ modelLoad ->loadModel ('Folder ' );
129
- break ;
130
- case MIDAS_RESOURCE_USER :
131
- $ model = $ modelLoad ->loadModel ('User ' );
132
- break ;
133
- default :
134
- throw new Zend_Exception ("Undefined type " );
135
- }
136
- $ dao = $ model ->load ($ id );
137
-
138
- if ($ dao == false )
139
- {
140
- throw new Exception ('Invalid resource type or id. ' , MIDAS_INVALID_PARAMETER );
141
- }
142
-
143
- $ uuid = $ dao ->getUuid ();
144
-
145
- if ($ uuid == false )
146
- {
147
- throw new Exception ('Invalid resource type or id. ' , MIDAS_INVALID_PARAMETER );
148
- }
149
-
150
- return $ uuid ;
151
- }
152
-
153
97
/**
154
98
* Get a resource by its UUID
155
99
* @param uuid Universal identifier for the resource
@@ -387,7 +331,7 @@ function uploadPerform($args)
387
331
}
388
332
389
333
/**
390
- * Create a new community
334
+ * Create a new community or update an existing one using the uuid
391
335
* @param token Authentication token
392
336
* @param name The community name
393
337
* @param description (Optional) The community description
@@ -461,7 +405,7 @@ function communityCreate($args)
461
405
462
406
if ($ communityDao === false )
463
407
{
464
- throw new Exception ('Request failed ' , MIDAS_INTERNAL_ERROR );
408
+ throw new Exception ('Create community failed ' , MIDAS_INTERNAL_ERROR );
465
409
}
466
410
467
411
return $ communityDao ->toArray ();
@@ -591,7 +535,7 @@ function communityDelete($args)
591
535
}
592
536
593
537
/**
594
- * Create a folder
538
+ * Create a folder or update an existing one if one exists by the uuid passed
595
539
* @param token Authentication token
596
540
* @param name The name of the folder to create
597
541
* @param description (Optional) The description of the folder
@@ -654,7 +598,7 @@ function folderCreate($args)
654
598
$ new_folder = $ folderModel ->createFolder ($ name , $ description , $ folder , $ uuid );
655
599
if ($ new_folder === false )
656
600
{
657
- throw new Exception ('Request failed ' , MIDAS_INTERNAL_ERROR );
601
+ throw new Exception ('Create folder failed ' , MIDAS_INTERNAL_ERROR );
658
602
}
659
603
$ policyGroup = $ folder ->getFolderpolicygroup ();
660
604
$ policyUser = $ folder ->getFolderpolicyuser ();
@@ -778,6 +722,78 @@ function folderDownload($args)
778
722
$ this ->controller ->redirect ('/download/?folders= ' .$ folder ->getKey ());
779
723
}
780
724
725
+ /**
726
+ * Create an item or update an existing one if one exists by the uuid passed
727
+ * @param token Authentication token
728
+ * @param name The name of the item to create
729
+ * @param description (Optional) The description of the item
730
+ * @param uuid (Optional) Uuid of the item. If none is passed, will generate one.
731
+ * @param privacy (Optional) Default 'Public'.
732
+ * @param parentid The id of the parent folder
733
+ * @return The item object that was created
734
+ */
735
+ function itemCreate ($ args )
736
+ {
737
+ $ this ->_validateParams ($ args , array ('name ' ));
738
+ $ userDao = $ this ->_getUser ($ args );
739
+ if ($ userDao == false )
740
+ {
741
+ throw new Exception ('Cannot create item anonymously ' , MIDAS_INVALID_POLICY );
742
+ }
743
+
744
+ $ modelLoader = new MIDAS_ModelLoader ();
745
+ $ itemModel = $ modelLoader ->loadModel ('Item ' );
746
+ $ name = $ args ['name ' ];
747
+ $ description = $ args ['description ' ];
748
+
749
+ $ uuid = isset ($ args ['uuid ' ]) ? $ args ['uuid ' ] : '' ;
750
+ $ record = false ;
751
+ if (!empty ($ uuid ))
752
+ {
753
+ $ componentLoader = new MIDAS_ComponentLoader ();
754
+ $ uuidComponent = $ componentLoader ->loadComponent ('Uuid ' );
755
+ $ record = $ uuidComponent ->getByUid ($ uuid );
756
+ }
757
+ if ($ record != false && $ record instanceof ItemDao)
758
+ {
759
+ if (!$ itemModel ->policyCheck ($ record , $ userDao , MIDAS_POLICY_WRITE ))
760
+ {
761
+ throw new Exception ('Invalid policy ' , MIDAS_INVALID_POLICY );
762
+ }
763
+ $ record ->setName ($ name );
764
+ if (isset ($ args ['description ' ]))
765
+ {
766
+ $ record ->setDescription ($ args ['description ' ]);
767
+ }
768
+ if (isset ($ args ['privacy ' ]))
769
+ {
770
+ $ record ->setPrivacy ($ args ['privacy ' ]);
771
+ }
772
+ $ itemModel ->save ($ record );
773
+ return $ record ->toArray ();
774
+ }
775
+ else
776
+ {
777
+ if (!array_key_exists ('parentid ' , $ args ))
778
+ {
779
+ throw new Exception ('Parameter parentid is not defined ' , MIDAS_INVALID_PARAMETER );
780
+ }
781
+ $ folderModel = $ modelLoader ->loadModel ('Folder ' );
782
+ $ folder = $ folderModel ->load ($ args ['parentid ' ]);
783
+ if ($ folder == false )
784
+ {
785
+ throw new Exception ('Parent folder doesn \'t exist ' , MIDAS_INVALID_PARAMETER );
786
+ }
787
+ $ item = $ itemModel ->createItem ($ name , $ description , $ folder , $ uuid );
788
+ if ($ item === false )
789
+ {
790
+ throw new Exception ('Create new item failed ' , MIDAS_INTERNAL_ERROR );
791
+ }
792
+
793
+ return $ item ->toArray ();
794
+ }
795
+ }
796
+
781
797
/**
782
798
* Get an item's information
783
799
* @param token (Optional) Authentication token
@@ -805,7 +821,7 @@ function itemGet($args)
805
821
$ owningFolders = $ item ->getFolders ();
806
822
if (count ($ owningFolders ) > 0 )
807
823
{
808
- $ itemArray ['folder_id ' ] = $ owningFolders [0 ]->parent_id ;
824
+ $ itemArray ['folder_id ' ] = $ owningFolders [0 ]->getKey () ;
809
825
}
810
826
811
827
$ revisionsArray = array ();
@@ -817,8 +833,13 @@ function itemGet($args)
817
833
{
818
834
$ revisions = $ item ->getRevisions ();
819
835
}
836
+
820
837
foreach ($ revisions as $ revision )
821
838
{
839
+ if (!$ revision )
840
+ {
841
+ continue ;
842
+ }
822
843
$ bitstreamArray = array ();
823
844
$ bitstreams = $ revision ->getBitstreams ();
824
845
foreach ($ bitstreams as $ b )
0 commit comments