@@ -42,6 +42,9 @@ public DomainClass(Class c, boolean readOnly){
4242 public boolean isReadOnly (){
4343 return readOnly ;
4444 }
45+ public String toString (){
46+ return c .toString () + (readOnly ? " (readonly)" : "" );
47+ }
4548 }
4649
4750
@@ -193,11 +196,13 @@ else if (params.length==2){
193196 //standard CRUD operation.
194197 if (method .startsWith ("get" )){
195198
199+ //Find and return model
196200 String className = method .substring (3 );
197201 DomainClass c = getClass (className );
198202 if (c !=null ) return get (c .c , request , database );
199203
200204
205+ //Special case for plural-form of a model. Return list of models.
201206 if (className .endsWith ("ies" )){ //Categories == Category
202207 c = getClass (className .substring (0 , className .length ()-3 ) + "y" );
203208 }
@@ -211,16 +216,39 @@ else if (className.endsWith("s")){ //Sources == Source
211216
212217 }
213218 else if (method .startsWith ("save" )){
219+
220+ //Find model and save
214221 String className = method .substring (4 );
215222 DomainClass c = getClass (className );
216223 if (c !=null ){
217224 if (c .isReadOnly ()){
218- return new ServiceResponse ( 403 , "Write access forbidden." );
225+ return get ( c . c , request , database );
219226 }
220227 else {
221228 return save (c .c , request , database );
222229 }
223230 }
231+
232+
233+ //Special case for plural-form of a model
234+ if (className .endsWith ("ies" )){ //Categories == Category
235+ c = getClass (className .substring (0 , className .length ()-3 ) + "y" );
236+ }
237+ else if (className .endsWith ("ses" )){ //Classes == Class
238+ c = getClass (className .substring (0 , className .length ()-2 ));
239+ }
240+ else if (className .endsWith ("s" )){ //Sources == Source
241+ c = getClass (className .substring (0 , className .length ()-1 ));
242+ }
243+ if (c !=null ){
244+ if (c .isReadOnly ()){
245+ return list (c .c , request , database );
246+ }
247+ else {
248+ return new ServiceResponse (501 , "Not Implemented." );
249+ }
250+ }
251+
224252 }
225253 else if (method .startsWith ("delete" )){
226254 String className = method .substring (6 );
0 commit comments