@implementation SOGoGroupAppointmentFolder
+- (void)dealloc {
+ [self->uidToFolder release];
+ [super dealloc];
+}
+
/* looking up shared objects */
- (SOGoGroupsFolder *)lookupGroupsFolder {
return [[self container] valueForKey:@"uids"];
}
+/* folders */
+
+- (SOGoAppointmentFolder *)folderForUID:(NSString *)_uid {
+ if (self->uidToFolder == nil) {
+ // TODO: can we trigger a fetch?
+ [self logWithFormat:
+ @"ERROR: called -folderForUID method before fetchCoreInfos .."];
+ return nil;
+ }
+
+ return [self->uidToFolder objectForKey:_uid];
+}
+
/* merging */
- (BOOL)doesRecord:(NSDictionary *)_rec conflictWith:(NSDictionary *)_other {
/* functionality */
-- (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
- to:(NSCalendarDate *)_endDate
- memberFolder:(id)_folder
-{
+- (SOGoAppointmentFolder *)calendarFolderForMemberFolder:(id)_folder {
SOGoAppointmentFolder *aptFolder;
if (![_folder isNotNull])
return nil;
aptFolder = [_folder lookupName:@"Calendar" inContext:nil acquire:NO];
- if (![aptFolder isNotNull]) {
- [self logWithFormat:@"ERROR: member folder no 'Calendar': %@", _folder];
+ if (![aptFolder isNotNull])
return nil;
- }
if (![aptFolder respondsToSelector:@selector(fetchCoreInfosFrom:to:)]) {
[self logWithFormat:@"ERROR: folder does not implemented required API: %@",
_folder];
return nil;
}
-
- return [aptFolder fetchCoreInfosFrom:_startDate to:_endDate];
+ return aptFolder;
+}
+
+- (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
+ to:(NSCalendarDate *)_endDate
+ folder:(SOGoAppointmentFolder *)_folder
+{
+ if (![_folder isNotNull])
+ return nil;
+ return [_folder fetchCoreInfosFrom:_startDate to:_endDate];
}
- (NSArray *)fetchCoreInfosFrom:(NSCalendarDate *)_startDate
NSMutableDictionary *uidToRecord;
unsigned i, count;
+ [self sleep];
+
if ((count = [_folders count]) == 0)
return [NSArray array];
- if (count == 1) {
- return [self fetchCoreInfosFrom:_startDate to:_endDate
- memberFolder:[_folders objectAtIndex:0]];
- }
+
+ if (self->uidToFolder == nil)
+ self->uidToFolder = [[NSMutableDictionary alloc] initWithCapacity:7*count];
+ else
+ [self->uidToFolder removeAllObjects];
uidToRecord = [NSMutableDictionary dictionaryWithCapacity:(7 * count)];
result = [NSMutableArray arrayWithCapacity:(7 * count)];
for (i = 0; i < count; i++) {
+ SOGoAppointmentFolder *aptFolder;
id results;
NSDictionary *record;
+ aptFolder = [self calendarFolderForMemberFolder:
+ [_folders objectAtIndex:i]];
+ if (![aptFolder isNotNull]) {
+ [self debugWithFormat:@"did not find a Calendar folder in folder: %@",
+ [_folders objectAtIndex:i]];
+ continue;
+ }
+
results = [self fetchCoreInfosFrom:_startDate to:_endDate
- memberFolder:[_folders objectAtIndex:i]];
+ folder:aptFolder];
if (![results isNotNull]) continue;
-
+
results = [results objectEnumerator];
while ((record = [results nextObject])) {
NSString *uid;
/* record not yet in result set */
[uidToRecord setObject:record forKey:uid];
[result addObject:record];
+
+ [self->uidToFolder setObject:aptFolder forKey:uid];
}
else if ([self doesRecord:existingRecord conflictWith:record]) {
/* record already registered and it conflicts (diff values) */
/* URL generation */
- (NSString *)baseURLForAptWithUID:(NSString *)_uid inContext:(id)_ctx {
- //NSString *url;
+ /* Note: fetchCore must have been called before this works */
+ SOGoAppointmentFolder *folder;
+
+ if ([_uid length] == 0) {
+ [self logWithFormat:@"ERROR: got invalid UID."];
+ return nil;
+ }
- if ([_uid length] == 0)
+ if ((folder = [self folderForUID:_uid]) == nil) {
+ [self logWithFormat:@"ERROR: did not find a folder containing UID: '%@'",
+ _uid];
+ return nil;
+ }
+ if (![folder respondsToSelector:_cmd]) {
+ [self logWithFormat:@"ERROR: found folder cannot construct UID URLs: %@",
+ folder];
return nil;
+ }
-#warning TODO: fix URL generation for aggregate
- [self logWithFormat:@"FIXME: URL generation for viewer"];
+ [self debugWithFormat:@"found ID %@ in folder: %@", _uid, folder];
- // need to locate the folder containing the apt, then call it
- return [super baseURLForAptWithUID:_uid inContext:_ctx];
+ return [folder baseURLForAptWithUID:_uid inContext:_ctx];
}
@end /* SOGoGroupAppointmentFolder */