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

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

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

revision 1.4 by joko, Sun Feb 9 05:01:10 2003 UTC revision 1.11 by jonen, Tue May 11 20:03:48 2004 UTC
# Line 1  Line 1 
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 pod text below for usage and distribution rights.
8  ##  ##
9  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
10  ##    $Log$  ##    $Log$
11    ##    Revision 1.11  2004/05/11 20:03:48  jonen
12    ##    bugfix[joko] related to Attribute Map
13    ##
14    ##    Revision 1.10  2003/06/25 23:03:57  joko
15    ##    no debugging
16    ##
17    ##    Revision 1.9  2003/05/13 08:17:52  joko
18    ##    buildAttributeMap now propagates error
19    ##
20    ##    Revision 1.8  2003/03/27 15:31:15  joko
21    ##    fixes to modules regarding new namespace(s) below Data::Mungle::*
22    ##
23    ##    Revision 1.7  2003/02/21 08:01:11  joko
24    ##    debugging, logging
25    ##    renamed module
26    ##
27    ##    Revision 1.6  2003/02/14 14:03:49  joko
28    ##    + logging, debugging
29    ##    - refactored code to sister module
30    ##
31    ##    Revision 1.5  2003/02/11 05:30:47  joko
32    ##    + minor fixes and some debugging mud
33    ##
34  ##    Revision 1.4  2003/02/09 05:01:10  joko  ##    Revision 1.4  2003/02/09 05:01:10  joko
35  ##    + major structure changes  ##    + major structure changes
36  ##    - refactored code to sister modules  ##    - refactored code to sister modules
# Line 52  Line 77 
77  ##    + minor cosmetics for logging  ##    + minor cosmetics for logging
78  ##  ##
79  ##    Revision 1.2  2002/12/01 04:43:25  joko  ##    Revision 1.2  2002/12/01 04:43:25  joko
80  ##    + mapping deatil entries may now be either an ARRAY or a HASH  ##    + mapping detail entries may now be either an ARRAY or a HASH
81  ##    + erase flag is used now (for export-operations)  ##    + erase flag is used now (for export-operations)
82  ##    + expressions to refer to values inside deep nested structures  ##    + expressions to refer to values inside deep nested structures
83  ##    - removed old mappingV2-code  ##    - removed old mappingV2-code
# Line 64  Line 89 
89  ##  ##
90  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko  ##    Revision 1.1  2002/10/10 03:44:21  cvsjoko
91  ##    + new  ##    + new
92  ##    ----------------------------------------------------------------------------------------  ## -------------------------------------------------------------------------
93    
94    
95  package Data::Transfer::Sync::Core;  package Data::Transfer::Sync::Core;
# Line 79  use mixin::with qw( Data::Transfer::Sync Line 104  use mixin::with qw( Data::Transfer::Sync
104    
105  use Data::Dumper;  use Data::Dumper;
106    
107  use misc::HashExt;  #use misc::HashExt;
108  use Data::Compare::Struct qw( getDifference isEmpty );  use Hash::Serializer;
109    use Data::Mungle::Compare::Struct qw( getDifference isEmpty );
110    use Data::Mungle::Transform::Deep qw( deep_copy expand );
111  use Data::Storage::Container;  use Data::Storage::Container;
112  use DesignPattern::Object;  use DesignPattern::Object;
113    use shortcuts::database qw( quotesql );
114    
115  # get logger instance  # get logger instance
116  my $logger = Log::Dispatch::Config->instance;  my $logger = Log::Dispatch::Config->instance;
# Line 113  sub _init { Line 141  sub _init {
141      $self->{container}->addStorage($_, $self->{storages}->{$_});      $self->{container}->addStorage($_, $self->{storages}->{$_});
142    }    }
143        
144      # trace
145        #print Dumper($self);
146        #exit;
147    
148    return 1;    return 1;
149        
150  }  }
# Line 140  sub _run { Line 172  sub _run {
172    $logger->debug( __PACKAGE__ . "->_run" );    $logger->debug( __PACKAGE__ . "->_run" );
173    
174    # for statistics    # for statistics
175    my $tc = OneLineDumpHash->new( {} );    my $tc = Hash::Serializer->new( {} );
176    my $results;    my $results;
177        
178    # set of objects is already in $self->{args}    # set of objects is already in $self->{args}
# Line 163  sub _run { Line 195  sub _run {
195      return;      return;
196    }    }
197    
198      #print Dumper(@$results);
199      #exit;
200    
201    # check if we actually *have* a synchronization method    # check if we actually *have* a synchronization method
202    if (!$self->{options}->{metadata}->{syncMethod}) {    if (!$self->{options}->{metadata}->{syncMethod}) {
# Line 174  sub _run { Line 207  sub _run {
207        
208    # dereference    # dereference
209    my @results = @{$results};    my @results = @{$results};
210      #print Dumper(@results);
211    
212    # iterate through set    # iterate through set
213    foreach my $source_node_real (@results) {    foreach my $source_node_real (@results) {
214    
215        print ":" if $self->{verbose};
216    
217        #print Dumper($source_node_real);
218    
219      $tc->{total}++;      $tc->{total}++;
220    
221  #print "========================  iter", "\n";  #print "========================  iter", "\n";
# Line 187  sub _run { Line 225  sub _run {
225      #   - is a "deep_copy" needed here if occouring modifications take place?      #   - is a "deep_copy" needed here if occouring modifications take place?
226      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?      #   - puuhhhh, i guess a deep_copy would destroy tangram mechanisms?
227      #   - after all, just take care for now that this object doesn't get updated!      #   - after all, just take care for now that this object doesn't get updated!
228        #   - so, just use its reference for now - if some cloning is needed in future, do this here!
229      my $source_node = $source_node_real;      my $source_node = $source_node_real;
230        #my $source_node = expand($source_node_real);
231    
232      # modify entry - handle new style callbacks (the readers)      # modify entry - handle new style callbacks (the readers)
233  #print Dumper($source_node);  
234  #exit;      # trace
235        #print Dumper($source_node);
236        #exit;
237    
238      my $descent = 'source';      my $descent = 'source';
239    
# Line 199  sub _run { Line 241  sub _run {
241      my $map_callbacks = {};      my $map_callbacks = {};
242      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {      if (my $callbacks = $self->{meta}->{$descent}->{Callback}) {
243    
244          # trace
245            #print Dumper($callbacks);
246            #exit;
247    
248        my $error = 0;        my $error = 0;
249    
250        foreach my $node (keys %{$callbacks->{read}}) {        foreach my $node (keys %{$callbacks->{read}}) {
251                    
252            #print "cb_node: $node", "\n";
253            
254          my $object = $source_node;          my $object = $source_node;
255          my $value; # = $source_node->{$node};          my $value; # = $source_node->{$node};
256    
257          # trace
258            #print Dumper($self->{options});
259    
260          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
261          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';          #my $perl_callback = $self->{meta}->{$descent}->{node} . '::' . $node . '_read';
262          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';          my $perl_callback = $self->{meta}->{$descent}->{nodeType} . '::' . $node . '_read';
# Line 213  sub _run { Line 264  sub _run {
264          #print $evalstring, "\n"; exit;          #print $evalstring, "\n"; exit;
265          my $cb_result = eval($evalstring);          my $cb_result = eval($evalstring);
266          if ($@) {          if ($@) {
           die $@;  
267            $error = 1;            $error = 1;
268            print $@, "\n";            $logger->error( __PACKAGE__ . "->_run: $@" );
269              next;
270          }          }
271          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)          # ------------  half-redundant: make $self->callCallback($object, $value, $opts)
272                    
# Line 225  sub _run { Line 276  sub _run {
276    
277      }      }
278    
279  #print Dumper($source_node);      # trace
280          #print Dumper($source_node);
281    
282      # exclude defined fields  (simply delete from object)      # exclude defined fields  (simply delete from object)
283      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};      map { delete $source_node->{$_} } @{$self->{meta}->{source}->{subnodes_exclude}};
# Line 234  sub _run { Line 286  sub _run {
286      $self->{node} = {};      $self->{node} = {};
287      $self->{node}->{source}->{payload} = $source_node;      $self->{node}->{source}->{payload} = $source_node;
288    
289  #print "res - ident", "\n";      # trace
290          #print Dumper($self->{node});
291          #exit;
292    
293      # determine ident of entry      # determine ident of entry
294      my $identOK = $self->_resolveNodeIdent('source');      my $identOK = $self->_resolveNodeIdent('source');
# Line 256  sub _run { Line 310  sub _run {
310    
311  #print "checksum", "\n";  #print "checksum", "\n";
312            
     print ":" if $self->{verbose};  
   
313      #print Dumper($self);      #print Dumper($self);
314            
315      # determine status of entry by synchronization method      # determine status of entry by synchronization method
# Line 290  sub _run { Line 342  sub _run {
342        # determine if entry is "new" or "dirty"        # determine if entry is "new" or "dirty"
343        # after all, this seems to be the point where the hammer falls.....        # after all, this seems to be the point where the hammer falls.....
344        print "c" if $self->{verbose};        print "c" if $self->{verbose};
345  #print Dumper($self->{node});  
346  #exit;        # trace
347            #print Dumper($self->{node});
348            #exit;
349    
350        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};        $self->{node}->{status}->{new} = !$self->{node}->{target}->{checksum};
351        if (!$self->{node}->{status}->{new}) {        if (!$self->{node}->{status}->{new}) {
352          $self->{node}->{status}->{dirty} =          $self->{node}->{status}->{dirty} =
# Line 306  sub _run { Line 361  sub _run {
361        $tc->{skip}++;        $tc->{skip}++;
362        print "s" if $self->{verbose};        print "s" if $self->{verbose};
363        next;        next;
         
364      }      }
365    
366      # first reaction on entry-status: continue with next entry if the current is already "in sync"      # first reaction on entry-status: continue with next entry if the current is already "in sync"
# Line 315  sub _run { Line 369  sub _run {
369        next;        next;
370      }      }
371    
372      # build map to actually transfer the data from source to target      #print Dumper($self->{node}->{source});
     $self->buildAttributeMap();  
   
373    
374  #print Dumper($self->{node}); exit;      # build map to actually transfer the data from source to target
375        if (!$self->buildAttributeMap()) {
376          #$logger->warning( __PACKAGE__ . "->_run: Attribute Map could not be created. Will not insert or modify node.");
377          push( @{$tc->{error_per_row}}, "Attribute Map could not be created. Will not insert or modify node $self->{node}->{source}->{ident}.");
378          #push( @{$tc->{error_per_row}}, "Attribute Map could not be created. Will not insert or modify node " . Dumper($self->{node}->{source}) . ".");
379          $tc->{error}++;
380          print "e" if $self->{verbose};
381          next;
382        }
383    
384  #print "attempt", "\n";      # trace
385          #print Dumper($self->{node}); exit;
386          #print "attempt", "\n";
387    
388      # additional (new) checks for feature "write-protection"      # additional (new) checks for feature "write-protection"
389      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {      if ($self->{meta}->{target}->{storage}->{isWriteProtected}) {
# Line 334  sub _run { Line 396  sub _run {
396        next;        next;
397      }      }
398    
399  #print Dumper($self);      # trace
400  #exit;        #print Dumper($self);
401          #exit;
402    
403      # transfer contents of map to target      # transfer contents of map to target
404      if ($self->{node}->{status}->{new}) {      if ($self->{node}->{status}->{new}) {
# Line 371  sub _run { Line 434  sub _run {
434            
435      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority      # change ident in source (take from target), if transfer was ok and target is an IdentAuthority
436      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing      # this is (for now) called a "retransmit" indicated by a "r"-character when verbosing
437      if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {      #if ($self->{node}->{status}->{ok} && $self->{options}->{target}->{storage}->{idAuthority}) {
438        if ($self->{node}->{status}->{ok} && $self->{meta}->{target}->{isIdentAuthority}) {
439        print "r" if $self->{verbose};        print "r" if $self->{verbose};
440        #print Dumper($self->{meta});        #print Dumper($self->{meta});
441        #print Dumper($self->{node});        #print Dumper($self->{node});
# Line 379  sub _run { Line 443  sub _run {
443        $self->_doModifySource_IdentChecksum($self->{node}->{target}->{ident});        $self->_doModifySource_IdentChecksum($self->{node}->{target}->{ident});
444      }      }
445    
446        #print "UNLOAD", "\n";
447        #$self->{meta}->{source}->{storage}->unload( $self->{node}->{source}->{payload} );
448    
449    }    }
450    
451    print "\n" if $self->{verbose};    print "\n" if $self->{verbose};
# Line 394  sub _run { Line 461  sub _run {
461            
462      # todo!!!      # todo!!!
463      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );      #sysevent( { usermsg => $msg, level => $level }, $taskEvent );
464      $logger->info( __PACKAGE__ . "->_run: $msg" );      #$logger->info( __PACKAGE__ . "->_run: $msg" );
465        $logger->info($msg . "\n");
466    
467    return $tc;    return $tc;
468    
# Line 449  sub _dumpCompact { Line 517  sub _dumpCompact {
517  sub _doTransferToTarget {  sub _doTransferToTarget {
518    my $self = shift;    my $self = shift;
519    my $action = shift;    my $action = shift;
520    #print Dumper($self->{node});      
521    #exit;    # trace
522        #print Dumper($self->{meta});
523        #print Dumper($self->{node});
524        #exit;
525        
526    $self->_modifyNode('target', $action, $self->{node}->{map});    $self->_modifyNode('target', $action, $self->{node}->{map});
527  }  }
528    
# Line 551  sub _prepareNode_DummyIdent { Line 623  sub _prepareNode_DummyIdent {
623      $i++;      $i++;
624    }    }
625    
626    print "\n" if $self->{verbose};    #print "\n" if $self->{verbose};
627        
628    if (!$i) {    if (!$i) {
629      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );      $logger->warning( __PACKAGE__ . "->_prepareNode_DummyIdent: no nodes touched" );
# Line 568  sub _otherSide { Line 640  sub _otherSide {
640    return '';    return '';
641  }  }
642    
 sub _erase_all {  
   my $self = shift;  
   my $descent = shift;  
   #my $node = shift;  
   my $node = $self->{meta}->{$descent}->{node};  
   $self->{meta}->{$descent}->{storage}->eraseAll($node);  
 }  
643    
644  1;  1;
645    __END__

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

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