/[cvs]/nfo/perl/scripts/outlook2ldap/libs/Torus/Core.pm
ViewVC logotype

Annotation of /nfo/perl/scripts/outlook2ldap/libs/Torus/Core.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sat Jan 18 18:23:20 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.1: +104 -4 lines
+ modifications using Data::Transfer::Sync

1 joko 1.1 package Torus::Core;
2    
3 joko 1.2 use base qw(
4     DesignPattern::Object
5     DesignPattern::Object::Logger
6     );
7 joko 1.1
8     use strict;
9     use warnings;
10    
11     use loadConfig;
12 joko 1.2 #use Torus::Driver::ldap;
13     use Data::Transfer::Sync;
14    
15     my $logger = Log::Dispatch::Config->instance;
16    
17 joko 1.1
18     my $DEBUGLEVEL = $config->get("debug_level");
19     my $TRACELEVEL = $config->get("trace_level");
20     my $bool_started;
21    
22    
23     sub addItem {
24    
25     my $torusObjectType = shift;
26     my $mapiEntry = shift;
27     my $basedn = shift;
28     my $ldapEntry;
29    
30     if (!$bool_started) {
31     Torus::Driver::ldap::connectStore();
32     }
33    
34     $bool_started = 1;
35    
36     if ($DEBUGLEVEL > 3) {
37     print STDOUT "=" x 3, " ", __PACKAGE__, " ", "=" x 30, "\n";
38     print STDOUT "recieved torus-object (type=$torusObjectType)", "\n";
39     print STDOUT "trying to write to (basedn='$basedn')", "\n";
40     }
41    
42     if ($torusObjectType eq 'MapiContact') {
43     $basedn = Torus::Driver::ldap::createOuSafe($basedn);
44     my $entry = Torus::Driver::ldap::prepareEntry($basedn, $mapiEntry);
45     if (my $result = Torus::Driver::ldap::addEntry($entry)) {
46     #my $error = 0;
47     #$error = 1 if $result->code >= 0;
48     #Torus::Driver::ldap::traceEntry($mapiEntry, $entry, { error => $error, prefix => $result->error }) if $TRACELEVEL >= 2;
49     #undef $result;
50     Torus::Driver::ldap::processResult($entry->{identifier}, $result);
51     }
52     }
53 joko 1.2
54     }
55    
56     sub startSync {
57    
58     my $self = shift;
59     my $opts = shift;
60    
61     my $ldapLocator = Data::Storage::Locator->new(
62     ldap => {
63     type => "NetLDAP",
64     # dsn => "ldap:host=192.168.1.56;binddn='cn=root, dc=labnet, dc=de';pass=Geheim",
65     dsn => "ldap:host=192.168.10.150;binddn='cn=root, o=netfrag.org, c=de';pass=secret",
66     #schema => 'BizWorks::BackendDbSchema',
67     #classnames => [qw( SystemEvent LangText )],
68     #classnames => [qw( SystemEvent Person Address LangText )],
69     #test_availability => 1,
70     #test_integrity => 1,
71     #test_emptyness => 1,
72     # TODO: re-enable this! (multiple-target-logging!)
73     #logger => 1,
74     want_transactions => 0,
75     syncable => 1,
76     },
77     );
78     my $ldapStorage = Data::Storage->new($ldapLocator);
79     $ldapStorage->connect();
80    
81     my $mapiStorage;
82    
83    
84     # create a new synchronization object
85     my $sync = Data::Transfer::Sync->new();
86    
87    
88     # resolve mapping metadata for syncing requested resource
89     # if now mapping is given explicitely, try to use mapping named like "target"
90     $opts->{mapping} ||= $opts->{target};
91     # was: ($nodemapping and $propmapping were package-globals)
92     # is: (both mappings are retrieved from mapping-module/package/object
93     # resolve mapping module
94     my $modulename = $self->{config}->{mappings}->{$opts->{mapping}};
95     $opts->{mapping_module} = $modulename;
96    
97     #print Dumper($opts);
98    
99     # mungle & check the options
100     # TODO: refactor this and the innards.....
101    
102     #$opts = $sync->prepareSyncOptions($opts);
103     if (!$sync->prepareOptions($opts)) {
104     $logger->critical( __PACKAGE__ . "->startSync: 'Data::Transfer::Sync::prepareSyncOptions' failed.");
105     }
106    
107     #print Dumper($opts);
108    
109     if (!$sync->checkOptions($opts)) {
110     $logger->critical( __PACKAGE__ . "->startSync: 'Data::Transfer::Sync::checkOptions' failed.");
111     return;
112     }
113    
114     # branch to execution path for special targets
115     # detect for option 'handler' which could be a CODEref
116     if ($opts->{handler} && ref $opts->{handler} eq 'CODE') {
117     $logger->info( __PACKAGE__ . "->startSync: Running (special handler code - no generic sync!) on '$opts->{target}' with MODE $opts->{mode}, NODE $opts->{target_node}");
118     $opts->{handler}->($self, $opts);
119     return;
120     }
121    
122     # determine write-protection(s) from options
123     my @write_protects;
124     push @write_protects, 'L' if $opts->{source_write_protect};
125     push @write_protects, 'R' if $opts->{target_write_protect};
126    
127     # configure synchronization-object
128     $sync->configure(
129     storages => {
130     #L => $self->{bizWorks}->{$opts->{source}},
131     L => $mapiStorage,
132     #R => $self->{bizWorks}->{$opts->{target}},
133     R => $ldapStorage,
134     },
135     id_authorities => [qw( L ) ],
136     checksum_authorities => [qw( L ) ],
137     write_protected => \@write_protects,
138     verbose => 1,
139     );
140    
141     # patch options
142     $opts->{source} = "L:$opts->{source_node}" if $opts->{source_node};
143     $opts->{target} = "R:$opts->{target_node}" if $opts->{target_node};
144    
145     #print Dumper($opts);
146    
147     $sync->syncNodes($opts);
148 joko 1.1
149     }
150    
151     1;

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