From e4855b891df3f7ed1f54eeb9444c038da192a280 Mon Sep 17 00:00:00 2001 From: helge Date: Mon, 16 Aug 2004 09:24:40 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/trunk@246 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Appointments/ChangeLog | 4 + .../Appointments/SOGoAppointmentFolder.h | 10 ++ .../Appointments/SOGoAppointmentFolder.m | 115 ++++++++++++++++++ .../Appointments/SOGoAppointmentObject.h | 7 +- .../Appointments/SOGoAppointmentObject.m | 64 ++-------- SOGo/SoObjects/Appointments/Version | 2 +- SOGo/UI/Scheduler/UIxAppointmentProposal.wox | 4 +- 7 files changed, 147 insertions(+), 59 deletions(-) diff --git a/SOGo/SoObjects/Appointments/ChangeLog b/SOGo/SoObjects/Appointments/ChangeLog index 80689259..099263e4 100644 --- a/SOGo/SoObjects/Appointments/ChangeLog +++ b/SOGo/SoObjects/Appointments/ChangeLog @@ -1,5 +1,9 @@ 2004-08-16 Helge Hess + * SOGoAppointmentObject.m, SOGoAppointmentFolder.m: moved calendar + folder lookup methods to folder class (the object uses its container + to lookup the folder) (v0.9.9) + * SOGoAppointmentObject.m: finished multi folder storage methods (v0.9.8) diff --git a/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.h b/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.h index 819a7b79..3bd0874d 100644 --- a/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.h +++ b/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.h @@ -60,6 +60,16 @@ - (NSString *)baseURLForAptWithUID:(NSString *)_uid inContext:(id)_ctx; +/* folder management */ + +- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx; + +- (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx; + +- (NSArray *)uidsFromICalPersons:(NSArray *)_persons; +- (NSArray *)lookupCalendarFoldersForICalPerson:(NSArray *)_persons + inContext:(id)_ctx; + @end #endif /* __Appointments_SOGoAppointmentFolder_H__ */ diff --git a/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.m b/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.m index 320c35e8..24f7b923 100644 --- a/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SOGo/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -21,7 +21,9 @@ // $Id$ #include "SOGoAppointmentFolder.h" +#include #include +#include #include "common.h" #include #include @@ -232,6 +234,119 @@ static NSTimeZone *MET = nil; return [url stringByAppendingString:_uid]; } +/* folder management */ + +- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx { + // TODO: DUP to SOGoGroupFolder + NSException *error = nil; + NSArray *path; + id ctx, result; + + if (![_uid isNotNull]) + return nil; + + if (_ctx == nil) _ctx = [[WOApplication application] context]; + + /* create subcontext, so that we don't destroy our environment */ + + if ((ctx = [_ctx createSubContext]) == nil) { + [self logWithFormat:@"ERROR: could not create SOPE subcontext!"]; + return nil; + } + + /* build path */ + + path = _uid != nil ? [NSArray arrayWithObjects:&_uid count:1] : nil; + + /* traverse path */ + + result = [[ctx application] traversePathArray:path inContext:ctx + error:&error acquire:NO]; + if (error != nil) { + [self logWithFormat:@"ERROR: folder lookup failed (uid=%@): %@", + _uid, error]; + return nil; + } + + [self debugWithFormat:@"Note: got folder for uid %@ path %@: %@", + _uid, [path componentsJoinedByString:@"=>"], result]; + return result; +} + +- (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx { + /* Note: can return NSNull objects in the array! */ + NSMutableArray *folders; + NSEnumerator *e; + NSString *uid; + + if ([_uids count] == 0) return nil; + folders = [NSMutableArray arrayWithCapacity:16]; + e = [_uids objectEnumerator]; + while ((uid = [e nextObject])) { + id folder; + + folder = [self lookupHomeFolderForUID:uid inContext:nil]; + if ([folder isNotNull]) { + folder = [folder lookupName:@"Calendar" inContext:nil acquire:NO]; + if ([folder isKindOfClass:[NSException class]]) + folder = nil; + } + if (![folder isNotNull]) + [self logWithFormat:@"Note: did not find folder for uid: '%@'", uid]; + + /* Note: intentionally add 'null' folders to allow a mapping */ + [folders addObject:folder ? folder : [NSNull null]]; + } + return folders; +} + +- (NSArray *)uidsFromICalPersons:(NSArray *)_persons { + /* Note: can return NSNull objects in the array! */ + NSMutableArray *uids; + AgenorUserManager *um; + unsigned i, count; + + if (_persons == nil) + return nil; + + count = [_persons count]; + uids = [NSMutableArray arrayWithCapacity:count + 1]; + um = [AgenorUserManager sharedUserManager]; + + for (i = 0; i < count; i++) { + iCalPerson *person; + NSString *email; + NSString *uid; + + person = [_persons objectAtIndex:i]; + email = [person email]; + if ([email isNotNull]) { + uid = [um getUIDForEmail:email]; + if ([uid isNotNull]) { + if ([uid hasPrefix:@"mailto:"]) + uid = [uid substringFromIndex:7]; + } + } + else + uid = nil; + + [uids addObject:(uid != nil ? uid : (id)[NSNull null])]; + } + return uids; +} + +- (NSArray *)lookupCalendarFoldersForICalPerson:(NSArray *)_persons + inContext:(id)_ctx +{ + /* Note: can return NSNull objects in the array! */ + NSArray *uids; + + if ((uids = [self uidsFromICalPersons:_persons]) == nil) + return nil; + + return [self lookupCalendarFoldersForUIDs:uids inContext:_ctx]; +} + /* GET */ - (id)GETAction:(WOContext *)_ctx { diff --git a/SOGo/SoObjects/Appointments/SOGoAppointmentObject.h b/SOGo/SoObjects/Appointments/SOGoAppointmentObject.h index e4d5beee..feb854d5 100644 --- a/SOGo/SoObjects/Appointments/SOGoAppointmentObject.h +++ b/SOGo/SoObjects/Appointments/SOGoAppointmentObject.h @@ -36,7 +36,7 @@ appointments with an externally generated unique key. */ -@class NSString, NSException; +@class NSString, NSArray, NSException; @interface SOGoAppointmentObject : SOGoContentObject { @@ -46,6 +46,11 @@ - (NSString *)iCalString; +/* folder management */ + +- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx; +- (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx; + /* raw saving */ - (NSException *)primarySaveContentString:(NSString *)_iCalString; diff --git a/SOGo/SoObjects/Appointments/SOGoAppointmentObject.m b/SOGo/SoObjects/Appointments/SOGoAppointmentObject.m index 0c30e089..badce9c4 100644 --- a/SOGo/SoObjects/Appointments/SOGoAppointmentObject.m +++ b/SOGo/SoObjects/Appointments/SOGoAppointmentObject.m @@ -42,7 +42,7 @@ - (NSArray *)attendeeUIDsFromAppointment:(SOGoAppointment *)_apt { AgenorUserManager *um; - NSMutableArray *uids; + NSMutableArray *uids; NSArray *attendees; unsigned i, count; NSString *email, *uid; @@ -56,7 +56,7 @@ uids = [NSMutableArray arrayWithCapacity:count + 1]; um = [AgenorUserManager sharedUserManager]; - + /* add organizer */ email = [[_apt organizer] email]; @@ -106,60 +106,11 @@ /* folder management */ -- (id)_primaryLookupFolderForUID:(NSString *)_uid inContext:(id)_ctx { - // TODO: DUP to SOGoGroupFolder - NSException *error = nil; - NSArray *path; - id ctx, result; - - if (_ctx == nil) _ctx = [[WOApplication application] context]; - - /* create subcontext, so that we don't destroy our environment */ - - if ((ctx = [_ctx createSubContext]) == nil) { - [self logWithFormat:@"ERROR: could not create SOPE subcontext!"]; - return nil; - } - - /* build path */ - - path = _uid != nil ? [NSArray arrayWithObjects:&_uid count:1] : nil; - - /* traverse path */ - - result = [[ctx application] traversePathArray:path inContext:ctx - error:&error acquire:NO]; - if (error != nil) { - [self logWithFormat:@"ERROR: folder lookup failed (uid=%@): %@", - _uid, error]; - return nil; - } - - [self debugWithFormat:@"Note: got folder for uid %@ path %@: %@", - _uid, [path componentsJoinedByString:@"=>"], result]; - return result; +- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx { + return [[self container] lookupHomeFolderForUID:_uid inContext:_ctx]; } - (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx { - NSMutableArray *folders; - NSEnumerator *e; - NSString *uid; - - if ([_uids count] == 0) return nil; - folders = [NSMutableArray arrayWithCapacity:16]; - e = [_uids objectEnumerator]; - while ((uid = [e nextObject])) { - id folder; - - folder = [self _primaryLookupFolderForUID:uid inContext:nil]; - folder = [folder lookupName:@"Calendar" inContext:nil acquire:NO]; - if (![folder isNotNull]) { - [self logWithFormat:@"Note: did not find folder for uid: '%@'", uid]; - continue; - } - - [folders addObject:folder]; - } - return folders; + return [[self container] lookupCalendarFoldersForUIDs:_uids inContext:_ctx]; } /* store in all the other folders */ @@ -177,7 +128,10 @@ while ((folder = [e nextObject])) { NSException *error; SOGoAppointmentObject *apt; - + + if (![folder isNotNull]) /* no folder was found for given UID */ + continue; + apt = [folder lookupName:[self nameInContainer] inContext:ctx acquire:NO]; if (![apt isNotNull]) { diff --git a/SOGo/SoObjects/Appointments/Version b/SOGo/SoObjects/Appointments/Version index 4ae9cc8e..5099e3e0 100644 --- a/SOGo/SoObjects/Appointments/Version +++ b/SOGo/SoObjects/Appointments/Version @@ -1,3 +1,3 @@ # $Id: Version,v 1.9 2004/05/19 14:30:45 helge Exp $ -SUBMINOR_VERSION:=8 +SUBMINOR_VERSION:=9 diff --git a/SOGo/UI/Scheduler/UIxAppointmentProposal.wox b/SOGo/UI/Scheduler/UIxAppointmentProposal.wox index 323ca063..42ee2516 100644 --- a/SOGo/UI/Scheduler/UIxAppointmentProposal.wox +++ b/SOGo/UI/Scheduler/UIxAppointmentProposal.wox @@ -59,7 +59,7 @@ @@ -73,7 +73,7 @@ -- 2.39.5