/*
- Copyright (C) 2004 SKYRIX Software AG
+ Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of OpenGroupware.org.
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#ifndef __Appointments_SOGoAppointmentFolder_H__
#define __Appointments_SOGoAppointmentFolder_H__
The SOGoAppointmentFolder maps to an GCS folder of type 'appointment', that
is, a content folder containing iCalendar files (and a proper quicktable).
+
+ Important:
+ The folder assumes a 1:1 mapping between the vevent UID field and the
+ resource name in the content store. In other words, you are not allowed to
+ create two different vevent-files with the same uid in the store.
*/
-@class NSString, NSArray, NSCalendarDate, NSException;
+@class NSString, NSArray, NSCalendarDate, NSException, NSMutableDictionary;
@class GCSFolder;
@interface SOGoAppointmentFolder : SOGoFolder
{
+ NSMutableDictionary *uidToFilename;
}
+ (NSString *)globallyUniqueObjectId;
- (NSArray *)calendarUIDs;
+/* vevent UID handling */
+
+- (NSString *)resourceNameForEventUID:(NSString *)_uid;
+
/* fetching */
- (NSArray *)fetchFields:(NSArray *)_fields
static NGLogger *logger = nil;
static NSTimeZone *MET = nil;
++ (int)version {
+ return [super version] + 1 /* v1 */;
+}
+ (void)initialize {
NGLoggerManager *lm;
static BOOL didInit = NO;
if (didInit) return;
didInit = YES;
+
+ NSAssert2([super version] == 0,
+ @"invalid superclass (%@) version %i !",
+ NSStringFromClass([self superclass]), [super version]);
lm = [NGLoggerManager defaultLoggerManager];
logger = [lm loggerForDefaultKey:@"SOGoAppointmentFolderDebugEnabled"];
}
- (void)dealloc {
+ [self->uidToFilename release];
[super dealloc];
}
return MET;
}
+/* vevent UID handling */
+
+- (NSString *)resourceNameForEventUID:(NSString *)_u inFolder:(GCSFolder *)_f {
+ static NSArray *nameFields = nil;
+ EOQualifier *qualifier;
+ NSArray *records;
+
+ if (![_u isNotNull]) return nil;
+ if (_f == nil) {
+ [self errorWithFormat:@"(%s): missing folder for fetch!",
+ __PRETTY_FUNCTION__];
+ return nil;
+ }
+
+ if (nameFields == nil)
+ nameFields = [[NSArray alloc] initWithObjects:@"c_name", nil];
+
+ qualifier = [EOQualifier qualifierWithQualifierFormat:@"uid = %@", _u];
+ records = [_f fetchFields:nameFields matchingQualifier:qualifier];
+
+ if ([records count] == 1)
+ return [[records objectAtIndex:0] valueForKey:@"c_name"];
+ if ([records count] == 0)
+ return nil;
+
+ [self errorWithFormat:
+ @"The storage contains more than file with the same UID!"];
+ return [[records objectAtIndex:0] valueForKey:@"c_name"];
+}
+
+- (NSString *)resourceNameForEventUID:(NSString *)_uid {
+ /* caches UIDs */
+ GCSFolder *folder;
+ NSString *rname;
+
+ if (![_uid isNotNull])
+ return nil;
+ if ((rname = [self->uidToFilename objectForKey:_uid]) != nil)
+ return [rname isNotNull] ? rname : nil;
+
+ if ((folder = [self ocsFolder]) == nil) {
+ [self errorWithFormat:@"(%s): missing folder for fetch!",
+ __PRETTY_FUNCTION__];
+ return nil;
+ }
+
+ if (self->uidToFilename == nil)
+ self->uidToFilename = [[NSMutableDictionary alloc] initWithCapacity:16];
+
+ if ((rname = [self resourceNameForEventUID:_uid inFolder:folder]) == nil)
+ [self->uidToFilename setObject:[NSNull null] forKey:_uid];
+ else
+ [self->uidToFilename setObject:rname forKey:_uid];
+
+ return rname;
+}
+
/* fetching */
- (NSMutableDictionary *)fixupRecord:(NSDictionary *)_record
if (records != nil) {
records = [self fixupRecords:records fetchRange:r];
if (logger)
- [self debugWithFormat:@"fetched %i records: %@", [records count], records];
+ [self debugWithFormat:@"fetched %i records: %@",[records count],records];
ma = [NSMutableArray arrayWithArray:records];
}
-
+
/* fetch recurrent apts now */
sql = [NSString stringWithFormat:@"(startdate < %d) AND (cycleenddate > %d)"
@" AND (iscycle = 1)",
if (infos == nil) {
infos = [[NSArray alloc] initWithObjects:
@"title",
- @"location", @"orgmail", @"status", @"ispublic",
+ @"location", @"orgmail", @"status", @"ispublic",
@"isallday", @"priority",
@"partmails", @"partstates",
nil];
/* URL generation */
- (NSString *)baseURLForAptWithUID:(NSString *)_uid inContext:(id)_ctx {
+ // TODO: who calls this?
NSString *url;
if ([_uid length] == 0)
url = [self baseURLInContext:_ctx];
if (![url hasSuffix:@"/"])
url = [url stringByAppendingString:@"/"];
+
+ // TODO: this should run a query to determine the uid!
return [url stringByAppendingString:_uid];
}
/*
- Copyright (C) 2004 SKYRIX Software AG
+ Copyright (C) 2004-2005 SKYRIX Software AG
This file is part of OpenGroupware.org.
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id: SOGoAppointmentFolder.m 137 2004-07-02 17:42:14Z helge $
#include "SOGoGroupAppointmentFolder.h"
#include "common.h"
@implementation SOGoGroupAppointmentFolder
++ (int)version {
+ return [super version] + 0 /* v1 */;
+}
++ (void)initialize {
+ NSAssert2([super version] == 1,
+ @"invalid superclass (%@) version %i !",
+ NSStringFromClass([self superclass]), [super version]);
+}
+
- (void)dealloc {
[self->uidToFolder release];
[super dealloc];