Started altering tag service to filter out emergent tags

pull/14/head
Sam Bosley 13 years ago
parent 23fc2277b8
commit 28d05d6325

@ -241,7 +241,7 @@ public class EditPeopleControlSet extends PopupControlSet {
@Override @Override
public void run() { public void run() {
ArrayList<JSONObject> collaborators = new ArrayList<JSONObject>(); ArrayList<JSONObject> collaborators = new ArrayList<JSONObject>();
TodorooCursor<Metadata> tags = TagService.getInstance().getTags(task.getId()); TodorooCursor<Metadata> tags = TagService.getInstance().getTags(task.getId(), true);
try { try {
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) {

@ -394,7 +394,7 @@ public final class ActFmSyncService {
} }
if(Flags.checkAndClear(Flags.TAGS_CHANGED) || newlyCreated) { if(Flags.checkAndClear(Flags.TAGS_CHANGED) || newlyCreated) {
TodorooCursor<Metadata> cursor = TagService.getInstance().getTags(task.getId()); TodorooCursor<Metadata> cursor = TagService.getInstance().getTags(task.getId(), false);
try { try {
if(cursor.getCount() == 0) { if(cursor.getCount() == 0) {
params.add("tags"); params.add("tags");

@ -38,7 +38,7 @@ public class TagCaseMigrator {
public void performTagCaseMigration(@SuppressWarnings("unused") Context context) { public void performTagCaseMigration(@SuppressWarnings("unused") Context context) {
if (!Preferences.getBoolean(PREF_CASE_MIGRATION_PERFORMED, false)) { if (!Preferences.getBoolean(PREF_CASE_MIGRATION_PERFORMED, false)) {
TagService.Tag[] allTagData = TagService.getInstance().getGroupedTags( TagService.Tag[] allTagData = TagService.getInstance().getGroupedTags(
TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all); TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all, false);
boolean shouldShowDialog = false; boolean shouldShowDialog = false;
for (int i = 0; i < allTagData.length - 1; i++) { for (int i = 0; i < allTagData.length - 1; i++) {

@ -35,7 +35,7 @@ public class TagCustomFilterCriteriaExposer extends BroadcastReceiver {
// built in criteria: tags // built in criteria: tags
{ {
TagService.Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE, TagService.Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
TaskDao.TaskCriteria.activeAndVisible()); TaskDao.TaskCriteria.activeAndVisible(), false);
String[] tagNames = new String[tags.length]; String[] tagNames = new String[tags.length];
for(int i = 0; i < tags.length; i++) for(int i = 0; i < tags.length; i++)
tagNames[i] = tags[i].tag; tagNames[i] = tags[i].tag;

@ -37,7 +37,7 @@ public class TagDetailExposer extends BroadcastReceiver {
} }
public String getTaskDetails(long id) { public String getTaskDetails(long id) {
String tagList = TagService.getInstance().getTagsAsString(id); String tagList = TagService.getInstance().getTagsAsString(id, false);
if(tagList.length() == 0) if(tagList.length() == 0)
return null; return null;

@ -193,10 +193,15 @@ public final class TagService {
* @param activeStatus criterion for specifying completed or uncompleted * @param activeStatus criterion for specifying completed or uncompleted
* @return empty array if no tags, otherwise array * @return empty array if no tags, otherwise array
*/ */
public Tag[] getGroupedTags(Order order, Criterion activeStatus) { public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) {
Criterion criterion;
if (includeEmergent)
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(KEY));
else
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(KEY), Criterion.not(TAG.in(getEmergentTags())));
Query query = Query.select(TAG, REMOTE_ID, COUNT). Query query = Query.select(TAG, REMOTE_ID, COUNT).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))). join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(Criterion.and(activeStatus, MetadataCriteria.withKey(KEY))). where(criterion).
orderBy(order).groupBy(TAG); orderBy(order).groupBy(TAG);
TodorooCursor<Metadata> cursor = metadataDao.query(query); TodorooCursor<Metadata> cursor = metadataDao.query(query);
try { try {
@ -211,15 +216,38 @@ public final class TagService {
} }
} }
private String[] getEmergentTags() {
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();
}
}
/** /**
* Return tags on the given task * Return tags on the given task
* *
* @param taskId * @param taskId
* @return cursor. PLEASE CLOSE THE CURSOR! * @return cursor. PLEASE CLOSE THE CURSOR!
*/ */
public TodorooCursor<Metadata> getTags(long taskId) { public TodorooCursor<Metadata> getTags(long taskId, boolean includeEmergent) {
Query query = Query.select(TAG, REMOTE_ID).where(Criterion.and(MetadataCriteria.withKey(KEY), Criterion criterion;
MetadataCriteria.byTask(taskId))).orderBy(Order.asc(Functions.upper(TAG))); if (includeEmergent)
criterion = Criterion.and(MetadataCriteria.withKey(KEY),
MetadataCriteria.byTask(taskId));
else
criterion = Criterion.and(MetadataCriteria.withKey(KEY),
MetadataCriteria.byTask(taskId), Criterion.not(TAG.in(getEmergentTags())));
Query query = Query.select(TAG, REMOTE_ID).where(criterion).orderBy(Order.asc(Functions.upper(TAG)));
return metadataDao.query(query); return metadataDao.query(query);
} }
@ -229,8 +257,8 @@ public final class TagService {
* @param taskId * @param taskId
* @return empty string if no tags, otherwise string * @return empty string if no tags, otherwise string
*/ */
public String getTagsAsString(long taskId) { public String getTagsAsString(long taskId, boolean includeEmergent) {
return getTagsAsString(taskId, ", "); return getTagsAsString(taskId, ", ", includeEmergent);
} }
/** /**
@ -239,9 +267,9 @@ public final class TagService {
* @param taskId * @param taskId
* @return empty string if no tags, otherwise string * @return empty string if no tags, otherwise string
*/ */
public String getTagsAsString(long taskId, String separator) { protected String getTagsAsString(long taskId, String separator, boolean includeEmergent) {
StringBuilder tagBuilder = new StringBuilder(); StringBuilder tagBuilder = new StringBuilder();
TodorooCursor<Metadata> tags = getTags(taskId); TodorooCursor<Metadata> tags = getTags(taskId, includeEmergent);
try { try {
int length = tags.getCount(); int length = tags.getCount();
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
@ -285,7 +313,7 @@ public final class TagService {
HashMap<String, Tag> tags = new HashMap<String, Tag>(); HashMap<String, Tag> tags = new HashMap<String, Tag>();
Tag[] tagsByAlpha = getGroupedTags(TagService.GROUPED_TAGS_BY_ALPHA, Tag[] tagsByAlpha = getGroupedTags(TagService.GROUPED_TAGS_BY_ALPHA,
TaskCriteria.activeAndVisible()); TaskCriteria.activeAndVisible(), false);
for(Tag tag : tagsByAlpha) for(Tag tag : tagsByAlpha)
if(!TextUtils.isEmpty(tag.tag)) if(!TextUtils.isEmpty(tag.tag))
tags.put(tag.tag, tag); tags.put(tag.tag, tag);

@ -223,7 +223,7 @@ public final class TagsControlSet extends PopupControlSet {
public void readFromTask(Task task) { public void readFromTask(Task task) {
super.readFromTask(task); super.readFromTask(task);
if(model.getId() != AbstractModel.NO_ID) { if(model.getId() != AbstractModel.NO_ID) {
TodorooCursor<Metadata> cursor = tagService.getTags(model.getId()); TodorooCursor<Metadata> cursor = tagService.getTags(model.getId(), false);
LinkedHashSet<String> tags = new LinkedHashSet<String>(cursor.getCount()); LinkedHashSet<String> tags = new LinkedHashSet<String>(cursor.getCount());
try { try {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {

@ -138,7 +138,7 @@ public class Astrid2TaskProvider extends ContentProvider {
public Cursor getTags() { public Cursor getTags() {
Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE, Tag[] tags = TagService.getInstance().getGroupedTags(TagService.GROUPED_TAGS_BY_SIZE,
Criterion.all); Criterion.all, true);
MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST); MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST);
@ -195,7 +195,7 @@ public class Astrid2TaskProvider extends ContentProvider {
task.readFromCursor(cursor); task.readFromCursor(cursor);
StringBuilder taskTags = new StringBuilder(); StringBuilder taskTags = new StringBuilder();
TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId()); TodorooCursor<Metadata> tagCursor = TagService.getInstance().getTags(task.getId(), true);
try { try {
for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext()) for(tagCursor.moveToFirst(); !tagCursor.isAfterLast(); tagCursor.moveToNext())
taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR); taskTags.append(tagCursor.get(TagService.TAG)).append(TAG_SEPARATOR);

Loading…
Cancel
Save