Skip to content

Commit

Permalink
rollback study initialization if there is an error
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kurz committed Jun 21, 2023
1 parent 311e4bc commit 41c8cd9
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,28 @@ public void setStatus(Long studyId, Study.Status status, User user) {
throw BadRequestException.StateChange(study.getStudyState(), status);
}

studyRepository.setStateById(studyId, status);
Study.Status oldState = study.getStudyState();

studyRepository.setStateById(studyId, status);
studyRepository.getById(studyId).ifPresent(s -> {
interventionService.alignInterventionsWithStudyState(s);
participantService.alignParticipantsWithStudyState(s);
observationService.alignObservationsWithStudyState(s);
integrationService.alignIntegrationsWithStudyState(s);
try {
alignWithStudyState(s);
} catch (Exception e) {
//ROLLBACK
studyRepository.setStateById(studyId, oldState);
studyRepository.getById(studyId).ifPresent(this::alignWithStudyState);
throw new BadRequestException("Study cannot be initialized");
}
});
}

private void alignWithStudyState(Study s) {
interventionService.alignInterventionsWithStudyState(s);
participantService.alignParticipantsWithStudyState(s);
observationService.alignObservationsWithStudyState(s);
integrationService.alignIntegrationsWithStudyState(s);
}

public Map<MoreUser, Set<StudyRole>> getACL(Long studyId) {
return aclRepository.getACL(studyId);
}
Expand Down

0 comments on commit 41c8cd9

Please sign in to comment.