[Bps-public-commit] r11556 - in SVN-PropDB: . lib/Prophet lib/Prophet/Replica/Hiveminder
jesse at bestpractical.com
jesse at bestpractical.com
Sat Apr 5 20:02:16 EDT 2008
Author: jesse
Date: Sat Apr 5 20:02:06 2008
New Revision: 11556
Modified:
SVN-PropDB/ (props changed)
SVN-PropDB/lib/Prophet/Replica.pm
SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm
SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm
Log:
r29271 at 68-246-6-57: jesse | 2008-04-05 13:58:30 -1000
* initial support for pull from hiveminder (no deletes yet)
Modified: SVN-PropDB/lib/Prophet/Replica.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica.pm (original)
+++ SVN-PropDB/lib/Prophet/Replica.pm Sat Apr 5 20:02:06 2008
@@ -51,7 +51,6 @@
# XXX TODO HACK NEED A PROPER WAY TO DETERMINE SYNC SOURCE
if ( $args->{url} =~ /^rt:/ ) {
$class = 'Prophet::Replica::RT';
- }
elsif ($args->{url} =~ /^hiveminder:/ ) {
$class = 'Prophet::Replica::Hiveminder';
} else {
Modified: SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm (original)
+++ SVN-PropDB/lib/Prophet/Replica/Hiveminder.pm Sat Apr 5 20:02:06 2008
@@ -15,7 +15,7 @@
use Prophet::Replica::Hiveminder::PullEncoder;
use App::Cache;
-__PACKAGE__->mk_accessors(qw/m hm_url/);
+__PACKAGE__->mk_accessors(qw/hm_username hm hm_url ressource/);
our $DEBUG = $Prophet::Handle::DEBUG;
@@ -32,7 +32,7 @@
sub setup {
my $self = shift;
- my ( $server, $type, $query ) = $self->{url} =~ m/^hiveminder:(.*?)$/
+ my ( $server) = $self->{url} =~ m/^hm:(.*?)$/
or die "Can't parse hiveminder server spec";
my $uri = URI->new($server);
my ( $username, $password );
@@ -42,7 +42,6 @@
}
$self->hm_url("$uri");
- $self->hm( Jifyt RT::Client::REST->new( server => $server ) );
( $username, $password ) = $self->prompt_for_login( $uri, $username ) unless $password;
@@ -54,6 +53,7 @@
));
+ $self->hm_username($username);
my $cli = Prophet::CLI->new();
$self->state_handle( $cli->get_handle_for_replica( $self, 'state' ) );
}
@@ -70,7 +70,7 @@
sub uuid {
my $self = shift;
- return $self->uuid_for_url( join( '/', $self->hm_url, $self->hm->username ) );
+ return $self->uuid_for_url( join( '/', $self->hm_url, $self->hm_username ) );
}
@@ -93,7 +93,7 @@
my @changesets;
my %tix;
my $recoder = Prophet::Replica::Hiveminder::PullEncoder->new( { sync_source => $self } );
- for my $task ( $self->find_matching_tasks ) {
+ for my $task ( @{$self->find_matching_tasks} ) {
push @changesets, @{ $recoder->run(
task => $task,
transactions => $self->find_matching_transactions( task => $task->{id}, starting_transaction => $first_rev )) };
@@ -123,14 +123,14 @@
# hiveminder taskemail ~= prophet change
sub find_matching_transactions {
my $self = shift;
- my %args = validate( @_, { task => 1, starting_transaction => 1 } );
+ my %args = validate( @_, {task => 1, starting_transaction => 1 } );
- my ($task) = validate_pos( @_, 1 );
- my $txns = $self->hm->search( 'TaskTransaction', task_id => $args{task} );
- foreach my $txn ( @{ $txns || [] } ) {
- next if $txn < $args{'starting_transaction'}; # Skip things we've pushed
+ my $txns = $self->hm->search( 'TaskTransaction', task_id => $args{task} ) || [];
+ foreach my $txn ( @$txns) {
+ next if $txn->{'id'} < $args{'starting_transaction'}; # Skip things we've pushed
- next if $self->prophet_has_seen_transaction($txn);
+ warn $txn->{'id'};
+ next if $self->prophet_has_seen_transaction($txn->{'id'});
$txn->{history_entries} = $self->hm->search( 'TaskHistory', transaction_id => $txn->{'id'} );
$txn->{email_entries} = $self->hm->search( 'TaskEmail', transaction_id => $txn->{'id'} );
}
@@ -138,4 +138,66 @@
}
+
+
+
+
+
+{
+
+
+
+# XXXXXXXX
+# XXXXXXXXX
+# XXX todo code in this block cargo culted from the RT Replica type
+
+
+
+
+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->handle, type => 'ticket' );
+ $ticket->load( uuid => $uuid_for_remote_id );
+ return $ticket->prop( $self->uuid . '-id' );
+}
+
+sub uuid_for_remote_id {
+ my ( $self, $id ) = @_;
+ return $self->_lookup_remote_id($id)|| $self->uuid_for_url( $self->hm_url . "/ticket/$id" );
+}
+
+our $REMOTE_ID_METATYPE = "_remote_id_map";
+
+sub _remote_id_storage {
+ my $self = shift;
+ return $self->state_handle->metadata_storage($REMOTE_ID_METATYPE, 'prophet-uuid');
+}
+
+sub _lookup_remote_id {
+ my $self = shift;
+ my ($id) = validate_pos( @_, 1 );
+
+ return $self->_remote_id_storage->( $self->uuid_for_url( $self->hm_url . "/ticket/$id" ) );
+}
+
+sub _set_remote_id {
+ my $self = shift;
+ my %args = validate( @_,
+ { uuid => 1,
+ remote_id => 1
+ }
+ );
+ return $self->_remote_id_storage->(
+ $self->uuid_for_url( $self->hm_url . "/ticket/" . $args{'remote_id'} ),
+ $args{uuid} );
+}
+
+}
+
+
+
+
+
1;
Modified: SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm (original)
+++ SVN-PropDB/lib/Prophet/Replica/Hiveminder/PullEncoder.pm Sat Apr 5 20:02:06 2008
@@ -16,6 +16,7 @@
my $self = shift;
my %args = validate( @_, { task => 1, transactions => 1 } );
+ warn YAML::Dump(\%args);
warn "Working on " . $args{'task'}->{id};
my @changesets;
@@ -27,106 +28,65 @@
original_sequence_no => $txn->{'id'},
}
);
+ # In Hiveminder, a changeset has only one change
+ my $change = Prophet::Change->new( { node_type => 'ticket',
+ node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
+ change_type => ($txn->{type} eq 'create' ? 'add_file' :'update_file' )
+ }
+ );
+ warn "We're not yet detecting create vs update vs delete";
+ $changeset->add_change({ change => $change});
foreach my $entry ( @{ $txn->{'history_entries'} } ) {
+ # Each of these entries is essentially a propchange
+ $self->add_prop_change( change => $change, history_entry => $entry,
+ previous_state => $previous_state,
+ );
- if ( my $sub = $self->can( '_recode_entry_' . $entry->{'field'} ) ) {
- $sub->(
- $self => previous_state => $previous_state,
- entry => $entry,
- txn => $txn,
- changeset => $changeset
- );
- }
- else {
- die "failed to know how to handle this entry: " . YAML::Dump($entry);
- }
}
foreach my $email (@{$txn->{email_entries}}) {
- if(my $sub = $self->can('_recode_email_'.'blah') {
- $sub->(
- $self => previous_state => $previous_state,
+ if(my $sub = $self->can('_recode_email_'.'blah')) {
+ $sub->( $self =>
+ previous_state => $previous_state,
email => $email,
txn => $txn,
changeset => $changeset
);
}
-
}
$self->translate_prop_names($changeset);
unshift @changesets, $changeset unless $changeset->is_empty;
}
-
- return \@changesets;
+ return \@changesets;
}
-sub _recode_entry_Status {
- my $self = shift;
- my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
-
- $args{txn}->{'Type'} = 'Set';
- return $self->_recode_entry_Set(%args);
-}
-sub _recode_entry_Told {
- my $self = shift;
- my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
- $args{txn}->{'Type'} = 'Set';
- return $self->_recode_entry_Set(%args);
-}
-sub _recode_entry_Set {
+sub add_prop_change {
my $self = shift;
- my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
-
- my $change = Prophet::Change->new(
- { node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
- change_type => 'update_file'
- }
- );
+ my %args = validate( @_, { history_entry => 1, previous_state => 1, change => 1 } );
- if ( $args{txn}->{Field} eq 'Queue' ) {
- my $current_queue = $args{task}->{'Queue'};
- my $user = $args{txn}->{Creator};
- if ( $args{txn}->{Description} =~ /Queue changed from (.*) to $current_queue by $user/ ) {
- $args{txn}->{old_value} = $1;
- $args{txn}->{new_value} = $current_queue;
- }
-
- } elsif ( $args{txn}->{Field} eq 'Owner' ) {
- $args{'txn'}->{new_value} = $self->resolve_user_id_to( name => $args{'txn'}->{'new_value'} ),
- $args{'txn'}->{old_value}
- = $self->resolve_user_id_to( name => $args{'txn'}->{'old_value'} )
-
- }
-
- $args{'changeset'}->add_change( { change => $change } );
- if ( $args{'previous_state'}->{ $args{txn}->{Field} } eq $args{txn}->{'new_value'} ) {
- $args{'previous_state'}->{ $args{txn}->{Field} } = $args{txn}->{'old_value'};
+ if ( $args{'previous_state'}->{ $args{history_entry}->{field} } eq $args{history_entry}->{'new_value'} ) {
+ $args{'previous_state'}->{ $args{history_entry}->{field} } = $args{history_entry}->{'old_value'};
} else {
- $args{'previous_state'}->{ $args{txn}->{Field} } = $args{txn}->{'old_value'};
- warn $args{'previous_state'}->{ $args{txn}->{Field} } . " != "
- . $args{txn}->{'new_value'} . "\n\n"
+ $args{'previous_state'}->{ $args{history_entry}->{field} } = $args{history_entry}->{'old_value'};
+ warn $args{'previous_state'}->{ $args{history_entry}->{field} } . " != "
+ . $args{history_entry}->{'new_value'} . "\n\n"
. YAML::Dump( \%args );
}
- $change->add_prop_change(
- name => $args{txn}->{'Field'},
- old => $args{txn}->{'old_value'},
- new => $args{txn}->{'new_value'}
+ $args{change}->add_prop_change(
+ name => $args{history_entry}->{'field'},
+ old => $args{history_entry}->{'old_value'},
+ new => $args{history_entry}->{'new_value'}
);
}
-*_recode_entry_Steal = \&_recode_entry_Set;
-*_recode_entry_Take = \&_recode_entry_Set;
-*_recode_entry_Give = \&_recode_entry_Set;
-
-sub _recode_entry_Create {
+sub _recode_entry_create {
my $self = shift;
my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
@@ -154,31 +114,6 @@
}
-sub _recode_entry_AddLink {
- my $self = shift;
- my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
- my $new_state = $args{'previous_state'}->{ $args{'txn'}->{'Field'} };
- $args{'previous_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
- $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
- $args{'txn'}->{'new_value'},
- $args{'txn'}->{'old_value'}
- );
-
- my $change = Prophet::Change->new(
- { node_type => 'ticket',
- node_uuid => $self->sync_source->uuid_for_remote_id( $args{'previous_state'}->{'id'} ),
- change_type => 'update_file'
- }
- );
- $args{'changeset'}->add_change( { change => $change } );
- $change->add_prop_change(
- name => $args{'txn'}->{'Field'},
- old => $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
- new => $new_state
- );
-
-}
-
sub _recode_content_update {
my $self = shift;
my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
@@ -220,10 +155,10 @@
my $self = shift;
my %args = validate( @_, { txn => 1, previous_state => 1, changeset => 1 } );
- my $new_state = $args{'previous_state'}->{ $args{'txn'}->{'Field'} };
+ my $new_state = $args{'previous_state'}->{ $args{'txn'}->{'field'} };
- $args{'previous_state'}->{ $args{'txn'}->{'Field'} } = $self->warp_list_to_old_value(
- $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
+ $args{'previous_state'}->{ $args{'txn'}->{'field'} } = $self->warp_list_to_old_value(
+ $args{'previous_state'}->{ $args{'txn'}->{'field'} },
$self->resolve_user_id_to( email => $args{'txn'}->{'new_value'} ),
$self->resolve_user_id_to( email => $args{'txn'}->{'old_value'} )
@@ -238,8 +173,8 @@
);
$args{'changeset'}->add_change( { change => $change } );
$change->add_prop_change(
- name => $args{'txn'}->{'Field'},
- old => $args{'previous_state'}->{ $args{'txn'}->{'Field'} },
+ name => $args{'txn'}->{'field'},
+ old => $args{'previous_state'}->{ $args{'txn'}->{'field'} },
new => $new_state
);
More information about the Bps-public-commit
mailing list