Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2aea398e authored by Stefan Niedermann's avatar Stefan Niedermann
Browse files

Remove NoteIdPair in favor of Note entity

parent 2c3b1376
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import java.util.List;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.persistence.entity.NoteIdPair;
import it.niedermann.owncloud.notes.shared.model.Capabilities;

import static it.niedermann.owncloud.notes.persistence.NotesDatabaseTestUtil.getOrAwaitValue;
@@ -126,7 +125,7 @@ public class NotesDaoTest {
        db.getNoteDao().addNote(new Note(666, 1234L, Calendar.getInstance(), "T", "C", "", false, "1", LOCAL_EDITED, account.getId(), "", 0));
        db.getNoteDao().addNote(new Note(987, 6969L, Calendar.getInstance(), "T", "C", "", false, "1", LOCAL_DELETED, account.getId(), "", 0));

        final List<NoteIdPair> pair = db.getNoteDao().getRemoteIdAndId(account.getId());
        final List<Note> pair = db.getNoteDao().getRemoteIdAndId(account.getId());
        assertEquals(2, pair.size());
        assertTrue(pair.stream().anyMatch(note -> 815 == note.getId() && Long.valueOf(4711).equals(note.getRemoteId())));
        assertTrue(pair.stream().anyMatch(note -> 666 == note.getId() && Long.valueOf(1234).equals(note.getRemoteId())));
+1 −2
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.CategoryOptions;
import it.niedermann.owncloud.notes.persistence.entity.Converters;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.persistence.entity.NoteIdPair;
import it.niedermann.owncloud.notes.persistence.entity.NotesListWidgetData;
import it.niedermann.owncloud.notes.persistence.entity.SingleNoteWidgetData;
import it.niedermann.owncloud.notes.persistence.migration.Migration_10_11;
@@ -221,7 +220,7 @@ public abstract class NotesDatabase extends RoomDatabase {
    public Map<Long, Long> getIdMap(long accountId) {
        validateAccountId(accountId);
        Map<Long, Long> result = new HashMap<>();
        for (NoteIdPair pair : getNoteDao().getRemoteIdAndId(accountId)) {
        for (Note pair : getNoteDao().getRemoteIdAndId(accountId)) {
            result.put(pair.getRemoteId(), pair.getId());
        }
        return result;
+2 −3
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@ import it.niedermann.owncloud.notes.persistence.NoteServerSyncHelper;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.CategoryWithNotesCount;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.persistence.entity.NoteIdPair;
import it.niedermann.owncloud.notes.shared.model.DBStatus;

@SuppressWarnings("JavadocReference")
@@ -136,8 +135,8 @@ public interface NoteDao {
    @Query("SELECT DISTINCT remoteId FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED'")
    List<Long> getRemoteIds(long accountId);

    @Query("SELECT id, remoteId FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED'")
    List<NoteIdPair> getRemoteIdAndId(long accountId);
    @Query("SELECT id, remoteId, 0 as accountId, '' as title, 0 as favorite, '' as excerpt, 0 as modified, '' as eTag, 0 as status, '' as category, '' as content, 0 as scrollY  FROM NOTE WHERE accountId = :accountId AND status != 'LOCAL_DELETED'")
    List<Note> getRemoteIdAndId(long accountId);

    /**
     * Get a single {@link Note} by {@link Note#remoteId} (aka. Nextcloud file id)
+0 −41
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.persistence.entity;

public class NoteIdPair {

    private long id;
    private Long remoteId;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public Long getRemoteId() {
        return remoteId;
    }

    public void setRemoteId(Long remoteId) {
        this.remoteId = remoteId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof NoteIdPair)) return false;

        NoteIdPair that = (NoteIdPair) o;

        if (id != that.id) return false;
        return remoteId != null ? remoteId.equals(that.remoteId) : that.remoteId == null;
    }

    @Override
    public int hashCode() {
        int result = (int) (id ^ (id >>> 32));
        result = 31 * result + (remoteId != null ? remoteId.hashCode() : 0);
        return result;
    }
}