/[cvs]/nfo/perl/libs/Data/Transfer/Sync/API.pm
ViewVC logotype

Diff of /nfo/perl/libs/Data/Transfer/Sync/API.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by joko, Mon Jan 20 16:59:48 2003 UTC revision 1.4 by joko, Sun Feb 9 05:03:02 2003 UTC
# Line 6  Line 6 
6  ##  ##
7  ##    ----------------------------------------------------------------------------------------  ##    ----------------------------------------------------------------------------------------
8  ##    $Log$  ##    $Log$
9    ##    Revision 1.4  2003/02/09 05:03:02  joko
10    ##    + minor fix regarding namespace of api versioning extension module
11    ##
12    ##    Revision 1.3  2003/02/09 04:59:27  joko
13    ##    + api versioning mechanism
14    ##    + major structure changes
15    ##    - refactored code to sister modules
16    ##
17  ##    Revision 1.2  2003/01/20 16:59:48  joko  ##    Revision 1.2  2003/01/20 16:59:48  joko
18  ##    + cosmetics and debugging  ##    + cosmetics and debugging
19  ##  ##
# Line 20  package Data::Transfer::Sync::API; Line 28  package Data::Transfer::Sync::API;
28  use strict;  use strict;
29  use warnings;  use warnings;
30    
31    use base qw( DesignPattern::Bridge );
32    
33  use mixin::with qw( Data::Transfer::Sync );  use mixin::with qw( Data::Transfer::Sync );
34    
35    
36  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main  # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -   main
37    
38  use Data::Dumper;  use Data::Dumper;
39    use Hash::Merge qw( merge );
40    
41  use Data::Compare::Struct qw( getDifference isEmpty );  use Data::Compare::Struct qw( isEmpty );
 use Data::Transform::Deep qw( merge );  
