Added a convenience method for getting uuid from RemoteModels

pull/14/head
Sam Bosley 12 years ago
parent d7d90cb72e
commit a1007f2440

@ -49,4 +49,20 @@ abstract public class RemoteModel extends AbstractModel {
/** constant value for no uuid */ /** constant value for no uuid */
public static final String NO_UUID = "0"; //$NON-NLS-1$ public static final String NO_UUID = "0"; //$NON-NLS-1$
/**
* Utility method to get the identifier of the model, if it exists.
*
* @return {@value #NO_UUID} if this model was not added to the database
*/
abstract public String getUuid();
protected String getUuidHelper(StringProperty uuid) {
if(setValues != null && setValues.containsKey(uuid.name))
return setValues.getAsString(uuid.name);
else if(values != null && values.containsKey(uuid.name))
return values.getAsString(uuid.name);
else
return NO_UUID;
}
} }

@ -196,6 +196,11 @@ public final class TagData extends RemoteModel {
return getIdHelper(ID); return getIdHelper(ID);
} }
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers // --- parcelable helpers
public static final Creator<TagData> CREATOR = new ModelCreator<TagData>(TagData.class); public static final Creator<TagData> CREATOR = new ModelCreator<TagData>(TagData.class);

@ -321,6 +321,11 @@ public final class Task extends RemoteModel {
return getIdHelper(ID); return getIdHelper(ID);
} }
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers // --- parcelable helpers
public static final Creator<Task> CREATOR = new ModelCreator<Task>(Task.class); public static final Creator<Task> CREATOR = new ModelCreator<Task>(Task.class);

@ -169,7 +169,12 @@ public class Update extends RemoteModel {
@Override @Override
public long getId() { public long getId() {
return getIdHelper(ID); return getIdHelper(ID);
}; }
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers // --- parcelable helpers

@ -144,6 +144,11 @@ public final class User extends RemoteModel {
return getIdHelper(ID); return getIdHelper(ID);
} }
@Override
public String getUuid() {
return getUuidHelper(UUID);
}
// --- parcelable helpers // --- parcelable helpers
public static final Creator<User> CREATOR = new ModelCreator<User>(User.class); public static final Creator<User> CREATOR = new ModelCreator<User>(User.class);

@ -3,7 +3,6 @@ package com.todoroo.astrid.tags;
import com.todoroo.andlib.data.Property.LongProperty; import com.todoroo.andlib.data.Property.LongProperty;
import com.todoroo.andlib.data.Property.StringProperty; import com.todoroo.andlib.data.Property.StringProperty;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
public class TagMetadata { public class TagMetadata {
@ -32,15 +31,12 @@ public class TagMetadata {
* New metadata object for linking a task to the specified tag. The task * New metadata object for linking a task to the specified tag. The task
* object should be saved and have the uuid property. All parameters * object should be saved and have the uuid property. All parameters
* are manditory * are manditory
* @param task * @param taskId
* @param tagName * @param tagName
* @param taskUuid
* @param tagUuid * @param tagUuid
* @return * @return
*/ */
public static Metadata newTagMetadata(Task task, String tagName, String tagUuid) {
return newTagMetadata(task.getId(), task.getValue(Task.UUID), tagName, tagUuid);
}
public static Metadata newTagMetadata(long taskId, String taskUuid, String tagName, String tagUuid) { public static Metadata newTagMetadata(long taskId, String taskUuid, String tagName, String tagUuid) {
Metadata link = new Metadata(); Metadata link = new Metadata();
link.setValue(Metadata.KEY, KEY); link.setValue(Metadata.KEY, KEY);

@ -256,7 +256,7 @@ public final class TagService {
} }
public void createLink(Task task, String tagName, String tagUuid) { public void createLink(Task task, String tagName, String tagUuid) {
Metadata link = TagMetadata.newTagMetadata(task, tagName, tagUuid); Metadata link = TagMetadata.newTagMetadata(task.getId(), task.getUuid(), tagName, tagUuid);
if (metadataDao.update(Criterion.and(MetadataCriteria.byTaskAndwithKey(task.getId(), TagMetadata.KEY), if (metadataDao.update(Criterion.and(MetadataCriteria.byTaskAndwithKey(task.getId(), TagMetadata.KEY),
TagMetadata.TASK_UUID.eq(task.getValue(Task.UUID)), TagMetadata.TAG_UUID.eq(tagUuid)), link) <= 0) { TagMetadata.TASK_UUID.eq(task.getValue(Task.UUID)), TagMetadata.TAG_UUID.eq(tagUuid)), link) <= 0) {
metadataDao.createNew(link); metadataDao.createNew(link);

Loading…
Cancel
Save