--- nfo/perl/libs/Data/Transfer/Sync/Metadata.pm 2003/02/09 05:02:05 1.2 +++ nfo/perl/libs/Data/Transfer/Sync/Metadata.pm 2003/05/13 08:13:25 1.7 @@ -1,11 +1,30 @@ -## $Id: Metadata.pm,v 1.2 2003/02/09 05:02:05 joko Exp $ +## ------------------------------------------------------------------------- +## +## $Id: Metadata.pm,v 1.7 2003/05/13 08:13:25 joko Exp $ ## ## Copyright (c) 2002 Andreas Motl ## -## See COPYRIGHT section in pod text below for usage and distribution rights. +## See COPYRIGHT section in associated pod text +## or below for usage and distribution rights. ## -## ---------------------------------------------------------------------------------------- +## ------------------------------------------------------------------------- ## $Log: Metadata.pm,v $ +## Revision 1.7 2003/05/13 08:13:25 joko +## moved "sub buildAttributeMap" to Map.pm +## +## Revision 1.6 2003/03/28 03:08:17 joko +## fix regarding namespace update +## +## Revision 1.5 2003/02/21 08:34:58 joko +## modified object hierarchy +## renamed method +## +## Revision 1.4 2003/02/14 14:06:20 joko +## + minor fix to old metadata structure +## +## Revision 1.3 2003/02/11 06:28:24 joko +## + changes to metadata structure +## ## Revision 1.2 2003/02/09 05:02:05 joko ## + major structure changes ## - refactored code to sister modules @@ -27,15 +46,11 @@ use mixin::with qw( Data::Transfer::Sync ); -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main +use Data::Dumper; # get logger instance my $logger = Log::Dispatch::Config->instance; -use Data::Dumper; - - - # TODO: refactor (still)!!! take this list from already established/given metadata .... # .... also internally: passing around and mungling these metadata doesn't make sense anymore. sub options2metadata { @@ -43,7 +58,10 @@ $logger->debug( __PACKAGE__ . "->transformMetadata" ); -#print Dumper($self->{options}); + # trace + #print Dumper($self->{options}); + #print Dumper($self->{args_raw}); + #exit; # decompose identifiers and write to metadata (for each descent) foreach ('source', 'target') { @@ -60,7 +78,7 @@ $self->{meta}->{$_}->{nodeName} = $self->{options}->{$_}->{nodeName}; # Filter - if (my $item_filter = $self->{args}->{$_ . '_filter'}) { + if (my $item_filter = $self->{options}->{$_}->{filter}) { $self->{meta}->{$_}->{filter} = $item_filter; } @@ -79,25 +97,41 @@ } # TypeProvider - if (my $item_type = $self->{args}->{$_ . '_type'}) { + # FIXME! this is still Vdeprecated!!! + if (my $item_type = $self->{options}->{$_ . '_type'}) { my @item_type = split(':', $item_type); $self->{meta}->{$_}->{TypeProvider} = { method => $item_type[0], arg => $item_type[1] }; } + + # trace + #print Dumper($self); + #exit; # Callbacks - writers (will be triggered _before_ writing to target) - if (my $item_writers = $self->{args}->{$_ . '_callbacks_write'}) { + if (my $item_writers = $self->{options}->{$_}->{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'}) { + if (my $item_readers = $self->{options}->{$_}->{callbacks}->{read}) { my $descent = $_; map { $self->{meta}->{$descent}->{Callback}->{read}->{$_}++; } @$item_readers; } - # resolve storage objects - $self->{meta}->{$_}->{storage} = $self->{options}->{$_}->{storage}->{handle}; + # resolve storage handles + $self->{meta}->{$_}->{storage} = $self->{options}->{$_}->{storage}->{handle}; + + # transfer storage handle options to metadata + #map { $self->{meta}->{$_}->{isIdentAuthority} = 1 } @{$self->{id_authorities}}; + #map { $self->{meta}->{$_}->{isChecksumAuthority} = 1; } @{$self->{checksum_authorities}}; + #map { $self->{meta}->{$_}->{isWriteProtected} = 1; } @{$self->{write_protected}}; + #print Dumper($self->{options}->{$_}); + #exit; + $self->{meta}->{$_}->{isIdentAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isIdentAuthority}; + $self->{meta}->{$_}->{isWriteProtected} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isWriteProtected}; + $self->{meta}->{$_}->{isChecksumAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isChecksumAuthority}; + } #print Dumper($self->{meta}); @@ -180,107 +214,5 @@ } - -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"; - -} - 1; +__END__