[Bps-public-commit] r16305 - in sd/trunk/lib/App/SD: . Replica/hm

ruz at bestpractical.com ruz at bestpractical.com
Wed Oct 15 19:45:28 EDT 2008


Author: ruz
Date: Wed Oct 15 19:45:28 2008
New Revision: 16305

Modified:
   sd/trunk/lib/App/SD/ForeignReplica.pm
   sd/trunk/lib/App/SD/Replica/hm.pm
   sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm
   sd/trunk/lib/App/SD/Replica/rt.pm

Log:
* push comments into HM
* move record_pushed_ticket into lib/App/SD/ForeignReplica.pm

Modified: sd/trunk/lib/App/SD/ForeignReplica.pm
==============================================================================
--- sd/trunk/lib/App/SD/ForeignReplica.pm	(original)
+++ sd/trunk/lib/App/SD/ForeignReplica.pm	Wed Oct 15 19:45:28 2008
@@ -91,7 +91,6 @@
 sub remote_id_for_uuid {
     my ( $self, $uuid_or_luid ) = @_;
 
-
     # XXX: should not access CLI handle
     my $ticket = Prophet::Record->new(
         handle => Prophet::CLI->new->app_handle->handle,
@@ -99,8 +98,9 @@
     );
     $ticket->load( $uuid_or_luid =~ /^\d+$/? 'luid': 'uuid', $uuid_or_luid );
     my $prop = $self->uuid . '-id';
-    return scalar $ticket->prop( $prop )
-        or die "ticket #$uuid_or_luid has no property '$prop'";
+    my $id = $ticket->prop( $prop )
+        or warn "ticket #$uuid_or_luid has no property '$prop'";
+    return $id;
 }
 
 sub _set_remote_id_for_uuid {
@@ -117,9 +117,23 @@
         handle => Prophet::CLI->new->app_handle->handle,
         type   => 'ticket'
     );
-    $ticket->load( uuid => $args{'uuid'});
-    $ticket->set_props( props => {  $self->uuid.'-id' => $args{'remote_id'}});
+    $ticket->load( uuid => $args{'uuid'} );
+    $ticket->set_props( props => { $self->uuid.'-id' => $args{'remote_id'} } );
+
+}
 
+
+# XXX TODO, rename this
+sub record_pushed_ticket {
+    my $self = shift;
+    my %args = validate(
+        @_,
+        {   uuid      => 1,
+            remote_id => 1
+        }
+    );
+    $self->_set_uuid_for_remote_id(%args);
+    $self->_set_remote_id_for_uuid(%args);
 }
 
 __PACKAGE__->meta->make_immutable;

Modified: sd/trunk/lib/App/SD/Replica/hm.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm.pm	Wed Oct 15 19:45:28 2008
@@ -155,19 +155,6 @@
     return "/task/".$id;
 }
 
-
-# XXX TODO, can this get generalized out (take the rt one to ForeignReplica.pm?
-sub record_pushed_ticket {
-    my $self = shift;
-    my %args = validate(
-        @_,
-        {   uuid      => 1,
-            remote_id => 1
-        }
-    );
-    $self->_set_uuid_for_remote_id(%args);
-}
-
 __PACKAGE__->meta->make_immutable;
 no Moose;
 1;

Modified: sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/hm/PushEncoder.pm	Wed Oct 15 19:45:28 2008
@@ -76,29 +76,25 @@
     # lalala
     $self->sync_source->record_pushed_transaction( transaction => $txns->[0]->{id}, changeset => $changeset );
     return $task->{content}->{id};
-
-    #    return $ticket->id;
-
 }
 
 sub integrate_comment {
     my $self = shift;
     my ($change, $changeset) = validate_pos( @_, { isa => 'Prophet::Change' }, {isa => 'Prophet::ChangeSet'} );
-    use Data::Dumper;
-
-    print STDERR Dumper [$change, $changeset];
 
     my %props = map { $_->name => $_->new_value } $change->prop_changes;
 
-    # XXX, TODO, FIXME: $props{'ticket'} is a luid. is it ok?
     my $ticket_id = $self->sync_source->remote_id_for_uuid( $props{'ticket'} )
-        or die "Couldn't remote id of sd ticket $props{'ticket'}";
-    my $hm = $self->sync_source->hm;
-    use Data::Dumper;
-    print STDERR Dumper [ $hm->act( 'CreateTaskEmail',
+        or die "Couldn't get remote id of SD ticket";
+
+    my $email = $self->comment_as_email( \%props );
+    my $status = $self->sync_source->hm->act( 'CreateTaskEmail',
         task_id => $ticket_id,
-        message => $props{'content'},
-    ) ];
+        message => $email->as_string,
+    );
+    return $status->{'content'}{'id'} if $status->{'success'};
+
+    die "Couldn't integrate comment: ". $status->{'error'};
 }
 
 sub integrate_ticket_update {
@@ -130,6 +126,23 @@
     return { %$attr, %source_props };
 }
 
+sub comment_as_email {
+    my $self = shift;
+    my $props = shift;
+
+    require Email::Simple;
+    require Email::Simple::Creator;
+
+    my $res = Email::Simple->create(
+        header => [
+            From => $props->{'creator'},
+            Date => $props->{'created'},
+        ],
+        body => $props->{'content'},
+    );
+    return $res;
+}
+
 sub _recode_props_for_integrate {
     my $self = shift;
     my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );

Modified: sd/trunk/lib/App/SD/Replica/rt.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/rt.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/rt.pm	Wed Oct 15 19:45:28 2008
@@ -74,17 +74,6 @@
         );
     }
 }
-sub record_pushed_ticket {
-    my $self = shift;
-    my %args = validate(
-        @_,
-        {   uuid      => 1,
-            remote_id => 1
-        }
-    );
-    $self->_set_uuid_for_remote_id(%args);
-    $self->_set_remote_id_for_uuid(%args);
-}
 
 sub _integrate_change {
     my $self = shift;



More information about the Bps-public-commit mailing list