Don't import duplicate tags

pull/467/head
Alex Baker 8 years ago
parent 0272097abc
commit 902731734f

@ -12,6 +12,7 @@ import android.content.res.Resources;
import android.os.Handler;
import android.text.TextUtils;
import com.google.common.collect.Iterables;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.PropertyVisitor;
@ -36,6 +37,7 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import javax.inject.Inject;
@ -229,6 +231,13 @@ public class TasksXmlImporter {
}
metadata.clear();
deserializeModel(metadata, Metadata.PROPERTIES);
if (metadata.getKey().equals(TaskToTagMetadata.KEY)) {
String uuid = metadata.getValue(TaskToTagMetadata.TAG_UUID);
List<Metadata> metadatas = metadataDao.byTaskAndKey(currentTask.getId(), TaskToTagMetadata.KEY);
if (Iterables.any(metadatas, existing -> uuid.equals(existing.getValue(TaskToTagMetadata.TAG_UUID)))) {
return;
}
}
metadata.setId(Metadata.NO_ID);
metadata.setTask(currentTask.getId());
metadataDao.persist(metadata);
@ -350,7 +359,9 @@ public class TasksXmlImporter {
private void parseTagdata() {
tagdata.clear();
deserializeModel(tagdata, TagData.PROPERTIES);
tagDataDao.persist(tagdata);
if (tagDataDao.getByUuid(tagdata.getUuid()) == null) {
tagDataDao.persist(tagdata);
}
}
}
}

@ -145,6 +145,11 @@ public class MetadataDao {
dao.query(callback, Query.select(Metadata.PROPERTIES).where(Metadata.TASK.eq(taskId)));
}
public List<Metadata> byTaskAndKey(long taskId, String key) {
return dao.toList(Query.select(Metadata.PROPERTIES).where(
Criterion.and(Metadata.TASK.eq(taskId), Metadata.KEY.eq(key))));
}
public void byTaskAndKey(long taskId, String key, Callback<Metadata> callback) {
dao.query(callback, Query.select(Metadata.PROPERTIES).where(
Criterion.and(Metadata.TASK.eq(taskId), Metadata.KEY.eq(key))));

Loading…
Cancel
Save