diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-10-07 21:34:22 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-10-07 21:34:22 +0300 |
commit | 0a88b63e31ef292cbe20673cfeb20b298c17b5ed (patch) | |
tree | 907fca629ac46a4e1439496acf61cd0f71cb2e9b /app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters | |
parent | 87a0528bb7c7532c446db2d3fa0db82957af2f41 (diff) |
proposal functions for #52
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters')
3 files changed, 28 insertions, 6 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index 9e1eb9b92..e478583ef 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -386,6 +386,7 @@ public class DataBaseAdapter { public LiveData<List<User>> getUsersForAccount(final long accountId){ return db.getUserDao().getUsersForAccount(accountId); } + public LiveData<List<User>> searchUserByUidOrDisplayName(final long accountId, final String searchTerm){ validateSearchTerm(searchTerm); return db.getUserDao().searchUserByUidOrDisplayName(accountId, "%"+searchTerm.trim()+"%"); @@ -396,6 +397,14 @@ public class DataBaseAdapter { return db.getLabelDao().searchLabelByTitle(accountId, boardId,"%"+searchTerm.trim()+"%"); } + public LiveData<List<User>> findProposalsForUsersToAssign(final long accountId, long notAssignedToLocalCardId, final int topX){ + return db.getUserDao().findProposalsForUsersToAssign(accountId, notAssignedToLocalCardId, topX); + } + + public LiveData<List<Label>> findProposalsForLabelsToAssign(final long accountId, final long boardId, long notAssignedToLocalCardId, final int topX){ + return db.getLabelDao().findProposalsForLabelsToAssign(accountId, boardId, notAssignedToLocalCardId, topX); + } + public Attachment getAttachmentByRemoteIdDirectly(long accountId, Long id) { return db.getAttachmentDao().getAttachmentByRemoteIdDirectly(accountId, id); @@ -413,10 +422,6 @@ public class DataBaseAdapter { } private void validateSearchTerm(String searchTerm){ - // TODO @desperateCoder - // Issue: https://github.com/stefan-niedermann/nextcloud-deck/issues/52 - // if searchTerm.length() === 0 - // then return a list (max. 3 entries) with the users / labels / whatever which are assigned most often, ordered by count of how often they are assigned to any cards and which are NOT yet assigned to this card. if (searchTerm == null || searchTerm.trim().length()<1) { throw new IllegalArgumentException("please provide a proper search term! \""+searchTerm+"\" doesn't seem right..."); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java index a3efd8f63..c867274be 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java @@ -34,4 +34,12 @@ public interface LabelDao extends GenericDao<Label> { @Query("SELECT * FROM label WHERE accountId = :accountId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List<Label> getLocallyChangedLabelsDirectly(long accountId); + + @Query("SELECT l.* " + + "FROM joincardwithlabel j LEFT JOIN label l ON j.labelId = l.localId " + + "WHERE l.accountId = :accountId AND l.boardId = :boardId " + + "AND NOT EXISTS (select 1 from joincardwithlabel jl where jl.labelId = l.localId and jl.cardId = :notAssignedToLocalCardId) " + + "GROUP BY j.labelId ORDER BY count(*) DESC " + + "LIMIT :topX") + LiveData<List<Label>> findProposalsForLabelsToAssign(long accountId, long boardId, long notAssignedToLocalCardId, int topX); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java index 9267c2272..d324519f3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java @@ -1,10 +1,11 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; -import java.util.List; - import androidx.lifecycle.LiveData; import androidx.room.Dao; import androidx.room.Query; + +import java.util.List; + import it.niedermann.nextcloud.deck.model.User; @Dao @@ -30,4 +31,12 @@ public interface UserDao extends GenericDao<User> { @Query("SELECT * FROM user WHERE localId = :localUserId") User getUserByLocalIdDirectly(long localUserId); + + @Query("SELECT u.* " + + "FROM joincardwithuser j LEFT JOIN user u ON j.userId = u.localId " + + "WHERE u.accountId = :accountId " + + "AND NOT EXISTS (select 1 from joincardwithuser ju where ju.userId = u.localId and ju.cardId = :notAssignedToLocalCardId) " + + "GROUP BY j.userId ORDER BY count(*) DESC " + + "LIMIT :topX") + LiveData<List<User>> findProposalsForUsersToAssign(long accountId, long notAssignedToLocalCardId, int topX); }
\ No newline at end of file |