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

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

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

revision 1.1 by joko, Mon Jan 20 16:58:46 2003 UTC revision 1.7 by joko, Tue May 13 08:13:25 2003 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 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
29    ##    + major structure changes
30    ##    - refactored code to sister modules
31    ##
32  ##    Revision 1.1  2003/01/20 16:58:46  joko  ##    Revision 1.1  2003/01/20 16:58:46  joko
33  ##    + initial check-in: here they are....  ##    + initial check-in: here they are....
34  ##  ##
# Line 23  use warnings; Line 46  use warnings;
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;  
   
   
 sub _preCheckOptions {  
   
   my $self = shift;  
   my $opts = shift;  
   
 #print Dumper($opts);  
 #exit;  
   
   # the type of the to-be-synced item  
   if (!$opts->{source}->{nodeType}) {  
     $logger->error( __PACKAGE__ . "->_preCheckOptions failed: Please specify \"source-type\".");  
     return;  
   }  
   # the name of the (container-) node the items are listed in  
   if (!$opts->{source}->{nodeName}) {  
     $logger->error( __PACKAGE__ . "->_preCheckOptions failed: Please specify \"source-node\".");  
     return;  
   }  
   
   # a "map"-declaration which module to use for mapping- and/or lookup-purposes  
   if (!$opts->{map}) {  
     $logger->warning( __PACKAGE__ . "->_preCheckOptions: No mapping supplied - please check key 'map|mappings' in global configuration or specify additional argument '--mapping-module'.");  
     return;  
   }  
   if (!$opts->{map}->{moduleName}) {  
     $logger->warning( __PACKAGE__ . "->_preCheckOptions: Currently only perl-modules can provide mappings: Please specify one with '--mapping-module'.");  
     return;  
   }  
   
   return 1;  
   
 }  
   
 # TODO: refactor!!! take this list from already established/given metadata  
 sub _buildMetadataV1 {  
   my $self = shift;  
   
   # decompose identifiers for each partner  
   foreach ('source', 'target') {  
       
     # get/set metadata for further processing  
   
     # Partner and Node (e.g.: "L:Country" or "R:countries.csv")  
     if (my $item = $self->{args}->{$_}) {  
       my @item = split(':', $item);  
       $self->{meta}->{$_}->{dbkey} = $item[0];  
       $self->{meta}->{$_}->{node} = $item[1];  
     }  
       
     # Filter  
     if (my $item_filter = $self->{args}->{$_ . '_filter'}) {  
       $self->{meta}->{$_}->{filter} = $item_filter;  
     }  
   
     # IdentProvider  
     if (my $item_ident = $self->{args}->{$_ . '_ident'}) {  
       my @item_ident = split(':', $item_ident);  
       $self->{meta}->{$_}->{IdentProvider} = { method => $item_ident[0], arg => $item_ident[1] };  
     }  
   
 #print Dumper($self->{meta});  
   
     # TODO: ChecksumProvider  
   
     # exclude properties/subnodes  
     if (my $item_exclude = $self->{args}->{$_ . '_exclude'}) {  
       $self->{meta}->{$_}->{subnodes_exclude} = $item_exclude;  
     }  
       
     # TypeProvider  
     if (my $item_type = $self->{args}->{$_ . '_type'}) {  
       my @item_type = split(':', $item_type);  
       $self->{meta}->{$_}->{TypeProvider} = { method => $item_type[0], arg => $item_type[1] };  
     }  
       
     # Callbacks - writers (will be triggered _before_ writing to target)  
     if (my $item_writers = $self->{args}->{$_ . '_callbacks_write'}) {  
       my $descent = $_;     # this is important since the following code inside the map wants to use its own context variables  
       map { $self->{meta}->{$descent}->{Callback}->{write}->{$_}++; } @$item_writers;  
     }  
       
     # Callbacks - readers (will be triggered _after_ reading from source)  
     if (my $item_readers = $self->{args}->{$_ . '_callbacks_read'}) {  
       my $descent = $_;  
       map { $self->{meta}->{$descent}->{Callback}->{read}->{$_}++; } @$item_readers;  
     }  
       
     # resolve storage objects  
     #$self->{$_} = $self->{container}->{storage}->{$self->{meta}->{$_}->{dbkey}};  
     # relink references to metainfo  
     $self->{meta}->{$_}->{storage} = $self->{container}->{storage}->{$self->{meta}->{$_}->{dbkey}};  
     #print "iiiiisprov: ", Dumper($self->{meta}->{$_}->{storage}), "\n";  
   }  
   
 }  
   
   
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 _buildMetadataV2 {  sub options2metadata {
57    my $self = shift;    my $self = shift;
58    
59  #print Dumper($self->{options});    $logger->debug( __PACKAGE__ . "->transformMetadata" );
60    
61      # trace
62        #print Dumper($self->{options});
63        #print Dumper($self->{args_raw});
64        #exit;
65    
66    # decompose identifiers for each partner    # decompose identifiers and write to metadata (for each descent)
67    foreach ('source', 'target') {    foreach ('source', 'target') {
68            
69      # get/set metadata for further processing      # get/set metadata for further processing
# Line 144  sub _buildMetadataV2 { Line 72  sub _buildMetadataV2 {
72      $self->{options}->{$_}->{nodeType} ||= '';      $self->{options}->{$_}->{nodeType} ||= '';
73      $self->{options}->{$_}->{nodeName} ||= '';      $self->{options}->{$_}->{nodeName} ||= '';
74    
75      # Partner and Node (e.g.: "L:Country" or "R:countries.csv")      # Partner and Node (compare the V1-notations: "L:Country" or "R:countries.csv")
76      $self->{meta}->{$_}->{dbKey} = $self->{options}->{$_}->{dbKey};      $self->{meta}->{$_}->{dbKey} = $self->{options}->{$_}->{dbKey};
77      $self->{meta}->{$_}->{nodeType} = $self->{options}->{$_}->{nodeType};      $self->{meta}->{$_}->{nodeType} = $self->{options}->{$_}->{nodeType};
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    
# Line 161  sub _buildMetadataV2 { Line 89  sub _buildMetadataV2 {
89      }      }
90    
91      # TODO: ChecksumProvider      # TODO: ChecksumProvider
92        # already inside {options} - get it out from there and put into {meta} here!
93    
94      # exclude properties/subnodes      # exclude properties/subnodes
95      if (my $item_exclude = $self->{options}->{$_}->{exclude}) {      if (my $item_exclude = $self->{options}->{$_}->{exclude}) {
# Line 168  sub _buildMetadataV2 { Line 97  sub _buildMetadataV2 {
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});
# Line 195  sub _buildMetadataV2 { Line 140  sub _buildMetadataV2 {
140  }  }
141    
142    
143  sub _buildFieldmappingV1 {  sub options2metadata_accessor {
144    my $self = shift;    my $self = shift;
145    
146    # build mapping    $logger->debug( __PACKAGE__ . "->_transformMetadata_accessor" );
   # incoming: and Array of node map entries (Array or Hash) - e.g.  
   #   [ 'source:item_name' => 'target:class_val' ]  
   #   { source => 'event->startDateTime', target => 'begindate' }  
   foreach (@{$self->{args}->{mapping}}) {  
     if (ref $_ eq 'ARRAY') {  
       my @entry1 = split(':', $_->[0]);  
       my @entry2 = split(':', $_->[1]);  
       my $descent = [];  
       my $node = [];  
       $descent->[0] = $entry1[0];  
       $descent->[1] = $entry2[0];  
       $node->[0] = $entry1[1];  
       $node->[1] = $entry2[1];  
       push @{$self->{meta}->{$descent->[0]}->{childnodes}}, $node->[0];  
       push @{$self->{meta}->{$descent->[1]}->{childnodes}}, $node->[1];  
     } elsif (ref $_ eq 'HASH') {  
       foreach my $entry_key (keys %$_) {  
         my $entry_val = $_->{$entry_key};  
         push @{$self->{meta}->{$entry_key}->{childnodes}}, $entry_val;  
       }  
     }  
147    
148    }    # build accessor metadata (for each descent)
149      foreach my $descent ('source', 'target') {
150    
151    return 1;        # the database type plays a role here to handle special nodesets:
152          # there may be a) childless/non-strict nodesets (e.g. a CSV-file)
153          # or b) normal ones - here the node-name corresponds more or less directly to
154          # the physical location in the storage hierarchy below us (e.g. MAPI or LDAP)
155          # or c) sets of nodes which are physically mapped by node-type (e.g. a RDBMS or a ODBMS)
156          my $dbType = $self->{meta}->{$descent}->{storage}->{locator}->{type};
157          
158            # a, b and c are "accessor-type"s (of 'none', 'node-name', 'node-type')
159            # the following code resolves these types to '$accessorType'
160            # and properly sets '$accessorName'
161    
162            # don't continue for certain storage handlers
163              # HACK for DBD::CSV - re-enable for other DBDs
164              #next if $dbType eq 'DBI';
165      
166            # get nodename
167    
168              # get node-name
169                my $nodename = $self->{meta}->{$descent}->{node};   # V1
170                $nodename ||= $self->{meta}->{$descent}->{nodeName};    # V2
171    
172              # check if nodename is actually a CODEref, execute it to get a mapped/filtered target-nodename
173                #print "----", ref $nodename, "\n";
174                #if ($nodename =~ m/CODE/) {
175                #  print Dumper($self);
176                #  #exit;
177                #  $nodename = $nodename->($nodename);
178                #}
179    
180            # determine nodeset accessor -type and -name
181              # defaults
182              my $accessorType = 'none';
183              my $accessorName = '';
184              
185              # if explicit address was given in options, just use it!
186              if (my $address = $self->{options}->{$descent}->{address}) {
187                $accessorType = 'direct-address';
188                $accessorName = $address;
189              }
190              
191              # c)
192              elsif (($dbType eq 'DBI' || $dbType eq 'Tangram') && $self->{meta}->{$descent}->{nodeType}) {
193                $accessorType = 'node-type';
194                $accessorName = $self->{meta}->{$descent}->{nodeType};
195              }
196    
197              # b)
198              elsif ($nodename) {
199                $accessorType = 'node-name';
200                $accessorName = $nodename;
201              }
202    
203          # write accessor information to metadata
204          $self->{meta}->{$descent}->{accessorType} = $accessorType;
205          $self->{meta}->{$descent}->{accessorName} = $accessorName;
206        
207        }
208    
209      # trace
210        #print Dumper($self->{meta});
211        #print Dumper($self->{options});
212        #exit;
213    
214  }  }
215    
216    
217  1;  1;
218    __END__

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.7

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