Skip to content

Commit f20e838

Browse files
authored
Merge pull request #7 from existanze/master
You can't call execute anymore
2 parents 4fbd6e9 + 5bdd8a5 commit f20e838

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

.java-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.8

src/main/java/com/odoojava/api/Session.java

+43-19
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,18 @@
1818
*/
1919
package com.odoojava.api;
2020

21-
import java.util.ArrayList;
21+
import java.util.*;
2222
import javax.xml.bind.DatatypeConverter;
2323

24-
import java.io.InputStream;
25-
import java.io.OutputStream;
2624
import java.net.MalformedURLException;
2725
import java.net.URL;
2826
import java.nio.ByteBuffer;
29-
import java.nio.charset.Charset;
30-
import java.util.HashMap;
31-
import java.util.Map;
3227

3328
import org.apache.xmlrpc.XmlRpcException;
3429

3530
import com.odoojava.api.OdooXmlRpcProxy.RPCProtocol;
3631
import com.odoojava.api.OdooXmlRpcProxy.RPCServices;
3732
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
38-
import com.odoojava.api.OdooApiException;
39-
import java.util.Arrays;
4033

4134
/**
4235
* *
@@ -190,7 +183,7 @@ public void startSession() throws Exception {
190183
private void checkVersionCompatibility() throws XmlRpcException, OdooApiException {
191184

192185
if (this.getServerVersion().getMajor() < 8 || this.getServerVersion().getMajor() > 13) {
193-
throw new OdooApiException("Only Odoo Version from v8.x to 12.x are maintained. "
186+
throw new OdooApiException("Only Odoo Version from v8.x to 13.x are maintained. "
194187
+ "Please choose another version of the library");
195188
}
196189

@@ -278,10 +271,6 @@ public Object[] call_report_jsonrpc(String reportModel, String reportMethod, Arr
278271
methodparams.add(reportModel);
279272
methodparams.add(reportMethod);
280273
methodparams.add( args);
281-
282-
// methodparams.put("color", 8);
283-
// methodparams.put("memo", "another note");
284-
// note_id = call(url, "object", "execute", DB, uid, PASS, 'note.note', 'create', args)
285274

286275
jsonparams.put("args", methodparams);
287276

@@ -390,6 +379,36 @@ public Object executeCommand(final String objectName, final String commandName,
390379
return objectClient.execute("execute", params);
391380
}
392381

382+
/**
383+
* Executes any command on the server linked to the /xmlrpc/object service. All
384+
* parameters are prepended by: "databaseName,userID,password" This method
385+
* execute the command without the context parameter Its purpose is to be used
386+
* by Odoo version prior to v10 or for v10 methods that mustn't use the context
387+
*
388+
* @param objectName Object or model name to execute the command on
389+
* @param commandName Command name to execute
390+
* @param parameters List of parameters for the command. For easy of use,
391+
* consider the OdooCommand object or ObjectAdapter
392+
* @param context The user context
393+
* @return The result of the call
394+
* @throws XmlRpcException
395+
*/
396+
public Object executeCommandKw(final String objectName, final String commandName, final Object[] parameters, Context context)
397+
throws XmlRpcException {
398+
399+
List<Object> paramsList = new ArrayList<>();
400+
paramsList.addAll(Arrays.asList(new Object[] { databaseName, userID, password, objectName, commandName }));
401+
if (parameters != null && parameters.length > 0) {
402+
paramsList.add(Arrays.asList(parameters));
403+
}
404+
405+
Map<String, Context> c = new HashMap<>();
406+
c.put("context",context);
407+
paramsList.add(c);
408+
return objectClient.execute("execute_kw", paramsList);
409+
410+
}
411+
393412
/**
394413
* Executes any command on the server linked to the /xmlrpc/object service.
395414
* parameters and Context are prepended .The context MUST NOT have been already
@@ -406,13 +425,18 @@ public Object executeCommandWithContext(final String objectName, final String co
406425
final Object[] parameters) throws XmlRpcException {
407426
Object[] connectionParams = new Object[] { databaseName, userID, password, objectName, commandName };
408427

409-
// Combine the parameters with the context
410-
Object[] params = new Object[1 + (parameters == null ? 0 : parameters.length)];
411-
if (parameters != null && parameters.length > 0) {
412-
System.arraycopy(parameters, 0, params, 0, parameters.length);
428+
if(this.getServerVersion().getMajor() < 13){
429+
// Combine the parameters with the context
430+
Object[] params = new Object[1 + (parameters == null ? 0 : parameters.length)];
431+
if (parameters != null && parameters.length > 0) {
432+
System.arraycopy(parameters, 0, params, 0, parameters.length);
433+
}
434+
System.arraycopy(new Object[] { getContext() }, 0, params, parameters.length, 1);
435+
return executeCommand(objectName, commandName, params);
436+
}else{
437+
return executeCommandKw(objectName, commandName, parameters,getContext());
413438
}
414-
System.arraycopy(new Object[] { getContext() }, 0, params, parameters.length, 1);
415-
return executeCommand(objectName, commandName, params);
439+
416440
}
417441

418442
/**

0 commit comments

Comments
 (0)