42    
43  # get logger instance  # get logger instance
44  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
45    
46  sub _init {  
47    sub api_constructor {
48    my $self = shift;    my $self = shift;
49      $logger->debug( __PACKAGE__ . "->api_constructor: Loading API");
50      $self->_loadVersionExtensions();
51  }  }
52    
 sub checkOptions {  
   my $self = shift;  
   my $opts = shift;  
     
   my $result = 1;  
     
   # check - do we have a target node?  
   if (!$opts->{target_node}) {  
     $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'target node' could be determined.");  
     $result = 0;  
   }  
53    
54    # check - do we have a mapping?  sub _loadVersionExtensions {
55    if (!$opts->{mapping} && !$opts->{mapping_module}) {    my $self = shift;
56      $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'mapping' could be determined.");    my $syncVersion = $self->{sync_version};
57      $result = 0;    $syncVersion ||= '';
58    }    $logger->debug( __PACKAGE__ . "->loadVersionExtensions( version='$syncVersion' )");
59        #print Dumper($self);
60    return $result;    #exit;
61        my $module = "API::$syncVersion";
62      $self->load($module);
63  }  }
64    
65  sub checkOptionsV2 {  
66    sub configure {
67    my $self = shift;    my $self = shift;
68    
69  #print Dumper($self->{options});  #print "YAI\n";
70    #print Dumper(@_);
71    #exit;
72    
73    my $result = 1;    $logger->debug( __PACKAGE__ . "->configure");
74    
75    # check - do we have a target node?    my @args = @_;
76    if (!$self->{options}->{target}->{nodeName}) {  
77      $logger->warning( __PACKAGE__ . "->checkOptionsV2: No target given - please check metadata declaration.");  #print Dumper(@args);
78      $result = 0;  
79    }    if (!isEmpty(\@args)) {
80          my %properties = @_;
81    # check - do we have a mapping?      # merge args to properties
82    if (!$self->{options}->{fieldmap}) {      #map { $self->{$_} = $properties{$_}; } keys %properties;
83      $logger->warning( __PACKAGE__ . "->checkOptionsV2: Error while resolving resource metadata - no 'fieldmap' could be determined.");  #print Dumper($self);
84      $result = 0;  #print Dumper(\%properties);
85        if ($self->{options}) {
86        my $options_new = merge($self->{options}, \%properties);
87    #print Dumper($options_new);
88        $self->{options} = $options_new;
89    #print Dumper($self->{options});
90        } else {
91          $self->{options} = \%properties;
92        }
93        $self->_init();
94        #$self->_initV1();
95      } else {
96        #print "no args!", "\n";
97    }    }
     
   # TODO: extend!  
98    
99    return $result;  #print Dumper($self);
100    #exit;
101    
102      $self->{state}->{configured} = 1;
103      return 1;
104  }  }
105    
106    
107  sub prepareOptions {  sub setArguments {
108      my $self = shift;
109      my $args_raw = shift;
110      $self->{args_raw} = $args_raw;
111    }
112    
113    sub readArguments {
114    my $self = shift;    my $self = shift;
   my $opts = shift;  
115    
116  #print Dumper($opts);      my %syncConfig;
117        tie %syncConfig, 'Tie::IxHash';
118        %syncConfig = (
119          map => {
120            moduleName => $self->{args_raw}->{'mapping-module'},
121          },
122          source => {
123            dbKey => $self->{args_raw}->{source},
124            nodeType => $self->{args_raw}->{'source-type'},
125            nodeName => $self->{args_raw}->{'source-node'},
126          },
127          target => {
128            dbKey => $self->{args_raw}->{target},
129            nodeName => $self->{args_raw}->{'target-node'},
130          },
131          process => {
132            mode => $self->{args_raw}->{mode},
133            erase => $self->{args_raw}->{erase},
134            import => $self->{args_raw}->{import},
135            prepare => $self->{args_raw}->{prepare},
136          },
137    #      metadata => {
138    #        config => $self->{config_metadata},
139    #      }
140        );
141    
142      $self->{args} = \%syncConfig;
143    
144    }
145    
146    
147    # TODO: some feature to show off the progress of synchronization (cur/max * 100)
148    sub syncNodes {
149    
150      my $self = shift;
151      my $args = shift;
152    
153      $logger->debug( __PACKAGE__ . "->syncNodes: starting" );
154    
155    #print Dumper($self);
156  #exit;  #exit;
157    
158    $opts->{mode} ||= '';  #print Dumper($self->{options});
159    $opts->{erase} ||= 0;    $self->_prepareOptions();
   $opts->{prepare} ||= 0;  
   #$opts->{import} ||= 0;  
     
   if (!$opts->{source_node}) {  
     $logger->error( __PACKAGE__ . "->prepareOptions failed: Please specify source-node!");  
     return;  
   }  
     
   $logger->notice( __PACKAGE__ . "->prepareOptions( source_node $opts->{source_node} mode $opts->{mode} erase $opts->{erase} prepare $opts->{prepare} )");  
160    
161    #if (!$opts->{mapping} || !$opts->{mapping_module}) {  #print Dumper($self->{options});
   if (!$opts->{mapping}) {  
     $logger->warning( __PACKAGE__ . "->prepareOptions: No mapping supplied - please check key 'mappings' in global configuration or specify additional argument '--mapping'.");  
     #return;  
   }  
162    
163    $opts->{mapping_module} ||= $opts->{mapping};    if (!$self->checkOptions()) {
164    my $evstring = "use $opts->{mapping_module};";      $logger->critical( __PACKAGE__ . "->syncNodes: 'Data::Transfer::Sync::checkOptions' failed.");
   eval($evstring);  
   if ($@) {  
     $logger->warning( __PACKAGE__ . "->prepareOptions: error while trying to access mapping - $@");  
165      return;      return;
166    }    }
167    
168    # resolve mapping metadata (returned from sub)    if (!$self->{state}->{configured}) {
169    my $mapObject = $opts->{mapping_module}->new();      $logger->critical( __PACKAGE__ . "->syncNodes: Synchronization object is not configured/initialized correctly." );
   #print Dumper($map);  
   my $source_node_name = $opts->{source_node};  
   # check if mapping for certain node is contained in mapping object  
   if (!$mapObject->can($source_node_name)) {  
     $logger->warning( __PACKAGE__ . "->prepareOptions: Can't access mapping for node \"$source_node_name\" - please check $opts->{mapping_module}.");  
170      return;      return;
171    }    }
   my $map = $mapObject->$source_node_name;  
172    
173  #print Dumper($map);    # remember arguments through the whole processing
174      $self->{args} = $args;
175    
176    # check here if "target" is actually a CODEref - in this case: resolve it - deprecated!!! ???    # hash to hold and/or fill in metadata required for the processing
177    if (ref $map->{target} eq 'CODE') {    $self->{meta} = {};
     $map->{target} = $map->{target}->($source_node_name);  
   }  
178        
179    # resolve expressions (on nodename-level) here    # hash to sum up results
180    if ($map->{target} =~ m/^(code|expr):(.+?)$/) {    # TODO: re-implement! (sync-statistics???)
     my $target_dynamic_type = $1;  
     my $target_dynamic_expression = $2;  
     if (lc $target_dynamic_type eq 'code') {  
 #      $map->{target} = $mapObject->$target_dynamic_expression($map);  
     }  
   }  
181    
182    # remove asymmetries from $map (patch keys)    # detect synchronization method to determine which optical symbol (directed arrow) to use
183    $map->{source_node} = $map->{source}; delete $map->{source};    my $mode = $self->{args}->{mode};   # V1
184    $map->{target_node} = $map->{target}; delete $map->{target};    $mode ||= $self->{options}->{process}->{mode};    # V2
185    $map->{mapping} = $map->{details}; delete $map->{details};    my $direction_arrow = $self->_getDirectedArrow($mode);
   $map->{direction} = $map->{mode}; delete $map->{mode};  
   
   # defaults (mostly for backward-compatibility)  
   $map->{source_node} ||= $source_node_name;  
   $map->{source_ident} ||= 'storage_method:id';  
   $map->{target_ident} ||= 'property:oid';  
   $map->{direction} ||= $opts->{mode};         # | PUSH | PULL | FULL  
   $map->{method} ||= 'checksum';                # | timestamp  
   $map->{source_exclude} ||= [qw( cs )];  
186    
187    # merge map to opts    # determine code versions
188    map { $opts->{$_} = $map->{$_}; } keys %$map;      my $code_metadata_version;
189            # first, try to use version supplied by mapping-metadata
190  #print Dumper($opts);      $code_metadata_version = $self->{options}->{metadata}->{version};
191        # if not set, inherit from global 'sync_version'
192        $code_metadata_version ||= $self->{sync_version};
193    
194      # load additional code from versioned namespace into current instance
195        my $dynModule = "Metadata::$code_metadata_version";
196        $self->load($dynModule);
197        
198      # build metadata using versioned code and stuff
199        $self->options2metadata();
200        $self->options2metadata_accessor();
201    
202      # tracing
203        #print Dumper($self);
204        #exit;
205    
206    # TODO: move this to checkOptions...    $logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" );
     
   # check - do we have a target?  
   if (!$opts->{target_node}) {  
     $logger->warning( __PACKAGE__ . "->prepareOptions: No target given - please check metadata declaration.");  
     return;  
   }  
207    
208      return if !$self->buildFieldmapping();
209      return if !$self->_touchNodeSet();
210      return if !$self->_prepare_sync();
211    
212    #return $opts;    # tracing
213    return 1;      #print Dumper($self);
214        #print Dumper($self->{args});
215        #print Dumper($self->{options});
216        #print Dumper($self->{meta});
217        #print Dumper($self->{metadata});
218        #exit;
219    
220      # finally, tell the core to start the synchronization process
221      $self->_run();
222      
223  }  }
224    
225  sub prepareOptionsV2 {  
226    sub _prepareOptions {
227    
228    my $self = shift;    my $self = shift;
229    my $opts = shift;    
230      my $opts = $self->{args};
231    
232    # patch options    # patch options
233        $opts->{source}->{nodeName} ||= '';
234        $opts->{target}->{nodeName} ||= '';
235      $opts->{process}->{mode} ||= '';      $opts->{process}->{mode} ||= '';
     $opts->{process}->{prepare} ||= 0;  
236      $opts->{process}->{erase} ||= 0;      $opts->{process}->{erase} ||= 0;
237        $opts->{process}->{prepare} ||= 0;
238    
239      # defaults (mostly for backward-compatibility to V1 -
240      # but code mungled here out of prepareOptions_V1 from Version::V1)
241        $opts->{metadata}->{syncMethod} ||= 'checksum';                # | timestamp
242        $opts->{source}->{ident} ||= 'storage_method:id';
243        $opts->{source}->{exclude} ||= [qw( cs )];
244        $opts->{target}->{ident} ||= 'property:oid';
245        #$map->{source_node} ||= $source_node_name;
246        #$map->{direction} ||= $opts->{mode};         # | PUSH | PULL | FULL
247    
248    # pre-check options    # pre-check options
249      if (!$self->_preCheckOptions($opts)) {      if (!$self->_preCheckOptions($opts)) {
250        $logger->error( __PACKAGE__ . "->prepareOptionsV2: _preCheckOptions failed.");        $logger->error( __PACKAGE__ . "->_prepareOptions: _preCheckOptions failed.");
251        return;        return;
252      }      }
253    
254    # inform user about option preparation    # inform user about option preparation
255    $logger->notice( __PACKAGE__ . "->prepareOptionsV2( source.node='$opts->{source}->{nodeName}', target.node='$opts->{target}->{nodeName}', mode='$opts->{process}->{mode}', e='$opts->{process}->{erase}', p='$opts->{process}->{prepare}' )");    $logger->debug( __PACKAGE__ . "->_prepareOptions( source.node='$opts->{source}->{nodeName}', target.node='$opts->{target}->{nodeName}', mode='$opts->{process}->{mode}', e='$opts->{process}->{erase}', p='$opts->{process}->{prepare}' )");
256    
257    # try to load mapping-metadata-container    # try to load mapping-metadata-container
258    #my $mapObject = getNewPerlObjectByPkgName($opts->{map}->{moduleName});      # How? Create a new instance of the given
259    my $mapObject = DesignPattern::Object->fromPackage($opts->{map}->{moduleName});      # perl module/package name in ->{...}->{moduleName}.
260        # This instance is used later in the innards of the sync,
261        # that's why the module (class) should have a certain layout
262        # enabling the core to use it for gathering metadata while processing.
263        my $mapObject = DesignPattern::Object->fromPackage($opts->{map}->{moduleName});
264    
265    # try to resolve map from metadata-container    # try to resolve map from metadata-container
266    
# Line 208  sub prepareOptionsV2 { Line 268  sub prepareOptionsV2 {
268      my $source_nodeType = $opts->{source}->{nodeType};      my $source_nodeType = $opts->{source}->{nodeType};
269            
270      # check if mapping for certain node is contained in mapping object      # check if mapping for certain node is contained in mapping object
271      if (!$mapObject->can($source_nodeType)) {      if (!$mapObject || !$mapObject->can($source_nodeType)) {
272        $logger->warning( __PACKAGE__ . "->prepareOptionsV2: Can't access mapping for source-type=\"$source_nodeType\" - please check \"$opts->{map}->{moduleName}\".");        $logger->warning( __PACKAGE__ . "->_prepareOptions: Can't access mapping for source-type=\"$source_nodeType\" - please check \"$opts->{map}->{moduleName}\".");
273        return;        return;
274      }      }
275    
   
276      # get map      # get map
277      my $map = $mapObject->$source_nodeType;      my $map = $mapObject->$source_nodeType;
278      #print Dumper($map);      #print Dumper($map);
279        
280  =pod        my $map_version = $map->{metadata}->{version};
281        # FIXME: backward compatibility
282        if (!$map_version) {
283          $self->options_to_V2($map);
284        }
285    
286        # trace
287          #print Dumper($map);
288          #exit;
289          #print "ref: ", ref $map->{target}, "\n";
290          #print "target: ", $map->{target}, "\n";
291        
292      # check here if "target" is actually a CODEref - in this case: resolve it - deprecated!!! ???      # check here if "target" is actually a CODEref - in this case: resolve it - deprecated!!! ???
293      if (ref $map->{target}->{address} eq 'CODE') {      if (ref $map->{target}->{address} eq 'CODE') {
294        $map->{target}->{address} = $map->{target}->{address}->($source_nodeType);        $map->{target}->{address} = $map->{target}->{address}->($source_nodeType);
295      }      }
296            
297      # resolve expressions (on nodename-level) here      # resolve expressions (on nodename-level) here
298      if ($map->{target}->{address} =~ m/^(code|expr):(.+?)$/) {      elsif ($map->{target}->{address} =~ m/^(code|expr):(.+?)$/) {
299        my $target_dynamic_type = $1;        my $target_dynamic_type = $1;
300        my $target_dynamic_expression = $2;        my $target_dynamic_expression = $2;
301        if (lc $target_dynamic_type eq 'code') {        if (lc $target_dynamic_type eq 'code') {
302          $map->{target} = $mapObject->$target_dynamic_expression($map);          $map->{target} = $mapObject->$target_dynamic_expression($map);
303        }        }
304      }      }
 =cut  
305    
306    #map { $opts->{$_} = $map->{$_}; } keys %$map;    # merging - V1
307    my $opts_merged = merge( $opts, $map );      #map { $opts->{$_} = $map->{$_}; } keys %$map;
308        # trace
309          #print Dumper($self->{options});
310      
311      # merging - V2
312    
313        # merge local map with local opts
314          # enable cloning
315          # FIXME: do we really need cloning here? trade safety/encapsulation for speed?
316          Hash::Merge::set_clone_behavior(1);
317          Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
318          my $locals_merged = merge( $opts, $map );
319    
320        # trace
321          #print Dumper($opts);
322          #print Dumper($map);
323          #print Dumper($locals_merged);
324          #exit;
325    
326        # merge local-merged ones with instance-wide options
327          Hash::Merge::set_clone_behavior(0);
328          $self->{options} = merge( $self->{options}, $locals_merged );
329      
330        # trace
331          #print Dumper($self->{options});
332          #exit;
333      
334    
   $self->{options} = $opts_merged;  
335    $self->{state}->{options_ready} = 1;    $self->{state}->{options_ready} = 1;
336    
337    return 1;    return 1;
# Line 245  sub prepareOptionsV2 { Line 339  sub prepareOptionsV2 {
339  }  }
340    
341    
342  sub configure {  sub _preCheckOptions {
   my $self = shift;  
   my @args = @_;  
   if (!isEmpty(\@args)) {  
     my %properties = @_;  
     # merge args to properties  
     map { $self->{$_} = $properties{$_}; } keys %properties;  
     $self->_init();  
     $self->_initV1();  
   } else {  
     #print "no args!", "\n";  
   }  
   #print Dumper($self);  
   $self->{state}->{configured} = 1;  
   return 1;  
 }  
343    
 sub configureV2 {  
344    my $self = shift;    my $self = shift;
345    my @args = @_;    my $opts = shift;
   if (!isEmpty(\@args)) {  
     my %properties = @_;  
     # merge args to properties  
     #map { $self->{$_} = $properties{$_}; } keys %properties;  
     $self->{options} = merge($self->{options}, \%properties);  
     $self->_init();  
     #$self->_initV1();  
   } else {  
     #print "no args!", "\n";  
   }  
   
 #print Dumper($self);  
   
   $self->{state}->{configured} = 1;  
   return 1;  
 }  
346    
347  sub _getDirectedArrow {    # trace
348    my $self = shift;      #print Dumper($opts);
349    my $mode = shift;      #exit;
350    $mode ||= '';      
351        if (!$opts->{process}->{mode}) {
352    if (lc $mode eq 'push') {      $logger->error( __PACKAGE__ . "->_preCheckOptions failed: Please specify \"--action=(load|save)\".");
353      return '->';      return;
   } elsif (lc $mode eq 'pull') {  
     return '<-';  
   } elsif (lc $mode eq 'full') {  
     return '<->';  
   } else {  
     return '';  
354    }    }
 }  
   
 # TODO: some feature to show off the progress of synchronization (cur/max * 100)  
 sub syncNodes {  
   
   my $self = shift;  
   my $args = shift;  
355    
356    if (!$self->{state}->{configured}) {    # the type of the to-be-synced item
357      $logger->critical( __PACKAGE__ . "->syncNodes: Synchronization object is not configured/initialized correctly." );    if (!$opts->{source}->{nodeType}) {
358        $logger->error( __PACKAGE__ . "->_preCheckOptions failed: Please specify \"source-type\".");
359      return;      return;
360    }    }
361      # the name of the (container-) node the items are listed in
362    # remember arguments through the whole processing    if (!$opts->{source}->{nodeName}) {
363    $self->{args} = $args;      $logger->error( __PACKAGE__ . "->_preCheckOptions failed: Please specify \"source-node\".");
364        return;
   $logger->debug( __PACKAGE__ . "->syncNodes: starting" );  
   
   # hash to hold and/or fill in metadata required for the processing  
   $self->{meta} = {};  
     
   # hash to sum up results  
   # TODO: re-implement! (sync-statistics???)  
   
   # detect synchronization method to determine which optical symbol (directed arrow) to use  
   my $mode = $self->{args}->{mode};   # V1  
   $mode ||= $self->{options}->{process}->{mode};    # V2  
   my $direction_arrow = $self->_getDirectedArrow($mode);  
   
   if (!$self->{options}->{metadata}->{version} || $self->{options}->{metadata}->{version} < 0.2) {  
     $self->_buildMetadataV1();  
   } else {  
     $self->_buildMetadataV2();  
365    }    }
366    
367    $logger->info( __PACKAGE__ . "->syncNodes: source=$self->{meta}->{source}->{dbKey}/$self->{meta}->{source}->{nodeName} [$self->{meta}->{source}->{nodeType}] $direction_arrow target=$self->{meta}->{target}->{dbKey}/$self->{meta}->{target}->{nodeName} [$self->{meta}->{target}->{nodeType}]" );    # a "map"-declaration which module to use for mapping- and/or lookup-purposes
368      if (!$opts->{map}) {
369    return if !$self->_buildFieldmappingV1();      $logger->warning( __PACKAGE__ . "->_preCheckOptions: No mapping supplied - please check key 'map|mappings' in global configuration or specify additional argument '--mapping-module'.");
370    return if !$self->_handleNodeContainers();      return;
371    return if !$self->_prepareSync();    }
372      if (!$opts->{map}->{moduleName}) {
373        $logger->warning( __PACKAGE__ . "->_preCheckOptions: Currently only perl-modules can provide mappings: Please specify one with '--mapping-module=My::Mapping::Module'.");
374        return;
375      }
376    
377  #print Dumper($self);    return 1;
 #print Dumper($self->{args});  
 #print Dumper($self->{options});  
 #print Dumper($self->{meta});  
 #print Dumper($self->{metadata});  
378    
   $self->_syncNodes();  
     
379  }  }
380    
381    
 sub _handleNodeContainers {  
   my $self = shift;  
   
   # check partners/nodes: does partner exist / is node available?  
   foreach my $partner (keys %{$self->{meta}}) {  
       
     # 1. check partners & storages  
     if (!$self->{meta}->{$partner}) {  
       $logger->critical( __PACKAGE__ . "->_handleNodeContainers: Could not find partner '$partner' in configuration metadata." );  
       next;  
     }  
   
     my $dbkey = $self->{meta}->{$partner}->{dbKey};  
   
 #print Dumper($self->{meta});  
   
     if (!$self->{meta}->{$partner}->{storage}) {  
       $logger->critical( __PACKAGE__ . "->_handleNodeContainers: Could not access storage ( partner='$partner', dbKey='$dbkey' ) - configuration-error?" );  
       next;  
     }  
       
     # TODO:  
     # 2. check if partners (and nodes?) are actually available....  
     # eventually pre-check mode of access-attempt (read/write) here to provide an "early-croak" if possible  
       
 #    print Dumper($self->{meta}->{$partner}->{storage}->{locator});  
     
     my $dbType = $self->{meta}->{$partner}->{storage}->{locator}->{type};  
 #print "dbType: $dbType", "\n";  
       
     # 3. check nodes  
     next if $dbType eq 'DBI';    # HACK for DBD::CSV - re-enable for others  
     # get node-name  
 #      print Dumper($self);  
     #print Dumper($self->{meta}->{$partner});  
     #print "öö", $self->{meta}->{$partner}->{node}, "\n";  
     my $nodename = $self->{meta}->{$partner}->{node};   # V1  
     $nodename ||= $self->{meta}->{$partner}->{nodeName};    # V2  
     # check if nodename is actually a CODEref, execute it to get a mapped/filtered target-nodename  
   
 #print "nodename: $nodename", "\n";  
   
     $logger->debug( __PACKAGE__ . "->_handleNodeContainers: Accessing dbType=\"$dbType\", nodename=\"$nodename\"." );  
       
 =pod  
     #print "----", ref $nodename, "\n";  
     if ($nodename =~ m/CODE/) {  
       print Dumper($self);  
       #exit;  
       $nodename = $nodename->($nodename);  
     }  
 =cut      
   
 #print Dumper($self);  
       
     #print "partner: $partner - nodename: $nodename", "\n";  
       
     if (!$self->{meta}->{$partner}->{storage}->existsChildNode($nodename)) {  
 #print "ex", "\n";  
 #exit;  
   
       if ($partner eq 'target' && $self->{options}->{target}->{autocreateFolders}) {  
         if (!$self->{meta}->{$partner}->{storage}->createChildNode($nodename)) {  
           $logger->critical( __PACKAGE__ . "->_handleNodeContainers: Could not create node '$self->{meta}->{$partner}->{nodeName}\@$self->{meta}->{$partner}->{dbKey}' [$self->{meta}->{$partner}->{nodeType}]." );  
           next;  
         }  
       } else {  
         $logger->critical( __PACKAGE__ . "->_handleNodeContainers: Could not reach node \"$nodename\" at partner \"$partner\"." );  
         next;  
       }  
     }  
       
   }  
     
   return 1;  
   
 }  
