Changeset 10477
- Timestamp:
- 01/05/11 07:03:56 (2 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
-
MongoDBPlugin/lib/Foswiki/Plugins/MongoDBPlugin.pm (modified) (1 diff)
-
MongoDBPlugin/lib/Foswiki/Plugins/MongoDBPlugin/DB.pm (modified) (1 diff)
-
RestPlugin/data/System/RestPlugin.txt (modified) (1 diff)
-
RestPlugin/lib/Foswiki/Plugins/RestPlugin/MANIFEST (modified) (1 diff)
-
RestPlugin/lib/Foswiki/UI/Query.pm (modified) (8 diffs)
-
RestPlugin/test/unit/RestPlugin/RestPluginCurlTests.pm (modified) (3 diffs)
-
RestPlugin/test/unit/RestPlugin/RestPluginTests.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/MongoDBPlugin/lib/Foswiki/Plugins/MongoDBPlugin.pm
r10471 r10477 248 248 #i don't know why, but this is never triggered, but without it, i get a crash. 249 249 #so, i presume there is a weird case where it happens 250 print STDERR "-B---($web . $topic) $key - ".ref($savedMeta->{$key})."\n";251 print STDERR Dumper($savedMeta->{$key})."\n";252 print STDERR "\n######################################################## BOOOOOOOOM\n";250 #print STDERR "-B---($web . $topic) $key - ".ref($savedMeta->{$key})."\n"; 251 #print STDERR Dumper($savedMeta->{$key})."\n"; 252 #print STDERR "\n######################################################## BOOOOOOOOM\n"; 253 253 next; 254 254 } -
trunk/MongoDBPlugin/lib/Foswiki/Plugins/MongoDBPlugin/DB.pm
r10471 r10477 30 30 #I wish 31 31 #use constant MONITOR => $Foswiki::cfg{MONITOR}{'Foswiki::Plugins::MongoDBPlugin'} || 0; 32 use constant MONITOR => 1;32 use constant MONITOR => 0; 33 33 34 34 sub new { -
trunk/RestPlugin/data/System/RestPlugin.txt
r10345 r10477 70 70 Creates a new element in a container. So if you want to create a new topic, the URI is that of the web you want to place it, and the payload will contain a value that has a =_topic= 71 71 ---++++ PATCH 72 modifies an existing item, changing only the elements sent in the payload - thus allowing you to modify just the topic text, the value of one 'named' FIELD, or one Attachement's data. 72 73 ---++++ DELETE 73 74 -
trunk/RestPlugin/lib/Foswiki/Plugins/RestPlugin/MANIFEST
r10227 r10477 11 11 pub/System/RestPlugin/Edit-chalk-10g.png 12 12 pub/System/RestPlugin/formfield_example.png 13 pub/System/RestPlugin/Image :Edit-chalk-10bo.png13 pub/System/RestPlugin/Image-Edit-chalk-10bo.png 14 14 pub/System/RestPlugin/Wiki-text-icon.png 15 15 -
trunk/RestPlugin/lib/Foswiki/UI/Query.pm
r10308 r10477 420 420 mapMimeType($requestContentType) ); 421 421 if ( $elementAlias eq 'topic' ) { 422 copyFrom( $topicObject, $value ); #copy meta..422 mergeFrom( $topicObject, $value ); #copy meta.. 423 423 424 424 #print STDERR ")))))".Foswiki::Serialise::serialise( $session, $value, 'perl' )."(((((\n" if MONITOR_ALL; … … 426 426 if ( defined( $value->{_text} ) ); 427 427 $topicObject->save(); 428 $res->pushHeader( 'Location', 429 getResourceURI( $topicObject, $elementAlias) ); 428 430 $result = Foswiki::Serialise::convertMeta($topicObject); 429 431 } … … 431 433 if ( ( not defined($attachment) ) or ( $attachment eq '' ) ) { 432 434 my $hash = { "FILEATTACHMENT" => $value }; 433 copyFrom( $topicObject, $hash ); #copy meta..435 mergeFrom( $topicObject, $hash ); #copy meta.. 434 436 435 437 #print STDERR ")))))".Foswiki::Serialise::serialise( $session, $value, 'perl' )."(((((\n" if MONITOR_ALL; … … 469 471 data => $topicObject 470 472 ); 471 } 472 $res->pushHeader( 'Location', 473 getResourceURI( $result, $elementAlias) ); 473 $res->pushHeader( 'Location', 474 getResourceURI( $result, $elementAlias) ); 475 $result = Foswiki::Serialise::convertMeta($result); ###TODO: Extractme 476 } 477 474 478 $res->status(201); 475 479 } … … 723 727 my $elementAlias = shift; #TODO: derive this from the meta.. 724 728 729 #ASSERT($meta->isa('Foswiki::Meta')) if DEBUG; 730 725 731 print STDERR "getResourceURI - getScriptUrl(" 726 732 . $meta->web . ", " … … 799 805 ######################## 800 806 #yes, this is a simplified copy from Foswiki::Meta::copyFrom so we can copy from a random hashref 801 #TODO: this is not a PUT/POST, its a PATCH.802 807 sub copyFrom { 803 808 my ( $meta, $other, $type, $filter ) = @_; 804 805 #ASSERT( $meta->{_web} && $meta->{_topic}, '$this is not a topic object' )806 # if DEBUG;807 #ASSERT( $other->isa('Foswiki::Meta') && $other->{_web} && $other->{_topic},808 # 'other is not a topic object' )809 # if DEBUG;810 809 811 810 if ($type) { … … 817 816 { 818 817 my %datum = %$item; 819 push( @data, \%datum ); 820 } 821 } 822 print STDERR "--------------actually modifying $type..\n" 823 if MONITOR_ALL; 824 $meta->putAll( $type, @data ); 818 push(@data, \%datum) 819 } 820 } 821 $meta->putAll($type, @data) 825 822 } 826 823 else { … … 828 825 unless ( $k =~ /^_/ ) { 829 826 copyFrom( $meta, $other, $k ); 827 } 828 } 829 } 830 } 831 #this is the PATCH version of copyfrom 832 sub mergeFrom { 833 my ( $meta, $other, $type, $filter ) = @_; 834 835 if ($type) { 836 return if $type =~ /^_/; 837 foreach my $item ( @{ $other->{$type} } ) { 838 if ( !$filter 839 || ( $item->{name} && $item->{name} =~ /$filter/ ) ) 840 { 841 my $old = $meta->get($type, $item->{name}); 842 my %hash = (); 843 #Merge old element with new data - that way keys that are not in the payload still get used. 844 %hash = %$old if (defined($old)); 845 @hash{keys(%$item)} = values(%$item); 846 $meta->putKeyed($type, \%hash) 847 } 848 } 849 } 850 else { 851 foreach my $k ( keys %$other ) { 852 unless ( $k =~ /^_/ ) { 853 mergeFrom( $meta, $other, $k ); 830 854 } 831 855 } -
trunk/RestPlugin/test/unit/RestPlugin/RestPluginCurlTests.pm
r10241 r10477 10 10 use JSON (); 11 11 use File::Path qw(mkpath); 12 13 use constant MONITOR => 0; 12 14 13 15 sub new { … … 107 109 . $url; 108 110 109 print STDERR "\n\n----\n$curlCommand\n----\n" ;111 print STDERR "\n\n----\n$curlCommand\n----\n" if MONITOR; 110 112 my $result = `$curlCommand 2>&1` 111 113 ; # grrrr, aparently they output the header info into stderr … … 200 202 $replytext =~ s/"date":(.*?),/"date":"EXTRACTED_FOR_TESTING",/g; 201 203 202 print STDERR "\njson expected:\n" ;203 print STDERR $expectedReplyPayload ;204 print STDERR "\njson got:\n" ;205 print STDERR $replytext ;204 print STDERR "\njson expected:\n" if MONITOR; 205 print STDERR $expectedReplyPayload if MONITOR; 206 print STDERR "\njson got:\n" if MONITOR; 207 print STDERR $replytext if MONITOR; 206 208 my $replyObj = 207 209 Foswiki::Serialise::deserialise( $this->{session}, $replytext, -
trunk/RestPlugin/test/unit/RestPlugin/RestPluginTests.pm
r10285 r10477 13 13 14 14 # Set to 1 for debug 15 use constant MONITOR_ALL => 0;15 use constant MONITOR_ALL => 1; 16 16 17 17 my $UI_FN; … … 273 273 { 274 274 275 #print STDERR "----- ".$fromJSON->{FIELD}[0]->{name}.": ".$fromJSON->{FIELD}[0]->{value}."\n" if MONITOR_ALL;275 print STDERR "----- ".$fromJSON->{FIELD}[0]->{name}.": ".$fromJSON->{FIELD}[0]->{value}."\n" if MONITOR_ALL; 276 276 my $partialItem = JSON::from_json( $replytext, { allow_nonref => 1 } ); 277 277 $partialItem->{FIELD}[0]->{value} = 'Something new, something blue'; … … 299 299 'GET', {} ); 300 300 301 #print STDERR "-------reply-----\n".$replytext."\n------------\n" if MONITOR_ALL;301 print STDERR "-------reply-----\n".$replytext."\n------------\n" if MONITOR_ALL; 302 302 303 303 my $NEWfromJSON = JSON::from_json( $replytext, { allow_nonref => 1 } ); … … 308 308 'Something new, something blue' 309 309 ); 310 $this->assert_equals( 311 $NEWfromJSON->{FIELD}[0]->{name}, 312 'Summary' 313 ); 314 $this->assert_equals( 315 $NEWfromJSON->{FIELD}[0]->{title}, 316 'Summary' 317 ); 310 318 311 319 $this->assert_str_not_equals( $NEWfromJSON->{_raw_text}, … … 321 329 } 322 330 } 331 332 #modify partial item updates 333 sub testPATCH_OneArrayElementByName_Topic { 334 my $this = shift; 335 336 #GET the topic 337 my ( $meta, $text ) = 338 Foswiki::Func::readTopic( $this->{test_web}, "Improvement2" ); 339 my ( $replytext, $hdr ) = $this->call_UI_query( 340 '/' . $this->{test_web} . '/Improvement2/topic.json', 341 'GET', {} ); 342 my $fromJSON = JSON::from_json( $replytext, { allow_nonref => 1 } ); 343 $this->assert_deep_equals( $fromJSON, 344 Foswiki::Serialise::convertMeta($meta) ); 345 346 #send PATCH with only the one 347 { 348 349 print STDERR "----- ".$fromJSON->{FIELD}[0]->{name}.": ".$fromJSON->{FIELD}[0]->{value}."\n" if MONITOR_ALL; 350 my $partialItem = {"FIELD" => [{"name"=>"Summary", "value" => 'Something new, something blue'}]}; 351 my $sendJSON = JSON::to_json($partialItem); 352 353 print STDERR "------------\n".$sendJSON."\n------------\n" if MONITOR_ALL; 354 355 ( $replytext, $hdr ) = $this->call_UI_query( 356 '/' . $this->{test_web} . '/Improvement2/topic.json', 357 'PATCH', { 'POSTDATA' => $sendJSON } ); 358 359 #my $replyHash = JSON::from_json( $replytext, { allow_nonref => 1 } ); 360 } 361 362 #then make sure it saved using GET.. 363 { 364 my ( $meta, $text ) = 365 Foswiki::Func::readTopic( $this->{test_web}, "Improvement2" ); 366 my ( $replytext, $hdr ) = $this->call_UI_query( 367 '/' . $this->{test_web} . '/Improvement2/topic.json', 368 'GET', {} ); 369 370 print STDERR "-------reply-----\n".$replytext."\n------------\n" if MONITOR_ALL; 371 372 my $NEWfromJSON = JSON::from_json( $replytext, { allow_nonref => 1 } ); 373 $this->assert_deep_equals( $NEWfromJSON, 374 Foswiki::Serialise::convertMeta($meta) ); 375 $this->assert_equals( 376 $NEWfromJSON->{FIELD}[0]->{value}, 377 'Something new, something blue' 378 ); 379 380 $this->assert_str_not_equals( $NEWfromJSON->{_raw_text}, 381 $fromJSON->{_raw_text} ); 382 $this->assert_equals( $NEWfromJSON->{_text}, $fromJSON->{_text} ); 383 384 #make sure the other FIELD is still as it was before. 385 $this->assert_equals( $NEWfromJSON->{FIELD}[1]->{value}, 386 $fromJSON->{FIELD}[1]->{value} ); 387 $this->assert_equals( 'work it out yourself!', 388 $NEWfromJSON->{FIELD}[1]->{value} ); 389 $this->assert_equals( 'Details', $NEWfromJSON->{FIELD}[1]->{name} ); 390 } 391 } 392 393 323 394 324 395 #modify partial item updates
Note: See TracChangeset
for help on using the changeset viewer.
