1 |
joko |
1.1 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
## -------------------------------------------------------------------------------- |
4 |
janosch |
1.4 |
## $Id: feed.pl,v 1.3 2003/01/20 16:29:48 joko Exp $ |
5 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
6 |
joko |
1.2 |
## $Log: feed.pl,v $ |
7 |
janosch |
1.4 |
## Revision 1.3 2003/01/20 16:29:48 joko |
8 |
|
|
## + new mechanism to pass configuration-metadata to Torus: |
9 |
|
|
## > process => Torus->new( |
10 |
|
|
## > config_metadata => { file => '../etc/syncOutlookContacts.ini' }, |
11 |
|
|
## > ) |
12 |
|
|
## and stuff .... |
13 |
|
|
## |
14 |
joko |
1.3 |
## Revision 1.2 2003/01/19 03:34:59 joko |
15 |
|
|
## + new command-line-arguments |
16 |
|
|
## |
17 |
joko |
1.2 |
## Revision 1.1 2003/01/18 18:20:45 joko |
18 |
|
|
## + initial check-in |
19 |
|
|
## |
20 |
joko |
1.1 |
## -------------------------------------------------------------------------------- |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
package main; |
24 |
|
|
|
25 |
|
|
use strict; |
26 |
|
|
use warnings; |
27 |
|
|
|
28 |
|
|
BEGIN { |
29 |
|
|
use FindBin qw($Bin); |
30 |
|
|
#require "$Bin/use_libs.pl"; |
31 |
|
|
} |
32 |
|
|
|
33 |
joko |
1.2 |
use Tie::IxHash; |
34 |
|
|
|
35 |
joko |
1.1 |
|
36 |
janosch |
1.4 |
use lib qw( ../libs ../etc ); |
37 |
|
|
use org::netfrag::preambel; |
38 |
joko |
1.1 |
use Torus::Logger; |
39 |
|
|
use Torus::Core; |
40 |
|
|
|
41 |
|
|
my $logger = Log::Dispatch::Config->instance; |
42 |
|
|
|
43 |
|
|
#use BizWorks::Script::Feed; |
44 |
|
|
|
45 |
|
|
#=pod |
46 |
|
|
#my $context = BizWorks::RunMe->new( app => $bizWorks, process => $bizProcess, logger => $logger ); |
47 |
|
|
#my $context = BizWorks::RunMe->new(); |
48 |
|
|
my $context = BizWorks::Script::Feed->new(); |
49 |
|
|
$context->getoptions(); |
50 |
|
|
$context->{opt}->{mapping_module} = $context->{opt}->{mapping}; |
51 |
|
|
#$context->verifyoptions(); |
52 |
|
|
#$context->options2actions(); |
53 |
|
|
#$context->run(); |
54 |
|
|
#$context->suspend(); |
55 |
|
|
#$context->set( app => $bizWorks, process => $bizProcess, logger => $logger ); |
56 |
|
|
my $bizWorks; |
57 |
|
|
$context->set( |
58 |
|
|
app => $bizWorks, |
59 |
joko |
1.3 |
process => Torus->new( |
60 |
|
|
config_metadata => { file => '../etc/syncOutlookContacts.ini' }, |
61 |
|
|
), |
62 |
joko |
1.1 |
logger => $logger, |
63 |
joko |
1.3 |
#config => { mappings => { 'LdapAddress' => 'xyz' } }, |
64 |
|
|
|
65 |
joko |
1.1 |
); |
66 |
|
|
#print Dumper($context); |
67 |
|
|
#print Dumper($context->{process}->{bizWorks}->{backend}); |
68 |
|
|
$context->run(); |
69 |
|
|
#exit; |
70 |
|
|
#print Dumper($context); |
71 |
|
|
#$context->suspend(); |
72 |
|
|
#=cut |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
#=pod |
76 |
|
|
#my $context = OEF::Component::Task->new( guid => 'ac65ea820a263948af8b4947f33f7719' ); |
77 |
|
|
#my $context = OEF::Component::Task->new( guid => '767ee9ab030bb4163e67ab26ab9a8894' ); |
78 |
|
|
#my $context = OEF::Component::Task->new( guid => '3a5c85995270ee8b17a8701c6f709ecf' ); |
79 |
|
|
#my $context2 = OEF::Component::Task->new( guid => $context->getGuid() ); |
80 |
|
|
#my $context2 = OEF::Component::Task->new( guid => '79d69fa4308d88181b882ef8d3433534' ); |
81 |
|
|
|
82 |
|
|
#$context2->resume(); |
83 |
|
|
#print Dumper($context2); |
84 |
|
|
#print Dumper($context2->{process}->{bizWorks}->{backend}); |
85 |
|
|
#$context2->{process}->{bizWorks}->{backend}->connect(); |
86 |
|
|
#$context2->run(); |
87 |
|
|
#=cut |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
package BizWorks::Script::Feed; |
91 |
|
|
|
92 |
|
|
use strict; |
93 |
|
|
use warnings; |
94 |
|
|
|
95 |
|
|
use Data::Dumper; |
96 |
|
|
use Getopt::Long; |
97 |
|
|
|
98 |
|
|
#use base 'OEF::Component::Task'; |
99 |
|
|
use base qw( |
100 |
|
|
DesignPattern::Object |
101 |
|
|
DesignPattern::Object::Logger |
102 |
|
|
); |
103 |
|
|
|
104 |
|
|
sub usage { |
105 |
|
|
my $self = shift; |
106 |
|
|
print "\n"; |
107 |
|
|
print <<EOU; |
108 |
|
|
usage: |
109 |
|
|
feed.pl --source=<dbkey> --node=<node> --target=<dbkey> --action=<action> [--mapping=] |
110 |
|
|
|
111 |
|
|
source: dbkey links to a configuration resource representing a storage (~= database) |
112 |
|
|
node: the name of a node on the first level below the source storage |
113 |
|
|
target: dbkey links to a configuration resource representing a storage |
114 |
|
|
action: <action> is issued on given dbkey as source node |
115 |
|
|
sync FULL sync (PULL & PUSH) |
116 |
|
|
load|save PULL or PUSH syncs |
117 |
|
|
import|export IMPORT and EXPORT syncs |
118 |
|
|
mapping: future use: specify name of a perl module / xml file which describes/outlines the mapping |
119 |
|
|
EOU |
120 |
|
|
exit; |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
sub getoptions { |
124 |
|
|
my $self = shift; |
125 |
|
|
|
126 |
|
|
GetOptions( |
127 |
|
|
'source=s' => \$self->{opt}->{source}, |
128 |
joko |
1.2 |
'source-type=s' => \$self->{opt}->{'source-type'}, |
129 |
|
|
'source-node=s' => \$self->{opt}->{'source-node'}, |
130 |
joko |
1.1 |
'target=s' => \$self->{opt}->{target}, |
131 |
joko |
1.2 |
'target-node=s' => \$self->{opt}->{'target-node'}, |
132 |
joko |
1.1 |
'action=s' => \$self->{opt}->{action}, |
133 |
joko |
1.2 |
'mapping-module=s' => \$self->{opt}->{'mapping-module'}, |
134 |
joko |
1.1 |
'prepare' => \$self->{opt}->{prepare}, |
135 |
|
|
'fresh' => \$self->{opt}->{fresh}, |
136 |
|
|
'help' => \&usage, |
137 |
|
|
); |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
sub set { |
141 |
|
|
my $self = shift; |
142 |
|
|
my $data = { @_ }; |
143 |
|
|
#return bless $self, $class; |
144 |
|
|
foreach (keys %$data) { |
145 |
|
|
#print $_, "\n"; |
146 |
|
|
$self->{$_} = $data->{$_}; |
147 |
|
|
} |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
=pod |
151 |
|
|
sub run { |
152 |
|
|
my $self = shift; |
153 |
|
|
$self->{var} ||= 0; |
154 |
|
|
print __PACKAGE__, "\n"; |
155 |
|
|
print "var: ", $self->{var}, "\n"; |
156 |
|
|
$self->{var}++; |
157 |
|
|
} |
158 |
|
|
=cut |
159 |
|
|
|
160 |
|
|
sub run { |
161 |
|
|
|
162 |
|
|
my $self = shift; |
163 |
|
|
|
164 |
|
|
#print Dumper($self->{opt}); |
165 |
|
|
|
166 |
|
|
# TODO: move this to the synchronization (startup) somehow... (one level towards the core - just one....) |
167 |
|
|
if ($self->{opt}->{target} eq 'testdata') { |
168 |
|
|
#print Dumper($self->{opt}); |
169 |
|
|
$self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE"); |
170 |
|
|
$self->{process}->load('Setup/Data/Test'); |
171 |
|
|
#print "2", "\n"; |
172 |
|
|
return $self->{process}->handler(); |
173 |
|
|
} |
174 |
|
|
|
175 |
|
|
#print Dumper($self->{opt}); |
176 |
|
|
|
177 |
|
|
#$self->{process}->load('Setup'); |
178 |
|
|
|
179 |
|
|
# TODO: |
180 |
|
|
# - move this to Data::Transfer::Sync::checkOptions!!! |
181 |
|
|
# - remove the tail of this "if" at the bottom of this block! |
182 |
|
|
#if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) { |
183 |
|
|
my $mode = ''; |
184 |
|
|
my $erase = 0; |
185 |
|
|
my $import = 0; |
186 |
|
|
$mode = 'PUSH' if $self->{opt}->{action} eq 'save'; |
187 |
|
|
$mode = 'PULL' if $self->{opt}->{action} eq 'load'; |
188 |
|
|
if ($self->{opt}->{action} eq 'import') { |
189 |
|
|
$mode = 'PULL'; |
190 |
|
|
$erase = 1; |
191 |
|
|
$import = 1; |
192 |
|
|
} |
193 |
|
|
if ($self->{opt}->{action} eq 'export') { |
194 |
|
|
$mode = 'PUSH'; |
195 |
|
|
$erase = 1; |
196 |
|
|
#$import = 1; |
197 |
|
|
} |
198 |
joko |
1.2 |
|
199 |
|
|
|
200 |
|
|
#print Dumper($self->{opt}); |
201 |
|
|
#exit; |
202 |
|
|
|
203 |
|
|
my %syncConfig; |
204 |
|
|
tie %syncConfig, 'Tie::IxHash'; |
205 |
|
|
%syncConfig = ( |
206 |
|
|
map => { |
207 |
|
|
moduleName => $self->{opt}->{'mapping-module'}, |
208 |
|
|
}, |
209 |
|
|
source => { |
210 |
|
|
dbKey => $self->{opt}->{source}, |
211 |
|
|
nodeType => $self->{opt}->{'source-type'}, |
212 |
|
|
nodeName => $self->{opt}->{'source-node'}, |
213 |
|
|
}, |
214 |
|
|
target => { |
215 |
|
|
dbKey => $self->{opt}->{target}, |
216 |
|
|
nodeName => $self->{opt}->{'target-node'}, |
217 |
|
|
}, |
218 |
|
|
process => { |
219 |
|
|
mode => $mode, |
220 |
|
|
erase => $erase, |
221 |
|
|
import => $import, |
222 |
|
|
prepare => $self->{opt}->{prepare}, |
223 |
|
|
}, |
224 |
joko |
1.3 |
metadata => { |
225 |
|
|
config => $self->{config_metadata}, |
226 |
|
|
} |
227 |
joko |
1.2 |
); |
228 |
|
|
|
229 |
|
|
#print Dumper(\%syncConfig); |
230 |
|
|
|
231 |
|
|
$self->{process}->startSync( \%syncConfig ); |
232 |
joko |
1.1 |
|
233 |
|
|
=pod |
234 |
|
|
} else { |
235 |
|
|
#print "\n", "Target is not syncable", "\n"; |
236 |
|
|
print "\n", "Target is not syncable", "\n"; |
237 |
|
|
$self->usage(); |
238 |
|
|
} |
239 |
|
|
=cut |
240 |
|
|
|
241 |
|
|
#$self->{process}->{outlook}->disconnect(); |
242 |
|
|
return; |
243 |
|
|
|
244 |
|
|
if ($self->{opt}->{action} eq 'load') { |
245 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
246 |
|
|
fillResources(); |
247 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
248 |
|
|
fillTestData(); |
249 |
|
|
} else { |
250 |
|
|
$self->usage(); |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
} elsif ($self->{opt}->{action} eq 'save') { |
254 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
255 |
|
|
$self->{process}->backupResources(); |
256 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
257 |
|
|
print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n"; |
258 |
|
|
} else { |
259 |
|
|
$self->usage(); |
260 |
|
|
} |
261 |
|
|
|
262 |
|
|
} elsif ($self->{opt}->{action} eq 'import') { |
263 |
|
|
if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); } |
264 |
|
|
|
265 |
|
|
} else { |
266 |
|
|
$self->usage(); |
267 |
|
|
} |
268 |
|
|
|
269 |
|
|
$self->{process}->{storage}->disconnect(); |
270 |
|
|
|
271 |
|
|
} |
272 |
|
|
|
273 |
|
|
1; |
274 |
|
|
|
275 |
|
|
|
276 |
|
|
package BizWorks::RunMe; |
277 |
|
|
|
278 |
|
|
use strict; |
279 |
|
|
use warnings; |
280 |
|
|
|
281 |
|
|
#use base 'OEF::Component::Task'; |
282 |
|
|
use base qw( |
283 |
|
|
DesignPattern::Object |
284 |
|
|
DesignPattern::Object::Logger |
285 |
|
|
); |
286 |
|
|
|
287 |
|
|
use Getopt::Long; |
288 |
|
|
#use BizWorks::Boot qw( $bizWorks $bizProcess ); |
289 |
|
|
use Data::Dumper; |
290 |
|
|
use Getopt::Long; |
291 |
|
|
use Carp; |
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
sub getoptions { |
297 |
|
|
my $self = shift; |
298 |
|
|
|
299 |
|
|
$self->{'opt'}->{'source'} = 'backend'; |
300 |
|
|
$self->{'opt'}->{'target'} = 'testdata'; |
301 |
|
|
$self->{'opt'}->{'action'} = 'load'; |
302 |
|
|
|
303 |
|
|
# TODO: use some core function/method (e.g. 'init_hash($hashref, $value, $force = 0)') |
304 |
|
|
$self->{opt}->{source} ||= ''; |
305 |
|
|
$self->{opt}->{node} ||= ''; |
306 |
|
|
$self->{opt}->{target} ||= ''; |
307 |
|
|
$self->{opt}->{action} ||= ''; |
308 |
|
|
$self->{opt}->{mapping} ||= ''; |
309 |
|
|
$self->{opt}->{prepare} ||= ''; |
310 |
|
|
$self->{opt}->{fresh} ||= ''; |
311 |
|
|
|
312 |
|
|
} |
313 |
|
|
|
314 |
|
|
|
315 |
|
|
sub run { |
316 |
|
|
|
317 |
|
|
my $self = shift; |
318 |
|
|
|
319 |
|
|
#print Dumper($self->{opt}); |
320 |
|
|
|
321 |
|
|
# TODO: move this to the synchroninzation (startup) somehow... (one level towards the core - just one....) |
322 |
|
|
if ($self->{opt}->{target} eq 'testdata') { |
323 |
|
|
#print Dumper($self->{opt}); |
324 |
|
|
$self->{logger}->info( __PACKAGE__ . "->run: Running (special handler code - no generic sync!) on '$self->{opt}->{target}' with action $self->{opt}->{action} - no NODE"); |
325 |
|
|
$self->{process}->load('Setup/Data/Test'); |
326 |
|
|
#print "2", "\n"; |
327 |
|
|
return $self->{process}->handler(); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
#print Dumper($self->{opt}); |
331 |
|
|
|
332 |
|
|
#$self->{process}->load('Setup'); |
333 |
|
|
|
334 |
|
|
# TODO: |
335 |
|
|
# - move this to Data::Transfer::Sync::checkOptions!!! |
336 |
|
|
# - remove the tail of this "if" at the bottom of this block! |
337 |
|
|
#if ($self->{app}->{config}->{databases}->{$self->{opt}->{target}}->{syncable}) { |
338 |
|
|
my $mode = ''; |
339 |
|
|
my $erase = 0; |
340 |
|
|
my $import = 0; |
341 |
|
|
$mode = 'PUSH' if $self->{opt}->{action} eq 'save'; |
342 |
|
|
$mode = 'PULL' if $self->{opt}->{action} eq 'load'; |
343 |
|
|
if ($self->{opt}->{action} eq 'import') { |
344 |
|
|
$mode = 'PULL'; |
345 |
|
|
$erase = 1; |
346 |
|
|
$import = 1; |
347 |
|
|
} |
348 |
|
|
if ($self->{opt}->{action} eq 'export') { |
349 |
|
|
$mode = 'PUSH'; |
350 |
|
|
$erase = 1; |
351 |
|
|
#$import = 1; |
352 |
|
|
} |
353 |
|
|
$self->{process}->startSync({ |
354 |
|
|
source => $self->{opt}->{source}, |
355 |
|
|
source_node => $self->{opt}->{node}, |
356 |
|
|
target => $self->{opt}->{target}, |
357 |
|
|
mode => $mode, |
358 |
|
|
erase => $erase, |
359 |
|
|
import => $import, |
360 |
|
|
mapping => $self->{opt}->{mapping}, |
361 |
|
|
prepare => $self->{opt}->{prepare}, |
362 |
|
|
}); |
363 |
|
|
|
364 |
|
|
=pod |
365 |
|
|
} else { |
366 |
|
|
#print "\n", "Target is not syncable", "\n"; |
367 |
|
|
print "\n", "Target is not syncable", "\n"; |
368 |
|
|
$self->usage(); |
369 |
|
|
} |
370 |
|
|
=cut |
371 |
|
|
|
372 |
|
|
$self->{process}->{storage}->disconnect(); |
373 |
|
|
return; |
374 |
|
|
|
375 |
|
|
if ($self->{opt}->{action} eq 'load') { |
376 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
377 |
|
|
fillResources(); |
378 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
379 |
|
|
fillTestData(); |
380 |
|
|
} else { |
381 |
|
|
$self->usage(); |
382 |
|
|
} |
383 |
|
|
|
384 |
|
|
} elsif ($self->{opt}->{action} eq 'save') { |
385 |
|
|
if ($self->{opt}->{target} eq 'resources') { |
386 |
|
|
$self->{process}->backupResources(); |
387 |
|
|
} elsif ($self->{opt}->{target} eq 'testdata') { |
388 |
|
|
print "could not save $self->{opt}->{resource}, it's stored inside a perl module", "\n"; |
389 |
|
|
} else { |
390 |
|
|
$self->usage(); |
391 |
|
|
} |
392 |
|
|
|
393 |
|
|
} elsif ($self->{opt}->{action} eq 'import') { |
394 |
|
|
if (!$self->{opt}->{node}) { print "option \"--action=import\" requires option \"--node\"", "\n"; $self->usage(); } |
395 |
|
|
|
396 |
|
|
} else { |
397 |
|
|
$self->usage(); |
398 |
|
|
} |
399 |
|
|
|
400 |
|
|
$self->{process}->{storage}->disconnect(); |
401 |
|
|
|
402 |
|
|
} |
403 |
|
|
|
404 |
|
|
|
405 |
|
|
1; |