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