mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Journalmanager: rename CRUD method to be more consistent.
All are now on of: list, delete, create and update.
This commit is contained in:
parent
87af98f92d
commit
fc52194d39
@ -35,7 +35,7 @@ public class JournalEntryManager extends BaseManager {
|
||||
this.client = httpClient;
|
||||
}
|
||||
|
||||
public List<Entry> getEntries(Crypto.CryptoManager crypto, String last) throws Exceptions.HttpException, Exceptions.IntegrityException {
|
||||
public List<Entry> list(Crypto.CryptoManager crypto, String last) throws Exceptions.HttpException, Exceptions.IntegrityException {
|
||||
Entry previousEntry = null;
|
||||
HttpUrl.Builder urlBuilder = this.remote.newBuilder();
|
||||
if (last != null) {
|
||||
@ -62,7 +62,7 @@ public class JournalEntryManager extends BaseManager {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void putEntries(List<Entry> entries, String last) throws Exceptions.HttpException {
|
||||
public void create(List<Entry> entries, String last) throws Exceptions.HttpException {
|
||||
HttpUrl.Builder urlBuilder = this.remote.newBuilder();
|
||||
if (last != null) {
|
||||
urlBuilder.addQueryParameter("last", last);
|
||||
|
@ -40,7 +40,7 @@ public class JournalManager extends BaseManager {
|
||||
this.client = httpClient;
|
||||
}
|
||||
|
||||
public List<Journal> getJournals() throws Exceptions.HttpException {
|
||||
public List<Journal> list() throws Exceptions.HttpException {
|
||||
Request request = new Request.Builder()
|
||||
.get()
|
||||
.url(remote)
|
||||
@ -57,7 +57,7 @@ public class JournalManager extends BaseManager {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void deleteJournal(Journal journal) throws Exceptions.HttpException {
|
||||
public void delete(Journal journal) throws Exceptions.HttpException {
|
||||
HttpUrl remote = this.remote.resolve(journal.getUid() + "/");
|
||||
Request request = new Request.Builder()
|
||||
.delete()
|
||||
@ -67,7 +67,7 @@ public class JournalManager extends BaseManager {
|
||||
newCall(request);
|
||||
}
|
||||
|
||||
public void putJournal(Journal journal) throws Exceptions.HttpException {
|
||||
public void create(Journal journal) throws Exceptions.HttpException {
|
||||
RequestBody body = RequestBody.create(JSON, journal.toJson());
|
||||
|
||||
Request request = new Request.Builder()
|
||||
@ -78,7 +78,7 @@ public class JournalManager extends BaseManager {
|
||||
newCall(request);
|
||||
}
|
||||
|
||||
public void updateJournal(Journal journal) throws Exceptions.HttpException {
|
||||
public void update(Journal journal) throws Exceptions.HttpException {
|
||||
HttpUrl remote = this.remote.resolve(journal.getUid() + "/");
|
||||
RequestBody body = RequestBody.create(JSON, journal.toJson());
|
||||
|
||||
|
@ -17,7 +17,6 @@ import android.content.ContentProviderClient;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SyncResult;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
@ -48,13 +47,11 @@ import com.etesync.syncadapter.journalmanager.JournalManager;
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
import com.etesync.syncadapter.model.JournalEntity;
|
||||
import com.etesync.syncadapter.model.JournalModel;
|
||||
import com.etesync.syncadapter.model.ServiceDB;
|
||||
import com.etesync.syncadapter.model.ServiceEntity;
|
||||
import com.etesync.syncadapter.ui.PermissionsActivity;
|
||||
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.Cleanup;
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.OkHttpClient;
|
||||
|
||||
@ -153,7 +150,7 @@ public abstract class SyncAdapterService extends Service {
|
||||
|
||||
List<Pair<JournalManager.Journal, CollectionInfo>> journals = new LinkedList<>();
|
||||
|
||||
for (JournalManager.Journal journal : journalsManager.getJournals()) {
|
||||
for (JournalManager.Journal journal : journalsManager.list()) {
|
||||
Crypto.CryptoManager crypto;
|
||||
if (journal.getKey() != null) {
|
||||
crypto = new Crypto.CryptoManager(journal.getVersion(), settings.getKeyPair(), journal.getKey());
|
||||
@ -176,7 +173,7 @@ public abstract class SyncAdapterService extends Service {
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalsManager.putJournal(journal);
|
||||
journalsManager.create(journal);
|
||||
journals.add(new Pair<>(journal, info));
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,6 @@ import com.etesync.syncadapter.model.SyncEntry;
|
||||
import com.etesync.syncadapter.resource.LocalCollection;
|
||||
import com.etesync.syncadapter.resource.LocalResource;
|
||||
import com.etesync.syncadapter.ui.DebugInfoActivity;
|
||||
import com.etesync.syncadapter.utils.Base64;
|
||||
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
||||
@ -283,7 +282,7 @@ abstract public class SyncManager {
|
||||
int count = data.count(EntryEntity.class).where(EntryEntity.JOURNAL.eq(getJournalEntity())).get().value();
|
||||
if ((remoteCTag != null) && (count == 0)) {
|
||||
// If we are updating an existing installation with no saved journal, we need to add
|
||||
remoteEntries = journal.getEntries(crypto, null);
|
||||
remoteEntries = journal.list(crypto, null);
|
||||
int i = 0;
|
||||
for (JournalEntryManager.Entry entry : remoteEntries) {
|
||||
SyncEntry cEntry = SyncEntry.fromJournalEntry(crypto, entry);
|
||||
@ -295,7 +294,7 @@ abstract public class SyncManager {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
remoteEntries = journal.getEntries(crypto, remoteCTag);
|
||||
remoteEntries = journal.list(crypto, remoteCTag);
|
||||
}
|
||||
|
||||
App.log.info("Fetched " + String.valueOf(remoteEntries.size()) + " entries");
|
||||
@ -331,7 +330,7 @@ abstract public class SyncManager {
|
||||
try {
|
||||
if (!localEntries.isEmpty()) {
|
||||
for (List<JournalEntryManager.Entry> entries : ListUtils.partition(localEntries, MAX_PUSH)) {
|
||||
journal.putEntries(entries, remoteCTag);
|
||||
journal.create(entries, remoteCTag);
|
||||
remoteCTag = entries.get(entries.size() - 1).getUid();
|
||||
pushed += entries.size();
|
||||
}
|
||||
|
@ -14,8 +14,6 @@ import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Bundle;
|
||||
import android.provider.CalendarContract;
|
||||
import android.provider.ContactsContract;
|
||||
@ -36,12 +34,10 @@ import com.etesync.syncadapter.journalmanager.JournalManager;
|
||||
import com.etesync.syncadapter.model.CollectionInfo;
|
||||
import com.etesync.syncadapter.model.JournalEntity;
|
||||
import com.etesync.syncadapter.model.JournalModel;
|
||||
import com.etesync.syncadapter.model.ServiceDB;
|
||||
import com.etesync.syncadapter.model.ServiceEntity;
|
||||
|
||||
import io.requery.Persistable;
|
||||
import io.requery.sql.EntityDataStore;
|
||||
import lombok.Cleanup;
|
||||
import okhttp3.HttpUrl;
|
||||
|
||||
public class CreateCollectionFragment extends DialogFragment implements LoaderManager.LoaderCallbacks<Exception> {
|
||||
@ -151,11 +147,11 @@ public class CreateCollectionFragment extends DialogFragment implements LoaderMa
|
||||
info.uid = JournalManager.Journal.genUid();
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
} else {
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, settings.password(), info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.updateJournal(journal);
|
||||
journalManager.update(journal);
|
||||
}
|
||||
|
||||
// 2. add collection to service
|
||||
|
@ -122,7 +122,7 @@ public class DeleteCollectionFragment extends DialogFragment implements LoaderMa
|
||||
JournalManager journalManager = new JournalManager(HttpClient.create(getContext(), account), principal);
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(collectionInfo.version, settings.password(), collectionInfo.uid);
|
||||
|
||||
journalManager.deleteJournal(new JournalManager.Journal(crypto, collectionInfo.toJson(), collectionInfo.uid));
|
||||
journalManager.delete(new JournalManager.Journal(crypto, collectionInfo.toJson(), collectionInfo.uid));
|
||||
JournalEntity journalEntity = JournalEntity.fetch(data, collectionInfo.getServiceEntity(data), collectionInfo.uid);
|
||||
journalEntity.setDeleted(true);
|
||||
data.update(journalEntity);
|
||||
|
@ -82,18 +82,18 @@ public class ServiceTest {
|
||||
info.displayName = "Test";
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
|
||||
// Try pushing the same journal (uid clash)
|
||||
try {
|
||||
caught = null;
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
} catch (Exceptions.HttpException e) {
|
||||
caught = e;
|
||||
}
|
||||
assertNotNull(caught);
|
||||
|
||||
List<JournalManager.Journal> journals = journalManager.getJournals();
|
||||
List<JournalManager.Journal> journals = journalManager.list();
|
||||
assertEquals(journals.size(), 1);
|
||||
CollectionInfo info2 = CollectionInfo.fromJson(journals.get(0).getContent(crypto));
|
||||
assertEquals(info2.displayName, info.displayName);
|
||||
@ -101,17 +101,17 @@ public class ServiceTest {
|
||||
// Update journal
|
||||
info.displayName = "Test 2";
|
||||
journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.updateJournal(journal);
|
||||
journalManager.update(journal);
|
||||
|
||||
journals = journalManager.getJournals();
|
||||
journals = journalManager.list();
|
||||
assertEquals(journals.size(), 1);
|
||||
info2 = CollectionInfo.fromJson(journals.get(0).getContent(crypto));
|
||||
assertEquals(info2.displayName, info.displayName);
|
||||
|
||||
// Delete journal
|
||||
journalManager.deleteJournal(journal);
|
||||
journalManager.delete(journal);
|
||||
|
||||
journals = journalManager.getJournals();
|
||||
journals = journalManager.list();
|
||||
assertEquals(journals.size(), 0);
|
||||
|
||||
// Bad HMAC
|
||||
@ -120,11 +120,11 @@ public class ServiceTest {
|
||||
info.displayName = "Test 3";
|
||||
//// We assume this doesn't update the hmac.
|
||||
journal.setContent(crypto, info.toJson());
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
|
||||
try {
|
||||
caught = null;
|
||||
for (JournalManager.Journal journal1 : journalManager.getJournals()) {
|
||||
for (JournalManager.Journal journal1 : journalManager.list()) {
|
||||
Crypto.CryptoManager crypto1 = new Crypto.CryptoManager(info.version, Helpers.keyBase64, journal1.getUid());
|
||||
journal1.verify(crypto1);
|
||||
}
|
||||
@ -144,7 +144,7 @@ public class ServiceTest {
|
||||
info.displayName = "Test";
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
|
||||
JournalEntryManager journalEntryManager = new JournalEntryManager(httpClient, remote, info.uid);
|
||||
JournalEntryManager.Entry previousEntry = null;
|
||||
@ -154,7 +154,7 @@ public class ServiceTest {
|
||||
List<JournalEntryManager.Entry> entries = new LinkedList<>();
|
||||
|
||||
entries.add(entry);
|
||||
journalEntryManager.putEntries(entries, null);
|
||||
journalEntryManager.create(entries, null);
|
||||
previousEntry = entry;
|
||||
|
||||
entries.clear();
|
||||
@ -165,14 +165,14 @@ public class ServiceTest {
|
||||
// Pushing a correct entries without the last parameter
|
||||
try {
|
||||
caught = null;
|
||||
journalEntryManager.putEntries(entries, null);
|
||||
journalEntryManager.create(entries, null);
|
||||
} catch (Exceptions.HttpException e) {
|
||||
caught = e;
|
||||
}
|
||||
assertNotNull(caught);
|
||||
|
||||
// Adding a second entry
|
||||
journalEntryManager.putEntries(entries, previousEntry.getUid());
|
||||
journalEntryManager.create(entries, previousEntry.getUid());
|
||||
previousEntry = entry2;
|
||||
|
||||
entries.clear();
|
||||
@ -180,9 +180,9 @@ public class ServiceTest {
|
||||
entries.add(entry2);
|
||||
|
||||
// Check last works:
|
||||
entries = journalEntryManager.getEntries(crypto, entry.getUid());
|
||||
entries = journalEntryManager.list(crypto, entry.getUid());
|
||||
assertEquals(entries.size(), 1);
|
||||
entries = journalEntryManager.getEntries(crypto, entry2.getUid());
|
||||
entries = journalEntryManager.list(crypto, entry2.getUid());
|
||||
assertEquals(entries.size(), 0);
|
||||
|
||||
// Corrupt the journal and verify we catch it
|
||||
@ -191,11 +191,11 @@ public class ServiceTest {
|
||||
entry2.update(crypto, "Content", null);
|
||||
entries.add(entry2);
|
||||
|
||||
journalEntryManager.putEntries(entries, previousEntry.getUid());
|
||||
journalEntryManager.create(entries, previousEntry.getUid());
|
||||
|
||||
try {
|
||||
caught = null;
|
||||
journalEntryManager.getEntries(crypto, null);
|
||||
journalEntryManager.list(crypto, null);
|
||||
} catch (Exceptions.IntegrityException e) {
|
||||
caught = e;
|
||||
}
|
||||
@ -244,7 +244,7 @@ public class ServiceTest {
|
||||
info.displayName = "Test";
|
||||
Crypto.CryptoManager crypto = new Crypto.CryptoManager(info.version, Helpers.keyBase64, info.uid);
|
||||
JournalManager.Journal journal = new JournalManager.Journal(crypto, info.toJson(), info.uid);
|
||||
journalManager.putJournal(journal);
|
||||
journalManager.create(journal);
|
||||
|
||||
assertEquals(journalManager.listMembers(journal).size(), 0);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user