开发者

"read" Data with multiple IDs from OpenERP using java with apache xml-rpc

Hi I am currently writing a servlet using Apache XML-RPC connecting to OpenERP. There are not any good resources around, and the java examples are very minimalistic and far from complete on the OpenERP site.

Has anyone a clue where I could find an API on how and what I can call on the OpenERP side?

I would really appreciate that!!!

On a further note, I am specifically looking for the syntax on how to "read" data, using java, with an input of multiple ids.

XmlRpcClient client = new XmlRpcClient();
XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
clientConfig.setEnabledForExtensions(true);
clientConfig.setServerURL(new URL(urlStringObject));
client.setConfig(clientConfig);

Object[] params2 = { "city", "name", "email", "create_date","write_date" };

Vector<Object> arg = new Vector<Object>();

arg.add(database);
arg.add(1);
arg.add(password);
arg.add("res.partner.address");
arg.add("read");
arg.add(9); // <- THE PYTHON SYNTAX SAYS input 'LIST OF IDS' here What is the Jave equivalent???
arg.add(params2);

HashMap ids = (HashMap) client.execute("execute", arg);

UPDATE

/* Search for all ids */
                xmlrpcConfigLogin.setServerURL(new URL(urlStringObject));
                Object[] searchQuery = new Object[] {"id", "!=", -1 };

                Vector queryVector = new Vector();
                queryVector.addElement(searchQuery);

                Object[] params = new Object[] { database, theloginId , password, tableName, "search", queryVector };
                Object[] po_ids = (Object[]) xmlrpcLogin.execute("execute", params);                

                /* Send Read Query */
                Object[] readQuery = {"name"};      

                Vector<Object> arg = new Vector<Object>();      
                arg.add(database);
                arg.add(1);
                arg.add(password);
                arg.add(tableName);
                arg.add("rea开发者_如何学编程d");
                arg.add(po_ids);
                arg.add(readQuery);         

                HashMap globalMap = new HashMap();

                Object[] hm = (Object[]) xmlrpcLogin.execute("execute", arg);                                   
                for (Object object : hm) {
                    HashMap hash = (HashMap)object;                             
                    globalMap.put("name", hash.get("name"));              
                    _log.info(hash.get("name"));
                }       

As you can see: It takes an Object[] of ids as input (po_ids)


I assume you've read through the developer book description of XML-RPC. I think that it's just a wrapper around all the methods in the ORM class. That's all the documentation I've seen. Other than that, I run OpenERP in debug mode and put a break point in the LocalService.__call__() method to see what parameters the client is sending to the server. (It's in server/bin/netsvc.py.) I've also seen developers just log every request that comes through that method.

As for how to make the calls in Java, I'm not familiar with the XmlRpcClient API, but it looks like it will accept an array of objects for a list, and probably anything that is enumerable. See if the description of data types is helpful, and check out the word tracker tutorial. It uses a Vector to hold a list parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