6 |
## |
## |
7 |
## ---------------------------------------------------------------------------------------- |
## ---------------------------------------------------------------------------------------- |
8 |
## $Log$ |
## $Log$ |
9 |
|
## Revision 1.5 2003/02/11 05:26:04 joko |
10 |
|
## + sub _tellWhatIWillDo |
11 |
|
## + re-enabled "branch to execution path for special targets" mechanism |
12 |
|
## |
13 |
|
## Revision 1.4 2003/02/09 05:03:02 joko |
14 |
|
## + minor fix regarding namespace of api versioning extension module |
15 |
|
## |
16 |
## Revision 1.3 2003/02/09 04:59:27 joko |
## Revision 1.3 2003/02/09 04:59:27 joko |
17 |
## + api versioning mechanism |
## + api versioning mechanism |
18 |
## + major structure changes |
## + major structure changes |
62 |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
$logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )"); |
63 |
#print Dumper($self); |
#print Dumper($self); |
64 |
#exit; |
#exit; |
65 |
my $module = "Version::$syncVersion"; |
my $module = "API::$syncVersion"; |
66 |
$self->load($module); |
$self->load($module); |
67 |
} |
} |
68 |
|
|
70 |
sub configure { |
sub configure { |
71 |
my $self = shift; |
my $self = shift; |
72 |
|
|
|
#print "YAI\n"; |
|
|
#print Dumper(@_); |
|
|
#exit; |
|
|
|
|
73 |
$logger->debug( __PACKAGE__ . "->configure"); |
$logger->debug( __PACKAGE__ . "->configure"); |
74 |
|
|
75 |
my @args = @_; |
my @args = @_; |
76 |
|
|
|
#print Dumper(@args); |
|
|
|
|
77 |
if (!isEmpty(\@args)) { |
if (!isEmpty(\@args)) { |
78 |
my %properties = @_; |
my %properties = @_; |
79 |
# merge args to properties |
# merge args to properties |
168 |
return; |
return; |
169 |
} |
} |
170 |
|
|
171 |
|
#print Dumper($args); |
172 |
|
|
173 |
# remember arguments through the whole processing |
# remember arguments through the whole processing |
174 |
$self->{args} = $args; |
$self->{args} = $args; |
175 |
|
|
199 |
$self->options2metadata(); |
$self->options2metadata(); |
200 |
$self->options2metadata_accessor(); |
$self->options2metadata_accessor(); |
201 |
|
|
202 |
|
# branch to execution path for special targets |
203 |
|
# detect for option 'handler' which could be a CODEref |
204 |
|
if ($self->{options}->{handler} && ref $self->{options}->{handler} eq 'CODE') { |
205 |
|
$logger->info( __PACKAGE__ . "->syncNodes: Running (special handler code - no generic sync!) on '$self->{options}->{target}->{dbKey}' with MODE $self->{options}->{process}->{mode}, NODE $self->{options}->{target}->{address}"); |
206 |
|
#print Dumper($self); |
207 |
|
#exit; |
208 |
|
# don't do this any more - it wasn't very nice somehow ... |
209 |
|
#$self->{options}->{handler}->($self->{app}, $self->{options}); |
210 |
|
# .... now: better let the parent application scope handle this via callback |
211 |
|
# not any more required for this: $self->{app} inside here (which isn't the app we mean here) |
212 |
|
# required for this: getting the options out of here: establish some getter method! ($self->getOptions(...)) |
213 |
|
# so.... |
214 |
|
#$self->{__bridge}->{parent_ref}-> |
215 |
|
|
216 |
|
# ahh okay, DesignPattern::Bridge moves closer to some Class::Inner!??? |
217 |
|
# so... |
218 |
|
# similar like above - but it isn't very nice anyway ... (no privateness, but: who cares?) |
219 |
|
#print Dumper($self->{__bridge}); |
220 |
|
# just take the global application instance and |
221 |
|
# throw it into the context of the mapping module - this is heavy! ;-) (but again, who cares...) |
222 |
|
# TODO: handle this more abstract *sometimes* |
223 |
|
#$self->{options}->{handler}->($self->{__bridge}->{parent}->{app}, $self->{options}); |
224 |
|
$self->{options}->{handler}->($self->{__bridge}->{parent}->{process}, $self->{options}); |
225 |
|
|
226 |
|
return; |
227 |
|
} |
228 |
|
|
229 |
|
# TODO: execution path branch V2!!! |
230 |
|
# option1: wrap this via callback to parent scope (like current impl. mechanism) |
231 |
|
# option2: branch directly from here (this needs refactoring of the sub handler) |
232 |
|
|
233 |
# tracing |
# tracing |
234 |
#print Dumper($self); |
#print Dumper($self); |
235 |
#exit; |
#exit; |
239 |
return if !$self->buildFieldmapping(); |
return if !$self->buildFieldmapping(); |
240 |
return if !$self->_touchNodeSet(); |
return if !$self->_touchNodeSet(); |
241 |
return if !$self->_prepare_sync(); |
return if !$self->_prepare_sync(); |
242 |
|
$self->_tellWhatIWillDo(); |
243 |
|
|
244 |
# tracing |
# tracing |
245 |
#print Dumper($self); |
#print Dumper($self); |
255 |
} |
} |
256 |
|
|
257 |
|
|
258 |
|
my $c_string_default = ''; |
259 |
|
sub c_string { |
260 |
|
my $value = shift; |
261 |
|
$value ||= "[$c_string_default]"; |
262 |
|
return $value; |
263 |
|
} |
264 |
|
|
265 |
|
sub _tellWhatIWillDo { |
266 |
|
my $self = shift; |
267 |
|
|
268 |
|
|
269 |
|
#return; |
270 |
|
|
271 |
|
# trace |
272 |
|
#print Dumper($self->{meta}); |
273 |
|
#exit; |
274 |
|
|
275 |
|
$c_string_default = 'n/a'; |
276 |
|
my $source = c_string($self->{opt}->{'source'}); |
277 |
|
my $source_node = c_string($self->{opt}->{'source-node'}); |
278 |
|
my $source_type = c_string($self->{opt}->{'source-type'}); |
279 |
|
my $target = c_string($self->{opt}->{'target'}); |
280 |
|
my $target_node = c_string($self->{opt}->{'target-node'}); |
281 |
|
my $target_type = c_string($self->{opt}->{'target-type'}); |
282 |
|
|
283 |
|
my $mapping_module = c_string($self->{opt}->{'mapping-module'}); |
284 |
|
my $mode = uc c_string($self->{opt}->{'mode'}); |
285 |
|
|
286 |
|
#my $ql = "$mode INTO $source NODE $source_node TYPE $source_type SELECT NODE $target_node TYPE $target_type FROM $target USING MODULE $mapping_module;"; |
287 |
|
#$logger->notice( __PACKAGE__ . ": $ql" ); |
288 |
|
my $ql = <<EOT; |
289 |
|
|
290 |
|
FETCH DATA |
291 |
|
FROM STORAGE $self->{meta}->{source}->{dbKey} |
292 |
|
AT NODE $self->{meta}->{source}->{accessorName}.$self->{meta}->{source}->{nodeName} |
293 |
|
USING IDENTIFIER $self->{meta}->{source}->{IdentProvider}->{method}.$self->{meta}->{source}->{IdentProvider}->{arg} |
294 |
|
CONVERT DATA |
295 |
|
CAST FROM $self->{meta}->{source}->{nodeType} TO $self->{meta}->{target}->{nodeType} |
296 |
|
MAP ATTRIBUTES FROM @{$self->{meta}->{source}->{childnodes}} TO @{$self->{meta}->{target}->{childnodes}} |
297 |
|
STORE DATA |
298 |
|
TO STORAGE $self->{meta}->{target}->{dbKey} |
299 |
|
AT NODE $self->{meta}->{target}->{accessorName}.$self->{meta}->{target}->{nodeName} |
300 |
|
USING IDENTIFIER $self->{meta}->{target}->{IdentProvider}->{method}.$self->{meta}->{target}->{IdentProvider}->{arg} |
301 |
|
EOT |
302 |
|
|
303 |
|
|
304 |
|
$logger->notice( $ql ); |
305 |
|
|
306 |
|
#exit; |
307 |
|
return; |
308 |
|
|
309 |
|
my $actioning = ucfirst $self->{opt}->{'action'} . 'ing'; |
310 |
|
|
311 |
|
# FIXME: this is weird! |
312 |
|
my $long = <<EOT; |
313 |
|
|
314 |
|
- $actioning data of type $target_type and |
315 |
|
filtered by $target_node from the storage named $target |
316 |
|
to the storage named $source - filtered by $source_node. |
317 |
|
- Will attempt to convert the data to $source_type. |
318 |
|
EOT |
319 |
|
chomp($long); |
320 |
|
$logger->notice( __PACKAGE__ . ": $long" ); |
321 |
|
|
322 |
|
} |
323 |
|
|
324 |
|
|
325 |
sub _prepareOptions { |
sub _prepareOptions { |
326 |
|
|
327 |
my $self = shift; |
my $self = shift; |
410 |
# merging - V2 |
# merging - V2 |
411 |
|
|
412 |
# merge local map with local opts |
# merge local map with local opts |
413 |
|
|
414 |
|
# delete undef'd items in $map |
415 |
|
|
416 |
# enable cloning |
# enable cloning |
417 |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
# FIXME: do we really need cloning here? trade safety/encapsulation for speed? |
418 |
Hash::Merge::set_clone_behavior(1); |
Hash::Merge::set_clone_behavior(1); |
419 |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
420 |
|
#Hash::Merge::set_behavior( 'STORAGE_PRECEDENT' ); |
421 |
|
#Hash::Merge::set_behavior( 'RETAINMENT_PRECEDENT' ); |
422 |
|
# TODO: add an option to Hash::Merge not to overwrite set items with undefined/empty/not assigned ones |
423 |
my $locals_merged = merge( $opts, $map ); |
my $locals_merged = merge( $opts, $map ); |
424 |
|
|
425 |
# trace |
# trace |
505 |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
# TODO: introduce different mechanism to make more then two partners (descents) possible |
506 |
($self->{meta}->{source}, $self->{meta}->{target}) = |
($self->{meta}->{source}, $self->{meta}->{target}) = |
507 |
($self->{meta}->{target}, $self->{meta}->{source}); |
($self->{meta}->{target}, $self->{meta}->{source}); |
508 |
|
#($self->{options}->{source}, $self->{options}->{target}) = |
509 |
|
# ($self->{options}->{target}, $self->{options}->{source}); |
510 |
|
|
511 |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
} elsif (lc $self->{options}->{process}->{mode} eq 'full') { |
512 |
# TODO: |
# TODO: |