Android OpenErp Search Request XMLRPC - android

I am working on an android application which is able to connect with an openerp server and retrive the userid and also the individual fields of the different contacts of that user.
below is the code on the things i have done so far
public int Search()
{
searchClient = new XMLRPCClient("http://"+lp.HOST+":"+lp.IN_PORT+lp.URL_XML+lp.URL_OBJECT);
try
{
record = (Array[]) searchClient.call("search",lp.DB_NAME, lp.uid1, lp.PASSWORD, "res.partnet.contact","execute", arguments);
}
catch(Exception e)
{
Log.i("------------------ CONNECTION FAILED Search", e.toString());
}
return 0;
}
i appreciate the help given
Thank you,

try to interchange the position of method search and execute.The method execute must be given before search.Also try searchClient.callEx instead call only like you do it above!
record = (Array[]) searchClient.callEx("execute",lp.DB_NAME, lp.uid1, lp.PASSWORD, "res.partnet.contact","search", arguments);

Related

Implement recursive function for SQLITE database

I am syncing lat-longs from local database to the server and change the status of rows in local database table if the lat-longs are successfully synced with the server, when user presses the button.
Problem
When button is pressed I hit the API for syncing lat-long to the server.
Some long-long is missing if the internet is slow (I want to send all lat-longs in exact sequence. If miss any lat-long, I try again to send the missing).
If all lat-longs are successfully synced only then EndRide Api is called.
This is the code when the button is pressed.
try {
cursor = db.getUnsyncedLatLngs(engIdForDB);
if (cursor.moveToFirst()) {
do {
//calling the method to save the unsynced name to MySQL
saveLatLngs(cursor.getInt(cursor.getColumnIndex(NewDatabaseForInRideData.COLUMN_ID)), cursor.getDouble(cursor.getColumnIndex(NewDatabaseForInRideData.Latitude)), cursor.getDouble(cursor.getColumnIndex(NewDatabaseForInRideData.Longitude)), engIdForDB);
} while (cursor.moveToNext());
}
} catch (Exception e) {
e.printStackTrace();
}
//Problem driverEndRideAsync is called even if some LatLng skiped to upload.
driverEndRideAsync(activity, abc, abc, 0, abc);
And for uploading lat-long to the server
private void saveLatLngs(final int id, final double lati, final double longi, String engId) {
RestClient.getApiService().update_data(abc, abc, lati, longi, String.valueOf(123), String.valueOf(123), String.valueOf(123), new Callback<String>() {
#Override
public void success(String s, Response response) {
try {
JSONObject jObj;
jObj = new JSONObject(s);
int flag = jObj.getInt("flag");
if (ApiResponseFlags.SOMETHING_WENT_WRONG.getOrdinal() == flag) {
db.updateNameStatus(id, NAME_NOT_SYNCED_WITH_SERVER, engId);
} else {
db.updateNameStatus(id, NAME_SYNCED_WITH_SERVER, engId);
}
} catch (JSONException e) {
e.printStackTrace();
}
android.util.Log.i("update_in_ride_data", " Success =" + response);
}
#Override
public void failure(RetrofitError error) {
android.util.Log.i("update_in_ride_data", " Error =" + error);
}
});
}
You have several problems in your implementation.
You are saving your lat-long fetched from your database table by calling an external API to your server inside a while loop. This is quite a bad implementation as this is creating a lot of AsyncTask in the background when you are trying to save each lat-long with an API service call.
The cleaner implementation requires development in your backend server which should take the lat-long as a batch (i.e. a bunch of lat-long will be saved at a time). In this implementation you will be able to save your lat-long by calling the API service once, instead of having it called multiple times for each of your entries.
Move the driverEndRideAsync(activity, abc, abc, 0, abc); function call inside your try block, so that it will not execute if you get an exception from that block while you are sending the lat-long data to your server using the API service.
If you are keeping this exact implementation in your server side, then I would suggest you to have a background service which will check if there is any data available to be synced with server in your database table after a certain time. In that case, you will have your data synced even if you get an exception while you are syncing your data with your server, because eventually the background service will detect un-synced data and will sync them with the server application.
Hope that helps.

Android - Parse - deleteInBackground, record not being deleted

I'm using Parse with Android in order to sync my data.
I'm trying to delete an object which is stored in the Parse cloud via
The callback returns and there's no exception, the Logcat message is "deleted".
But the object still exists in table when I check the Parse Data.
tastToEdit is an object from Task class (configured locally in my app).
ParseObject parse_task = new ParseObject("Task");
parse_task.put("Description",tastToEdit.getDescription());
parse_task.put("DueDate",tastToEdit.getDueDate());
parse_task.put("Priority",tastToEdit.getPriority().ordinal());
int com_state = (tastToEdit.getCompleted()) ? 1 : 0;
parse_task.put("IsCompleted",com_state);
parse_task.put("Location",0);
parse_task.put("Category",tastToEdit.getTask_catg().ordinal());
parse_task.put("Status", tastToEdit.getTask_sts().ordinal());
//parse_task.deleteInBackground();
parse_task.deleteInBackground(new DeleteCallback() {
public void done(ParseException e) {
if (e == null) {
Log.d("msg","deleted");
} else {
Log.d("msg", "not deleted");
e.printStackTrace();
}
}
});
What might be causing the callback to return as "deleted" but the object still remains?
Thanks in advance.
You are creating a new ParseObject and you try to delete it after but you don't provide an ObjectID.
A better way to do this will be to first do a ParseQuery for that task you are looking and the in the completion delete it.

