| 6 |
## |
## |
| 7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
| 8 |
## $Log$ |
## $Log$ |
| 9 |
|
## Revision 1.2 2002/12/01 04:43:25 joko |
| 10 |
|
## + mapping deatil entries may now be either an ARRAY or a HASH |
| 11 |
|
## + erase flag is used now (for export-operations) |
| 12 |
|
## + expressions to refer to values inside deep nested structures |
| 13 |
|
## - removed old mappingV2-code |
| 14 |
|
## + cosmetics |
| 15 |
|
## + sub _erase_all |
| 16 |
|
## |
| 17 |
## Revision 1.1 2002/11/29 04:45:50 joko |
## Revision 1.1 2002/11/29 04:45:50 joko |
| 18 |
## + initial check in |
## + initial check in |
| 19 |
## |
## |
| 31 |
use misc::HashExt; |
use misc::HashExt; |
| 32 |
use libp qw( md5_base64 ); |
use libp qw( md5_base64 ); |
| 33 |
use libdb qw( quotesql hash2Sql ); |
use libdb qw( quotesql hash2Sql ); |
| 34 |
use Data::Transform::OO qw( hash2object ); |
use Data::Transform::Deep qw( hash2object refexpr2perlref ); |
| 35 |
use Data::Compare::Struct qw( getDifference isEmpty ); |
use Data::Compare::Struct qw( getDifference isEmpty ); |
| 36 |
|
|
| 37 |
# get logger instance |
# get logger instance |
| 155 |
$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}" ); |
| 156 |
|
|
| 157 |
# build mapping |
# build mapping |
| 158 |
|
# incoming: and Array of node map entries (Array or Hash) - e.g. |
| 159 |
|
# [ 'source:item_name' => 'target:class_val' ] |
| 160 |
|
# { source => 'event->startDateTime', target => 'begindate' } |
| 161 |
foreach (@{$self->{args}->{mapping}}) { |
foreach (@{$self->{args}->{mapping}}) { |
| 162 |
my @key1 = split(':', $_->[0]); |
if (ref $_ eq 'ARRAY') { |
| 163 |
my @key2 = split(':', $_->[1]); |
my @entry1 = split(':', $_->[0]); |
| 164 |
push @{$self->{meta}->{$key1[0]}->{childnodes}}, $key1[1]; |
my @entry2 = split(':', $_->[1]); |
| 165 |
push @{$self->{meta}->{$key2[0]}->{childnodes}}, $key2[1]; |
my $descent = []; |
| 166 |
|
my $node = []; |
| 167 |
|
$descent->[0] = $entry1[0]; |
| 168 |
|
$descent->[1] = $entry2[0]; |
| 169 |
|
$node->[0] = $entry1[1]; |
| 170 |
|
$node->[1] = $entry2[1]; |
| 171 |
|
push @{$self->{meta}->{$descent->[0]}->{childnodes}}, $node->[0]; |
| 172 |
|
push @{$self->{meta}->{$descent->[1]}->{childnodes}}, $node->[1]; |
| 173 |
|
} elsif (ref $_ eq 'HASH') { |
| 174 |
|
foreach my $entry_key (keys %$_) { |
| 175 |
|
my $entry_val = $_->{$entry_key}; |
| 176 |
|
push @{$self->{meta}->{$entry_key}->{childnodes}}, $entry_val; |
| 177 |
|
} |
| 178 |
|
} |
| 179 |
|
|
| 180 |
} |
} |
| 181 |
|
|
| 182 |
# check partners/nodes: does partner exist / is node available? |
# check partners/nodes: does partner exist / is node available? |
| 217 |
#$self->_erase_all($opts->{source_node}); |
#$self->_erase_all($opts->{source_node}); |
| 218 |
} |
} |
| 219 |
|
|
| 220 |
|
# erase flag means: erase the target |
| 221 |
|
#if ($opts->{erase}) { |
| 222 |
|
if ($self->{args}->{erase}) { |
| 223 |
|
# TODO: move this method to the scope of the synchronization core and wrap it around different handlers |
| 224 |
|
#print "ERASE", "\n"; |
| 225 |
|
$self->_erase_all('target'); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
$self->_syncNodes(); |
$self->_syncNodes(); |
| 229 |
|
|
| 230 |
} |
} |
| 464 |
|
|
| 465 |
if ($tc->{error_per_row}) { |
if ($tc->{error_per_row}) { |
| 466 |
$msg .= "\n"; |
$msg .= "\n"; |
| 467 |
$msg .= "errors:" . "\n"; |
$msg .= "errors from \"error_per_row\":" . "\n"; |
| 468 |
$msg .= Dumper($tc->{error_per_row}); |
$msg .= Dumper($tc->{error_per_row}); |
| 469 |
} |
} |
| 470 |
|
|
| 605 |
for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) { |
for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) { |
| 606 |
#my $map_right = $self->{args}->{mapping}->{$key}; |
#my $map_right = $self->{args}->{mapping}->{$key}; |
| 607 |
|
|
| 608 |
|
$self->{node}->{source}->{propcache} = {}; |
| 609 |
|
$self->{node}->{target}->{propcache} = {}; |
| 610 |
|
|
| 611 |
# get property name |
# get property name |
| 612 |
$self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx]; |
$self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx]; |
| 613 |
$self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx]; |
$self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx]; |
| 625 |
$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}}; |
| 626 |
} |
} |
| 627 |
#$self->{node}->{map}->{$key} = $value; |
#$self->{node}->{map}->{$key} = $value; |
| 628 |
|
|
| 629 |
|
# detect expression |
| 630 |
|
# for transferring deeply nested structures described by expressions |
| 631 |
|
#print "val: $self->{node}->{source}->{propcache}->{value}", "\n"; |
| 632 |
|
if ($self->{node}->{source}->{propcache}->{property} =~ s/^expr://) { |
| 633 |
|
|
| 634 |
|
# create an anonymous sub to act as callback target dispatcher |
| 635 |
|
my $cb_dispatcher = sub { |
| 636 |
|
#print "=============== CALLBACK DISPATCHER", "\n"; |
| 637 |
|
#print "ident: ", $self->{node}->{source}->{ident}, "\n"; |
| 638 |
|
#return $self->{node}->{source}->{ident}; |
| 639 |
|
|
| 640 |
|
}; |
| 641 |
|
|
| 642 |
|
|
| 643 |
|
#print Dumper($self->{node}); |
| 644 |
|
|
| 645 |
|
# build callback map for helper function |
| 646 |
|
#my $cbmap = { $self->{meta}->{source}->{IdentProvider}->{arg} => $cb_dispatcher }; |
| 647 |
|
my $cbmap = {}; |
| 648 |
|
my $value = refexpr2perlref($self->{node}->{source}->{payload}, $self->{node}->{source}->{propcache}->{property}, $cbmap); |
| 649 |
|
$self->{node}->{source}->{propcache}->{value} = $value; |
| 650 |
|
} |
| 651 |
|
|
| 652 |
# encode values dependent on type of underlying storage here - expand cases... |
# encode values dependent on type of underlying storage here - expand cases... |
| 653 |
my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type}; |
my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type}; |
| 654 |
if ($storage_type eq 'DBI') { |
if ($storage_type eq 'DBI') { |
| 655 |
# ...for sql |
# ...for sql |
| 656 |
$self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value}); |
$self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value}); |
| 657 |
} elsif ($storage_type eq 'Tangram') { |
} |
| 658 |
|
elsif ($storage_type eq 'Tangram') { |
| 659 |
|
# iso? utf8 already possible? |
| 660 |
|
|
| 661 |
} elsif ($storage_type eq 'LDAP') { |
} elsif ($storage_type eq 'LDAP') { |
| 662 |
# TODO: encode utf8 here? |
# TODO: encode utf8 here? |
| 663 |
} |
} |
| 668 |
} |
} |
| 669 |
} |
} |
| 670 |
|
|
|
#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); |
|
|
#} |
|
|
} |
|
|
} |
|
| 671 |
|
|
| 672 |
# TODO: $logger->dump( ... ); |
# TODO: $logger->dump( ... ); |
| 673 |
#$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) ); |
#$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) ); |
| 1096 |
# 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) |
| 1097 |
sub _otherSide { |
sub _otherSide { |
| 1098 |
my $self = shift; |
my $self = shift; |
| 1099 |
my $side = shift; |
my $descent = shift; |
| 1100 |
return 'source' if $side eq 'target'; |
return 'source' if $descent eq 'target'; |
| 1101 |
return 'target' if $side eq 'source'; |
return 'target' if $descent eq 'source'; |
| 1102 |
return ''; |
return ''; |
| 1103 |
} |
} |
| 1104 |
|
|
| 1105 |
|
sub _erase_all { |
| 1106 |
|
my $self = shift; |
| 1107 |
|
my $descent = shift; |
| 1108 |
|
#my $node = shift; |
| 1109 |
|
my $node = $self->{meta}->{$descent}->{node}; |
| 1110 |
|
$self->{meta}->{$descent}->{storage}->eraseAll($node); |
| 1111 |
|
} |
| 1112 |
|
|
| 1113 |
|
|
| 1114 |
=pod |
=pod |
| 1115 |
|
|