382    
383    sub _prepare_sync {
384    
 sub _prepareSync {  
385    my $self = shift;    my $self = shift;
386    
387    # TODO:    # TODO:
# Line 435  sub _prepareSync { Line 389  sub _prepareSync {
389    #  -+  if action == PULL: swap metadata and start processing    #  -+  if action == PULL: swap metadata and start processing
390    #   -  if action == FULL: start processing, then swap metadata and (re-)start processing    #   -  if action == FULL: start processing, then swap metadata and (re-)start processing
391    
392      #print "dir: ", $self->{args}->{direction}, "\n";
393    
394    # manipulate metainfo according to direction of synchronization    # manipulate metainfo according to direction of synchronization
395    if (lc $self->{args}->{direction} eq 'push') {    if (lc $self->{options}->{process}->{mode} eq 'push') {
396      # just do it ...      # just do it ...    (don't modify any metadata)
397    } elsif (lc $self->{args}->{direction} eq 'pull') {    
398      #print "=======SWAP", "\n";    } elsif (lc $self->{options}->{process}->{mode} eq 'pull') {
399      # swap      # swap source and target metadata
400        # TODO: introduce different mechanism to make more then two partners (descents) possible
401      ($self->{meta}->{source}, $self->{meta}->{target}) =      ($self->{meta}->{source}, $self->{meta}->{target}) =
402          ($self->{meta}->{target}, $self->{meta}->{source});          ($self->{meta}->{target}, $self->{meta}->{source});
403    } elsif (lc $self->{args}->{direction} eq 'full') {    
404      } elsif (lc $self->{options}->{process}->{mode} eq 'full') {
405        # TODO:
406        # do a pull first and a push afterwards
407        # this requires us to be called somehow recursively - just one recursion level  ;-)
408      
409    } else {    } else {
410        # TODO: are there any other synchronization modes besides PULL, PUSH, FULL?
411      
412    }    }
413    
414    # import flag means: prepare the source node to be syncable    # import flag means: prepare the source node to be syncable
# Line 468  sub _prepareSync { Line 432  sub _prepareSync {
432    
433  }  }
434    
435    sub _getDirectedArrow {
436      my $self = shift;
437      my $mode = shift;
438      $mode ||= '';
439      
440      if (lc $mode eq 'push') {
441        return '->';
442      } elsif (lc $mode eq 'pull') {
443        return '<-';
444      } elsif (lc $mode eq 'full') {
445        return '<->';
446      } else {
447        return '';
448      }
449    }
450    
451  1;  1;

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed