Search in sources :

Example 1 with TodoListHeaderDAO

use of de.djuelg.neuronizer.storage.model.TodoListHeaderDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImplTest method testTodoListHeaderInsertTwice.

@Test
public void testTodoListHeaderInsertTwice() {
    clearRealm();
    TodoListHeader header = createHeader();
    repository.insert(header);
    boolean success = repository.insert(header);
    assertFalse(success);
    TodoListHeaderDAO dao = realm.where(TodoListHeaderDAO.class).equalTo("uuid", header.getUuid()).findFirst();
    assertNotNull(dao);
    fillRealm();
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 2 with TodoListHeaderDAO

use of de.djuelg.neuronizer.storage.model.TodoListHeaderDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImplTest method fillRealm.

private void fillRealm() {
    final TodoListDAO todoListDAO = new TodoListDAO("uuid0", "Todo List 1", 0, 0, 0, 0);
    final TodoListHeaderDAO headerDAO = new TodoListHeaderDAO("uuid1", "Header 1", 0, 0, 0, false, "uuid0");
    final TodoListItemDAO itemDAO = new TodoListItemDAO("uuid2", "Item 1", 0, 0, 0, false, "", false, "uuid0", "uuid1");
    final TodoListHeaderDAO headerDAO2 = new TodoListHeaderDAO("uuid3", "Header 2", 0, 0, 0, false, "uuid3");
    final TodoListItemDAO itemDAO2 = new TodoListItemDAO("uuid4", "Item 2", 0, 0, 0, false, "", false, "uuid0", "uuid3");
    final TodoListItemDAO itemDAO3 = new TodoListItemDAO("uuid5", "Item 3", 0, 0, 0, false, "", false, "uuid0", "uuid3");
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            realm.copyToRealm(todoListDAO);
            realm.copyToRealm(headerDAO);
            realm.copyToRealm(headerDAO2);
            realm.copyToRealm(itemDAO);
            realm.copyToRealm(itemDAO2);
            realm.copyToRealm(itemDAO3);
        }
    });
}
Also used : TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm) TodoListDAO(de.djuelg.neuronizer.storage.model.TodoListDAO) TodoListItemDAO(de.djuelg.neuronizer.storage.model.TodoListItemDAO)

Example 3 with TodoListHeaderDAO

use of de.djuelg.neuronizer.storage.model.TodoListHeaderDAO in project Neuronizer by djuelg.

the class PreviewRepositoryImpl method constructPreview.

private TodoListPreview constructPreview(Realm realm, TodoListDAO todoListDAO, ItemsPerPreview itemsPerPreview) {
    TodoList todoList = RealmConverter.convert(todoListDAO);
    Optional<TodoListHeaderDAO> headerDAO = Optional.fromNullable(realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", todoListDAO.getUuid()).findAllSorted("position", Sort.DESCENDING).where().findFirst());
    TodoListHeader header = headerDAO.transform(new TodoListHeaderDAOConverter()).orNull();
    List<TodoListItem> items = getItemPreviewOfHeader(realm, header, itemsPerPreview);
    return new TodoListPreview(todoList, header, items);
}
Also used : TodoListHeaderDAOConverter(de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter) TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem) TodoListPreview(de.djuelg.neuronizer.domain.model.preview.TodoListPreview) TodoList(de.djuelg.neuronizer.domain.model.preview.TodoList)

Example 4 with TodoListHeaderDAO

use of de.djuelg.neuronizer.storage.model.TodoListHeaderDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method getHeadersOfTodoListId.

@Override
public List<TodoListHeader> getHeadersOfTodoListId(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListHeaderDAO> headerDAOs = realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", uuid).findAll();
    List<TodoListHeader> headers = new ArrayList<>(headerDAOs.size());
    for (TodoListHeaderDAO dao : headerDAOs) {
        headers.add(RealmConverter.convert(dao));
    }
    realm.close();
    return headers;
}
Also used : TodoListHeader(de.djuelg.neuronizer.domain.model.todolist.TodoListHeader) ArrayList(java.util.ArrayList) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Example 5 with TodoListHeaderDAO

use of de.djuelg.neuronizer.storage.model.TodoListHeaderDAO in project Neuronizer by djuelg.

the class TodoListRepositoryImpl method getSectionsOfTodoListId.

@Override
public List<TodoListSection> getSectionsOfTodoListId(String uuid) {
    Realm realm = Realm.getInstance(configuration);
    RealmResults<TodoListHeaderDAO> headerDAOs = realm.where(TodoListHeaderDAO.class).equalTo("parentTodoListUuid", uuid).findAll();
    List<TodoListSection> sections = new ArrayList<>(headerDAOs.size());
    for (TodoListHeaderDAO dao : headerDAOs) {
        sections.add(constructSection(realm, dao));
    }
    realm.close();
    return sections;
}
Also used : TodoListSection(de.djuelg.neuronizer.domain.model.todolist.TodoListSection) ArrayList(java.util.ArrayList) TodoListHeaderDAO(de.djuelg.neuronizer.storage.model.TodoListHeaderDAO) Realm(io.realm.Realm)

Aggregations

TodoListHeaderDAO (de.djuelg.neuronizer.storage.model.TodoListHeaderDAO)11 Realm (io.realm.Realm)8 TodoListHeader (de.djuelg.neuronizer.domain.model.todolist.TodoListHeader)5 MediumTest (android.support.test.filters.MediumTest)2 TodoListHeaderDAOConverter (de.djuelg.neuronizer.storage.converter.TodoListHeaderDAOConverter)2 TodoListDAO (de.djuelg.neuronizer.storage.model.TodoListDAO)2 TodoListItemDAO (de.djuelg.neuronizer.storage.model.TodoListItemDAO)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 TodoList (de.djuelg.neuronizer.domain.model.preview.TodoList)1 TodoListPreview (de.djuelg.neuronizer.domain.model.preview.TodoListPreview)1 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)1 TodoListSection (de.djuelg.neuronizer.domain.model.todolist.TodoListSection)1