Package services.publix
Class PublixUtils
- java.lang.Object
-
- services.publix.PublixUtils
-
public class PublixUtils extends java.lang.ObjectService class with functions that are common for all classes that extend Publix and don't belong in a controller.
-
-
Constructor Summary
Constructors Constructor Description PublixUtils(ResultCreator resultCreator, IdCookieService idCookieService, group.GroupAdministration groupAdministration, StudyResultDao studyResultDao, ComponentDao componentDao, ComponentResultDao componentResultDao, WorkerDao workerDao, UserDao userDao, StudyLogger studyLogger, IOUtils ioUtils)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortStudy(java.lang.String message, StudyResult studyResult)Does everything to abort a study: ends the current component with state ABORTED, finishes all other Components that might still be open, deletes all result data and ends the study with state ABORTED and sets the given message.voidcheckComponentBelongsToStudy(Study study, Component component)Checks if this component belongs to this study and throws an BadRequestPublixException if it doesn't.voidcheckStudyIsGroupStudy(Study study)Throws ForbiddenPublixException if group doesn't allow messaging.JatosPublix.JatosRunfetchJatosRunFromSession(play.mvc.Http.Session session)Retrieves the JatosRun object that maps to the jatos run parameter in the session.voidfinishOldestStudyResult()Checks if the max number of JATOS ID cookies is reached and if yes finishes the oldest one(s) with a state FAIL.java.lang.StringfinishStudyResult(java.lang.Boolean successful, java.lang.String message, StudyResult studyResult)Finishes a StudyResult (includes ComponentResults) and returns a confirmation code if it was successful.booleanisFirstComponentInPreviewStudy(ComponentResult componentResult)Returns true if the Study that belongs to the given ComponentResult allows previews and the component that belongs to the given ComponentResult is the first active component in the study.ComponentretrieveComponent(Study study, java.lang.Long componentId)Returns the component with the given component ID that belongs to the given study.java.util.Optional<ComponentResult>retrieveCurrentComponentResult(StudyResult studyResult)Returns an Optional of the last ComponentResult of this studyResult but only if it's not 'done'.ComponentretrieveFirstActiveComponent(Study study)Returns the first component in the given study that is active.java.util.Optional<java.nio.file.Path>retrieveLastUploadedResultFile(StudyResult studyResult, Component component, java.lang.String filename)Gets an uploaded result file with the given filename.UserretrieveSignedinUser(play.mvc.Http.Request request)Retrieves the currently signed-in user or throws an ForbiddenPublixException if none is signed in.ComponentResultretrieveStartedComponentResult(Component component, StudyResult studyResult)Gets the current ComponentResult from the storage or if it doesn't exist yet starts one for the given component.WorkerretrieveWorker(java.lang.Long workerId)Retrieves the worker with the given worker ID from the DB.voidsetPreStudyState(ComponentResult componentResult)Sets the StudyResult's StudyState to STARTED if the study is currently in state PRE and the study result moved away from the first active componentvoidsetUrlQueryParameter(play.mvc.Http.Request request, StudyResult studyResult)Get query string parameters from the calling URL and put them into the field urlQueryParameters in StudyResult as a JSON string.ComponentResultstartComponent(Component component, StudyResult studyResult)ComponentResultstartComponent(Component component, StudyResult studyResult, java.lang.String message)Start or restart a component.
-
-
-
Constructor Detail
-
PublixUtils
@Inject public PublixUtils(ResultCreator resultCreator, IdCookieService idCookieService, group.GroupAdministration groupAdministration, StudyResultDao studyResultDao, ComponentDao componentDao, ComponentResultDao componentResultDao, WorkerDao workerDao, UserDao userDao, StudyLogger studyLogger, IOUtils ioUtils)
-
-
Method Detail
-
retrieveWorker
public Worker retrieveWorker(java.lang.Long workerId)
Retrieves the worker with the given worker ID from the DB.
-
startComponent
public ComponentResult startComponent(Component component, StudyResult studyResult) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
-
startComponent
public ComponentResult startComponent(Component component, StudyResult studyResult, java.lang.String message) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
Start or restart a component. It either returns a newly started component or an exception but never null.
-
abortStudy
public void abortStudy(java.lang.String message, StudyResult studyResult)Does everything to abort a study: ends the current component with state ABORTED, finishes all other Components that might still be open, deletes all result data and ends the study with state ABORTED and sets the given message.
-
finishStudyResult
public java.lang.String finishStudyResult(java.lang.Boolean successful, java.lang.String message, StudyResult studyResult)Finishes a StudyResult (includes ComponentResults) and returns a confirmation code if it was successful.- Parameters:
successful- If true finishes all ComponentResults, generates a confirmation code and set the StudyResult's and current ComponentResult's state to FINISHED. If false it sets both states to FAIL and doesn't generate a confirmation code.message- Will be set in the StudyResult. Can be null.studyResult- A StudyResult- Returns:
- The confirmation code or null if it was unsuccessful
-
finishOldestStudyResult
public void finishOldestStudyResult() throws PublixExceptionChecks if the max number of JATOS ID cookies is reached and if yes finishes the oldest one(s) with a state FAIL. Usually there is only one ID cookie that is to be discarded, but if the jatos.idCookies.limit config value got recently decreased there will be more than one. This method should only be called during start of a study.- Throws:
PublixException
-
retrieveCurrentComponentResult
public java.util.Optional<ComponentResult> retrieveCurrentComponentResult(StudyResult studyResult)
Returns an Optional of the last ComponentResult of this studyResult but only if it's not 'done'.
-
retrieveStartedComponentResult
public ComponentResult retrieveStartedComponentResult(Component component, StudyResult studyResult) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
Gets the current ComponentResult from the storage or if it doesn't exist yet starts one for the given component. The current ComponentResult doesn't have to be of the given Component.
-
retrieveFirstActiveComponent
public Component retrieveFirstActiveComponent(Study study) throws NotFoundPublixException
Returns the first component in the given study that is active. If there is no such component it throws a NotFoundPublixException.- Throws:
NotFoundPublixException
-
retrieveComponent
public Component retrieveComponent(Study study, java.lang.Long componentId) throws NotFoundPublixException, BadRequestPublixException, ForbiddenPublixException
Returns the component with the given component ID that belongs to the given study.- Parameters:
study- A StudycomponentId- The component's ID- Returns:
- The Component
- Throws:
NotFoundPublixException- Thrown if such component doesn't exist.BadRequestPublixException- Thrown if the component doesn't belong to the given study.ForbiddenPublixException- Thrown if the component isn't active.
-
checkComponentBelongsToStudy
public void checkComponentBelongsToStudy(Study study, Component component) throws BadRequestPublixException
Checks if this component belongs to this study and throws an BadRequestPublixException if it doesn't.- Throws:
BadRequestPublixException
-
checkStudyIsGroupStudy
public void checkStudyIsGroupStudy(Study study) throws ForbiddenPublixException
Throws ForbiddenPublixException if group doesn't allow messaging.- Throws:
ForbiddenPublixException
-
setPreStudyState
public void setPreStudyState(ComponentResult componentResult) throws NotFoundPublixException
Sets the StudyResult's StudyState to STARTED if the study is currently in state PRE and the study result moved away from the first active component- Throws:
NotFoundPublixException
-
isFirstComponentInPreviewStudy
public boolean isFirstComponentInPreviewStudy(ComponentResult componentResult) throws NotFoundPublixException
Returns true if the Study that belongs to the given ComponentResult allows previews and the component that belongs to the given ComponentResult is the first active component in the study.- Throws:
NotFoundPublixException
-
setUrlQueryParameter
public void setUrlQueryParameter(play.mvc.Http.Request request, StudyResult studyResult)Get query string parameters from the calling URL and put them into the field urlQueryParameters in StudyResult as a JSON string.
-
retrieveLastUploadedResultFile
public java.util.Optional<java.nio.file.Path> retrieveLastUploadedResultFile(StudyResult studyResult, Component component, java.lang.String filename)
Gets an uploaded result file with the given filename. If component is given (not null) it only tries to get the file from component results belonging to this component. In case of several possible files (can happen with reloaded components) it returns the file uploaded last. If component is not given (equals null) it searches all component results of this study result for a file with this filename and returns the one that was uploaded last.
-
retrieveSignedinUser
public User retrieveSignedinUser(play.mvc.Http.Request request) throws ForbiddenPublixException
Retrieves the currently signed-in user or throws an ForbiddenPublixException if none is signed in.- Throws:
ForbiddenPublixException
-
fetchJatosRunFromSession
public JatosPublix.JatosRun fetchJatosRunFromSession(play.mvc.Http.Session session) throws ForbiddenPublixException, BadRequestPublixException
Retrieves the JatosRun object that maps to the jatos run parameter in the session.
-
-