2004-08-16 Helge Hess <helge.hess@skyrix.com>
+ * 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)
- (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__ */
// $Id$
#include "SOGoAppointmentFolder.h"
+#include <SOGoLogic/AgenorUserManager.h>
#include <OGoContentStore/OCSFolder.h>
+#include <NGiCal/NGiCal.h>
#include "common.h"
#include <unistd.h>
#include <stdlib.h>
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 {
appointments with an externally generated unique key.
*/
-@class NSString, NSException;
+@class NSString, NSArray, NSException;
@interface SOGoAppointmentObject : SOGoContentObject
{
- (NSString *)iCalString;
+/* folder management */
+
+- (id)lookupHomeFolderForUID:(NSString *)_uid inContext:(id)_ctx;
+- (NSArray *)lookupCalendarFoldersForUIDs:(NSArray *)_uids inContext:(id)_ctx;
+
/* raw saving */
- (NSException *)primarySaveContentString:(NSString *)_iCalString;
- (NSArray *)attendeeUIDsFromAppointment:(SOGoAppointment *)_apt {
AgenorUserManager *um;
- NSMutableArray *uids;
+ NSMutableArray *uids;
NSArray *attendees;
unsigned i, count;
NSString *email, *uid;
uids = [NSMutableArray arrayWithCapacity:count + 1];
um = [AgenorUserManager sharedUserManager];
-
+
/* add organizer */
email = [[_apt organizer] email];
/* 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 */
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]) {
# $Id: Version,v 1.9 2004/05/19 14:30:45 helge Exp $
-SUBMINOR_VERSION:=8
+SUBMINOR_VERSION:=9
<var:component className="UIxDatePickerScript" />
<var:component className="UIxDatePicker"
const:dateID="startDate"
- date="aptStartDate"
+ date="startDate"
label:label="browse start date"
/>
</span>
<td align="left" bgcolor="#FFFFF0" class="aptview_text" >
<var:component className="UIxDatePicker"
const:dateID="endDate"
- date="aptEndDate"
+ date="endDate"
label:label="browse end date"
/>
</td>