[Bps-public-commit] r13927 - in sd/trunk/lib/App/SD/Replica: Hiveminder

jesse at bestpractical.com jesse at bestpractical.com
Wed Jul 9 15:53:57 EDT 2008


Author: jesse
Date: Wed Jul  9 15:53:56 2008
New Revision: 13927

Added:
   sd/trunk/lib/App/SD/Replica/Hiveminder/PushEncoder.pm
Modified:
   sd/trunk/lib/App/SD/Replica/Hiveminder.pm
   sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm

Log:
* Hiveminder PushEncoder refactoring

Modified: sd/trunk/lib/App/SD/Replica/Hiveminder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/Hiveminder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/Hiveminder.pm	Wed Jul  9 15:53:56 2008
@@ -203,14 +203,21 @@
     return \%attr;
 }
 
-require App::SD::Replica::RT;
-
 sub _integrate_change {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
 
-    goto \&App::SD::Replica::RT::_integrate_change;
-
+    require App::SD::Replica::Hiveminder::PushEncoder;
+    my $recoder = App::SD::Replica::Hiveminder::PushEncoder->new( { sync_source => $self } );
+    $recoder->integrate_change($change,$changeset);
 }
 
+
+
 {
 
     # XXXXXXXX

Modified: sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm
==============================================================================
--- sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm	(original)
+++ sd/trunk/lib/App/SD/Replica/Hiveminder/PullEncoder.pm	Wed Jul  9 15:53:56 2008
@@ -1,8 +1,6 @@
 package App::SD::Replica::Hiveminder::PullEncoder;
 use Moose;
 use Params::Validate qw(:all);
-use UNIVERSAL::require;
-
 use Memoize;
 
 has sync_source => (

Added: sd/trunk/lib/App/SD/Replica/Hiveminder/PushEncoder.pm
==============================================================================
--- (empty file)
+++ sd/trunk/lib/App/SD/Replica/Hiveminder/PushEncoder.pm	Wed Jul  9 15:53:56 2008
@@ -0,0 +1,110 @@
+package App::SD::Replica::Hiveminder::PushEncoder;
+use Moose; 
+use Params::Validate;
+use Path::Class;
+has sync_source => 
+    ( isa => 'App::SD::Replica::Hiveminder',
+      is => 'rw');
+
+
+sub integrate_change {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+    my $id;
+    eval {
+        if (    $change->record_type eq 'ticket'
+            and $change->change_type eq 'add_file' 
+    )
+        {
+            $id = $self->integrate_ticket_create( $change, $changeset );
+            $self->sync_source->record_pushed_ticket(
+                uuid      => $change->record_uuid,
+                remote_id => $id
+            );
+
+        } elsif ( $change->record_type eq 'attachment'
+            and $change->change_type eq 'add_file' 
+        
+        ) {
+            $id = $self->integrate_attachment( $change, $changeset );
+        } elsif ( $change->record_type eq 'comment' 
+            and $change->change_type eq 'add_file' 
+        ) {
+            $id = $self->integrate_comment( $change, $changeset );
+        } elsif ( $change->record_type eq 'ticket' ) {
+            $id = $self->integrate_ticket_update( $change, $changeset );
+
+        } else {
+            return undef;
+        }
+
+        $self->sync_source->record_pushed_transactions(
+            ticket    => $id,
+            changeset => $changeset
+        );
+
+    };
+    warn $@ if $@;
+    return $id;
+}
+
+
+
+sub integrate_ticket_create {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos( @_, { isa => 'Prophet::Change' }, { isa => 'Prophet::ChangeSet' } );
+
+    # Build up a ticket object out of all the record's attributes
+
+    my $task = $self->sync_source->hm->create(
+        'Task',
+        owner           => 'me',
+        group           => 0,
+        requestor       => 'me',
+        complete        => 0,
+        will_complete   => 1,
+        repeat_stacking => 0,
+        %{ $self->_recode_props_for_integrate($change) }
+
+    );
+
+    my $txns = $self->sync_source->hm->search( 'TaskTransaction', task_id => $task->{content}->{id} );
+
+    # lalala
+    $self->sync_source->record_pushed_transaction( transaction => $txns->[0]->{id}, changeset => $changeset );
+    return $task->{content}->{id};
+
+    #    return $ticket->id;
+
+}
+
+sub integrate_comment {
+    warn "comment not yet";
+}
+
+sub integrate_ticket_update {
+    warn "update not yet";
+}
+
+sub _recode_props_for_integrate {
+    my $self = shift;
+    my ($change) = validate_pos( @_, { isa => 'Prophet::Change' } );
+
+    my %props = map { $_->name => $_->new_value } $change->prop_changes;
+    my %attr;
+
+    for my $key ( keys %props ) {
+        # XXX: fill me in
+        #        next unless ( $key =~ /^(summary|queue|status|owner|custom)/ );
+        $attr{$key} = $props{$key};
+    }
+    return \%attr;
+}
+
+
+1;
+



More information about the Bps-public-commit mailing list