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

Contents of /nfo/perl/libs/Data/Transfer/Sync/API/V1.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Sun Feb 9 05:04:32 2003 UTC (21 years, 7 months ago) by joko
Branch: MAIN
+ initial commit

1 ## -------------------------------------------------------------------------
2 ##
3 ## $Id: Sync.pm,v 1.15 2003/01/20 16:58:07 joko Exp $
4 ##
5 ## Copyright (c) 2002, 2003 Andreas Motl <andreas.motl@ilo.de>
6 ##
7 ## This module is licensed under the same terms as Perl itself.
8 ##
9 ## -------------------------------------------------------------------------
10 ## $Log: Sync.pm,v $
11 ## -------------------------------------------------------------------------
12
13
14 package Data::Transfer::Sync::API::V1;
15
16 use strict;
17 use warnings;
18
19 use mixin::with qw( Data::Transfer::Sync );
20
21
22 # start here
23
24 use Data::Dumper;
25
26 # get logger instance
27 my $logger = Log::Dispatch::Config->instance;
28
29
30 sub checkOptions {
31 my $self = shift;
32
33 #print Dumper($self->{options});
34
35 my $result = 1;
36
37 # check - do we have a target node?
38 if (!$self->{options}->{target}->{nodeName}) {
39 $logger->warning( __PACKAGE__ . "->checkOptions: name of target node missing - please check metadata or specify '--target-node=*'.");
40 $result = 0;
41 }
42
43 # check - do we have a mapping?
44 if (!$self->{options}->{details}) {
45 $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'fieldmap' could be determined.");
46 $result = 0;
47 }
48
49 # TODO: extend!
50
51 return $result;
52
53 }
54
55
56 sub checkOptions_V1 {
57 my $self = shift;
58 my $opts = shift;
59
60 my $result = 1;
61
62 # check - do we have a target node?
63 if (!$opts->{target_node}) {
64 $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'target node' could be determined.");
65 $result = 0;
66 }
67
68 # check - do we have a mapping?
69 if (!$opts->{mapping} && !$opts->{mapping_module}) {
70 $logger->warning( __PACKAGE__ . "->checkOptions: Error while resolving resource metadata - no 'mapping' could be determined.");
71 $result = 0;
72 }
73
74 return $result;
75
76 }
77
78
79 sub configure_V1 {
80 my $self = shift;
81 $logger->debug( __PACKAGE__ . "->configure");
82 my @args = @_;
83 if (!isEmpty(\@args)) {
84 my %properties = @_;
85 # merge args to properties
86 map { $self->{$_} = $properties{$_}; } keys %properties;
87 $self->_init();
88 $self->_initV1();
89 } else {
90 #print "no args!", "\n";
91 }
92 #print Dumper($self);
93 $self->{state}->{configured} = 1;
94 return 1;
95 }
96
97
98 sub prepareOptions_V1_old {
99
100 my $self = shift;
101 my $opts = shift;
102
103 $opts->{mode} ||= '';
104 $opts->{erase} ||= 0;
105 $opts->{prepare} ||= 0;
106 #$opts->{import} ||= 0;
107
108 if (!$opts->{source_node}) {
109 $logger->error( __PACKAGE__ . "->prepareOptions failed: Please specify source-node!");
110 return;
111 }
112
113 $logger->notice( __PACKAGE__ . "->prepareOptions( source_node $opts->{source_node} mode $opts->{mode} erase $opts->{erase} prepare $opts->{prepare} )");
114
115 #if (!$opts->{mapping} || !$opts->{mapping_module}) {
116 if (!$opts->{mapping}) {
117 $logger->warning( __PACKAGE__ . "->prepareOptions: No mapping supplied - please check key 'mappings' in global configuration or specify additional argument '--mapping'.");
118 #return;
119 }
120
121 $opts->{mapping_module} ||= $opts->{mapping};
122 my $evstring = "use $opts->{mapping_module};";
123 eval($evstring);
124 if ($@) {
125 $logger->warning( __PACKAGE__ . "->prepareOptions: error while trying to access mapping - $@");
126 return;
127 }
128
129 # resolve mapping metadata (returned from sub)
130 my $mapObject = $opts->{mapping_module}->new();
131 #print Dumper($map);
132 my $source_node_name = $opts->{source_node};
133 # check if mapping for certain node is contained in mapping object
134 if (!$mapObject->can($source_node_name)) {
135 $logger->warning( __PACKAGE__ . "->prepareOptions: Can't access mapping for node \"$source_node_name\" - please check $opts->{mapping_module}.");
136 return;
137 }
138 my $map = $mapObject->$source_node_name;
139
140 #print Dumper($map);
141
142 # check here if "target" is actually a CODEref - in this case: resolve it - deprecated!!! ???
143 if (ref $map->{target} eq 'CODE') {
144 $map->{target} = $map->{target}->($source_node_name);
145 }
146
147 # resolve expressions (on nodename-level) here
148 if ($map->{target} =~ m/^(code|expr):(.+?)$/) {
149 my $target_dynamic_type = $1;
150 my $target_dynamic_expression = $2;
151 if (lc $target_dynamic_type eq 'code') {
152 # $map->{target} = $mapObject->$target_dynamic_expression($map);
153 }
154 }
155
156 # remove asymmetries from $map (patch keys)
157 $map->{source_node} = $map->{source}; delete $map->{source};
158 $map->{target_node} = $map->{target}; delete $map->{target};
159 $map->{mapping} = $map->{details}; delete $map->{details};
160 $map->{direction} = $map->{mode}; delete $map->{mode};
161
162 # defaults (mostly for backward-compatibility)
163 $map->{source_node} ||= $source_node_name;
164 $map->{source_ident} ||= 'storage_method:id';
165 $map->{target_ident} ||= 'property:oid';
166 $map->{direction} ||= $opts->{mode}; # | PUSH | PULL | FULL
167 $map->{method} ||= 'checksum'; # | timestamp
168 $map->{source_exclude} ||= [qw( cs )];
169
170 # merge map to opts
171 map { $opts->{$_} = $map->{$_}; } keys %$map;
172
173 #print Dumper($opts);
174
175 # TODO: move this to checkOptions...
176
177 # check - do we have a target?
178 if (!$opts->{target_node}) {
179 $logger->warning( __PACKAGE__ . "->prepareOptions: No target given - please check metadata declaration.");
180 return;
181 }
182
183
184 #return $opts;
185 return 1;
186
187 }
188
189 # backward compatibility - this is active!!!
190 sub options_to_V2 {
191 my $self = shift;
192 my $map = shift;
193
194 $logger->debug( __PACKAGE__ . "->options_to_V2");
195
196 # move the 'target' address
197 $map->{target} = { address => $map->{target} };
198
199 $map->{source}->{ident} = $map->{source_ident};
200 delete $map->{source_ident};
201 $map->{source}->{type} = $map->{source_type};
202 delete $map->{source_type};
203
204 $map->{target}->{ident} = $map->{target_ident};
205 delete $map->{target_ident};
206
207 }
208
209
210
211 1;

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