Package daos.common
Class StudyResultDao
- java.lang.Object
-
- daos.common.AbstractDao
-
- daos.common.StudyResultDao
-
@Singleton public class StudyResultDao extends AbstractDao
DAO for StudyResult and StudyResultStatus
-
-
Field Summary
-
Fields inherited from class daos.common.AbstractDao
jpa
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckAndIncrementOpenAiApiCount(java.lang.String uuid, int callLimit)Checks if the number of OpenAI calls for the given StudyResult is lower than the threshold (callLimit).intcount()Returns the number of StudyResult rowsintcountByBatch(Batch batch, java.lang.String workerTypeToBeExcluded)Returns the number of StudyResults belonging to the given batch but excludes results from the given workerTypeToBeExcluded.intcountByBatchAndWorkerType(Batch batch, java.lang.String workerType)Returns the number of StudyResults belonging to the given batch and given worker type.intcountByGroup(GroupResult groupResult)Returns the number of StudyResults belonging to the given group.intcountByStudy(Study study)Returns the number of StudyResults belonging to the given study.intcountByWorker(Worker worker, User user)Returns the number of StudyResults belonging to the given worker.java.util.Map<java.lang.Long,java.lang.Integer>countComponentResultsForStudyResultIds(java.util.List<java.lang.Long> srids)intcountTotal()Returns the total number of StudyResults (including the deleted ones)voidcreate(StudyResult studyResult)java.util.List<StudyResult>findAllByBatch(Batch batch)java.util.List<StudyResult>findAllByBatch(Batch batch, java.lang.String workerTypeToBeExcluded, int first, int max)Returns paginated StudyResults that belong to the given Batch but excludes results from the given workerTypeToBeExcluded.java.util.List<StudyResult>findAllByBatchAndWorkerType(Batch batch, java.lang.String workerType, int first, int max)Returns paginated StudyResults that belong to the given Batch and worker type.java.util.List<StudyResult>findAllByGroup(GroupResult groupResult, int first, int max)We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)java.util.List<StudyResult>findAllByStudy(Study study, int first, int max)Returns paginated StudyResults that belong to the given Study We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)java.util.List<StudyResult>findAllByWorker(Worker worker, User user, int first, int max)Returns paginated StudyResults that belong to the given Worker and User.StudyResultfindById(java.lang.Long id)java.util.List<StudyResult>findByIds(java.util.List<java.lang.Long> ids)java.util.List<StudyResult>findByIds(java.util.List<java.lang.Long> ids, int first, int max)java.util.Optional<StudyResult>findByStudyCode(java.lang.String studyCode)java.util.Optional<StudyResult>findByUuid(java.lang.String uuid)java.util.List<StudyResult>findIdleGroupMembers(int idleAfterSeconds)Returns a list of StudyResults that are active members of a group and have been idle for a while.java.util.List<java.lang.Long>findIdsByBatchIds(java.util.List<java.lang.Long> batchIds)java.util.List<java.lang.Long>findIdsByComponentResultIds(java.util.List<java.lang.Long> crids)Returns a list of unique study result IDs that belong to the given list of component result IDs.java.util.List<java.lang.Long>findIdsByGroupIds(java.util.List<java.lang.Long> groupIds)java.util.List<java.lang.Long>findIdsByStudyId(java.lang.Long studyId)java.util.List<java.lang.Long>findIdsFromListThatBelongToStudy(java.util.List<java.lang.Long> srids, java.lang.Long studyId)java.util.List<StudyResultStatus>findLastSeen(int limit)Find the StudyResultStatus with the most recent lastSeenjava.util.Optional<StudyResultStatus>findLastStarted(Study study)Find the StudyResultStatus with the most recent startDate that belongs to the given studybooleanisStudyRunning(java.lang.String uuid)Checks if the StudyResult with the given UUID is currently running.voidrefresh(StudyResult studyResult)voidremove(StudyResult studyResult)voidsetQuotaReached(java.lang.Long studyResultId)voidupdate(StudyResult studyResult)voidupdateLastSeenDateIfOlderThan(java.lang.Long id, java.time.Duration duration)voidupdateStudySessionData(java.lang.Long id, java.lang.String studySessionData)Only update the 'studySessionData' field and leave everything else untouched
-
-
-
Method Detail
-
create
public void create(StudyResult studyResult)
-
update
public void update(StudyResult studyResult)
-
updateStudySessionData
public void updateStudySessionData(java.lang.Long id, java.lang.String studySessionData)Only update the 'studySessionData' field and leave everything else untouched
-
remove
public void remove(StudyResult studyResult)
-
refresh
public void refresh(StudyResult studyResult)
-
findById
public StudyResult findById(java.lang.Long id)
-
findByIds
public java.util.List<StudyResult> findByIds(java.util.List<java.lang.Long> ids)
-
findByIds
public java.util.List<StudyResult> findByIds(java.util.List<java.lang.Long> ids, int first, int max)
-
findByUuid
public java.util.Optional<StudyResult> findByUuid(java.lang.String uuid)
-
findByStudyCode
public java.util.Optional<StudyResult> findByStudyCode(java.lang.String studyCode)
-
findIdleGroupMembers
public java.util.List<StudyResult> findIdleGroupMembers(int idleAfterSeconds)
Returns a list of StudyResults that are active members of a group and have been idle for a while. An idle StudyResult is one that has an active group result and a lastSeenDate that is older than the given seconds.
-
count
public int count()
Returns the number of StudyResult rows
-
countTotal
public int countTotal()
Returns the total number of StudyResults (including the deleted ones)
-
countByStudy
public int countByStudy(Study study)
Returns the number of StudyResults belonging to the given study.
-
countByBatch
public int countByBatch(Batch batch, java.lang.String workerTypeToBeExcluded)
Returns the number of StudyResults belonging to the given batch but excludes results from the given workerTypeToBeExcluded.
-
countByWorker
public int countByWorker(Worker worker, User user)
Returns the number of StudyResults belonging to the given worker. It checks for each StudyResult if its Study has the given User as a member.
-
countByGroup
public int countByGroup(GroupResult groupResult)
Returns the number of StudyResults belonging to the given group.
-
countByBatchAndWorkerType
public int countByBatchAndWorkerType(Batch batch, java.lang.String workerType)
Returns the number of StudyResults belonging to the given batch and given worker type. If the worker type is 'MT' it additionally returns the number of 'MTSandbox' results.
-
findIdsByStudyId
public java.util.List<java.lang.Long> findIdsByStudyId(java.lang.Long studyId)
-
findAllByStudy
public java.util.List<StudyResult> findAllByStudy(Study study, int first, int max)
Returns paginated StudyResults that belong to the given Study We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)
-
findAllByBatch
public java.util.List<StudyResult> findAllByBatch(Batch batch)
-
findAllByBatch
public java.util.List<StudyResult> findAllByBatch(Batch batch, java.lang.String workerTypeToBeExcluded, int first, int max)
Returns paginated StudyResults that belong to the given Batch but excludes results from the given workerTypeToBeExcluded. We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)
-
findAllByBatchAndWorkerType
public java.util.List<StudyResult> findAllByBatchAndWorkerType(Batch batch, java.lang.String workerType, int first, int max)
Returns paginated StudyResults that belong to the given Batch and worker type. If the worker type is 'MT' it additionally returns the MTSandbox results. We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)
-
findAllByWorker
public java.util.List<StudyResult> findAllByWorker(Worker worker, User user, int first, int max)
Returns paginated StudyResults that belong to the given Worker and User. It checks for each StudyResult if its Study has the given User as a member. We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)
-
findAllByGroup
public java.util.List<StudyResult> findAllByGroup(GroupResult groupResult, int first, int max)
We can't use ScrollableResults for pagination since the MySQL Hibernate driver doesn't support it (https://stackoverflow.com/a/2826512/1278769)
-
findLastStarted
public java.util.Optional<StudyResultStatus> findLastStarted(Study study)
Find the StudyResultStatus with the most recent startDate that belongs to the given study
-
findLastSeen
public java.util.List<StudyResultStatus> findLastSeen(int limit)
Find the StudyResultStatus with the most recent lastSeen
-
findIdsByComponentResultIds
public java.util.List<java.lang.Long> findIdsByComponentResultIds(java.util.List<java.lang.Long> crids)
Returns a list of unique study result IDs that belong to the given list of component result IDs.
-
findIdsFromListThatBelongToStudy
public java.util.List<java.lang.Long> findIdsFromListThatBelongToStudy(java.util.List<java.lang.Long> srids, java.lang.Long studyId)
-
findIdsByBatchIds
public java.util.List<java.lang.Long> findIdsByBatchIds(java.util.List<java.lang.Long> batchIds)
-
findIdsByGroupIds
public java.util.List<java.lang.Long> findIdsByGroupIds(java.util.List<java.lang.Long> groupIds)
-
countComponentResultsForStudyResultIds
public java.util.Map<java.lang.Long,java.lang.Integer> countComponentResultsForStudyResultIds(java.util.List<java.lang.Long> srids)
-
setQuotaReached
public void setQuotaReached(java.lang.Long studyResultId)
-
updateLastSeenDateIfOlderThan
public void updateLastSeenDateIfOlderThan(java.lang.Long id, java.time.Duration duration)
-
isStudyRunning
public boolean isStudyRunning(java.lang.String uuid)
Checks if the StudyResult with the given UUID is currently running. A study is considered running if its state is not FINISHED, ABORTED, or FAIL.
-
checkAndIncrementOpenAiApiCount
public boolean checkAndIncrementOpenAiApiCount(java.lang.String uuid, int callLimit)Checks if the number of OpenAI calls for the given StudyResult is lower than the threshold (callLimit). If yes, it increments the counter and returns true. If the threshold is reached, it returns false.
-
-