How to tell the if the City is incorrect in OpenWeatherMap api and in android

I am creating an app which will tell the weather condition of a city using the OpenWeatherMap.org api. In this app I let user to write a city name and the data will be fetched from the web. But what if the user entered wrong city.
For example if a user entered Lomdon instead of London.
What should I do in that case. The Api I am using is
"http://api.openweathermap.org/data/2.5/weather?q="+city name
Thanks in advance for the help, I am new to android development.
If the city is incorrect your API returns an error message. You can check it like this:
"http://api.openweathermap.org/data/2.5/weather?q=Lomdon"
try {
String msg = jsonObject.getString("message");
if (msg.equalsIgnoreCase("Error: Not found city")) {
Log.e("TAG", "City not found");
} else {
// Use the data
}
} catch (JSONException e) {
e.printStackTrace();
}
The reason I didn't use cod which looks like the return code, is that if the city is found cod is an int and if it's not found it's a string. Kind of misleading to design the JSON like that.

Android xmpp MUC setting default configuration

Am using the Xabber open source project and am able to create a new group, But it always says: This room is locked from entry until configuration is confirmed. I tried to set a default configuration but it throws me exception: 401 not authorized. Whats exactly the problem.
final MultiUserChat multiUserChat;
try {
multiUserChat = new MultiUserChat(xmppConnection, room);
// CHANAKYA: set default config for the MUC
// Send an empty room configuration form which indicates that we want
// an instant room
try {
multiUserChat.sendConfigurationForm(new Form(Form.TYPE_SUBMIT));
} catch (XMPPException e) {
e.printStackTrace();
}
I was also facing the same error. Here I modified the code and it's work for me.
Error 401 is not authorized error when we are calling the any getConfigurationForm(), without joining it.
multiUserChat.join(nickname, password);
setConfig(multiUserChat); // Here I am calling submit form
private void setConfig(MultiUserChat multiUserChat) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields
.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.Type.hidden.equals(field.getType())
&& field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
And now I am able to successfully submit the form without any exception. Hope this will work for you.
You must have permissions to set the configuration. This can usually be changed in the server settings. If you have Openfire for example you should go to Group Chat>Group chat settings>Click your Group Chat service>Room Creation Permissions or Administrators.
You are probably unable to change this client side, it's only possible if you have access to the server you are trying to connect to.

android-json-rpc, receiving invalid response

I am trying to get responses from a JSON-RPC Service on Android, I'm currently developing on 3.0 Honeycomb.
This is the library I am using:
http://code.google.com/p/android-json-rpc/
and I am using this JSON-RPC service page for testing:
http://www.raboof.com/projects/jayrock/demo.ashx
The connection seems to work, but I keep getting this Exception
org.alexd.jsonrpc.JSONRPCException: Invalid JSON response
I've tried different methods and survey pages, but I always get the same Exception. Where am I going wrong?
The relevant code is below. AsyncTask is used because since 3.0 Android doesn't allow network connections in the main stream. Thanks in advance.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
JSONHandler task = new JSONHandler();
task.execute(new String[] {"http://www.raboof.com/projects/jayrock/demo.ashx"});
}
private class JSONHandler extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... urls) {
for (String url : urls) {
JSONRPCClient client = JSONRPCClient.create(url);
client.setConnectionTimeout(2000);
client.setSoTimeout(2000);
try {
client.call("counter");
} catch (JSONRPCException e) {
e.printStackTrace(); //Invalid JSON Response caught here
}
}
return null;
}
}
I have tested your system using the last version of the library. It work great. You need to us callInt("counter") and it will be ok.
There is the code I used:
public JSONRPCClient client = JSONRPCClient.create("http://www.raboof.com/projects/jayrock/demo.ashx", JSONRPCClient.Versions.VERSION_2);
try{
int resInt = client.callInt("counter");
} catch (JSONException e) {
Log.i("JSON-RPC Client", e.toString());
}
I hope this can help.
PS: with this new version, you use parameters send as an array, or using a JSONObject to send named parameters. This is only possible if using the version 2.0 of the JSON-RPC protocol.
This is the only JSON-RPC client I've been able to get to work with Zend_Json_Server on Android (and I've tried a few).
Make sure to set the version to 2.0 also, as this client doesn't work unless your server is explicitly using the 2.0 spec:
$server = new Zend_Json_Server();
$server->setClass('My_Class');
$server->getRequest()->setVersion("2.0");
if ('GET' == $_SERVER['REQUEST_METHOD']) {
// Indicate the URL endpoint, and the JSON-RPC version used:
$server->setTarget('/ajax.php')
->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);
// Grab the SMD
$smd = $server->getServiceMap();
// Return the SMD to the client
header('Content-Type: application/json');
echo $smd;
return;
}
$server->handle();

Categories

Resources