--- nfo/perl/scripts/outlook2ldap/libs/Torus/Core.pm 2003/01/18 15:38:10 1.1 +++ nfo/perl/scripts/outlook2ldap/libs/Torus/Core.pm 2003/01/18 18:23:20 1.2 @@ -1,14 +1,19 @@ package Torus::Core; -require Exporter; -our @ISA = qw(Exporter); -our @EXPORT = qw( ); +use base qw( + DesignPattern::Object + DesignPattern::Object::Logger +); use strict; use warnings; use loadConfig; -use Torus::Driver::ldap; +#use Torus::Driver::ldap; +use Data::Transfer::Sync; + +my $logger = Log::Dispatch::Config->instance; + my $DEBUGLEVEL = $config->get("debug_level"); my $TRACELEVEL = $config->get("trace_level"); @@ -48,4 +53,99 @@ } +sub startSync { + + my $self = shift; + my $opts = shift; + + my $ldapLocator = Data::Storage::Locator->new( + ldap => { + type => "NetLDAP", +# dsn => "ldap:host=192.168.1.56;binddn='cn=root, dc=labnet, dc=de';pass=Geheim", + dsn => "ldap:host=192.168.10.150;binddn='cn=root, o=netfrag.org, c=de';pass=secret", + #schema => 'BizWorks::BackendDbSchema', + #classnames => [qw( SystemEvent LangText )], + #classnames => [qw( SystemEvent Person Address LangText )], + #test_availability => 1, + #test_integrity => 1, + #test_emptyness => 1, + # TODO: re-enable this! (multiple-target-logging!) + #logger => 1, + want_transactions => 0, + syncable => 1, + }, + ); + my $ldapStorage = Data::Storage->new($ldapLocator); + $ldapStorage->connect(); + + my $mapiStorage; + + + # create a new synchronization object + my $sync = Data::Transfer::Sync->new(); + + + # resolve mapping metadata for syncing requested resource + # if now mapping is given explicitely, try to use mapping named like "target" + $opts->{mapping} ||= $opts->{target}; + # was: ($nodemapping and $propmapping were package-globals) + # is: (both mappings are retrieved from mapping-module/package/object + # resolve mapping module + my $modulename = $self->{config}->{mappings}->{$opts->{mapping}}; + $opts->{mapping_module} = $modulename; + +#print Dumper($opts); + + # mungle & check the options + # TODO: refactor this and the innards..... + + #$opts = $sync->prepareSyncOptions($opts); + if (!$sync->prepareOptions($opts)) { + $logger->critical( __PACKAGE__ . "->startSync: 'Data::Transfer::Sync::prepareSyncOptions' failed."); + } + +#print Dumper($opts); + + if (!$sync->checkOptions($opts)) { + $logger->critical( __PACKAGE__ . "->startSync: 'Data::Transfer::Sync::checkOptions' failed."); + return; + } + + # branch to execution path for special targets + # detect for option 'handler' which could be a CODEref + if ($opts->{handler} && ref $opts->{handler} eq 'CODE') { + $logger->info( __PACKAGE__ . "->startSync: Running (special handler code - no generic sync!) on '$opts->{target}' with MODE $opts->{mode}, NODE $opts->{target_node}"); + $opts->{handler}->($self, $opts); + return; + } + + # determine write-protection(s) from options + my @write_protects; + push @write_protects, 'L' if $opts->{source_write_protect}; + push @write_protects, 'R' if $opts->{target_write_protect}; + + # configure synchronization-object + $sync->configure( + storages => { + #L => $self->{bizWorks}->{$opts->{source}}, + L => $mapiStorage, + #R => $self->{bizWorks}->{$opts->{target}}, + R => $ldapStorage, + }, + id_authorities => [qw( L ) ], + checksum_authorities => [qw( L ) ], + write_protected => \@write_protects, + verbose => 1, + ); + + # patch options + $opts->{source} = "L:$opts->{source_node}" if $opts->{source_node}; + $opts->{target} = "R:$opts->{target_node}" if $opts->{target_node}; + +#print Dumper($opts); + + $sync->syncNodes($opts); + +} + 1;