Fixed up api signature generation, also fixed up Producteev duplicate task creation

pull/14/head
Tim Su 14 years ago
parent b34ac067ac
commit d66138e512

@ -8,11 +8,13 @@ import android.content.Intent;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import com.flurry.android.FlurryAgent;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider; import com.todoroo.astrid.producteev.sync.ProducteevSyncProvider;
import com.todoroo.astrid.utility.Constants;
import com.todoroo.astrid.utility.Preferences; import com.todoroo.astrid.utility.Preferences;
/** /**
@ -54,7 +56,9 @@ public class ProducteevBackgroundService extends Service {
return; return;
PluginServices.getTaskService(); PluginServices.getTaskService();
FlurryAgent.onStartSession(context, Constants.FLURRY_KEY);
new ProducteevSyncProvider().synchronize(context); new ProducteevSyncProvider().synchronize(context);
FlurryAgent.onEndSession(context);
} }
// --- alarm management // --- alarm management

@ -188,7 +188,7 @@ public class ProducteevControlSet implements TaskEditControlSet {
else else
metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId()); metadata.setValue(ProducteevTask.RESPONSIBLE_ID, responsibleUser.getId());
if(metadata.getSetValues().size() > 0 ) { if(metadata.getSetValues().size() > 0) {
metadataService.save(metadata); metadataService.save(metadata);
task.setValue(Task.MODIFICATION_DATE, DateUtilities.now()); task.setValue(Task.MODIFICATION_DATE, DateUtilities.now());
} }

@ -2,13 +2,12 @@ package com.todoroo.astrid.producteev.api;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.commons.codec.digest.DigestUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -509,8 +508,7 @@ public class ProducteevInvoker {
} }
sigBuilder.append(apiSecret); sigBuilder.append(apiSecret);
byte[] digest = MessageDigest.getInstance("MD5").digest(sigBuilder.toString().getBytes("UTF-8")); String signature = DigestUtils.md5Hex(sigBuilder.toString());
String signature = String.format("%1$032X", new BigInteger(1, digest).toString(16));
requestBuilder.append("api_sig").append('=').append(signature); requestBuilder.append("api_sig").append('=').append(signature);
return requestBuilder.toString(); return requestBuilder.toString();
} }

@ -20,17 +20,17 @@ import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria; import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
import com.todoroo.astrid.model.StoreObject; import com.todoroo.astrid.model.StoreObject;
import com.todoroo.astrid.model.Task; import com.todoroo.astrid.model.Task;
import com.todoroo.astrid.producteev.ProducteevUtilities; import com.todoroo.astrid.producteev.ProducteevUtilities;
import com.todoroo.astrid.rmilk.data.MilkNote; import com.todoroo.astrid.rmilk.data.MilkNote;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
public final class ProducteevDataService { public final class ProducteevDataService {
@ -58,7 +58,7 @@ public final class ProducteevDataService {
private TaskDao taskDao; private TaskDao taskDao;
@Autowired @Autowired
private MetadataDao metadataDao; private MetadataService metadataService;
@Autowired @Autowired
private StoreObjectDao storeObjectDao; private StoreObjectDao storeObjectDao;
@ -75,11 +75,11 @@ public final class ProducteevDataService {
// --- task and metadata methods // --- task and metadata methods
/** /**
* Clears RTM metadata information. Used when user logs out of RTM * Clears metadata information. Used when user logs out of service
*/ */
public void clearMetadata() { public void clearMetadata() {
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevTask.METADATA_KEY)); metadataService.deleteWhere(Metadata.KEY.eq(ProducteevTask.METADATA_KEY));
metadataDao.deleteWhere(Metadata.KEY.eq(ProducteevNote.METADATA_KEY)); metadataService.deleteWhere(Metadata.KEY.eq(ProducteevNote.METADATA_KEY));
storeObjectDao.deleteWhere(StoreObject.TYPE.eq(ProducteevDashboard.TYPE)); storeObjectDao.deleteWhere(StoreObject.TYPE.eq(ProducteevDashboard.TYPE));
} }
@ -140,16 +140,11 @@ public final class ProducteevDataService {
public void saveTaskAndMetadata(ProducteevTaskContainer task) { public void saveTaskAndMetadata(ProducteevTaskContainer task) {
taskDao.save(task.task, true); taskDao.save(task.task, true);
metadataDao.deleteWhere(Criterion.and(MetadataCriteria.byTask(task.task.getId()), task.metadata.add(task.pdvTask);
metadataService.synchronizeMetadata(task.task.getId(), task.metadata,
Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
MetadataCriteria.withKey(ProducteevNote.METADATA_KEY), MetadataCriteria.withKey(ProducteevNote.METADATA_KEY),
MetadataCriteria.withKey(TagService.KEY)))); MetadataCriteria.withKey(TagService.KEY)));
task.metadata.add(task.pdvTask);
task.pdvTask.setValue(Metadata.KEY, ProducteevTask.METADATA_KEY);
for(Metadata metadata : task.metadata) {
metadata.setValue(Metadata.TASK, task.task.getId());
metadataDao.persist(metadata);
}
} }
/** /**
@ -162,7 +157,7 @@ public final class ProducteevDataService {
// read tags, notes, etc // read tags, notes, etc
ArrayList<Metadata> metadata = new ArrayList<Metadata>(); ArrayList<Metadata> metadata = new ArrayList<Metadata>();
TodorooCursor<Metadata> metadataCursor = metadataDao.query(Query.select(Metadata.PROPERTIES). TodorooCursor<Metadata> metadataCursor = metadataService.query(Query.select(Metadata.PROPERTIES).
where(Criterion.and(MetadataCriteria.byTask(task.getId()), where(Criterion.and(MetadataCriteria.byTask(task.getId()),
Criterion.or(MetadataCriteria.withKey(TagService.KEY), Criterion.or(MetadataCriteria.withKey(TagService.KEY),
MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
@ -184,7 +179,7 @@ public final class ProducteevDataService {
* @return null if no metadata found * @return null if no metadata found
*/ */
public Metadata getTaskMetadata(long taskId) { public Metadata getTaskMetadata(long taskId) {
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select( TodorooCursor<Metadata> cursor = metadataService.query(Query.select(
Metadata.PROPERTIES).where( Metadata.PROPERTIES).where(
MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY))); MetadataCriteria.byTaskAndwithKey(taskId, ProducteevTask.METADATA_KEY)));
try { try {
@ -201,7 +196,7 @@ public final class ProducteevDataService {
* Reads task notes out of a task * Reads task notes out of a task
*/ */
public TodorooCursor<Metadata> getTaskNotesCursor(long taskId) { public TodorooCursor<Metadata> getTaskNotesCursor(long taskId) {
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES). TodorooCursor<Metadata> cursor = metadataService.query(Query.select(Metadata.PROPERTIES).
where(MetadataCriteria.byTaskAndwithKey(taskId, ProducteevNote.METADATA_KEY))); where(MetadataCriteria.byTaskAndwithKey(taskId, ProducteevNote.METADATA_KEY)));
return cursor; return cursor;
} }

@ -203,8 +203,6 @@ public class ProducteevSyncProvider extends SyncProvider<ProducteevTaskContainer
long userId = user.getLong("id_user"); long userId = user.getLong("id_user");
String lastServerSync = Preferences.getStringValue(ProducteevUtilities.PREF_SERVER_LAST_SYNC); String lastServerSync = Preferences.getStringValue(ProducteevUtilities.PREF_SERVER_LAST_SYNC);
if(lastServerSync != null)
lastServerSync = lastServerSync.substring(0, lastServerSync.lastIndexOf(' '));
// read dashboards // read dashboards
JSONArray dashboards = invoker.dashboardsShowList(lastServerSync); JSONArray dashboards = invoker.dashboardsShowList(lastServerSync);

@ -1,11 +1,17 @@
package com.todoroo.astrid.service; package com.todoroo.astrid.service;
import java.util.ArrayList;
import java.util.HashSet;
import android.content.ContentValues;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao; import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.model.Metadata; import com.todoroo.astrid.model.Metadata;
/** /**
@ -67,4 +73,51 @@ public class MetadataService {
public void save(Metadata metadata) { public void save(Metadata metadata) {
metadataDao.persist(metadata); metadataDao.persist(metadata);
} }
/**
* Synchronize metadata for given task id
* @param id
* @param metadata
* @param metadataKeys
*/
public void synchronizeMetadata(long taskId, ArrayList<Metadata> metadata,
Criterion metadataCriterion) {
HashSet<ContentValues> newMetadataValues = new HashSet<ContentValues>();
for(Metadata metadatum : metadata) {
metadatum.setValue(Metadata.TASK, taskId);
metadatum.clearValue(Metadata.ID);
newMetadataValues.add(metadatum.getMergedValues());
}
Metadata item = new Metadata();
TodorooCursor<Metadata> cursor = metadataDao.query(Query.select(Metadata.PROPERTIES).where(Criterion.and(MetadataCriteria.byTask(taskId),
metadataCriterion)));
try {
// try to find matches within our metadata list
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
item.readFromCursor(cursor);
long id = item.getId();
// clear item id when matching with incoming values
item.clearValue(Metadata.ID);
ContentValues itemMergedValues = item.getMergedValues();
if(newMetadataValues.contains(itemMergedValues)) {
newMetadataValues.remove(itemMergedValues);
continue;
}
// not matched. cut it
metadataDao.delete(id);
}
} finally {
cursor.close();
}
// everything that remains shall be written
for(ContentValues values : newMetadataValues) {
item.clear();
item.mergeWith(values);
metadataDao.persist(item);
}
}
} }

Loading…
Cancel
Save