Updated some tag service function implementations

pull/14/head
Sam Bosley 12 years ago
parent c366ce4c87
commit abc587c07a

@ -60,7 +60,6 @@ import com.todoroo.astrid.actfm.sync.ActFmPreferenceService;
import com.todoroo.astrid.actfm.sync.ActFmSyncService;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.dao.UserDao;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
@ -73,7 +72,6 @@ import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.abtesting.ABChooser;
import com.todoroo.astrid.tags.TagMetadata;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.ui.PeopleContainer;
import com.todoroo.astrid.ui.PeopleContainer.OnAddNewPersonListener;
@ -88,8 +86,6 @@ public class EditPeopleControlSet extends PopupControlSet {
private Task task;
private final ArrayList<Metadata> nonSharedTags = new ArrayList<Metadata>();
@Autowired ActFmPreferenceService actFmPreferenceService;
@Autowired ActFmSyncService actFmSyncService;
@ -248,21 +244,18 @@ public class EditPeopleControlSet extends PopupControlSet {
@Override
public void run() {
ArrayList<JSONObject> collaborators = new ArrayList<JSONObject>();
TodorooCursor<Metadata> tags = TagService.getInstance().getTags(task.getId(), true);
TodorooCursor<TagData> tags = TagService.getInstance().getTagDataForTask(task.getId(), true, TagData.NAME, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER);
try {
Metadata metadata = new Metadata();
TagData tagData = new TagData();
for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) {
metadata.readFromCursor(tags);
final String tag = metadata.getValue(TagMetadata.TAG_NAME);
TagData tagData = tagDataService.getTag(tag, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER);
if(tagData != null && tagData.getValue(TagData.MEMBER_COUNT) > 0) {
tagData.readFromCursor(tags);
final String tag = tagData.getValue(TagData.NAME);
if(tagData.getValue(TagData.MEMBER_COUNT) > 0) {
try {
addMembersFromTagData(tagData, tag, sharedPeople, collaborators);
} catch (JSONException e) {
exceptionService.reportError("json-reading-data", e);
}
} else {
nonSharedTags.add((Metadata) metadata.clone());
}
}

@ -18,6 +18,7 @@ import android.text.TextUtils;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.CountProperty;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
@ -196,7 +197,7 @@ public final class TagService {
if (includeEmergent)
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY));
else
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTagNames())));
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TagMetadata.KEY), Criterion.not(TagMetadata.TAG_UUID.in(getEmergentTagIds())));
Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID, COUNT).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(criterion).
@ -216,23 +217,6 @@ public final class TagService {
}
}
public String[] getEmergentTagNames() {
TodorooCursor<TagData> emergent = tagDataService.query(Query.select(TagData.NAME)
.where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0)));
try {
String[] tags = new String[emergent.getCount()];
TagData data = new TagData();
for (int i = 0; i < emergent.getCount(); i++) {
emergent.moveToPosition(i);
data.readFromCursor(emergent);
tags[i] = data.getValue(TagData.NAME);
}
return tags;
} finally {
emergent.close();
}
}
public Long[] getEmergentTagIds() {
TodorooCursor<TagData> emergent = tagDataService.query(Query.select(TagData.ID)
.where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0)));
@ -276,14 +260,28 @@ public final class TagService {
Criterion criterion;
if (includeEmergent)
criterion = Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
Metadata.DELETION_DATE.eq(0),
MetadataCriteria.byTask(taskId));
else
criterion = Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
MetadataCriteria.byTask(taskId), Criterion.not(TagMetadata.TAG_NAME.in(getEmergentTagNames())));
Metadata.DELETION_DATE.eq(0),
MetadataCriteria.byTask(taskId), Criterion.not(TagMetadata.TAG_UUID.in(getEmergentTagIds())));
Query query = Query.select(TagMetadata.TAG_NAME, TagMetadata.TAG_UUID).where(criterion).orderBy(Order.asc(Functions.upper(TagMetadata.TAG_NAME)));
return metadataDao.query(query);
}
public TodorooCursor<TagData> getTagDataForTask(long taskId, boolean includeEmergent, Property<?>... properties) {
Criterion criterion = TagData.REMOTE_ID.in(Query.select(TagMetadata.TAG_UUID)
.from(Metadata.TABLE)
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
Metadata.DELETION_DATE.eq(0),
Metadata.TASK.eq(taskId))));
if (!includeEmergent)
criterion = Criterion.and(Criterion.not(TagData.REMOTE_ID.in(getEmergentTagIds())), criterion);
return tagDataService.query(Query.select(properties).where(criterion));
}
/**
* Return tags as a comma-separated list of strings
*
@ -300,7 +298,7 @@ public final class TagService {
* @param taskId
* @return empty string if no tags, otherwise string
*/
protected String getTagsAsString(long taskId, String separator, boolean includeEmergent) {
public String getTagsAsString(long taskId, String separator, boolean includeEmergent) {
StringBuilder tagBuilder = new StringBuilder();
TodorooCursor<Metadata> tags = getTags(taskId, includeEmergent);
try {
@ -319,6 +317,7 @@ public final class TagService {
return tagBuilder.toString();
}
// TODO: UPDATE
public boolean deleteOrLeaveTag(Context context, String tag, String sql) {
int deleted = deleteTagMetadata(tag);
TagData tagData = PluginServices.getTagDataService().getTag(tag, TagData.ID, TagData.DELETION_DATE, TagData.MEMBER_COUNT, TagData.USER_ID);
@ -399,6 +398,7 @@ public final class TagService {
* @param taskId
* @param tags
*/
// TODO: UPDATE
public boolean synchronizeTags(long taskId, LinkedHashSet<String> tags) {
MetadataService service = PluginServices.getMetadataService();
@ -454,6 +454,7 @@ public final class TagService {
return tagWithCase;
}
// TODO: UPDATE
public int deleteTagMetadata(String tag) {
invalidateTaskCache(tag);
return PluginServices.getMetadataService().deleteWhere(tagEqIgnoreCase(tag, Criterion.all));

@ -27,13 +27,11 @@ import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.core.SortHelper;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.AstridDependencyInjector;
import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagMetadata;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TagService.Tag;
@ -200,14 +198,7 @@ public class Astrid2TaskProvider extends ContentProvider {
cursor.moveToNext();
task.readFromCursor(cursor);
StringBuilder taskTags = new StringBuilder();
TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId(), true);
try {
for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext())
taskTags.append(tagCursor.get(TagMetadata.TAG_NAME)).append(TAG_SEPARATOR);
} finally {
tagCursor.close();
}
String taskTags = TagService.getInstance().getTagsAsString(task.getId(), TAG_SEPARATOR, true);
Object[] values = new Object[7];
values[0] = task.getValue(Task.TITLE);
@ -216,7 +207,7 @@ public class Astrid2TaskProvider extends ContentProvider {
values[3] = task.getValue(Task.DUE_DATE);
values[4] = task.getValue(Task.IMPORTANCE);
values[5] = task.getId();
values[6] = taskTags.toString();
values[6] = taskTags;
ret.addRow(values);
}

Loading…
Cancel
Save