public class PublixUtils
extends java.lang.Object
Constructor and Description |
---|
PublixUtils(ResultCreator resultCreator,
IdCookieService idCookieService,
group.GroupAdministration groupAdministration,
StudyResultDao studyResultDao,
ComponentDao componentDao,
ComponentResultDao componentResultDao,
WorkerDao workerDao,
UserDao userDao,
StudyLogger studyLogger,
IOUtils ioUtils) |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
checkComponentBelongsToStudy(Study study,
Component component)
Checks if this component belongs to this study and throws an
BadRequestPublixException if it doesn't.
|
void |
checkStudyIsGroupStudy(Study study)
Throws ForbiddenPublixException if group doesn't allow messaging.
|
JatosPublix.JatosRun |
fetchJatosRunFromSession(play.mvc.Http.Session session)
Retrieves the JatosRun object that maps to the jatos run parameter in the session.
|
void |
finishOldestStudyResult()
Checks if the max number of ID cookies is reached and if yes finishes the oldest one with a
state FAIL.
|
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.
|
boolean |
isFirstComponentInPreviewStudy(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.
|
Component |
retrieveComponent(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'.
|
Component |
retrieveFirstActiveComponent(Study study)
Returns the first component in the given study that is active.
|
java.util.Optional<Component> |
retrieveLastComponent(StudyResult studyResult)
Returns an Optional of the last ComponentResult's component (of the given StudyResult.
|
java.util.Optional<java.io.File> |
retrieveLastUploadedResultFile(StudyResult studyResult,
Component component,
java.lang.String filename)
Gets an uploaded result file with the given filename.
|
User |
retrieveSignedinUser(play.mvc.Http.Request request)
Retrieves the currently signed-in user or throws an ForbiddenPublixException if none is signed in.
|
ComponentResult |
retrieveStartedComponentResult(Component component,
StudyResult studyResult)
Gets the current ComponentResult from the storage or if it doesn't exist
yet starts one for the given component.
|
Worker |
retrieveWorker(java.lang.Long workerId)
Retrieves the worker with the given worker ID from the DB.
|
void |
setPreStudyState(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 component
|
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.
|
ComponentResult |
startComponent(Component component,
StudyResult studyResult) |
ComponentResult |
startComponent(Component component,
StudyResult studyResult,
java.lang.String message)
Start or restart a component.
|
@Inject public PublixUtils(ResultCreator resultCreator, IdCookieService idCookieService, group.GroupAdministration groupAdministration, StudyResultDao studyResultDao, ComponentDao componentDao, ComponentResultDao componentResultDao, WorkerDao workerDao, UserDao userDao, StudyLogger studyLogger, IOUtils ioUtils)
public Worker retrieveWorker(java.lang.Long workerId) throws ForbiddenPublixException
ForbiddenPublixException
public ComponentResult startComponent(Component component, StudyResult studyResult) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
public ComponentResult startComponent(Component component, StudyResult studyResult, java.lang.String message) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
public void abortStudy(java.lang.String message, StudyResult studyResult)
public java.lang.String finishStudyResult(java.lang.Boolean successful, java.lang.String message, StudyResult studyResult)
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 StudyResultpublic void finishOldestStudyResult() throws PublixException
PublixException
public java.util.Optional<Component> retrieveLastComponent(StudyResult studyResult)
public java.util.Optional<ComponentResult> retrieveCurrentComponentResult(StudyResult studyResult)
public ComponentResult retrieveStartedComponentResult(Component component, StudyResult studyResult) throws ForbiddenReloadException, ForbiddenNonLinearFlowException, NotFoundPublixException
public Component retrieveFirstActiveComponent(Study study) throws NotFoundPublixException
NotFoundPublixException
public Component retrieveComponent(Study study, java.lang.Long componentId) throws NotFoundPublixException, BadRequestPublixException, ForbiddenPublixException
study
- A StudycomponentId
- The component's IDNotFoundPublixException
- 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.public void checkComponentBelongsToStudy(Study study, Component component) throws BadRequestPublixException
BadRequestPublixException
public void checkStudyIsGroupStudy(Study study) throws ForbiddenPublixException
ForbiddenPublixException
public void setPreStudyState(ComponentResult componentResult) throws NotFoundPublixException
NotFoundPublixException
public boolean isFirstComponentInPreviewStudy(ComponentResult componentResult) throws NotFoundPublixException
NotFoundPublixException
public void setUrlQueryParameter(play.mvc.Http.Request request, StudyResult studyResult)
public java.util.Optional<java.io.File> retrieveLastUploadedResultFile(StudyResult studyResult, Component component, java.lang.String filename)
public User retrieveSignedinUser(play.mvc.Http.Request request) throws ForbiddenPublixException
ForbiddenPublixException
public JatosPublix.JatosRun fetchJatosRunFromSession(play.mvc.Http.Session session) throws ForbiddenPublixException, BadRequestPublixException