| 6 |
## |
## |
| 7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
| 8 |
## $Log$ |
## $Log$ |
| 9 |
|
## Revision 1.4 2002/12/03 15:54:07 joko |
| 10 |
|
## + {import}-flag is now {prepare}-flag |
| 11 |
|
## |
| 12 |
|
## Revision 1.3 2002/12/01 22:26:59 joko |
| 13 |
|
## + minor cosmetics for logging |
| 14 |
|
## |
| 15 |
|
## Revision 1.2 2002/12/01 04:43:25 joko |
| 16 |
|
## + mapping deatil entries may now be either an ARRAY or a HASH |
| 17 |
|
## + erase flag is used now (for export-operations) |
| 18 |
|
## + expressions to refer to values inside deep nested structures |
| 19 |
|
## - removed old mappingV2-code |
| 20 |
|
## + cosmetics |
| 21 |
|
## + sub _erase_all |
| 22 |
|
## |
| 23 |
## Revision 1.1 2002/11/29 04:45:50 joko |
## Revision 1.1 2002/11/29 04:45:50 joko |
| 24 |
## + initial check in |
## + initial check in |
| 25 |
## |
## |
| 37 |
use misc::HashExt; |
use misc::HashExt; |
| 38 |
use libp qw( md5_base64 ); |
use libp qw( md5_base64 ); |
| 39 |
use libdb qw( quotesql hash2Sql ); |
use libdb qw( quotesql hash2Sql ); |
| 40 |
use Data::Transform::OO qw( hash2object ); |
use Data::Transform::Deep qw( hash2object refexpr2perlref ); |
| 41 |
use Data::Compare::Struct qw( getDifference isEmpty ); |
use Data::Compare::Struct qw( getDifference isEmpty ); |
| 42 |
|
|
| 43 |
# get logger instance |
# get logger instance |
| 161 |
$logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbkey}/$self->{meta}->{source}->{node} $direction_arrow target=$self->{meta}->{target}->{dbkey}/$self->{meta}->{target}->{node}" ); |
$logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbkey}/$self->{meta}->{source}->{node} $direction_arrow target=$self->{meta}->{target}->{dbkey}/$self->{meta}->{target}->{node}" ); |
| 162 |
|
|
| 163 |
# build mapping |
# build mapping |
| 164 |
|
# incoming: and Array of node map entries (Array or Hash) - e.g. |
| 165 |
|
# [ 'source:item_name' => 'target:class_val' ] |
| 166 |
|
# { source => 'event->startDateTime', target => 'begindate' } |
| 167 |
foreach (@{$self->{args}->{mapping}}) { |
foreach (@{$self->{args}->{mapping}}) { |
| 168 |
my @key1 = split(':', $_->[0]); |
if (ref $_ eq 'ARRAY') { |
| 169 |
my @key2 = split(':', $_->[1]); |
my @entry1 = split(':', $_->[0]); |
| 170 |
push @{$self->{meta}->{$key1[0]}->{childnodes}}, $key1[1]; |
my @entry2 = split(':', $_->[1]); |
| 171 |
push @{$self->{meta}->{$key2[0]}->{childnodes}}, $key2[1]; |
my $descent = []; |
| 172 |
|
my $node = []; |
| 173 |
|
$descent->[0] = $entry1[0]; |
| 174 |
|
$descent->[1] = $entry2[0]; |
| 175 |
|
$node->[0] = $entry1[1]; |
| 176 |
|
$node->[1] = $entry2[1]; |
| 177 |
|
push @{$self->{meta}->{$descent->[0]}->{childnodes}}, $node->[0]; |
| 178 |
|
push @{$self->{meta}->{$descent->[1]}->{childnodes}}, $node->[1]; |
| 179 |
|
} elsif (ref $_ eq 'HASH') { |
| 180 |
|
foreach my $entry_key (keys %$_) { |
| 181 |
|
my $entry_val = $_->{$entry_key}; |
| 182 |
|
push @{$self->{meta}->{$entry_key}->{childnodes}}, $entry_val; |
| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
|
| 186 |
} |
} |
| 187 |
|
|
| 188 |
# check partners/nodes: does partner exist / is node available? |
# check partners/nodes: does partner exist / is node available? |
| 216 |
|
|
| 217 |
# import flag means: prepare the source node to be syncable |
# import flag means: prepare the source node to be syncable |
| 218 |
# this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage |
# this is useful if there are e.g. no "ident" or "checksum" columns yet inside a DBI like (row-based) storage |
| 219 |
if ($self->{args}->{import}) { |
if ($self->{args}->{prepare}) { |
| 220 |
$self->_prepareNode_MetaProperties('source'); |
$self->_prepareNode_MetaProperties('source'); |
| 221 |
$self->_prepareNode_DummyIdent('source'); |
$self->_prepareNode_DummyIdent('source'); |
| 222 |
#return; |
#return; |
| 223 |
#$self->_erase_all($opts->{source_node}); |
#$self->_erase_all($opts->{source_node}); |
| 224 |
} |
} |
| 225 |
|
|
| 226 |
|
# erase flag means: erase the target |
| 227 |
|
#if ($opts->{erase}) { |
| 228 |
|
if ($self->{args}->{erase}) { |
| 229 |
|
# TODO: move this method to the scope of the synchronization core and wrap it around different handlers |
| 230 |
|
#print "ERASE", "\n"; |
| 231 |
|
$self->_erase_all('target'); |
| 232 |
|
} |
| 233 |
|
|
| 234 |
$self->_syncNodes(); |
$self->_syncNodes(); |
| 235 |
|
|
| 236 |
} |
} |
| 466 |
print "\n" if $self->{verbose}; |
print "\n" if $self->{verbose}; |
| 467 |
|
|
| 468 |
# build user-message from some stats |
# build user-message from some stats |
| 469 |
my $msg = "stats: $tc"; |
my $msg = "statistics: $tc"; |
| 470 |
|
|
| 471 |
if ($tc->{error_per_row}) { |
if ($tc->{error_per_row}) { |
| 472 |
$msg .= "\n"; |
$msg .= "\n"; |
| 473 |
$msg .= "errors:" . "\n"; |
$msg .= "errors from \"error_per_row\":" . "\n"; |
| 474 |
$msg .= Dumper($tc->{error_per_row}); |
$msg .= Dumper($tc->{error_per_row}); |
| 475 |
} |
} |
| 476 |
|
|
| 611 |
for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) { |
for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) { |
| 612 |
#my $map_right = $self->{args}->{mapping}->{$key}; |
#my $map_right = $self->{args}->{mapping}->{$key}; |
| 613 |
|
|
| 614 |
|
$self->{node}->{source}->{propcache} = {}; |
| 615 |
|
$self->{node}->{target}->{propcache} = {}; |
| 616 |
|
|
| 617 |
# get property name |
# get property name |
| 618 |
$self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx]; |
$self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx]; |
| 619 |
$self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx]; |
$self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx]; |
| 631 |
$self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}}; |
$self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}}; |
| 632 |
} |
} |
| 633 |
#$self->{node}->{map}->{$key} = $value; |
#$self->{node}->{map}->{$key} = $value; |
| 634 |
|
|
| 635 |
|
# detect expression |
| 636 |
|
# for transferring deeply nested structures described by expressions |
| 637 |
|
#print "val: $self->{node}->{source}->{propcache}->{value}", "\n"; |
| 638 |
|
if ($self->{node}->{source}->{propcache}->{property} =~ s/^expr://) { |
| 639 |
|
|
| 640 |
|
# create an anonymous sub to act as callback target dispatcher |
| 641 |
|
my $cb_dispatcher = sub { |
| 642 |
|
#print "=============== CALLBACK DISPATCHER", "\n"; |
| 643 |
|
#print "ident: ", $self->{node}->{source}->{ident}, "\n"; |
| 644 |
|
#return $self->{node}->{source}->{ident}; |
| 645 |
|
|
| 646 |
|
}; |
| 647 |
|
|
| 648 |
|
|
| 649 |
|
#print Dumper($self->{node}); |
| 650 |
|
|
| 651 |
|
# build callback map for helper function |
| 652 |
|
#my $cbmap = { $self->{meta}->{source}->{IdentProvider}->{arg} => $cb_dispatcher }; |
| 653 |
|
my $cbmap = {}; |
| 654 |
|
my $value = refexpr2perlref($self->{node}->{source}->{payload}, $self->{node}->{source}->{propcache}->{property}, $cbmap); |
| 655 |
|
$self->{node}->{source}->{propcache}->{value} = $value; |
| 656 |
|
} |
| 657 |
|
|
| 658 |
# encode values dependent on type of underlying storage here - expand cases... |
# encode values dependent on type of underlying storage here - expand cases... |
| 659 |
my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type}; |
my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type}; |
| 660 |
if ($storage_type eq 'DBI') { |
if ($storage_type eq 'DBI') { |
| 661 |
# ...for sql |
# ...for sql |
| 662 |
$self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value}); |
$self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value}); |
| 663 |
} elsif ($storage_type eq 'Tangram') { |
} |
| 664 |
|
elsif ($storage_type eq 'Tangram') { |
| 665 |
|
# iso? utf8 already possible? |
| 666 |
|
|
| 667 |
} elsif ($storage_type eq 'LDAP') { |
} elsif ($storage_type eq 'LDAP') { |
| 668 |
# TODO: encode utf8 here? |
# TODO: encode utf8 here? |
| 669 |
} |
} |
| 674 |
} |
} |
| 675 |
} |
} |
| 676 |
|
|
|
#print "self->{entry}: ", Dumper($self->{node}), "\n"; exit; |
|
|
|
|
|
# for transferring deeply nested structures described by expressions |
|
|
# this currently does not work! |
|
|
# TODO: re-enable this! |
|
|
if ($self->{args}->{mappingV2}) { |
|
|
|
|
|
# apply mapping from $self->{args}->{mappingV2} to $self->{node}->{map} |
|
|
foreach my $mapStep (@{$self->{args}->{mappingV2}}) { |
|
|
|
|
|
# prepare left/right keys/values |
|
|
my $left_key = $mapStep->{left}; |
|
|
my $left_val = _resolveMapStepExpr( $self->{node}->{source}->{payload}, $mapStep->{left} ); |
|
|
my $right_key = $mapStep->{right}; |
|
|
my $right_val = ( $mapStep->{right} ); |
|
|
#print "map: $map_right", "\n"; |
|
|
|
|
|
if ($mapStep->{method}) { |
|
|
if ($mapStep->{method} eq 'v:1') { |
|
|
$left_val = $left_key; |
|
|
} |
|
|
} |
|
|
|
|
|
#$self->{node}->{map}->{$key} = $value; |
|
|
#if ( grep(!/$right_key/, @{$self->{args}->{exclude}}) ) { |
|
|
$self->{node}->{map}->{$right_key} = $self->{R}->quoteSql($left_val); |
|
|
#} |
|
|
} |
|
|
} |
|
| 677 |
|
|
| 678 |
# TODO: $logger->dump( ... ); |
# TODO: $logger->dump( ... ); |
| 679 |
#$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) ); |
#$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) ); |
| 1102 |
# TODO: handle this in an abstract way (wipe out use of 'source' and/or 'target' inside core) |
# TODO: handle this in an abstract way (wipe out use of 'source' and/or 'target' inside core) |
| 1103 |
sub _otherSide { |
sub _otherSide { |
| 1104 |
my $self = shift; |
my $self = shift; |
| 1105 |
my $side = shift; |
my $descent = shift; |
| 1106 |
return 'source' if $side eq 'target'; |
return 'source' if $descent eq 'target'; |
| 1107 |
return 'target' if $side eq 'source'; |
return 'target' if $descent eq 'source'; |
| 1108 |
return ''; |
return ''; |
| 1109 |
} |
} |
| 1110 |
|
|
| 1111 |
|
sub _erase_all { |
| 1112 |
|
my $self = shift; |
| 1113 |
|
my $descent = shift; |
| 1114 |
|
#my $node = shift; |
| 1115 |
|
my $node = $self->{meta}->{$descent}->{node}; |
| 1116 |
|
$self->{meta}->{$descent}->{storage}->eraseAll($node); |
| 1117 |
|
} |
| 1118 |
|
|
| 1119 |
|
|
| 1120 |
=pod |
=pod |
| 1121 |
|
|