Remove Format1TaskImporter

pull/189/head
Alex Baker 10 years ago
parent 34511b83ff
commit 96f390f967

@ -43,8 +43,6 @@ public abstract class Property<TYPE> extends Field implements Cloneable {
public static final int PROP_FLAG_NULLABLE = 1;
/** Is this field a date? */
public static final int PROP_FLAG_DATE = 1 << 1;
/** Is this field a boolean? */
public static final int PROP_FLAG_BOOLEAN = 1 << 3;
/** Is this field a serialized JSON object? */
public static final int PROP_FLAG_JSON = 1 << 4;
/** Is this field for pictures? (usually as a json object containing "path" key or urls) */
@ -147,10 +145,6 @@ public abstract class Property<TYPE> extends Field implements Cloneable {
super(table, name);
}
public IntegerProperty(Table table, String name, int flags) {
super(table, name, flags);
}
protected IntegerProperty(String name, String expression) {
super(null, name, expression);
}

@ -149,20 +149,4 @@ public class Metadata extends AbstractModel {
public void setKey(String key) {
setValue(KEY, key);
}
public void setValue1(String value1) {
setValue(VALUE1, value1);
}
public void setValue2(String value2) {
setValue(VALUE2, value2);
}
public void setValue3(String value3) {
setValue(VALUE3, value3);
}
public void setValue4(String value4) {
setValue(VALUE4, value4);
}
}

@ -103,9 +103,6 @@ public class Task extends RemoteModel {
public static final LongProperty TIMER_START = new LongProperty(
TABLE, "timerStart", Property.PROP_FLAG_DATE);
public static final IntegerProperty POSTPONE_COUNT = new IntegerProperty(
TABLE, "postponeCount");
/** Flags for when to send reminders */
public static final IntegerProperty REMINDER_FLAGS = new IntegerProperty(
TABLE, "notificationFlags");
@ -199,7 +196,6 @@ public class Task extends RemoteModel {
defaultValues.put(REMINDER_SNOOZE.name, 0);
defaultValues.put(ESTIMATED_SECONDS.name, 0);
defaultValues.put(ELAPSED_SECONDS.name, 0);
defaultValues.put(POSTPONE_COUNT.name, 0);
defaultValues.put(NOTES.name, "");
defaultValues.put(TIMER_START.name, 0);
defaultValues.put(DETAILS.name, (String)null);
@ -392,10 +388,7 @@ public class Task extends RemoteModel {
* Checks whether this due date has a due time or only a date
*/
public boolean hasDueTime() {
if(!hasDueDate()) {
return false;
}
return hasDueTime(getDueDate());
return hasDueDate() && hasDueTime(getDueDate());
}
public boolean isOverdue() {
@ -584,14 +577,6 @@ public class Task extends RemoteModel {
return getValue(ESTIMATED_SECONDS);
}
public void setEstimatedSeconds(Integer estimatedSeconds) {
setValue(ESTIMATED_SECONDS, estimatedSeconds);
}
public void setPostponeCount(Integer postponeCount) {
setValue(POSTPONE_COUNT, postponeCount);
}
public void setELAPSED_SECONDS(Integer elapsedSeconds) {
setValue(ELAPSED_SECONDS, elapsedSeconds);
}

@ -9,8 +9,6 @@ import org.tasks.preferences.Preferences;
public class GtasksTestPreferenceService extends GtasksPreferenceService {
private long syncDate = 0;
public GtasksTestPreferenceService(Preferences preferences) {
super(preferences);
}
@ -20,12 +18,8 @@ public class GtasksTestPreferenceService extends GtasksPreferenceService {
return false;
}
public void setSyncDate(long date) {
syncDate = date;
}
@Override
public long getLastSyncDate() {
return syncDate;
return 0L;
}
}

@ -28,7 +28,6 @@ public class AdvancedRepeatTest extends AndroidTestCase {
private static final int PREV = -1;
private static final int THIS = 1;
private static final int NEXT = 2;
private static final int NEXT_NEXT = 3;
private Task task;
private long nextDueDate;

@ -41,14 +41,6 @@ public class BackupConstants {
/** Tag containing a tagdata item */
public static final String TAGDATA_TAG = "tagdata";
// --- format 1
public static final String TAG_TAG = "tag";
public static final String TAG_ATTR_NAME = "name";
public static final String SYNC_TAG = "sync";
public static final String SYNC_ATTR_SERVICE = "service";
public static final String SYNC_ATTR_REMOTE_ID = "remote_id";
// --- general
public static final String XML_ENCODING = "utf-8";

@ -1,66 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.backup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.tasks.date.DateTimeUtils.newDate;
/**
* Date Utility functions for backups
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class BackupDateUtilities {
private static final Logger log = LoggerFactory.getLogger(BackupDateUtilities.class);
private static final String ISO_8601_FORMAT = "yyyy-MM-dd'T'HH:mm:ssz";
/**
* Take an ISO 8601 string and return a Date object.
* On failure, returns null.
*/
public static Date getDateFromIso8601String(String s) {
SimpleDateFormat df = new SimpleDateFormat(ISO_8601_FORMAT);
try {
return df.parse(s);
} catch (ParseException e) {
log.error(e.getMessage(), e);
return null;
}
}
public static Date getTaskDueDateFromIso8601String(String s) {
System.err.println("Importing date string: " + s);
Date date = getDateFromIso8601String(s);
System.err.println("Got date: " + date);
if (date != null) {
if (date.getHours() == 23 && date.getMinutes() == 59 && date.getSeconds() == 59) {
date.setHours(12);
date.setMinutes(0);
date.setSeconds(0);
}
}
return date;
}
/**
* Get current date and time as a string. Used for naming backup files.
*/
public static String getDateForExport() {
DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
return df.format(newDate());
}
}

@ -37,9 +37,13 @@ import org.xmlpull.v1.XmlSerializer;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import javax.inject.Inject;
import static org.tasks.date.DateTimeUtils.newDate;
public class TasksXmlExporter {
private static final Logger log = LoggerFactory.getLogger(TasksXmlExporter.class);
@ -332,10 +336,10 @@ public class TasksXmlExporter {
String fileName;
switch(exportType) {
case EXPORT_TYPE_SERVICE:
fileName = String.format(BackupConstants.BACKUP_FILE_NAME, BackupDateUtilities.getDateForExport());
fileName = String.format(BackupConstants.BACKUP_FILE_NAME, getDateForExport());
break;
case EXPORT_TYPE_MANUAL:
fileName = String.format(BackupConstants.EXPORT_FILE_NAME, BackupDateUtilities.getDateForExport());
fileName = String.format(BackupConstants.EXPORT_FILE_NAME, getDateForExport());
break;
case EXPORT_TYPE_ON_UPGRADE:
fileName = String.format(BackupConstants.UPGRADE_FILE_NAME, latestSetVersionName);
@ -355,4 +359,8 @@ public class TasksXmlExporter {
}
}
private static String getDateForExport() {
DateFormat df = new SimpleDateFormat("yyMMdd-HHmm");
return df.format(newDate());
}
}

@ -16,27 +16,20 @@ import android.os.Handler;
import android.text.TextUtils;
import android.view.WindowManager.BadTokenException;
import com.google.ical.values.RRule;
import com.todoroo.andlib.data.AbstractModel;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.Property.PropertyVisitor;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.legacy.LegacyImportance;
import com.todoroo.astrid.legacy.LegacyRepeatInfo;
import com.todoroo.astrid.legacy.LegacyRepeatInfo.LegacyRepeatInterval;
import com.todoroo.astrid.legacy.LegacyTaskModel;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.tags.TagService;
import com.todoroo.astrid.tags.TaskToTagMetadata;
import org.slf4j.Logger;
@ -48,9 +41,6 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedHashSet;
import java.util.StringTokenizer;
import javax.inject.Inject;
@ -59,7 +49,6 @@ public class TasksXmlImporter {
private static final Logger log = LoggerFactory.getLogger(TasksXmlImporter.class);
private final TagDataService tagDataService;
private final TagService tagService;
private final MetadataService metadataService;
private final TaskService taskService;
@ -83,9 +72,8 @@ public class TasksXmlImporter {
}
@Inject
public TasksXmlImporter(TagDataService tagDataService, TagService tagService, MetadataService metadataService, TaskService taskService) {
public TasksXmlImporter(TagDataService tagDataService, MetadataService metadataService, TaskService taskService) {
this.tagDataService = tagDataService;
this.tagService = tagService;
this.metadataService = metadataService;
this.taskService = taskService;
}
@ -144,9 +132,7 @@ public class TasksXmlImporter {
// Process <astrid ... >
if (tag.equals(BackupConstants.ASTRID_TAG)) {
String format = xpp.getAttributeValue(null, BackupConstants.ASTRID_ATTR_FORMAT);
if(TextUtils.equals(format, FORMAT1)) {
new Format1TaskImporter(xpp);
} else if(TextUtils.equals(format, FORMAT2)) {
if(TextUtils.equals(format, FORMAT2)) {
new Format2TaskImporter(xpp);
} else if(TextUtils.equals(format, FORMAT3)) {
new Format3TaskImporter(xpp);
@ -407,239 +393,4 @@ public class TasksXmlImporter {
tagDataService.save(tagdata);
}
}
// =============================================================== FORMAT1
private static final String FORMAT1 = null;
private class Format1TaskImporter {
private final XmlPullParser xpp;
private Task currentTask = null;
private String upgradeNotes = null;
private boolean syncOnComplete = false;
private final LinkedHashSet<String> tags = new LinkedHashSet<>();
public Format1TaskImporter(XmlPullParser xpp) throws XmlPullParserException, IOException {
this.xpp = xpp;
while (xpp.next() != XmlPullParser.END_DOCUMENT) {
String tag = xpp.getName();
try {
if(BackupConstants.TASK_TAG.equals(tag) && xpp.getEventType() == XmlPullParser.END_TAG) {
saveTags();
} else if (tag == null || xpp.getEventType() == XmlPullParser.END_TAG) {
} else if (tag.equals(BackupConstants.TASK_TAG)) {
// Parse <task ... >
currentTask = parseTask();
} else if (currentTask != null) {
// These tags all require that we have a task to associate
// them with.
if (tag.equals(BackupConstants.TAG_TAG)) {
// Process <tag ... >
parseTag();
} else if (tag.equals(BackupConstants.SYNC_TAG)) {
// Process <sync ... >
parseSync();
}
}
} catch (Exception e) {
errorCount++;
log.error(e.getMessage(), e);
}
}
}
private void parseSync() {
String service = xpp.getAttributeValue(null, BackupConstants.SYNC_ATTR_SERVICE);
String remoteId = xpp.getAttributeValue(null, BackupConstants.SYNC_ATTR_REMOTE_ID);
if (service != null && remoteId != null) {
StringTokenizer strtok = new StringTokenizer(remoteId, "|"); //$NON-NLS-1$
String taskId = strtok.nextToken();
String taskSeriesId = strtok.nextToken();
String listId = strtok.nextToken();
Metadata metadata = new Metadata();
metadata.setTask(currentTask.getId());
metadata.setValue1(listId);
metadata.setValue2(taskSeriesId);
metadata.setValue3(taskId);
metadata.setValue4(syncOnComplete ? "1" : "0"); //$NON-NLS-1$ //$NON-NLS-2$
metadataService.save(metadata);
}
}
private void parseTag() {
String tagName = xpp.getAttributeValue(null, BackupConstants.TAG_ATTR_NAME);
tags.add(tagName);
}
private void saveTags() {
if(currentTask != null && tags.size() > 0) {
tagService.synchronizeTags(currentTask.getId(), currentTask.getUUID(), tags);
}
tags.clear();
}
private Task parseTask() {
taskCount++;
setProgressMessage(context.getString(R.string.import_progress_read,
taskCount));
String taskName = xpp.getAttributeValue(null, LegacyTaskModel.NAME);
Date creationDate = null;
String createdString = xpp.getAttributeValue(null,
LegacyTaskModel.CREATION_DATE);
if (createdString != null) {
creationDate = BackupDateUtilities.getDateFromIso8601String(createdString);
}
// if we don't have task name or creation date, skip
if (creationDate == null || taskName == null) {
skipCount++;
return null;
}
// if the task's name and creation date match an existing task, skip
TodorooCursor<Task> cursor = taskService.query(Query.select(Task.ID).
where(Criterion.and(Task.TITLE.eq(taskName),
Task.CREATION_DATE.like(creationDate.getTime()/1000L + "%"))));
try {
if(cursor.getCount() > 0) {
skipCount++;
return null;
}
} finally {
cursor.close();
}
// else, make a new task model and add away.
Task task = new Task();
int numAttributes = xpp.getAttributeCount();
for (int i = 0; i < numAttributes; i++) {
String fieldName = xpp.getAttributeName(i);
String fieldValue = xpp.getAttributeValue(i);
if(!setTaskField(task, fieldName, fieldValue)) {
log.info("Task: {}: Unknown field '{}' with value '{}' disregarded.", taskName, fieldName, fieldValue);
}
}
if(upgradeNotes != null) {
if(task.containsValue(Task.NOTES) && task.getNotes().length() > 0) {
task.setNotes(task.getNotes() + "\n" + upgradeNotes);
} else {
task.setNotes(upgradeNotes);
}
upgradeNotes = null;
}
// Save the task to the database.
taskService.save(task);
importCount++;
return task;
}
/** helper method to set field on a task */
private boolean setTaskField(Task task, String field, String value) {
switch (field) {
case LegacyTaskModel.ID:
// ignore
break;
case LegacyTaskModel.NAME:
task.setTitle(value);
break;
case LegacyTaskModel.NOTES:
task.setNotes(value);
break;
case LegacyTaskModel.PROGRESS_PERCENTAGE:
// ignore
break;
case LegacyTaskModel.IMPORTANCE:
task.setImportance(LegacyImportance.valueOf(value).ordinal());
break;
case LegacyTaskModel.ESTIMATED_SECONDS:
task.setEstimatedSeconds(Integer.parseInt(value));
break;
case LegacyTaskModel.ELAPSED_SECONDS:
task.setELAPSED_SECONDS(Integer.parseInt(value));
break;
case LegacyTaskModel.TIMER_START:
task.setTimerStart(
BackupDateUtilities.getDateFromIso8601String(value).getTime());
break;
case LegacyTaskModel.DEFINITE_DUE_DATE:
String preferred = xpp.getAttributeValue(null, LegacyTaskModel.PREFERRED_DUE_DATE);
if (preferred != null) {
Date preferredDate = BackupDateUtilities.getDateFromIso8601String(value);
upgradeNotes = "Project Deadline: " +
DateUtilities.getDateString(preferredDate);
}
task.setDueDate(
BackupDateUtilities.getTaskDueDateFromIso8601String(value).getTime());
break;
case LegacyTaskModel.PREFERRED_DUE_DATE:
String definite = xpp.getAttributeValue(null, LegacyTaskModel.DEFINITE_DUE_DATE);
if (definite == null) {
task.setDueDate(
BackupDateUtilities.getTaskDueDateFromIso8601String(value).getTime());
}
break;
case LegacyTaskModel.HIDDEN_UNTIL:
task.setHideUntil(
BackupDateUtilities.getDateFromIso8601String(value).getTime());
break;
case LegacyTaskModel.BLOCKING_ON:
// ignore
break;
case LegacyTaskModel.POSTPONE_COUNT:
task.setPostponeCount(Integer.parseInt(value));
break;
case LegacyTaskModel.NOTIFICATIONS:
task.setReminderPeriod(Integer.parseInt(value) * 1000L);
break;
case LegacyTaskModel.CREATION_DATE:
task.setCreationDate(
BackupDateUtilities.getDateFromIso8601String(value).getTime());
break;
case LegacyTaskModel.COMPLETION_DATE:
String completion = xpp.getAttributeValue(null, LegacyTaskModel.PROGRESS_PERCENTAGE);
if ("100".equals(completion)) {
task.setCompletionDate(
BackupDateUtilities.getDateFromIso8601String(value).getTime());
}
break;
case LegacyTaskModel.NOTIFICATION_FLAGS:
task.setReminderFlags(Integer.parseInt(value));
break;
case LegacyTaskModel.LAST_NOTIFIED:
task.setReminderLast(
BackupDateUtilities.getDateFromIso8601String(value).getTime());
break;
case "repeat_interval":
// handled below
break;
case "repeat_value":
int repeatValue = Integer.parseInt(value);
String repeatInterval = xpp.getAttributeValue(null, "repeat_interval");
if (repeatValue > 0 && repeatInterval != null) {
LegacyRepeatInterval interval = LegacyRepeatInterval.valueOf(repeatInterval);
LegacyRepeatInfo repeatInfo = new LegacyRepeatInfo(interval, repeatValue);
RRule rrule = repeatInfo.toRRule();
task.setRecurrence(rrule.toIcal());
}
break;
case LegacyTaskModel.FLAGS:
if (Integer.parseInt(value) == LegacyTaskModel.FLAG_SYNC_ON_COMPLETE) {
syncOnComplete = true;
}
break;
default:
return false;
}
return true;
}
}
}

@ -149,15 +149,14 @@ public class TaskDao extends RemoteModelDao<Task> {
}
}
public boolean handleSQLiteConstraintException(Task task) {
public void handleSQLiteConstraintException(Task task) {
TodorooCursor<Task> cursor = query(Query.select(Task.ID).where(
Task.UUID.eq(task.getUUID())));
if (cursor.getCount() > 0) {
cursor.moveToFirst();
task.setId(cursor.get(Task.ID));
return saveExisting(task);
saveExisting(task);
}
return false;
}
@Override

@ -1,18 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.legacy;
@SuppressWarnings("unused")
public enum LegacyImportance {
// MOST IMPORTANT
LEVEL_1,
LEVEL_2,
LEVEL_3,
LEVEL_4
// LEAST IMPORTANT
}

@ -1,56 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.legacy;
import com.google.ical.values.Frequency;
import com.google.ical.values.RRule;
/** Legacy repeatInfo class */
public class LegacyRepeatInfo {
/** Legacy repeat interval class */
public enum LegacyRepeatInterval {
DAYS,
WEEKS,
MONTHS,
HOURS
}
private final LegacyRepeatInterval interval;
private final int value;
public LegacyRepeatInfo(LegacyRepeatInterval repeatInterval, int value) {
this.interval = repeatInterval;
this.value = value;
}
public LegacyRepeatInterval getInterval() {
return interval;
}
public int getValue() {
return value;
}
public RRule toRRule() {
RRule rrule = new RRule();
rrule.setInterval(getValue());
switch(getInterval()) {
case DAYS:
rrule.setFreq(Frequency.DAILY);
break;
case WEEKS:
rrule.setFreq(Frequency.WEEKLY);
break;
case MONTHS:
rrule.setFreq(Frequency.MONTHLY);
break;
case HOURS:
rrule.setFreq(Frequency.HOURLY);
}
return rrule;
}
}

@ -1,34 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.legacy;
/** Legacy task class */
abstract public class LegacyTaskModel {
public static final String ID = "_id";
public static final String NAME = "name";
public static final String NOTES = "notes";
public static final String PROGRESS_PERCENTAGE = "progressPercentage";
public static final String IMPORTANCE = "importance";
public static final String ESTIMATED_SECONDS = "estimatedSeconds";
public static final String ELAPSED_SECONDS = "elapsedSeconds";
public static final String TIMER_START = "timerStart";
public static final String DEFINITE_DUE_DATE = "definiteDueDate";
public static final String PREFERRED_DUE_DATE = "preferredDueDate";
public static final String HIDDEN_UNTIL = "hiddenUntil";
public static final String POSTPONE_COUNT = "postponeCount";
public static final String NOTIFICATIONS = "notifications";
public static final String NOTIFICATION_FLAGS = "notificationFlags";
public static final String LAST_NOTIFIED = "lastNotified";
public static final String CREATION_DATE = "creationDate";
public static final String COMPLETION_DATE = "completionDate";
public static final String FLAGS = "flags";
public static final String BLOCKING_ON = "blockingOn";
// other flags
public static final int FLAG_SYNC_ON_COMPLETE = 1;
}
Loading…
Cancel
Save