[OGo-XML-RPC] Re: questions regarding ZOGi, WAS: [OGo-Users]custom fields and synchronizing ogo

Sebastian Reitenbach xmlrpc@opengroupware.org
Thu, 27 Mar 2008 13:26:53 +0100


xmlrpc@opengroupware.org wrote: 
> Hi Adam,
> 
> xmlrpc@opengroupware.org wrote: 
> > > I assume the two lines below the import line have to be on a single 
> line?
> > 
> > yep.
> > 
> > > Then I see a lot of, maybe only in my eyes, magic numbers, e.g.:
> > > permissions = [ { 'operations' : 'rw',
> > >                   'targetObjectId' : 970990 },
> > >                 { 'operations' : 'rw',
> > >                   'targetObjectId' : 11530 } ] 
> > > are 11530 and 970990 object ID values of accounts or teams in ogo?
> > 
> > Teams;  these permissions "rw" for teams 970990 & 11530 are set on all
> > imported values.  Obviously that would be different or unnecessary
> > depending on the site.  They can be objectIds of accounts or teams.
> > 
> > > then, a little bit later when creating the Enterprise:
> > > ...
> > >                  '_ACCESS' : permissions,
> > >                  '_COMPANYVALUES' : [ { 'attribute' : 'division',
> > >                                         'value' : 'WYC' },
> > >                                       { 'attribute' : 'salesperson',
> > >                                         'value' : row[0] },
> > > ...
> > > I assume this will create all companies with a "division" attribute 
with 
> > > value WYC?
> > 
> > Yep.
> > 
> I took a look at the example scripts on the zogi wiki, and I am able to 
> create a company, also the extended attributes. I am having a problem 
> creating adding the contact_id to an enterprise.
> 
> I took a look into the wiki, putObject examples, there you do sth like 
this:
> 
> ...
> person = {}
> person['targetObjectId'] = 10160
> ...
> enterprise['_CONTACTS'] = [ person ]
> ...
> enterprise = server.zogi.putObject(enterprise)
> 
> 
> The script I use, is:
> 
> #!/usr/bin/env python
> # all intranet: 10003
> #                
> 
> import sys, csv, xmlrpclib, time
> server = 
xmlrpclib.Server('http://admin:pw@localhost/zidestore/so/ogoroot')
> permissions = [ { 'operations' : 'rw',
>                   'targetObjectId' : 10003 } ]
> counter = 0
> reader = csv.reader(open("/root/bin/company.csv", "rb"), delimiter='|', 
> quoting=csv.QUOTE_NONE)
> for row in reader:
>     print 'Creating new enterprise'
>     person = {}
>     person['targetObjectId'] = row[11]
>     enterprise = server.zogi.putObject(
>                { 'objectId' : 0,
>                  'entityName' : 'Enterprise',
>                  'name' : row[1],
>                  'url' : row[2],
>                  '_ADDRESSES' : [ { 'name1' : row[1],
>                                     'street' : row[3],
>                                     'city' : row[6],
>                                     'state' : row[5],
>                                     'zip' : row[4],
>                                     'type' : 'ship' } ],
>                  '_ACCESS' : permissions,
>                  '_CONTACTS' : person,
>                  '_COMPANYVALUES' : [ { 'attribute' : 'contact_segments',
>                                         'value' : row[7] },
>                                       { 'attribute' : 'contact_markets',
>                                         'value' : row[8] },
>                                       { 'attribute' : 'country',
>                                         'value' : row[9] },
>                                       { 'attribute' : 'continent',
>                                         'value' : row[10] },
>                                       { 'attribute' : 'CSDB_Import',
>                                         'value' : 'YES' },
>                                       { 'attribute' : 'csdb_id',
>                                         'value' : row[0] }
>                                         ] }
>       )
>     print 'Created Enterprise#%d' % enterprise['objectId']
> 
> And I get an exception:
> 
> Creating new enterprise
> /usr/lib64/python2.4/xmllib.py:9: DeprecationWarning: The xmllib module is 
> obsolete.  Use xml.sax instead.
>   warnings.warn("The xmllib module is obsolete.  Use xml.sax instead.", 
> DeprecationWarning)
> Traceback (most recent call last):
>   File "./create_company.py", line 15, in ?
>     enterprise = server.zogi.putObject(
>   File "/usr/lib64/python2.4/xmlrpclib.py", line 1096, in __call__
>     return self.__send(self.__name, args)
>   File "/usr/lib64/python2.4/xmlrpclib.py", line 1383, in __request
>     verbose=self.__verbose
>   File "/usr/lib64/python2.4/xmlrpclib.py", line 1147, in request
>     return self._parse_response(h.getfile(), sock)
>   File "/usr/lib64/python2.4/xmlrpclib.py", line 1286, in _parse_response
>     return u.close()
>   File "/usr/lib64/python2.4/xmlrpclib.py", line 744, in close
>     raise Fault(**self._stack[0])
> xmlrpclib.Fault: <Fault 0: 'ObjcRuntimeException: NSShortInline8BitString 
> (instance) does not recognize objectForKey: {\n    methodName 
> = "zogi.putObject";\n    methodParameters = (\n        
> {\n            "_ACCESS" = (\n                {\n                    
> operations = rw;\n                    targetObjectId = 10003;
> \n                }\n            );\n            "_ADDRESSES" = (\n           
 
>   
> {\n                    city = asdf;\n                    name1 = 
> TESTCOMPANY;\n                    state = "";\n                    street 
= 
> Testblah;\n                    type = ship;\n                    zip = 
ZIP;
> \n                }\n            );\n            "_COMPANYVALUES" = (\n       
 
>       
> {\n                    attribute = "contact_segments";\n                    
> value = 2;\n                },\n                {\n                    
> attribute = "contact_markets";\n                    value = 1;
> \n                },\n                {\n                    attribute = 
> country;\n                    value = 10;\n                },\n               

> {\n                    attribute = continent;\n                    value = 
> 1;\n                },\n                {\n                    attribute 
> = "CSDB_Import";\n                    value = YES;\n                },\n      
 
>        
> {\n                    attribute = "csdb_id";\n                    value = 
> 401;\n                }\n            );\n            "_CONTACTS" = {\n        
 
>      
> targetObjectId = 894900;\n            };\n            entityName = 
> Enterprise;\n            name = TESTCOMPANY;\n            objectId = 0;\n     
 
>     
> url = "www.testcompany.de";\n        }\n    );\n}'>
> 
> 
> The CSV file had the following contents:
> 401|TESTCOMPANY|www.testcompany.de|Testblah|ZIP||asdf|2|1|10|1|894900
> 
> Maybe I am completely wrong, and _CONTACTS are the persons associated to 
the 
> company? 

when I want to update an existing record, I use the same script as above, 
but I specify an existing objectId, I get the following exception:


/usr/lib64/python2.4/xmllib.py:9: DeprecationWarning: The xmllib module is 
obsolete.  Use xml.sax instead.
  warnings.warn("The xmllib module is obsolete.  Use xml.sax instead.", 
DeprecationWarning)
Traceback (most recent call last):
  File "./create_or_update_company.py", line 15, in ?
    enterprise = server.zogi.putObject(
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1096, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1383, in __request
    verbose=self.__verbose
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1147, in request
    return self._parse_response(h.getfile(), sock)
  File "/usr/lib64/python2.4/xmlrpclib.py", line 1286, in _parse_response
    return u.close()
  File "/usr/lib64/python2.4/xmlrpclib.py", line 744, in close
    raise Fault(**self._stack[0])
xmlrpclib.Fault: <Fault 0: 'HTTP 500: No version supplied on company 
update'>


Below the zidestore log when running with PGDebuggingEnabled YES:
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: BEGIN 
TRANSACTION
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: SELECT 
t1.account, t1.anniversary, t1.assistant_name, t1.associated_categories, 
t1.associated_company, t1.associated_contacts, t1.bank, t1.bank_code, 
t1.birthday, t1.boss_name, t1.company_id, t1.contact_id, t1.db_status, 
t1.department, t1.description, t1.dir_server, t1.email, t1.email_alias, 
t1.fileas, t1.firstname, t1.freebusy_url, t1.im_address, t1.is_customer, 
t1.is_enterprise, t1.is_private, t1.is_readonly, t1.keywords, t1.login, 
t1.name_affix, t1.name_title, t1.number, t1.object_version, t1.occupation, 
t1.office, t1.owner_id, t1.partner_name, t1.priority, t1.sensitivity, 
t1.show_email2_as, t1.show_email3_as, t1.show_email_as, t1.source_url, 
t1.url FROM  enterprise t1 WHERE t1.company_id = 178630
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: SELECT 
DISTINCT t1.attribute, t1.company_id, t1.company_value_id, t1.db_status, 
t1.is_enum, t1.is_label_localized, t1.label, t1.type, t1.uid, 
t1.value_string FROM  company_value t1 WHERE t1.company_id IN (178630)
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: SELECT 
DISTINCT t1.company_id, t1.db_status, t1.info, t1.number, t1.real_number, 
t1.telephone_id, t1.type, t1.url FROM  telephone t1 WHERE t1.company_id IN 
(178630)
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: SELECT 
DISTINCT t1.comment, t1.company_id, t1.company_info_id, t1.db_status FROM  
company_info t1 WHERE t1.company_id IN (178630)
Mar 27 12:19:34 ogo-zidestore-1.5 [20522]: PG0x0x1045648 SQL: ROLLBACK 
TRANSACTION

The last statement before the ROLLBACK produces:
SELECT DISTINCT t1.comment, t1.company_id, t1.company_info_id, t1.db_status 
FROM  company_info t1 WHERE t1.company_id IN (178630);
 comment | company_id | company_info_id | db_status
---------+------------+-----------------+-----------
         |     178630 |          178640 | inserted


What can I do about the version?

> 
> I'm on a sles10sp1, using an ogo, about two or three months old.
> 
kind regards
Sebastian