]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/Contacts/SOGoContactFolder.m
Adding Attendees from AB works again
[scalable-opengroupware.org] / SOGo / SoObjects / Contacts / SOGoContactFolder.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21
22 #include "SOGoContactFolder.h"
23 #include <SOGo/SOGoCustomGroupFolder.h>
24 #include <SOGo/AgenorUserManager.h>
25 #include <GDLContentStore/GCSFolder.h>
26 #include <NGiCal/NGiCal.h>
27 #include "common.h"
28 #include <unistd.h>
29 #include <stdlib.h>
30
31 @implementation SOGoContactFolder
32
33 /* name lookup */
34
35 - (BOOL)isValidContactName:(NSString *)_key {
36   if ([_key length] == 0)
37     return NO;
38   
39   return YES;
40 }
41
42 - (id)contactWithName:(NSString *)_key inContext:(id)_ctx {
43   static Class ctClass = Nil;
44   id ct;
45   
46   if (ctClass == Nil)
47     ctClass = NSClassFromString(@"SOGoContactObject");
48   if (ctClass == Nil) {
49     [self errorWithFormat:@"missing SOGoContactObject class!"];
50     return nil;
51   }
52   
53   ct = [[ctClass alloc] initWithName:_key inContainer:self];
54   return [ct autorelease];
55 }
56
57 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
58   id obj;
59   
60   /* first check attributes directly bound to the application */
61   if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
62     return obj;
63   
64   if ([self isValidContactName:_key]) {
65 #if 0
66     if ([[self ocsFolder] versionOfContentWithName:_key])
67 #endif
68       return [self contactWithName:_key inContext:_ctx];
69   }
70
71   /* return 404 to stop acquisition */
72   return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
73 }
74
75 /* fetching */
76
77 - (NSArray *)fixupRecords:(NSArray *)_records {
78   return _records;
79 }
80
81 - (NSArray *)fetchCoreInfos {
82   NSArray     *fields, *records;
83
84   fields = [NSArray arrayWithObjects:
85                       @"c_name", @"cn",
86                       @"sn", @"givenname", @"l", 
87                       @"mail", @"telephonenumber",
88                     nil];
89   records = [[self ocsFolder] fetchFields:fields matchingQualifier:nil];
90   if (records == nil) {
91     [self errorWithFormat:@"(%s): fetch failed!", __PRETTY_FUNCTION__];
92     return nil;
93   }
94   records = [self fixupRecords:records];
95   //[self debugWithFormat:@"fetched %i records.", [records count]];
96   return records;
97 }
98
99 /* GET */
100
101 - (id)GETAction:(WOContext *)_ctx {
102   // TODO: I guess this should really be done by SOPE (redirect to
103   //       default method)
104   WOResponse *r;
105   NSString *uri;
106
107   uri = [[_ctx request] uri];
108   if (![uri hasSuffix:@"/"]) uri = [uri stringByAppendingString:@"/"];
109   uri = [uri stringByAppendingString:@"view"];
110   
111   r = [_ctx response];
112   [r setStatus:302 /* moved */];
113   [r setHeader:uri forKey:@"location"];
114   return r;
115 }
116
117 /* folder type */
118
119 - (NSString *)outlookFolderClass {
120   return @"IPF.Contact";
121 }
122
123 @end /* SOGoContactFolder */