Deprecated emergent tags, delete them from the database on migration

pull/14/head
Sam Bosley 12 years ago
parent a53474844c
commit 416d6076de

@ -138,6 +138,7 @@ public final class TagData extends RemoteModel {
public static final int FLAG_SILENT = 1 << 1; public static final int FLAG_SILENT = 1 << 1;
/** whether tag is emergent */ /** whether tag is emergent */
@Deprecated
public static final int FLAG_EMERGENT = 1 << 2; public static final int FLAG_EMERGENT = 1 << 2;
/** whether tag represents a featured list */ /** whether tag represents a featured list */

@ -188,7 +188,7 @@ public class EditPeopleControlSet extends PopupControlSet {
@Override @Override
public void run() { public void run() {
ArrayList<JSONObject> sharedPeople = new ArrayList<JSONObject>(); ArrayList<JSONObject> sharedPeople = new ArrayList<JSONObject>();
TodorooCursor<TagData> tags = TagService.getInstance().getTagDataForTask(task.getId(), true, TagData.NAME, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER); TodorooCursor<TagData> tags = TagService.getInstance().getTagDataForTask(task.getId(), TagData.NAME, TagData.MEMBER_COUNT, TagData.MEMBERS, TagData.USER);
try { try {
TagData tagData = new TagData(); TagData tagData = new TagData();
for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) { for(tags.moveToFirst(); !tags.isAfterLast(); tags.moveToNext()) {

@ -275,14 +275,12 @@ public class TagSettingsActivity extends FragmentActivity {
if (oldName.equalsIgnoreCase(newName)) { // Change the capitalization of a list manually if (oldName.equalsIgnoreCase(newName)) { // Change the capitalization of a list manually
tagData.setValue(TagData.NAME, newName); tagData.setValue(TagData.NAME, newName);
service.renameCaseSensitive(oldName, newName); service.renameCaseSensitive(oldName, newName);
tagData.setFlag(TagData.FLAGS, TagData.FLAG_EMERGENT, false);
} else { // Rename list--check for existing name } else { // Rename list--check for existing name
newName = service.getTagWithCase(newName); newName = service.getTagWithCase(newName);
tagName.setText(newName); tagName.setText(newName);
if (!newName.equals(oldName)) { if (!newName.equals(oldName)) {
tagData.setValue(TagData.NAME, newName); tagData.setValue(TagData.NAME, newName);
service.rename(oldName, newName); service.rename(oldName, newName);
tagData.setFlag(TagData.FLAGS, TagData.FLAG_EMERGENT, false);
} else { } else {
nameChanged = false; nameChanged = false;
} }

@ -574,9 +574,6 @@ public final class ActFmSyncService {
if(json.has("is_silent")) if(json.has("is_silent"))
model.setFlag(TagData.FLAGS, TagData.FLAG_SILENT,json.getBoolean("is_silent")); model.setFlag(TagData.FLAGS, TagData.FLAG_SILENT,json.getBoolean("is_silent"));
if(json.has("emergent"))
model.setFlag(TagData.FLAGS, TagData.FLAG_EMERGENT,json.getBoolean("emergent"));
if(!json.isNull("description")) if(!json.isNull("description"))
model.setValue(TagData.TAG_DESCRIPTION, json.getString("description")); model.setValue(TagData.TAG_DESCRIPTION, json.getString("description"));

@ -9,6 +9,7 @@ import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
@ -98,6 +99,28 @@ public class AstridNewSyncMigrator {
Log.e(LOG_TAG, "Error creating tag data", e); Log.e(LOG_TAG, "Error creating tag data", e);
} }
// --------------
// Delete all emergent tag data, we don't need it
// --------------
try {
TodorooCursor<TagData> emergentTags = tagDataDao.query(Query.select(TagData.ID, TagData.NAME).where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0)));
try {
TagData td = new TagData();
for (emergentTags.moveToFirst(); !emergentTags.isAfterLast(); emergentTags.moveToNext()) {
td.clear();
td.readFromCursor(emergentTags);
String name = td.getValue(TagData.NAME);
tagDataDao.delete(td.getId());
if (!TextUtils.isEmpty(name))
metadataService.deleteWhere(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), TaskToTagMetadata.TAG_NAME.eq(name)));
}
} finally {
emergentTags.close();
}
} catch (Exception e) {
Log.e(LOG_TAG, "Error clearing emergent tags");
}
// -------------- // --------------
// Then ensure that every remote model has a remote id, by generating one using the uuid generator for all those without one // Then ensure that every remote model has a remote id, by generating one using the uuid generator for all those without one
// -------------- // --------------
@ -252,14 +275,14 @@ public class AstridNewSyncMigrator {
if (ActFmInvoker.SYNC_DEBUG) if (ActFmInvoker.SYNC_DEBUG)
Log.w(LOG_TAG, "Incomplete linking task " + m.getValue(Metadata.TASK) + " to " + m.getValue(TaskToTagMetadata.TAG_NAME)); Log.w(LOG_TAG, "Incomplete linking task " + m.getValue(Metadata.TASK) + " to " + m.getValue(TaskToTagMetadata.TAG_NAME));
if (!m.containsNonNullValue(TaskToTagMetadata.TASK_UUID) || RemoteModel.NO_UUID.equals(m.getValue(TaskToTagMetadata.TASK_UUID))) { if (!m.containsNonNullValue(TaskToTagMetadata.TASK_UUID) || RemoteModel.isUuidEmpty(m.getValue(TaskToTagMetadata.TASK_UUID))) {
if (ActFmInvoker.SYNC_DEBUG) if (ActFmInvoker.SYNC_DEBUG)
Log.w(LOG_TAG, "No task uuid"); Log.w(LOG_TAG, "No task uuid");
updateTaskUuid(m); updateTaskUuid(m);
changes = true; changes = true;
} }
if (!m.containsNonNullValue(TaskToTagMetadata.TAG_UUID) || RemoteModel.NO_UUID.equals(m.getValue(TaskToTagMetadata.TAG_UUID))) { if (!m.containsNonNullValue(TaskToTagMetadata.TAG_UUID) || RemoteModel.isUuidEmpty(m.getValue(TaskToTagMetadata.TAG_UUID))) {
if (ActFmInvoker.SYNC_DEBUG) if (ActFmInvoker.SYNC_DEBUG)
Log.w(LOG_TAG, "No tag uuid"); Log.w(LOG_TAG, "No tag uuid");
updateTagUuid(m); updateTagUuid(m);

@ -44,7 +44,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, false); TagService.GROUPED_TAGS_BY_ALPHA, Criterion.all);
boolean shouldShowDialog = false; boolean shouldShowDialog = false;
for (int i = 0; i < allTagData.length - 1; i++) { for (int i = 0; i < allTagData.length - 1; i++) {

@ -41,7 +41,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(), false); TaskDao.TaskCriteria.activeAndVisible());
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;

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

@ -173,11 +173,9 @@ public final class TagService {
} }
public QueryTemplate untaggedTemplate() { public QueryTemplate untaggedTemplate() {
String[] emergentTags = getEmergentTagIds();
return new QueryTemplate().where(Criterion.and( return new QueryTemplate().where(Criterion.and(
Criterion.not(Task.UUID.in(Query.select(TaskToTagMetadata.TASK_UUID).from(Metadata.TABLE) Criterion.not(Task.UUID.in(Query.select(TaskToTagMetadata.TASK_UUID).from(Metadata.TABLE)
.where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), Metadata.DELETION_DATE.eq(0), Criterion.not(TaskToTagMetadata.TAG_UUID.in(emergentTags)))))), .where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), Metadata.DELETION_DATE.eq(0))))),
TaskCriteria.isActive(), TaskCriteria.isActive(),
TaskApiDao.TaskCriteria.ownedByMe(), TaskApiDao.TaskCriteria.ownedByMe(),
TaskCriteria.isVisible())); TaskCriteria.isVisible()));
@ -191,12 +189,8 @@ public final class TagService {
* @return empty array if no tags, otherwise array * @return empty array if no tags, otherwise array
*/ */
@Deprecated @Deprecated
public Tag[] getGroupedTags(Order order, Criterion activeStatus, boolean includeEmergent) { public Tag[] getGroupedTags(Order order, Criterion activeStatus) {
Criterion criterion; Criterion criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TaskToTagMetadata.KEY));
if (includeEmergent)
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TaskToTagMetadata.KEY));
else
criterion = Criterion.and(activeStatus, MetadataCriteria.withKey(TaskToTagMetadata.KEY), Criterion.not(TaskToTagMetadata.TAG_UUID.in(getEmergentTagIds())));
Query query = Query.select(TaskToTagMetadata.TAG_NAME, TaskToTagMetadata.TAG_UUID, COUNT). Query query = Query.select(TaskToTagMetadata.TAG_NAME, TaskToTagMetadata.TAG_UUID, COUNT).
join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))). join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))).
where(criterion). where(criterion).
@ -216,25 +210,6 @@ public final class TagService {
} }
} }
public String[] getEmergentTagIds() {
TodorooCursor<TagData> emergent = tagDataService.query(Query.select(TagData.UUID)
.where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_EMERGENT).gt(0)));
try {
ArrayList<String> tags = new ArrayList<String>();
TagData data = new TagData();
for (int i = 0; i < emergent.getCount(); i++) {
emergent.moveToPosition(i);
data.readFromCursor(emergent);
String uuid = data.getValue(TagData.UUID);
if (!TextUtils.isEmpty(uuid) && !"0".equals(uuid))
tags.add(uuid);
}
return tags.toArray(new String[tags.size()]);
} finally {
emergent.close();
}
}
public void createLink(Task task, String tagName) { public void createLink(Task task, String tagName) {
TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.UUID) TodorooCursor<TagData> existingTag = tagDataService.query(Query.select(TagData.NAME, TagData.UUID)
.where(TagData.NAME.eqCaseInsensitive(tagName))); .where(TagData.NAME.eqCaseInsensitive(tagName)));
@ -338,28 +313,20 @@ public final class TagService {
* @param taskId * @param taskId
* @return cursor. PLEASE CLOSE THE CURSOR! * @return cursor. PLEASE CLOSE THE CURSOR!
*/ */
public TodorooCursor<Metadata> getTags(long taskId, boolean includeEmergent) { public TodorooCursor<Metadata> getTags(long taskId) {
Criterion criterion; Criterion criterion = Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY),
if (includeEmergent)
criterion = Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY),
Metadata.DELETION_DATE.eq(0), Metadata.DELETION_DATE.eq(0),
MetadataCriteria.byTask(taskId)); MetadataCriteria.byTask(taskId));
else
criterion = Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY),
Metadata.DELETION_DATE.eq(0),
MetadataCriteria.byTask(taskId), Criterion.not(TaskToTagMetadata.TAG_UUID.in(getEmergentTagIds())));
Query query = Query.select(TaskToTagMetadata.TAG_NAME, TaskToTagMetadata.TAG_UUID).where(criterion).orderBy(Order.asc(Functions.upper(TaskToTagMetadata.TAG_NAME))); Query query = Query.select(TaskToTagMetadata.TAG_NAME, TaskToTagMetadata.TAG_UUID).where(criterion).orderBy(Order.asc(Functions.upper(TaskToTagMetadata.TAG_NAME)));
return metadataDao.query(query); return metadataDao.query(query);
} }
public TodorooCursor<TagData> getTagDataForTask(long taskId, boolean includeEmergent, Property<?>... properties) { public TodorooCursor<TagData> getTagDataForTask(long taskId, Property<?>... properties) {
Criterion criterion = TagData.UUID.in(Query.select(TaskToTagMetadata.TAG_UUID) Criterion criterion = TagData.UUID.in(Query.select(TaskToTagMetadata.TAG_UUID)
.from(Metadata.TABLE) .from(Metadata.TABLE)
.where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY), .where(Criterion.and(MetadataCriteria.withKey(TaskToTagMetadata.KEY),
Metadata.DELETION_DATE.eq(0), Metadata.DELETION_DATE.eq(0),
Metadata.TASK.eq(taskId)))); Metadata.TASK.eq(taskId))));
if (!includeEmergent)
criterion = Criterion.and(Criterion.not(TagData.UUID.in(getEmergentTagIds())), criterion);
return tagDataService.query(Query.select(properties).where(criterion)); return tagDataService.query(Query.select(properties).where(criterion));
} }
@ -377,8 +344,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, boolean includeEmergent) { public String getTagsAsString(long taskId) {
return getTagsAsString(taskId, ", ", includeEmergent); return getTagsAsString(taskId, ", ");
} }
/** /**
@ -387,9 +354,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, boolean includeEmergent) { public String getTagsAsString(long taskId, String separator) {
StringBuilder tagBuilder = new StringBuilder(); StringBuilder tagBuilder = new StringBuilder();
TodorooCursor<Metadata> tags = getTags(taskId, includeEmergent); TodorooCursor<Metadata> tags = getTags(taskId);
try { try {
int length = tags.getCount(); int length = tags.getCount();
Metadata metadata = new Metadata(); Metadata metadata = new Metadata();
@ -437,7 +404,7 @@ public final class TagService {
for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { for(cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
tagData.readFromCursor(cursor); tagData.readFromCursor(cursor);
Tag tag = new Tag(tagData); Tag tag = new Tag(tagData);
if(tagData.getValue(TagData.DELETION_DATE) > 0 || tagData.getFlag(TagData.FLAGS, TagData.FLAG_EMERGENT) || tagData.getFlag(TagData.FLAGS, TagData.FLAG_FEATURED)) { if(tagData.getValue(TagData.DELETION_DATE) > 0 || tagData.getFlag(TagData.FLAGS, TagData.FLAG_FEATURED)) {
continue; continue;
} }
if(TextUtils.isEmpty(tag.tag)) if(TextUtils.isEmpty(tag.tag))

@ -228,7 +228,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(), false); TodorooCursor<Metadata> cursor = tagService.getTags(model.getId());
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()) {

@ -104,7 +104,6 @@ import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.UpgradeService; import com.todoroo.astrid.service.UpgradeService;
import com.todoroo.astrid.subtasks.SubtasksListFragment; import com.todoroo.astrid.subtasks.SubtasksListFragment;
import com.todoroo.astrid.sync.SyncProviderPreferences; import com.todoroo.astrid.sync.SyncProviderPreferences;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TaskToTagMetadata; import com.todoroo.astrid.tags.TaskToTagMetadata;
import com.todoroo.astrid.taskrabbit.TaskRabbitMetadata; import com.todoroo.astrid.taskrabbit.TaskRabbitMetadata;
import com.todoroo.astrid.timers.TimerPlugin; import com.todoroo.astrid.timers.TimerPlugin;
@ -960,14 +959,12 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
if (getActiveTagData() != null) if (getActiveTagData() != null)
tagName = getActiveTagData().getValue(TagData.NAME); tagName = getActiveTagData().getValue(TagData.NAME);
String[] emergentTagIds = TagService.getInstance().getEmergentTagIds();
StringProperty tagProperty = new StringProperty(null, TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_UUID.name); StringProperty tagProperty = new StringProperty(null, TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_UUID.name);
Criterion tagsJoinCriterion = Criterion.and( Criterion tagsJoinCriterion = Criterion.and(
Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name).eq(TaskToTagMetadata.KEY), //$NON-NLS-1$ Field.field(TAGS_METADATA_JOIN + "." + Metadata.KEY.name).eq(TaskToTagMetadata.KEY), //$NON-NLS-1$
Field.field(TAGS_METADATA_JOIN + "." + Metadata.DELETION_DATE.name).eq(0), Field.field(TAGS_METADATA_JOIN + "." + Metadata.DELETION_DATE.name).eq(0),
Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)), Task.ID.eq(Field.field(TAGS_METADATA_JOIN + "." + Metadata.TASK.name)));
Criterion.not(tagProperty.in(emergentTagIds)));
if (tagName != null) if (tagName != null)
tagsJoinCriterion = Criterion.and(tagsJoinCriterion, Field.field(TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_NAME.name).neq(tagName)); tagsJoinCriterion = Criterion.and(tagsJoinCriterion, Field.field(TAGS_METADATA_JOIN + "." + TaskToTagMetadata.TAG_NAME.name).neq(tagName));

@ -142,7 +142,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, true); Criterion.all);
MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST); MatrixCursor ret = new MatrixCursor(TAGS_FIELD_LIST);
@ -198,7 +198,7 @@ public class Astrid2TaskProvider extends ContentProvider {
cursor.moveToNext(); cursor.moveToNext();
task.readFromCursor(cursor); task.readFromCursor(cursor);
String taskTags = TagService.getInstance().getTagsAsString(task.getId(), TAG_SEPARATOR, true); String taskTags = TagService.getInstance().getTagsAsString(task.getId(), TAG_SEPARATOR);
Object[] values = new Object[7]; Object[] values = new Object[7];
values[0] = task.getValue(Task.TITLE); values[0] = task.getValue(Task.TITLE);

Loading…
Cancel
Save