|
|
@ -5,6 +5,7 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package com.todoroo.astrid.tags;
|
|
|
|
package com.todoroo.astrid.tags;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Comparator;
|
|
|
|
import java.util.Comparator;
|
|
|
@ -104,13 +105,15 @@ public final class TagService {
|
|
|
|
public String tag;
|
|
|
|
public String tag;
|
|
|
|
public int count;
|
|
|
|
public int count;
|
|
|
|
public long id;
|
|
|
|
public long id;
|
|
|
|
public long remoteId;
|
|
|
|
public BigInteger uuid;
|
|
|
|
public String image;
|
|
|
|
public String image;
|
|
|
|
public long userId;
|
|
|
|
public long userId;
|
|
|
|
public long memberCount;
|
|
|
|
public long memberCount;
|
|
|
|
|
|
|
|
|
|
|
|
public static Tag tagFromRemoteId(long remoteId) {
|
|
|
|
@Deprecated public long remoteId;
|
|
|
|
TodorooCursor<TagData> tagData = PluginServices.getTagDataService().query(Query.select(TagData.PROPERTIES).where(TagData.REMOTE_ID.eq(remoteId)));
|
|
|
|
|
|
|
|
|
|
|
|
public static Tag tagFromUUID(BigInteger uuid) {
|
|
|
|
|
|
|
|
TodorooCursor<TagData> tagData = PluginServices.getTagDataService().query(Query.select(TagData.PROPERTIES).where(TagData.UUID.eq(uuid)));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (tagData.getCount() > 0) {
|
|
|
|
if (tagData.getCount() > 0) {
|
|
|
|
tagData.moveToFirst();
|
|
|
|
tagData.moveToFirst();
|
|
|
@ -129,6 +132,7 @@ public final class TagService {
|
|
|
|
tag = tagData.getValue(TagData.NAME);
|
|
|
|
tag = tagData.getValue(TagData.NAME);
|
|
|
|
count = tagData.getValue(TagData.TASK_COUNT);
|
|
|
|
count = tagData.getValue(TagData.TASK_COUNT);
|
|
|
|
remoteId = tagData.getValue(TagData.REMOTE_ID);
|
|
|
|
remoteId = tagData.getValue(TagData.REMOTE_ID);
|
|
|
|
|
|
|
|
uuid = tagData.getValue(TagData.UUID);
|
|
|
|
image = tagData.getValue(TagData.PICTURE);
|
|
|
|
image = tagData.getValue(TagData.PICTURE);
|
|
|
|
userId = tagData.getValue(TagData.USER_ID);
|
|
|
|
userId = tagData.getValue(TagData.USER_ID);
|
|
|
|
memberCount = tagData.getValue(TagData.MEMBER_COUNT);
|
|
|
|
memberCount = tagData.getValue(TagData.MEMBER_COUNT);
|
|
|
@ -148,10 +152,10 @@ public final class TagService {
|
|
|
|
public QueryTemplate queryTemplate(Criterion criterion) {
|
|
|
|
public QueryTemplate queryTemplate(Criterion criterion) {
|
|
|
|
Criterion fullCriterion = Criterion.and(
|
|
|
|
Criterion fullCriterion = Criterion.and(
|
|
|
|
Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY),
|
|
|
|
Field.field("mtags." + Metadata.KEY.name).eq(TagMetadata.KEY),
|
|
|
|
Field.field("mtags." + TagMetadata.TAG_UUID.name).eq(remoteId),
|
|
|
|
Field.field("mtags." + TagMetadata.TAG_UUID.name).eq(uuid),
|
|
|
|
Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0),
|
|
|
|
Field.field("mtags." + Metadata.DELETION_DATE.name).eq(0),
|
|
|
|
criterion);
|
|
|
|
criterion);
|
|
|
|
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.REMOTE_ID.eq(Field.field("mtags." + TagMetadata.TASK_UUID.name))))
|
|
|
|
return new QueryTemplate().join(Join.inner(Metadata.TABLE.as("mtags"), Task.UUID.eq(Field.field("mtags." + TagMetadata.TASK_UUID.name))))
|
|
|
|
.where(fullCriterion);
|
|
|
|
.where(fullCriterion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -208,7 +212,7 @@ public final class TagService {
|
|
|
|
ArrayList<Tag> array = new ArrayList<Tag>();
|
|
|
|
ArrayList<Tag> array = new ArrayList<Tag>();
|
|
|
|
for (int i = 0; i < cursor.getCount(); i++) {
|
|
|
|
for (int i = 0; i < cursor.getCount(); i++) {
|
|
|
|
cursor.moveToNext();
|
|
|
|
cursor.moveToNext();
|
|
|
|
Tag tag = Tag.tagFromRemoteId(cursor.get(TagMetadata.TAG_UUID));
|
|
|
|
Tag tag = Tag.tagFromUUID(cursor.get(TagMetadata.TAG_UUID));
|
|
|
|
if (tag != null)
|
|
|
|
if (tag != null)
|
|
|
|
array.add(tag);
|
|
|
|
array.add(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -236,7 +240,7 @@ public final class TagService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createLink(Task task, String tagName) {
|
|
|
|
public void createLink(Task task, String tagName) {
|
|
|
|
TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.REMOTE_ID)
|
|
|
|
TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.UUID)
|
|
|
|
.where(TagData.NAME.eqCaseInsensitive(tagName)));
|
|
|
|
.where(TagData.NAME.eqCaseInsensitive(tagName)));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TagData tagData;
|
|
|
|
TagData tagData;
|
|
|
@ -247,16 +251,16 @@ public final class TagService {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
tagData = new TagData(existingTag);
|
|
|
|
tagData = new TagData(existingTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
createLink(task, tagData.getValue(TagData.NAME), tagData.getValue(TagData.REMOTE_ID));
|
|
|
|
createLink(task, tagData.getValue(TagData.NAME), tagData.getValue(TagData.UUID));
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
existingTag.close();
|
|
|
|
existingTag.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void createLink(Task task, String tagName, long tagUuid) {
|
|
|
|
public void createLink(Task task, String tagName, BigInteger tagUuid) {
|
|
|
|
TodorooCursor<Metadata> existing = metadataDao.query(Query.select(Metadata.PROPERTIES)
|
|
|
|
TodorooCursor<Metadata> existing = metadataDao.query(Query.select(Metadata.PROPERTIES)
|
|
|
|
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
|
|
|
|
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),
|
|
|
|
TagMetadata.TASK_UUID.eq(task.getValue(Task.REMOTE_ID)),
|
|
|
|
TagMetadata.TASK_UUID.eq(task.getValue(Task.UUID)),
|
|
|
|
TagMetadata.TAG_UUID.eq(tagUuid),
|
|
|
|
TagMetadata.TAG_UUID.eq(tagUuid),
|
|
|
|
Metadata.DELETION_DATE.eq(0))));
|
|
|
|
Metadata.DELETION_DATE.eq(0))));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -416,8 +420,8 @@ public final class TagService {
|
|
|
|
* @param taskId
|
|
|
|
* @param taskId
|
|
|
|
* @param tags
|
|
|
|
* @param tags
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public boolean synchronizeTags(long taskId, long taskUuid, Set<String> tags) {
|
|
|
|
public boolean synchronizeTags(long taskId, BigInteger taskUuid, Set<String> tags) {
|
|
|
|
HashSet<Long> existingLinks = new HashSet<Long>();
|
|
|
|
HashSet<BigInteger> existingLinks = new HashSet<BigInteger>();
|
|
|
|
TodorooCursor<Metadata> links = metadataDao.query(Query.select(Metadata.PROPERTIES)
|
|
|
|
TodorooCursor<Metadata> links = metadataDao.query(Query.select(Metadata.PROPERTIES)
|
|
|
|
.where(Criterion.and(TagMetadata.TASK_UUID.eq(taskUuid), Metadata.DELETION_DATE.eq(0))));
|
|
|
|
.where(Criterion.and(TagMetadata.TASK_UUID.eq(taskUuid), Metadata.DELETION_DATE.eq(0))));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -430,16 +434,16 @@ public final class TagService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (String tag : tags) {
|
|
|
|
for (String tag : tags) {
|
|
|
|
TagData tagData = getTagDataWithCase(tag, TagData.NAME, TagData.REMOTE_ID);
|
|
|
|
TagData tagData = getTagDataWithCase(tag, TagData.NAME, TagData.UUID);
|
|
|
|
if (tagData == null) {
|
|
|
|
if (tagData == null) {
|
|
|
|
tagData = new TagData();
|
|
|
|
tagData = new TagData();
|
|
|
|
tagData.setValue(TagData.NAME, tag);
|
|
|
|
tagData.setValue(TagData.NAME, tag);
|
|
|
|
tagDataService.save(tagData);
|
|
|
|
tagDataService.save(tagData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (existingLinks.contains(tagData.getValue(TagData.REMOTE_ID))) {
|
|
|
|
if (existingLinks.contains(tagData.getValue(TagData.UUID))) {
|
|
|
|
existingLinks.remove(tagData.getValue(TagData.REMOTE_ID));
|
|
|
|
existingLinks.remove(tagData.getValue(TagData.UUID));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Metadata newLink = TagMetadata.newTagMetadata(taskId, taskUuid, tag, tagData.getValue(TagData.REMOTE_ID));
|
|
|
|
Metadata newLink = TagMetadata.newTagMetadata(taskId, taskUuid, tag, tagData.getValue(TagData.UUID));
|
|
|
|
metadataDao.createNew(newLink);
|
|
|
|
metadataDao.createNew(newLink);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|