Search in sources :

Example 21 with ActionFailureException

use of net.micode.notes.gtask.exception.ActionFailureException in project Notes by MiCode.

the class GTaskClient method createTaskList.

public void createTaskList(TaskList tasklist) throws NetworkFailureException {
    commitUpdate();
    try {
        JSONObject jsPost = new JSONObject();
        JSONArray actionList = new JSONArray();
        // action_list
        actionList.put(tasklist.getCreateAction(getActionId()));
        jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
        // client version
        jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
        // post
        JSONObject jsResponse = postRequest(jsPost);
        JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
        tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID));
    } catch (JSONException e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
        throw new ActionFailureException("create tasklist: handing jsonobject failed");
    }
}
Also used : ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException)

Example 22 with ActionFailureException

use of net.micode.notes.gtask.exception.ActionFailureException in project Notes by MiCode.

the class SqlData method commit.

public void commit(long noteId, boolean validateVersion, long version) {
    if (mIsCreate) {
        if (mDataId == INVALID_ID && mDiffDataValues.containsKey(DataColumns.ID)) {
            mDiffDataValues.remove(DataColumns.ID);
        }
        mDiffDataValues.put(DataColumns.NOTE_ID, noteId);
        Uri uri = mContentResolver.insert(Notes.CONTENT_DATA_URI, mDiffDataValues);
        try {
            mDataId = Long.valueOf(uri.getPathSegments().get(1));
        } catch (NumberFormatException e) {
            Log.e(TAG, "Get note id error :" + e.toString());
            throw new ActionFailureException("create note failed");
        }
    } else {
        if (mDiffDataValues.size() > 0) {
            int result = 0;
            if (!validateVersion) {
                result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, null, null);
            } else {
                result = mContentResolver.update(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, mDataId), mDiffDataValues, " ? in (SELECT " + NoteColumns.ID + " FROM " + TABLE.NOTE + " WHERE " + NoteColumns.VERSION + "=?)", new String[] { String.valueOf(noteId), String.valueOf(version) });
            }
            if (result == 0) {
                Log.w(TAG, "there is no update. maybe user updates note when syncing");
            }
        }
    }
    mDiffDataValues.clear();
    mIsCreate = false;
}
Also used : ActionFailureException(net.micode.notes.gtask.exception.ActionFailureException) Uri(android.net.Uri)

Aggregations

ActionFailureException (net.micode.notes.gtask.exception.ActionFailureException)22 JSONException (org.json.JSONException)14 JSONObject (org.json.JSONObject)14 JSONArray (org.json.JSONArray)7 Task (net.micode.notes.gtask.data.Task)5 SqlNote (net.micode.notes.gtask.data.SqlNote)4 TaskList (net.micode.notes.gtask.data.TaskList)4 Node (net.micode.notes.gtask.data.Node)3 Cursor (android.database.Cursor)2 Uri (android.net.Uri)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MetaData (net.micode.notes.gtask.data.MetaData)2 NetworkFailureException (net.micode.notes.gtask.exception.NetworkFailureException)2 HttpResponse (org.apache.http.HttpResponse)2 ClientProtocolException (org.apache.http.client.ClientProtocolException)2 ContentValues (android.content.ContentValues)1 LinkedList (java.util.LinkedList)1 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)1