[Rt-commit] [svn] r871 - in RTx-Atom: . html/Atom/0.3 html/Atom/0.3/Elements html/Atom/0.3/Get html/Atom/0.3/Set html/Atom/0.3/Update

autrijus at pallas.eruditorum.org autrijus at pallas.eruditorum.org
Tue May 11 16:42:33 EDT 2004


Author: autrijus
Date: Tue May 11 16:42:33 2004
New Revision: 871

Added:
   RTx-Atom/html/Atom/0.3/Elements/SetProperty
Modified:
   RTx-Atom/   (props changed)
   RTx-Atom/html/Atom/0.3/Get/Property
   RTx-Atom/html/Atom/0.3/Set/Property
   RTx-Atom/html/Atom/0.3/Update/index
   RTx-Atom/html/Atom/0.3/dhandler
Log:
 ----------------------------------------------------------------------
 r4784 at not:  autrijus | 2004-05-11T20:42:14.253360Z
 
 * "Set" now works.
 * Properly update verbs according to resource type.
 ----------------------------------------------------------------------


Added: RTx-Atom/html/Atom/0.3/Elements/SetProperty
==============================================================================
--- (empty file)
+++ RTx-Atom/html/Atom/0.3/Elements/SetProperty	Tue May 11 16:42:33 2004
@@ -0,0 +1,19 @@
+%# Sets property of a content.
+<%INIT>
+$Object->_ClassAccessible->{$Property}{read} or return(404, undef);
+$Object->_ClassAccessible->{$Property}{write} or return(403, undef);
+
+my $method = "Set$Property";
+my ($rv, $new_value) = ($Object->$method( $Value ))[0, -1];
+
+return( 
+    ($rv ? 200 : 400),
+    (defined($new_value) ? $new_value : ''),
+);
+
+</%INIT>
+<%ARGS>
+$Object
+$Property
+$Value
+</%ARGS>

Modified: RTx-Atom/html/Atom/0.3/Get/Property
==============================================================================
--- RTx-Atom/html/Atom/0.3/Get/Property	(original)
+++ RTx-Atom/html/Atom/0.3/Get/Property	Tue May 11 16:42:33 2004
@@ -1,6 +1,10 @@
 %# [GET EditURI]
 %# Retrieve a representation of an property.
 <%INIT>
+
+# Can't allow cache to happen at all
+eval { $Object->_expire( $Object->_gen_primary_cache_key()) };
+
 $Object->_ClassAccessible->{$Property}{read}
     or return $m->comp($ShowError, Status => 404);
 

Modified: RTx-Atom/html/Atom/0.3/Set/Property
==============================================================================
--- RTx-Atom/html/Atom/0.3/Set/Property	(original)
+++ RTx-Atom/html/Atom/0.3/Set/Property	Tue May 11 16:42:33 2004
@@ -1,16 +1,18 @@
 %# [PUT EditURI]
 %# Modifies a property with the serialization in the request body.
 <%INIT>
-$Object->_ClassAccessible->{$Property}{read}
-    or return $m->comp($ShowError, Status => 404);
-$Object->_ClassAccessible->{$Property}{write}
-    or return $m->comp($ShowError, Status => 403);
+my ($status, $msg) = $m->comp(
+    '../Elements/SetProperty',
+    Object => $Object, 
+    Property => $Property,
+    Value => $r->content,
+);
+
+return $m->comp($ShowError, Status => 403) unless defined $msg;
 
 $r->content_type('text/plain');
 
-my $method = "Set$Property";
-my ($status, $msg) = ($Object->$method( $r->content ))[0, -1];
-if ($status) {
+if ($status == 200) {
     print $Object->$Property;
 }
 else {

Modified: RTx-Atom/html/Atom/0.3/Update/index
==============================================================================
--- RTx-Atom/html/Atom/0.3/Update/index	(original)
+++ RTx-Atom/html/Atom/0.3/Update/index	Tue May 11 16:42:33 2004
@@ -1,5 +1,50 @@
 %# [POST PostURI] (Object)
-%# Updates an object, using an 'adverb' acceptable to that object's class.
-%# 200: Success.  Body is the object, serialized as an AtomEntry.
+%# Updates an object.
+%# 207: Updated.  Body is the status code and messages for each update.
 %# 400: Request failed.  Body is error message in text/plain.
 %# 404: The specific object does not exist, or does not support this adverb.
+<?xml version="1.0" encoding="utf-8"?>
+<?xml-stylesheet type="text/css" href="<% $BaseURI %>/NoAuth/feed.css"?>
+<entry xmlns="http://purl.org/atom/ns#" xmlns:html="http://www.w3.org/1999/xhtml">
+  <content type="multipart/parallel" mode="xml">
+    <body>
+% foreach my $result (@results) {
+      <response status="<% $result->[0] %>"><% $result->[1] %></response>
+% }
+    </body>
+  </content>
+</entry>
+<%INIT>
+my %args = $m->request_args;
+my $type = delete $args{type};
+
+# XXX - finish "Comment" and "Correspond" here
+die "$type not handled" if $type;
+
+my @results;
+foreach my $key (sort grep /^[A-Z]/, keys %args) {
+    my ($property, $method) = split(/-/, $key, 2);
+    $method ||= 'Set';
+
+    my $value = $args{$key};
+    push @results, [$m->comp(
+	"../Elements/\u\L$method\EProperty",
+	Object => $Object, 
+	Property => $property,
+	Value => $_,
+    )] for (UNIVERSAL::isa($value, 'ARRAY') ? @$value : $value);
+}
+
+$r->status(207);
+</%INIT>
+<%ARGS>
+$ShowLink
+$ShowEntry
+$BaseURI
+$Path
+$CollectionClass
+$X
+
+$Object
+$Resource
+</%ARGS>

Modified: RTx-Atom/html/Atom/0.3/dhandler
==============================================================================
--- RTx-Atom/html/Atom/0.3/dhandler	(original)
+++ RTx-Atom/html/Atom/0.3/dhandler	Tue May 11 16:42:33 2004
@@ -197,15 +197,6 @@
     Allow => join(', ', sort keys %Methods)
 );
 
-if ((@parts % 2) == 0) {
-    # FeedURI on collection
-    $verb = 'Search' if $verb eq 'Get';
-}
-elsif (0) {
-    # PostURI on object XXX
-    $verb = 'Update' if $verb eq 'Add';
-}
-
 my $map;
 $map = $m->comp('Elements/Introspect', Want => 'TopLevelCollections') if $type;
 
@@ -264,6 +255,15 @@
 $obj->Load($id) or return $m->comp('Elements/Error', Status => 404) if $id;
 my $resource = ($id ? $property ? 'Property' : 'Object' : 'Container');
 
+if ($resource eq 'Container') {
+    # FeedURI on collection
+    $verb = 'Search' if $verb eq 'Get';
+}
+elsif ($resource eq 'Object') {
+    # PostURI on object
+    $verb = 'Update' if $verb eq 'Add';
+}
+
 $m->comp(
     "$verb/index", %ARGS,
     Type => $type,


More information about the Rt-commit mailing list