|
|
@ -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);
|
|
|
|