use of nodomain.freeyourgadget.gadgetbridge.entities.Tag in project Gadgetbridge by Freeyourgadget.
the class DBHelper method getTag.
@NonNull
public static Tag getTag(@NonNull User user, @NonNull String name, @NonNull DaoSession session) {
TagDao tagDao = session.getTagDao();
QueryBuilder<Tag> qb = tagDao.queryBuilder();
Query<Tag> query = qb.where(TagDao.Properties.UserId.eq(user.getId()), TagDao.Properties.Name.eq(name)).build();
List<Tag> tags = query.list();
if (tags.size() > 0) {
return tags.get(0);
}
return createTag(user, name, null, session);
}
use of nodomain.freeyourgadget.gadgetbridge.entities.Tag in project Gadgetbridge by Freeyourgadget.
the class DBHelper method createTag.
static Tag createTag(@NonNull User user, @NonNull String name, @Nullable String description, @NonNull DaoSession session) {
Tag tag = new Tag();
tag.setUserId(user.getId());
tag.setName(name);
tag.setDescription(description);
session.getTagDao().insertOrReplace(tag);
return tag;
}
use of nodomain.freeyourgadget.gadgetbridge.entities.Tag in project Gadgetbridge by Freeyourgadget.
the class EntitiesTest method testActivityDescription.
@Test
public void testActivityDescription() {
User user = DBHelper.getUser(daoSession);
assertNotNull(user);
ActivityDescriptionDao descDao = daoSession.getActivityDescriptionDao();
assertEquals(0, descDao.count());
List<ActivityDescription> list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertTrue(list.isEmpty());
ActivityDescription desc = DBHelper.createActivityDescription(user, 10, 100, daoSession);
assertNotNull(desc);
assertEquals(user, desc.getUser());
assertEquals(10, desc.getTimestampFrom());
assertEquals(100, desc.getTimestampTo());
List<Tag> tagList = desc.getTagList();
assertEquals(0, tagList.size());
Tag t1 = DBHelper.getTag(user, "Table Tennis", daoSession);
assertNotNull(t1);
assertEquals("Table Tennis", t1.getName());
t1.setDescription("Table tennis training for Olympia");
tagList.add(t1);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(1, list.size());
ActivityDescription desc1 = list.get(0);
assertEquals(desc, desc1);
assertEquals(1, desc1.getTagList().size());
// check for partial range overlaps
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(1, list.size());
// Now with a second, adjacent ActivityDescription
ActivityDescription desc2 = DBHelper.createActivityDescription(user, 101, 200, daoSession);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(1, list.size());
// Now with a third, partially overlapping ActivityDescription
ActivityDescription desc3 = DBHelper.createActivityDescription(user, 5, 15, daoSession);
list = DBHelper.findActivityDecriptions(user, 10, 100, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 80, daoSession);
assertEquals(1, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 120, daoSession);
assertEquals(3, list.size());
list = DBHelper.findActivityDecriptions(user, 20, 120, daoSession);
assertEquals(2, list.size());
list = DBHelper.findActivityDecriptions(user, 5, 80, daoSession);
assertEquals(2, list.size());
}
Aggregations