mirror of
https://github.com/etesync/android
synced 2024-11-26 01:48:34 +00:00
Sync: make malformed entry errors non-fatal.
What we do is we mark them as failed and note the error, though we don't currently have a way to notify the user about these errors. This will follow in the next commit.
This commit is contained in:
parent
7eff4fd9e3
commit
9f6b63620e
@ -55,7 +55,7 @@ class App : Application() {
|
|||||||
get() = initDataStore()
|
get() = initDataStore()
|
||||||
|
|
||||||
fun initDataStore(): MyEntityDataStore {
|
fun initDataStore(): MyEntityDataStore {
|
||||||
val source = MyDatabaseSource(this, Models.DEFAULT, 4)
|
val source = MyDatabaseSource(this, Models.DEFAULT, 5)
|
||||||
val configuration = source.configuration
|
val configuration = source.configuration
|
||||||
return MyEntityDataStore(configuration)
|
return MyEntityDataStore(configuration)
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import io.requery.Generated;
|
|||||||
import io.requery.Index;
|
import io.requery.Index;
|
||||||
import io.requery.Key;
|
import io.requery.Key;
|
||||||
import io.requery.ManyToOne;
|
import io.requery.ManyToOne;
|
||||||
|
import io.requery.OneToOne;
|
||||||
import io.requery.PostLoad;
|
import io.requery.PostLoad;
|
||||||
import io.requery.ReferentialAction;
|
import io.requery.ReferentialAction;
|
||||||
import io.requery.Table;
|
import io.requery.Table;
|
||||||
@ -157,6 +158,22 @@ public class JournalModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "EntryError", uniqueIndexes = "entry_unique_together")
|
||||||
|
public static abstract class EntryError {
|
||||||
|
@Key
|
||||||
|
@Generated
|
||||||
|
int id;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
String error;
|
||||||
|
|
||||||
|
@Index("entry_unique_together")
|
||||||
|
@ForeignKey(update = ReferentialAction.CASCADE)
|
||||||
|
@OneToOne
|
||||||
|
Entry entry;
|
||||||
|
}
|
||||||
|
|
||||||
static class CollectionInfoConverter implements Converter<CollectionInfo, String> {
|
static class CollectionInfoConverter implements Converter<CollectionInfo, String> {
|
||||||
@Override
|
@Override
|
||||||
public Class<CollectionInfo> getMappedType() {
|
public Class<CollectionInfo> getMappedType() {
|
||||||
|
@ -299,13 +299,17 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun persistSyncEntry(uid: String?, syncEntry: SyncEntry) {
|
private fun persistSyncEntry(uid: String?, syncEntry: SyncEntry, error: String?) {
|
||||||
val entry = EntryEntity()
|
val entry = EntryEntity()
|
||||||
entry.uid = uid
|
entry.uid = uid
|
||||||
entry.content = syncEntry
|
entry.content = syncEntry
|
||||||
entry.journal = journalEntity
|
entry.journal = journalEntity
|
||||||
try {
|
try {
|
||||||
data.insert(entry)
|
data.insert(entry)
|
||||||
|
val entryError = EntryErrorEntity()
|
||||||
|
entryError.entry = entry
|
||||||
|
entryError.error = error
|
||||||
|
data.insert(entryError)
|
||||||
} catch (e: io.requery.sql.StatementExecutionException) {
|
} catch (e: io.requery.sql.StatementExecutionException) {
|
||||||
if (e.cause is java.sql.SQLIntegrityConstraintViolationException) {
|
if (e.cause is java.sql.SQLIntegrityConstraintViolationException) {
|
||||||
Logger.log.warning("Tried inserting an existing entry ${uid}")
|
Logger.log.warning("Tried inserting an existing entry ${uid}")
|
||||||
@ -352,7 +356,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
var i = 0
|
var i = 0
|
||||||
for (entry in remoteEntries!!) {
|
for (entry in remoteEntries!!) {
|
||||||
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
||||||
persistSyncEntry(entry.uid, cEntry)
|
persistSyncEntry(entry.uid, cEntry, null)
|
||||||
i++
|
i++
|
||||||
if (remoteCTag == entry.uid) {
|
if (remoteCTag == entry.uid) {
|
||||||
remoteEntries = remoteEntries?.drop(i)
|
remoteEntries = remoteEntries?.drop(i)
|
||||||
@ -381,9 +385,15 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
|
|
||||||
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
||||||
Logger.log.info("Processing resource for journal entry")
|
Logger.log.info("Processing resource for journal entry")
|
||||||
processSyncEntry(cEntry)
|
|
||||||
|
|
||||||
persistSyncEntry(entry.uid, cEntry)
|
var error: String? = null
|
||||||
|
try {
|
||||||
|
processSyncEntry(cEntry)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
error = e.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
persistSyncEntry(entry.uid, cEntry, error)
|
||||||
|
|
||||||
remoteCTag = entry.uid
|
remoteCTag = entry.uid
|
||||||
}
|
}
|
||||||
@ -404,7 +414,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
// Persist the entries after they've been pushed
|
// Persist the entries after they've been pushed
|
||||||
for (entry in entries) {
|
for (entry in entries) {
|
||||||
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
val cEntry = SyncEntry.fromJournalEntry(crypto, entry)
|
||||||
persistSyncEntry(entry.uid, cEntry)
|
persistSyncEntry(entry.uid, cEntry, null)
|
||||||
}
|
}
|
||||||
remoteCTag = entries[entries.size - 1].uid
|
remoteCTag = entries[entries.size - 1].uid
|
||||||
pushed += entries.size
|
pushed += entries.size
|
||||||
|
Loading…
Reference in New Issue
Block a user