1 |
|
## ------------------------------------------------------------------------- |
2 |
|
## |
3 |
## $Id$ |
## $Id$ |
4 |
## |
## |
5 |
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
6 |
## |
## |
7 |
## See COPYRIGHT section in pod text below for usage and distribution rights. |
## See COPYRIGHT section in associated pod text |
8 |
|
## or below for usage and distribution rights. |
9 |
## |
## |
10 |
## ---------------------------------------------------------------------------------------- |
## ------------------------------------------------------------------------- |
11 |
## $Log$ |
## $Log$ |
12 |
|
## Revision 1.7 2003/05/13 08:13:25 joko |
13 |
|
## moved "sub buildAttributeMap" to Map.pm |
14 |
|
## |
15 |
|
## Revision 1.6 2003/03/28 03:08:17 joko |
16 |
|
## fix regarding namespace update |
17 |
|
## |
18 |
|
## Revision 1.5 2003/02/21 08:34:58 joko |
19 |
|
## modified object hierarchy |
20 |
|
## renamed method |
21 |
|
## |
22 |
|
## Revision 1.4 2003/02/14 14:06:20 joko |
23 |
|
## + minor fix to old metadata structure |
24 |
|
## |
25 |
|
## Revision 1.3 2003/02/11 06:28:24 joko |
26 |
|
## + changes to metadata structure |
27 |
|
## |
28 |
## Revision 1.2 2003/02/09 05:02:05 joko |
## Revision 1.2 2003/02/09 05:02:05 joko |
29 |
## + major structure changes |
## + major structure changes |
30 |
## - refactored code to sister modules |
## - refactored code to sister modules |
46 |
use mixin::with qw( Data::Transfer::Sync ); |
use mixin::with qw( Data::Transfer::Sync ); |
47 |
|
|
48 |
|
|
49 |
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main |
use Data::Dumper; |
50 |
|
|
51 |
# get logger instance |
# get logger instance |
52 |
my $logger = Log::Dispatch::Config->instance; |
my $logger = Log::Dispatch::Config->instance; |
53 |
|
|
|
use Data::Dumper; |
|
|
|
|
|
|
|
|
|
|
54 |
# TODO: refactor (still)!!! take this list from already established/given metadata .... |
# TODO: refactor (still)!!! take this list from already established/given metadata .... |
55 |
# .... also internally: passing around and mungling these metadata doesn't make sense anymore. |
# .... also internally: passing around and mungling these metadata doesn't make sense anymore. |
56 |
sub options2metadata { |
sub options2metadata { |
58 |
|
|
59 |
$logger->debug( __PACKAGE__ . "->transformMetadata" ); |
$logger->debug( __PACKAGE__ . "->transformMetadata" ); |
60 |
|
|
61 |
#print Dumper($self->{options}); |
# trace |
62 |
|
#print Dumper($self->{options}); |
63 |
|
#print Dumper($self->{args_raw}); |
64 |
|
#exit; |
65 |
|
|
66 |
# decompose identifiers and write to metadata (for each descent) |
# decompose identifiers and write to metadata (for each descent) |
67 |
foreach ('source', 'target') { |
foreach ('source', 'target') { |
78 |
$self->{meta}->{$_}->{nodeName} = $self->{options}->{$_}->{nodeName}; |
$self->{meta}->{$_}->{nodeName} = $self->{options}->{$_}->{nodeName}; |
79 |
|
|
80 |
# Filter |
# Filter |
81 |
if (my $item_filter = $self->{args}->{$_ . '_filter'}) { |
if (my $item_filter = $self->{options}->{$_}->{filter}) { |
82 |
$self->{meta}->{$_}->{filter} = $item_filter; |
$self->{meta}->{$_}->{filter} = $item_filter; |
83 |
} |
} |
84 |
|
|
97 |
} |
} |
98 |
|
|
99 |
# TypeProvider |
# TypeProvider |
100 |
if (my $item_type = $self->{args}->{$_ . '_type'}) { |
# FIXME! this is still Vdeprecated!!! |
101 |
|
if (my $item_type = $self->{options}->{$_ . '_type'}) { |
102 |
my @item_type = split(':', $item_type); |
my @item_type = split(':', $item_type); |
103 |
$self->{meta}->{$_}->{TypeProvider} = { method => $item_type[0], arg => $item_type[1] }; |
$self->{meta}->{$_}->{TypeProvider} = { method => $item_type[0], arg => $item_type[1] }; |
104 |
} |
} |
105 |
|
|
106 |
|
# trace |
107 |
|
#print Dumper($self); |
108 |
|
#exit; |
109 |
|
|
110 |
# Callbacks - writers (will be triggered _before_ writing to target) |
# Callbacks - writers (will be triggered _before_ writing to target) |
111 |
if (my $item_writers = $self->{args}->{$_ . '_callbacks_write'}) { |
if (my $item_writers = $self->{options}->{$_}->{callbacks}->{write}) { |
112 |
my $descent = $_; # this is important since the following code inside the map wants to use its own context variables |
my $descent = $_; # this is important since the following code inside the map wants to use its own context variables |
113 |
map { $self->{meta}->{$descent}->{Callback}->{write}->{$_}++; } @$item_writers; |
map { $self->{meta}->{$descent}->{Callback}->{write}->{$_}++; } @$item_writers; |
114 |
} |
} |
115 |
|
|
116 |
# Callbacks - readers (will be triggered _after_ reading from source) |
# Callbacks - readers (will be triggered _after_ reading from source) |
117 |
if (my $item_readers = $self->{args}->{$_ . '_callbacks_read'}) { |
if (my $item_readers = $self->{options}->{$_}->{callbacks}->{read}) { |
118 |
my $descent = $_; |
my $descent = $_; |
119 |
map { $self->{meta}->{$descent}->{Callback}->{read}->{$_}++; } @$item_readers; |
map { $self->{meta}->{$descent}->{Callback}->{read}->{$_}++; } @$item_readers; |
120 |
} |
} |
121 |
|
|
122 |
# resolve storage objects |
# resolve storage handles |
123 |
$self->{meta}->{$_}->{storage} = $self->{options}->{$_}->{storage}->{handle}; |
$self->{meta}->{$_}->{storage} = $self->{options}->{$_}->{storage}->{handle}; |
124 |
|
|
125 |
|
# transfer storage handle options to metadata |
126 |
|
#map { $self->{meta}->{$_}->{isIdentAuthority} = 1 } @{$self->{id_authorities}}; |
127 |
|
#map { $self->{meta}->{$_}->{isChecksumAuthority} = 1; } @{$self->{checksum_authorities}}; |
128 |
|
#map { $self->{meta}->{$_}->{isWriteProtected} = 1; } @{$self->{write_protected}}; |
129 |
|
#print Dumper($self->{options}->{$_}); |
130 |
|
#exit; |
131 |
|
$self->{meta}->{$_}->{isIdentAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isIdentAuthority}; |
132 |
|
$self->{meta}->{$_}->{isWriteProtected} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isWriteProtected}; |
133 |
|
$self->{meta}->{$_}->{isChecksumAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isChecksumAuthority}; |
134 |
|
|
135 |
} |
} |
136 |
|
|
137 |
#print Dumper($self->{meta}); |
#print Dumper($self->{meta}); |
214 |
} |
} |
215 |
|
|
216 |
|
|
|
|
|
|
sub buildAttributeMap { |
|
|
|
|
|
my $self = shift; |
|
|
|
|
|
# field-structure for building sql |
|
|
# mapping of sql-fieldnames to object-attributes |
|
|
$self->{node}->{map} = {}; |
|
|
|
|
|
# manually set ... |
|
|
# ... object-id |
|
|
$self->{node}->{map}->{$self->{meta}->{target}->{IdentProvider}->{arg}} = $self->{node}->{source}->{ident}; |
|
|
# ... checksum |
|
|
$self->{node}->{map}->{cs} = $self->{node}->{source}->{checksum}; |
|
|
|
|
|
#print "sqlmap: ", Dumper($self->{node}->{map}), "\n"; |
|
|
|
|
|
#print Dumper($self); |
|
|
#exit; |
|
|
|
|
|
# for transferring flat structures via simple (1:1) mapping |
|
|
# TODO: diff per property / property value |
|
|
|
|
|
#if ($self->{args}->{mapping}) { |
|
|
# apply mapping from $self->{args}->{mapping} to $self->{node}->{map} |
|
|
#foreach my $key (@{$self->{meta}->{source}->{childnodes}}) { |
|
|
my @childnodes = @{$self->{meta}->{source}->{childnodes}}; |
|
|
for (my $mapidx = 0; $mapidx <= $#childnodes; $mapidx++) { |
|
|
#my $map_right = $self->{args}->{mapping}->{$key}; |
|
|
|
|
|
$self->{node}->{source}->{propcache} = {}; |
|
|
$self->{node}->{target}->{propcache} = {}; |
|
|
|
|
|
# get property name |
|
|
$self->{node}->{source}->{propcache}->{property} = $self->{meta}->{source}->{childnodes}->[$mapidx]; |
|
|
$self->{node}->{target}->{propcache}->{property} = $self->{meta}->{target}->{childnodes}->[$mapidx]; |
|
|
#print "map: $map_right", "\n"; |
|
|
|
|
|
# get property value |
|
|
my $value; |
|
|
|
|
|
# detect for callback - old style - (maybe the better???) |
|
|
if (ref($self->{node}->{target}->{map}) eq 'CODE') { |
|
|
#$value = &$map_right($objClone); |
|
|
} else { |
|
|
# plain (scalar?) value |
|
|
#$value = $objClone->{$map_right}; |
|
|
$self->{node}->{source}->{propcache}->{value} = $self->{node}->{source}->{payload}->{$self->{node}->{source}->{propcache}->{property}}; |
|
|
} |
|
|
#$self->{node}->{map}->{$key} = $value; |
|
|
|
|
|
# detect expression |
|
|
# for transferring deeply nested structures described by expressions |
|
|
#print "val: $self->{node}->{source}->{propcache}->{value}", "\n"; |
|
|
if ($self->{node}->{source}->{propcache}->{property} =~ s/^expr://) { |
|
|
|
|
|
# create an anonymous sub to act as callback target dispatcher |
|
|
my $cb_dispatcher = sub { |
|
|
#print "=============== CALLBACK DISPATCHER", "\n"; |
|
|
#print "ident: ", $self->{node}->{source}->{ident}, "\n"; |
|
|
#return $self->{node}->{source}->{ident}; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
#print Dumper($self->{node}); |
|
|
|
|
|
# build callback map for helper function |
|
|
#my $cbmap = { $self->{meta}->{source}->{IdentProvider}->{arg} => $cb_dispatcher }; |
|
|
my $cbmap = {}; |
|
|
my $value = refexpr2perlref($self->{node}->{source}->{payload}, $self->{node}->{source}->{propcache}->{property}, $cbmap); |
|
|
$self->{node}->{source}->{propcache}->{value} = $value; |
|
|
} |
|
|
|
|
|
# encode values dependent on type of underlying storage here - expand cases... |
|
|
my $storage_type = $self->{meta}->{target}->{storage}->{locator}->{type}; |
|
|
if ($storage_type eq 'DBI') { |
|
|
# ...for sql |
|
|
# quotemeta? |
|
|
$self->{node}->{source}->{propcache}->{value} = quotesql($self->{node}->{source}->{propcache}->{value}); |
|
|
|
|
|
} elsif ($storage_type eq 'Tangram') { |
|
|
# iso? utf8 already possible? |
|
|
|
|
|
} elsif ($storage_type eq 'LDAP') { |
|
|
# TODO: encode utf8 here? |
|
|
|
|
|
} |
|
|
|
|
|
# store value to transfer map |
|
|
$self->{node}->{map}->{$self->{node}->{target}->{propcache}->{property}} = $self->{node}->{source}->{propcache}->{value}; |
|
|
|
|
|
} |
|
|
#} |
|
|
|
|
|
|
|
|
# TODO: $logger->dump( ... ); |
|
|
#$logger->debug( "sqlmap:" . "\n" . Dumper($self->{node}->{map}) ); |
|
|
#print "sqlmap: ", Dumper($self->{node}->{map}), "\n"; |
|
|
#print "entrystatus: ", Dumper($self->{node}), "\n"; |
|
|
|
|
|
} |
|
|
|
|
217 |
1; |
1; |
218 |
|
__END__ |