[OGo-XML-RPC] Resources and appointments
Adam Williams
xmlrpc@opengroupware.org
Mon, 02 Oct 2006 06:09:57 -0400
--=-eYc2iHefsxpV14dUYb2o
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Thu, 2006-09-28 at 15:26 +0200, Tobias Kaefer wrote:
> Adam Tauno Williams:
> > Nope, it still works the way it did - by name. I've figured out how to
> > do it, I just need to make the patch. If your still working on your
> > project I'll see if I can get it out in the next 48 hours.
> 48 hours? You promise that? ;)
> I would be glad to have it in the next 2 weeks or so. So take yout time.
> I was just wondering, if this issue is still on the development schedu
Patch:
http://bugzilla.opengroupware.org/bugzilla/attachment.cgi?id=465&action=view
Example Script:
http://bugzilla.opengroupware.org/bugzilla/attachment.cgi?id=466&action=view
--=-eYc2iHefsxpV14dUYb2o
Content-Disposition: attachment; filename=setResourcesById.patch
Content-Type: text/x-patch; name=setResourcesById.patch; charset=utf-8
Content-Transfer-Encoding: 7bit
Index: XmlRpcAPI/Actions.subproj/DirectAction+Appointment.m
===================================================================
--- XmlRpcAPI/Actions.subproj/DirectAction+Appointment.m (revision 1803)
+++ XmlRpcAPI/Actions.subproj/DirectAction+Appointment.m (working copy)
@@ -646,6 +646,10 @@
-(id)appointment_setResourcesAction:(id)_app:(id)_resources {
SkyAppointmentDocument *app;
NSArray *resourceNames;
+ NSMutableArray *tmp;
+ EOGlobalID *resourceGID;
+ EOGenericRecord *resource;
+ int i;
/* If _args is a number convert it to a string */
if ([_app isKindOfClass:[NSNumber class]])
@@ -665,8 +669,29 @@
resourceNames = [_resources componentsSeparatedByString:@","];
}
else if ([_resources isKindOfClass:[NSArray class]]) {
- resourceNames = _resources;
- }
+ if([_resources isNotEmpty]) {
+ tmp = [[NSMutableArray alloc] initWithCapacity:[_resources count]];
+ if([[_resources objectAtIndex:0] isKindOfClass:[NSNumber class]]) {
+ /// First object in array is a number
+ /// Convert these resource ids into resource names
+ for(i = 0; i < [_resources count]; i++) {
+ resourceGID = [[[self commandContext]
+ documentManager]
+ globalIDForURL:[_resources objectAtIndex:i]];
+ if (resourceGID != nil) {
+ resource = [[self commandContext]
+ runCommand:@"appointmentresource::get-by-globalid",
+ @"gid", resourceGID,
+ nil];
+ NSLog(@"%s: resource name: %@",
+ __PRETTY_FUNCTION__, [[resource valueForKey:@"name"] lastObject]);
+ [tmp addObject:[[resource valueForKey:@"name"] lastObject]];
+ } /// End if resourceGID != nil
+ } /// End for
+ resourceNames = tmp;
+ } else resourceNames = _resources;
+ } else resourceNames = _resources;
+ } /// End [_resources isKindOfClass:[NSArray class]]
else {
return [self faultWithFaultCode:XMLRPC_FAULT_INVALID_PARAMETER
reason:@"resource list invalid type"];
--=-eYc2iHefsxpV14dUYb2o
Content-Disposition: attachment; filename=updateAppointmentResources.py
Content-Type: text/x-python; name=updateAppointmentResources.py; charset=utf-8
Content-Transfer-Encoding: 7bit
#!/usr/bin/env python
import xmlrpclib
server = xmlrpclib.Server('http://awilliam:fred@localhost/RPC2')
print "--------------------------"
result = server.appointment.getById("11570")
print result
print "--------------------------"
print "--------------------------"
server.appointment.setResources(11570, "North Conference Room");
result = server.appointment.getById("11570")
print result['resourceNames']
print "--------------------------"
server.appointment.setResources(11570, "South Conference Room,North Conference Room");
result = server.appointment.getById("11570")
print result['resourceNames']
print "--------------------------"
server.appointment.setResources(11570, [ "South Conference Room" ]);
result = server.appointment.getById("11570")
print result['resourceNames']
print "--------------------------"
server.appointment.setResources(11570, [ ]);
result = server.appointment.getById("11570")
print result['resourceNames']
print "--------------------------"
server.appointment.setResources(11570, [ 11700 ]);
result = server.appointment.getById("11570")
print result['resourceNames']
print "--------------------------"
server.appointment.setResources(11570, [ 11700, 11720 ]);
result = server.appointment.getById("11570")
print result['resourceNames']
--=-eYc2iHefsxpV14dUYb2o--