Make tag creation work better in TaskService.createWithValues

pull/14/head
Sam Bosley 12 years ago
parent 7175865a12
commit 0a8f523551

@ -235,6 +235,24 @@ public final class TagService {
}
}
public void createLink(Task task, String tagName) {
TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.REMOTE_ID)
.where(TagData.NAME.eqCaseInsensitive(tagName)));
try {
TagData tagData;
if (existingTag.getCount() == 0) {
tagData = new TagData();
tagData.setValue(TagData.NAME, tagName);
tagDataService.save(tagData);
} else {
tagData = new TagData(existingTag);
}
createLink(task, tagData.getValue(TagData.NAME), tagData.getValue(TagData.REMOTE_ID));
} finally {
existingTag.close();
}
}
public void createLink(Task task, String tagName, long tagUuid) {
TodorooCursor<Metadata> existing = metadataDao.query(Query.select(Metadata.PROPERTIES)
.where(Criterion.and(MetadataCriteria.withKey(TagMetadata.KEY),

@ -425,13 +425,8 @@ public class TaskService {
*/
private void quickAdd(Task task, List<String> tags) {
save(task);
Metadata metadata = new Metadata();
for(String tag : tags) {
metadata.setValue(Metadata.KEY, TagMetadata.KEY);
metadata.setValue(Metadata.TASK, task.getId());
metadata.setValue(TagMetadata.TAG_NAME, tag);
metadataDao.createNew(metadata);
TagService.getInstance().createLink(task, tag);
}
}
@ -536,10 +531,18 @@ public class TaskService {
Metadata metadata = new Metadata();
metadata.setValue(Metadata.TASK, task.getId());
metadata.mergeWith(forMetadata);
if (TagMetadata.KEY.equals(metadata.getValue(Metadata.KEY)))
metadata.setValue(TagMetadata.TASK_UUID, task.getValue(Task.REMOTE_ID));
if (TagMetadata.KEY.equals(metadata.getValue(Metadata.KEY))) {
if (metadata.containsNonNullValue(TagMetadata.TAG_UUID) && metadata.getValue(TagMetadata.TAG_UUID) != 0) {
// This is more efficient
TagService.getInstance().createLink(task, metadata.getValue(TagMetadata.TAG_NAME), metadata.getValue(TagMetadata.TAG_UUID));
} else {
// This is necessary for backwards compatibility
TagService.getInstance().createLink(task, metadata.getValue(TagMetadata.TAG_NAME));
}
} else {
PluginServices.getMetadataService().save(metadata);
}
}
return task;
}

Loading…
Cancel
Save