| 1 |
## ------------------------------------------------------------------------- |
| 2 |
## |
| 3 |
## $Id: Metadata.pm,v 1.6 2003/03/28 03:08:17 joko Exp $ |
| 4 |
## |
| 5 |
## Copyright (c) 2002 Andreas Motl <andreas.motl@ilo.de> |
| 6 |
## |
| 7 |
## See COPYRIGHT section in associated pod text |
| 8 |
## or below for usage and distribution rights. |
| 9 |
## |
| 10 |
## ------------------------------------------------------------------------- |
| 11 |
## $Log: Metadata.pm,v $ |
| 12 |
## Revision 1.6 2003/03/28 03:08:17 joko |
| 13 |
## fix regarding namespace update |
| 14 |
## |
| 15 |
## Revision 1.5 2003/02/21 08:34:58 joko |
| 16 |
## modified object hierarchy |
| 17 |
## renamed method |
| 18 |
## |
| 19 |
## Revision 1.4 2003/02/14 14:06:20 joko |
| 20 |
## + minor fix to old metadata structure |
| 21 |
## |
| 22 |
## Revision 1.3 2003/02/11 06:28:24 joko |
| 23 |
## + changes to metadata structure |
| 24 |
## |
| 25 |
## Revision 1.2 2003/02/09 05:02:05 joko |
| 26 |
## + major structure changes |
| 27 |
## - refactored code to sister modules |
| 28 |
## |
| 29 |
## Revision 1.1 2003/01/20 16:58:46 joko |
| 30 |
## + initial check-in: here they are.... |
| 31 |
## |
| 32 |
## Revision 1.1 2003/01/19 01:23:04 joko |
| 33 |
## + new from Data/Transfer/Sync.pm |
| 34 |
## |
| 35 |
## ---------------------------------------------------------------------------------------- |
| 36 |
|
| 37 |
|
| 38 |
package Data::Transfer::Sync::Metadata; |
| 39 |
|
| 40 |
use strict; |
| 41 |
use warnings; |
| 42 |
|
| 43 |
use mixin::with qw( Data::Transfer::Sync ); |
| 44 |
|
| 45 |
|
| 46 |
use Data::Dumper; |
| 47 |
|
| 48 |
# get logger instance |
| 49 |
my $logger = Log::Dispatch::Config->instance; |
| 50 |
|
| 51 |
# TODO: refactor (still)!!! take this list from already established/given metadata .... |
| 52 |
# .... also internally: passing around and mungling these metadata doesn't make sense anymore. |
| 53 |
sub options2metadata { |
| 54 |
my $self = shift; |
| 55 |
|
| 56 |
$logger->debug( __PACKAGE__ . "->transformMetadata" ); |
| 57 |
|
| 58 |
# trace |
| 59 |
#print Dumper($self->{options}); |
| 60 |
#print Dumper($self->{args_raw}); |
| 61 |
#exit; |
| 62 |
|
| 63 |
# decompose identifiers and write to metadata (for each descent) |
| 64 |
foreach ('source', 'target') { |
| 65 |
|
| 66 |
# get/set metadata for further processing |
| 67 |
|
| 68 |
$self->{options}->{$_}->{dbKey} ||= ''; |
| 69 |
$self->{options}->{$_}->{nodeType} ||= ''; |
| 70 |
$self->{options}->{$_}->{nodeName} ||= ''; |
| 71 |
|
| 72 |
# Partner and Node (compare the V1-notations: "L:Country" or "R:countries.csv") |
| 73 |
$self->{meta}->{$_}->{dbKey} = $self->{options}->{$_}->{dbKey}; |
| 74 |
$self->{meta}->{$_}->{nodeType} = $self->{options}->{$_}->{nodeType}; |
| 75 |
$self->{meta}->{$_}->{nodeName} = $self->{options}->{$_}->{nodeName}; |
| 76 |
|
| 77 |
# Filter |
| 78 |
if (my $item_filter = $self->{options}->{$_}->{filter}) { |
| 79 |
$self->{meta}->{$_}->{filter} = $item_filter; |
| 80 |
} |
| 81 |
|
| 82 |
# IdentProvider |
| 83 |
if (my $item_ident = $self->{options}->{$_}->{ident}) { |
| 84 |
my @item_ident = split(':', $item_ident); |
| 85 |
$self->{meta}->{$_}->{IdentProvider} = { method => $item_ident[0], arg => $item_ident[1] }; |
| 86 |
} |
| 87 |
|
| 88 |
# TODO: ChecksumProvider |
| 89 |
# already inside {options} - get it out from there and put into {meta} here! |
| 90 |
|
| 91 |
# exclude properties/subnodes |
| 92 |
if (my $item_exclude = $self->{options}->{$_}->{exclude}) { |
| 93 |
$self->{meta}->{$_}->{subnodes_exclude} = $item_exclude; |
| 94 |
} |
| 95 |
|
| 96 |
# TypeProvider |
| 97 |
# FIXME! this is still Vdeprecated!!! |
| 98 |
if (my $item_type = $self->{options}->{$_ . '_type'}) { |
| 99 |
my @item_type = split(':', $item_type); |
| 100 |
$self->{meta}->{$_}->{TypeProvider} = { method => $item_type[0], arg => $item_type[1] }; |
| 101 |
} |
| 102 |
|
| 103 |
# trace |
| 104 |
#print Dumper($self); |
| 105 |
#exit; |
| 106 |
|
| 107 |
# Callbacks - writers (will be triggered _before_ writing to target) |
| 108 |
if (my $item_writers = $self->{options}->{$_}->{callbacks}->{write}) { |
| 109 |
my $descent = $_; # this is important since the following code inside the map wants to use its own context variables |
| 110 |
map { $self->{meta}->{$descent}->{Callback}->{write}->{$_}++; } @$item_writers; |
| 111 |
} |
| 112 |
|
| 113 |
# Callbacks - readers (will be triggered _after_ reading from source) |
| 114 |
if (my $item_readers = $self->{options}->{$_}->{callbacks}->{read}) { |
| 115 |
my $descent = $_; |
| 116 |
map { $self->{meta}->{$descent}->{Callback}->{read}->{$_}++; } @$item_readers; |
| 117 |
} |
| 118 |
|
| 119 |
# resolve storage handles |
| 120 |
$self->{meta}->{$_}->{storage} = $self->{options}->{$_}->{storage}->{handle}; |
| 121 |
|
| 122 |
# transfer storage handle options to metadata |
| 123 |
#map { $self->{meta}->{$_}->{isIdentAuthority} = 1 } @{$self->{id_authorities}}; |
| 124 |
#map { $self->{meta}->{$_}->{isChecksumAuthority} = 1; } @{$self->{checksum_authorities}}; |
| 125 |
#map { $self->{meta}->{$_}->{isWriteProtected} = 1; } @{$self->{write_protected}}; |
| 126 |
#print Dumper($self->{options}->{$_}); |
| 127 |
#exit; |
| 128 |
$self->{meta}->{$_}->{isIdentAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isIdentAuthority}; |
| 129 |
$self->{meta}->{$_}->{isWriteProtected} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isWriteProtected}; |
| 130 |
$self->{meta}->{$_}->{isChecksumAuthority} = $self->{options}->{$_}->{storage}->{handle}->{locator}->{sync}->{isChecksumAuthority}; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
#print Dumper($self->{meta}); |
| 135 |
return 1; |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
sub options2metadata_accessor { |
| 141 |
my $self = shift; |
| 142 |
|
| 143 |
$logger->debug( __PACKAGE__ . "->_transformMetadata_accessor" ); |
| 144 |
|
| 145 |
# build accessor metadata (for each descent) |
| 146 |
foreach my $descent ('source', 'target') { |
| 147 |
|
| 148 |
# the database type plays a role here to handle special nodesets: |
| 149 |
# there may be a) childless/non-strict nodesets (e.g. a CSV-file) |
| 150 |
# or b) normal ones - here the node-name corresponds more or less directly to |
| 151 |
# the physical location in the storage hierarchy below us (e.g. MAPI or LDAP) |
| 152 |
# or c) sets of nodes which are physically mapped by node-type (e.g. a RDBMS or a ODBMS) |
| 153 |
my $dbType = $self->{meta}->{$descent}->{storage}->{locator}->{type}; |
| 154 |
|
| 155 |
# a, b and c are "accessor-type"s (of 'none', 'node-name', 'node-type') |
| 156 |
# the following code resolves these types to '$accessorType' |
| 157 |
# and properly sets '$accessorName' |
| 158 |
|
| 159 |
# don't continue for certain storage handlers |
| 160 |
# HACK for DBD::CSV - re-enable for other DBDs |
| 161 |
#next if $dbType eq 'DBI'; |
| 162 |
|
| 163 |
# get nodename |
| 164 |
|
| 165 |
# get node-name |
| 166 |
my $nodename = $self->{meta}->{$descent}->{node}; # V1 |
| 167 |
$nodename ||= $self->{meta}->{$descent}->{nodeName}; # V2 |
| 168 |
|
| 169 |
# check if nodename is actually a CODEref, execute it to get a mapped/filtered target-nodename |
| 170 |
#print "----", ref $nodename, "\n"; |
| 171 |
#if ($nodename =~ m/CODE/) { |
| 172 |
# print Dumper($self); |
| 173 |
# #exit; |
| 174 |
# $nodename = $nodename->($nodename); |
| 175 |
#} |
| 176 |
|
| 177 |
# determine nodeset accessor -type and -name |
| 178 |
# defaults |
| 179 |
my $accessorType = 'none'; |
| 180 |
my $accessorName = ''; |
| 181 |
|
| 182 |
# if explicit address was given in options, just use it! |
| 183 |
if (my $address = $self->{options}->{$descent}->{address}) { |
| 184 |
$accessorType = 'direct-address'; |
| 185 |
$accessorName = $address; |
| 186 |
} |
| 187 |
|
| 188 |
# c) |
| 189 |
elsif (($dbType eq 'DBI' || $dbType eq 'Tangram') && $self->{meta}->{$descent}->{nodeType}) { |
| 190 |
$accessorType = 'node-type'; |
| 191 |
$accessorName = $self->{meta}->{$descent}->{nodeType}; |
| 192 |
} |
| 193 |
|
| 194 |
# b) |
| 195 |
elsif ($nodename) { |
| 196 |
$accessorType = 'node-name'; |
| 197 |
$accessorName = $nodename; |
| 198 |
} |
| 199 |
|
| 200 |
# write accessor information to metadata |
| 201 |
$self->{meta}->{$descent}->{accessorType} = $accessorType; |
| 202 |
$self->{meta}->{$descent}->{accessorName} = $accessorName; |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
# trace |
| 207 |
#print Dumper($self->{meta}); |
| 208 |
#print Dumper($self->{options}); |
| 209 |
#exit; |
| 210 |
|
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
1; |
| 215 |
__END__ |