[Bps-public-commit] r15341 - in sd/branches/debbugs: . lib lib/App/SD/Replica

spang at bestpractical.com spang at bestpractical.com
Thu Aug 21 14:26:01 EDT 2008


Author: spang
Date: Thu Aug 21 14:26:00 2008
New Revision: 15341

Added:
   sd/branches/debbugs/lib/
      - copied from r15340, /sd/branches/debbugs/lib/
   sd/branches/debbugs/lib/App/SD/Replica/debbugs/
   sd/branches/debbugs/lib/App/SD/Replica/debbugs.pm
   sd/branches/debbugs/lib/App/SD/Replica/debbugs/PullEncoder.pm
   sd/branches/debbugs/lib/App/SD/Replica/debbugs/PushEncoder.pm
Modified:
   sd/branches/debbugs/   (props changed)

Log:
 r48814 at loki:  spang | 2008-08-21 19:25:44 +0100
 skeleton start for debbugs foreign replica


Added: sd/branches/debbugs/lib/App/SD/Replica/debbugs.pm
==============================================================================
--- (empty file)
+++ sd/branches/debbugs/lib/App/SD/Replica/debbugs.pm	Thu Aug 21 14:26:00 2008
@@ -0,0 +1,72 @@
+package App::SD::Replica::debbugs;
+use Moose;
+extends qw/Prophet::ForeignReplica/;
+
+use Params::Validate qw(:all);
+use Memoize;
+
+use Prophet::ChangeSet;
+
+use constant scheme => 'debbugs';
+
+# FIXME: what should this actually be?
+has debbugs => ( isa => 'Net::Debbugs', is => 'rw');
+has debbugs_url => ( isa => 'Str', is => 'rw');
+has debbugs_query => ( isa => 'Str', is => 'rw');
+
+sub setup {
+    my $self = shift;
+
+    # require any specific libs needed by this foreign replica
+
+    # parse the given url
+    # my ($foo, $bar, $baz) = $self->{url} =~ m/regex-here/
+
+    # ...
+}
+
+sub prophet_has_seen_transaction {
+    goto \&App::SD::Replica::RT::prophet_has_seen_transaction;
+}
+
+sub record_pushed_transaction {
+    goto \&App::SD::Replica::RT::record_pushed_transaction;
+}
+
+sub record_pushed_transactions {}
+
+sub remote_id_for_uuid {
+    my ( $self, $uuid_for_remote_id ) = @_;
+
+
+    # XXX: should not access CLI handle
+    my $ticket = Prophet::Record->new(
+        handle => Prophet::CLI->new->app_handle->handle,
+        type   => 'ticket'
+    );
+    $ticket->load( uuid => $uuid_for_remote_id );
+    my $id =  $ticket->prop( $self->uuid . '-id' );
+    return $id;
+}
+
+sub uuid_for_remote_id {
+    my ( $self, $id ) = @_;
+    return $self->_lookup_uuid_for_remote_id($id) ||
+        $self->uuid_for_url( $self->rt_url . "/ticket/$id" );
+}
+
+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;
+no Moose;
+1;

Added: sd/branches/debbugs/lib/App/SD/Replica/debbugs/PullEncoder.pm
==============================================================================
--- (empty file)
+++ sd/branches/debbugs/lib/App/SD/Replica/debbugs/PullEncoder.pm	Thu Aug 21 14:26:00 2008
@@ -0,0 +1,104 @@
+package App::SD::Replica::debbugs::PullEncoder;
+use Moose;
+
+use Params::Validate qw(:all);
+use Memoize;
+
+has sync_source => (
+    isa => 'App::SD::Replica::Debbugs',
+    is => 'rw',
+);
+
+our $DEBUG = $Prophet::Handle::DEBUG;
+
+sub run {
+    my $self = shift;
+    my %args = validate( @_, {
+            # mandatory args go here
+            example => 1,
+        }
+    );
+
+    # TODO: code goes here
+}
+
+our %PROP_MAP = (
+    remote_prop             => 'sd_prop',
+    # ...
+}
+
+=head2 translate_prop_names L<Prophet::ChangeSet>
+
+=cut
+
+sub translate_prop_names {
+    my $self      = shift;
+    my $changeset = shift;
+
+    # ...
+
+    return $changeset;
+}
+
+=head2 resolve_user_id_to_email ID
+
+This is only implemented in Hiveminder::PullEncoder; in RT::PullEncoder
+it's resolve_user_id_to. What's this for, actually?
+
+=cut
+
+sub resolve_user_id_to_email {
+    my $self = shift;
+    my $id   = shift;
+    return undef unless ($id);
+
+    # ...
+
+    # returns email address mapping to user id
+}
+
+memoize 'resolve_user_id_to_email';
+
+=head2 warp_list_to_old_value CURRENT_VALUE, ADD, DEL
+
+Both RT and Hiveminder use this, but what's it actually for?
+
+=cut
+
+sub warp_list_to_old_value {
+    my $self         = shift;
+    my $current_value = shift ||'';
+    my $add          = shift;
+    my $del          = shift;
+
+    my @new = grep { defined } split( /\s*,\s*/, $current_value );
+    my @old = (grep { defined $_ && $_ ne $add } @new, $del ) || ();
+    return join( ", ", @old );
+}
+
+=head2 find_matching_tickets QUERY
+
+=cut
+
+sub find_matching_tickets {
+    my $self = shift;
+    my ($query) = validate_pos(@_, 1);
+    return $self->sync_source->rt->search( type => 'ticket', query => $query );
+}
+
+=head2 find_matching_transactions TASK, START
+
+=cut
+
+sub find_matching_transactions {
+    my $self = shift;
+    my %args = validate( @_, { task => 1, starting_transaction => 1 } );
+
+    # ...
+
+    return \@matched;
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+1;

Added: sd/branches/debbugs/lib/App/SD/Replica/debbugs/PushEncoder.pm
==============================================================================
--- (empty file)
+++ sd/branches/debbugs/lib/App/SD/Replica/debbugs/PushEncoder.pm	Thu Aug 21 14:26:00 2008
@@ -0,0 +1,131 @@
+package App::SD::Replica::debbugs::PushEncoder;
+use Moose;
+
+use Params::Validate;
+use Path::Class;
+
+has sync_source => 
+    ( isa => 'App::SD::Replica::Debbugs',
+      is => 'rw');
+
+=head2 integrate_change L<Prophet::Change>, L<Prophet::ChangeSet>
+
+Should be able to leave as-is, theoretically.
+
+=cut
+
+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;
+}
+
+=head2 integrate_ticket_create L<Prophet::Change>, L<Prophet::ChangeSet>
+
+=cut
+
+sub integrate_ticket_create {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+    # ...
+
+    # returns the id of the new ticket
+    # XXX is this uuid or what?
+}
+
+=head2 integrate_comment L<Prophet::Change>, L<Prophet::ChangeSet>
+
+=cut
+
+sub integrate_comment {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+    # ...
+
+    # returns the remote id of the ticket for this change
+}
+
+=head2 integrate_attachment L<Prophet::Change>, L<Prophet::ChangeSet>
+
+=cut
+
+sub integrate_attachment {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+    # ...
+
+    # returns the remote id of the ticket for this change
+}
+
+=head2 integrate_ticket_update L<Prophet::Change>, L<Prophet::ChangeSet>
+
+=cut
+
+sub integrate_ticket_update {
+    my $self = shift;
+    my ( $change, $changeset ) = validate_pos(
+        @_,
+        { isa => 'Prophet::Change' },
+        { isa => 'Prophet::ChangeSet' }
+    );
+
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;



More information about the Bps-public-commit mailing list