Skip to content

Commit

Permalink
Some renaming where it's rather the session than a cookie.
Browse files Browse the repository at this point in the history
  • Loading branch information
kristian-lange committed Jan 4, 2015
1 parent 0a11917 commit 2e0378f
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 81 deletions.
6 changes: 3 additions & 3 deletions app/controllers/Authentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public static Result authenticate() {
if (loginForm.hasErrors()) {
return badRequest(views.html.jatos.auth.login.render(loginForm));
} else {
session(Users.COOKIE_EMAIL, loginForm.get().email);
session(Users.SESSION_EMAIL, loginForm.get().email);
return redirect(routes.Home.home());
}
}

@Security.Authenticated(Secured.class)
public static Result logout() {
Logger.info(CLASS_NAME + ".logout: " + session(Users.COOKIE_EMAIL));
session().remove(Users.COOKIE_EMAIL);
Logger.info(CLASS_NAME + ".logout: " + session(Users.SESSION_EMAIL));
session().remove(Users.SESSION_EMAIL);
flash("success", "You've been logged out");
return redirect(routes.Authentication.login());
}
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/ComponentResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static Result index(Long studyId, Long componentId, String errorMsg,
int httpStatus) throws ResultException {
Logger.info(CLASS_NAME + ".index: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ComponentModel component = ComponentModel.findById(componentId);
Expand Down Expand Up @@ -72,7 +72,7 @@ public static Result remove(String componentResultIds)
throws ResultException {
Logger.info(CLASS_NAME + ".remove: componentResultIds "
+ componentResultIds + ", " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();

List<Long> componentResultIdList = ControllerUtils
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Result tableDataByComponent(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".tableDataByComponent: studyId " + studyId
+ ", " + "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ComponentModel component = ComponentModel.findById(componentId);
Expand All @@ -128,7 +128,7 @@ public static Result exportData(String componentResultIds)
throws ResultException {
Logger.info(CLASS_NAME + ".exportData: componentResultIds "
+ componentResultIds + ", " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
// Remove cookie of jQuery.fileDownload plugin
response().discardCookie(ControllerUtils.JQDOWNLOAD_COOKIE_NAME);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/Components.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static Result showComponent(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".showComponent: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
StudyModel study = StudyModel.findById(studyId);
ComponentModel component = ComponentModel.findById(componentId);
Expand All @@ -55,7 +55,7 @@ public static Result showComponent(Long studyId, Long componentId)
@Transactional
public static Result create(Long studyId) throws ResultException {
Logger.info(CLASS_NAME + ".create: studyId " + studyId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
List<StudyModel> studyList = StudyModel.findAllByUser(loggedInUser
Expand All @@ -74,7 +74,7 @@ public static Result create(Long studyId) throws ResultException {
@Transactional
public static Result submit(Long studyId) throws ResultException {
Logger.info(CLASS_NAME + ".submit: studyId " + studyId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
List<StudyModel> studyList = StudyModel.findAllByUser(loggedInUser
Expand Down Expand Up @@ -103,7 +103,7 @@ public static Result edit(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".edit: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
List<StudyModel> studyList = StudyModel.findAllByUser(loggedInUser
Expand Down Expand Up @@ -131,7 +131,7 @@ public static Result submitEdited(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".submitEdited: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
List<StudyModel> studyList = StudyModel.findAllByUser(loggedInUser
Expand Down Expand Up @@ -182,7 +182,7 @@ public static Result changeProperty(Long studyId, Long componentId,
Logger.info(CLASS_NAME + ".changeProperty: studyId " + studyId + ", "
+ "componentId " + componentId + ", " + "active " + active
+ ", " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ComponentModel component = ComponentModel.findById(componentId);
Expand All @@ -201,7 +201,7 @@ public static Result cloneComponent(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".cloneComponent: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ComponentModel component = ComponentModel.findById(componentId);
Expand All @@ -222,7 +222,7 @@ public static Result remove(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".remove: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ComponentModel component = ComponentModel.findById(componentId);
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ControllerUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static UserModel retrieveUser(String email) throws ResultException {

public static UserModel retrieveLoggedInUser() throws ResultException {
UserModel loggedInUser = UserModel
.findByEmail(session(Users.COOKIE_EMAIL));
.findByEmail(session(Users.SESSION_EMAIL));
if (loggedInUser == null) {
String errorMsg = ErrorMessages.NO_USER_LOGGED_IN;
SimpleResult result = null;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class Home extends Controller {
public static Result home(String errorMsg, int httpStatus)
throws ResultException {
Logger.info(CLASS_NAME + ".home: " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
List<StudyModel> studyList = StudyModel.findAllByUser(loggedInUser
.getEmail());
Expand Down
31 changes: 16 additions & 15 deletions app/controllers/ImportExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class ImportExport extends Controller {

public static final String STUDYS_DIR_CONFIRM = "studysDirConfirm";
public static final String STUDYS_PROPERTIES_CONFIRM = "studysPropertiesConfirm";
private static final String TEMP_STUDYS_DIR = "tempStudyDir";
private static final String TEMP_COMPONENT_DIR = "tempStudyDir";
private static final String SESSION_TEMP_STUDYS_DIR = "tempStudyDir";
private static final String SESSION_TEMP_COMPONENT_DIR = "tempComponentDir";
private static final String CLASS_NAME = ImportExport.class.getSimpleName();

/**
Expand All @@ -46,14 +46,14 @@ public class ImportExport extends Controller {
@Transactional
public static Result importStudy() throws ResultException {
Logger.info(CLASS_NAME + ".importStudy: " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();

File tempStudyDir = unzipUploadedFile();
StudyModel uploadedStudy = unmarshalStudy(tempStudyDir, false);

// Remember study's dir name
session(TEMP_STUDYS_DIR, tempStudyDir.getName());
session(SESSION_TEMP_STUDYS_DIR, tempStudyDir.getName());

StudyModel currentStudy = StudyModel
.findByUuid(uploadedStudy.getUuid());
Expand Down Expand Up @@ -93,7 +93,7 @@ public static Result importStudy() throws ResultException {
@Transactional
public static Result importStudyConfirmed() throws ResultException {
Logger.info(CLASS_NAME + ".importStudyConfirmed: "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();

// Get confirmation: overwrite study's properties and/or study's dir
Expand Down Expand Up @@ -162,8 +162,8 @@ public static Result importStudyConfirmed() throws ResultException {
* variable afterwards.
*/
private static File getTempStudyDir() throws ResultException {
String tempStudyDirName = session(TEMP_STUDYS_DIR);
response().discardCookie(TEMP_STUDYS_DIR);
String tempStudyDirName = session(SESSION_TEMP_STUDYS_DIR);
session().remove(SESSION_TEMP_STUDYS_DIR);
if (tempStudyDirName == null || tempStudyDirName.isEmpty()) {
String errorMsg = ErrorMessages.IMPORT_OF_STUDY_FAILED;
ControllerUtils.throwHomeResultException(errorMsg,
Expand Down Expand Up @@ -268,7 +268,7 @@ private static File unzipUploadedFile() throws ResultException {
@Transactional
public static Result exportStudy(Long studyId) throws ResultException {
Logger.info(CLASS_NAME + ".exportStudy: studyId " + studyId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
// Remove cookie of jQuery.fileDownload plugin
response().discardCookie(ControllerUtils.JQDOWNLOAD_COOKIE_NAME);
StudyModel study = StudyModel.findById(studyId);
Expand All @@ -282,7 +282,8 @@ public static Result exportStudy(Long studyId) throws ResultException {
+ IOUtils.STUDY_FILE_SUFFIX);
studyAsJsonFile.deleteOnExit();
JsonUtils.asJsonForIO(study, studyAsJsonFile);
String studyDirPath = IOUtils.generateStudysPath(study.getDirName());
String studyDirPath = IOUtils
.generateStudysPath(study.getDirName());
zipFile = ZipUtil.zipStudy(studyDirPath, study.getDirName(),
studyAsJsonFile.getAbsolutePath());
studyAsJsonFile.delete();
Expand Down Expand Up @@ -311,7 +312,7 @@ public static Result exportComponent(Long studyId, Long componentId)
throws ResultException {
Logger.info(CLASS_NAME + ".exportComponent: studyId " + studyId + ", "
+ "componentId " + componentId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
// Remove cookie of jQuery.fileDownload plugin
response().discardCookie(ControllerUtils.JQDOWNLOAD_COOKIE_NAME);
StudyModel study = StudyModel.findById(studyId);
Expand Down Expand Up @@ -348,7 +349,7 @@ public static Result exportComponent(Long studyId, Long componentId)
@Transactional
public static Result importComponent(Long studyId) throws ResultException {
Logger.info(CLASS_NAME + ".importComponent: studyId " + studyId + ", "
+ "logged-in user's email " + session(Users.COOKIE_EMAIL));
+ "logged-in user's email " + session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ControllerUtils.checkStandardForStudy(study, studyId, loggedInUser);
Expand All @@ -368,7 +369,7 @@ public static Result importComponent(Long studyId) throws ResultException {
filePart.getFile(), study);

// Remember component's file name
session(TEMP_COMPONENT_DIR, filePart.getFile().getName());
session(SESSION_TEMP_COMPONENT_DIR, filePart.getFile().getName());

boolean componentExists = ComponentModel.findByUuid(uploadedComponent
.getUuid()) != null;
Expand All @@ -390,7 +391,7 @@ public static Result importComponentConfirmed(Long studyId)
throws ResultException {
Logger.info(CLASS_NAME + ".importComponentConfirmed: " + "studyId "
+ studyId + ", " + "logged-in user's email "
+ session(Users.COOKIE_EMAIL));
+ session(Users.SESSION_EMAIL));
StudyModel study = StudyModel.findById(studyId);
UserModel loggedInUser = ControllerUtils.retrieveLoggedInUser();
ControllerUtils.checkStandardForStudy(study, studyId, loggedInUser);
Expand All @@ -417,8 +418,8 @@ public static Result importComponentConfirmed(Long studyId)
*/
private static File getTempComponentFile(StudyModel study)
throws ResultException {
String tempComponentFileName = session(TEMP_COMPONENT_DIR);
response().discardCookie(TEMP_COMPONENT_DIR);
String tempComponentFileName = session(SESSION_TEMP_COMPONENT_DIR);
session().remove(SESSION_TEMP_COMPONENT_DIR);
if (tempComponentFileName == null || tempComponentFileName.isEmpty()) {
String errorMsg = ErrorMessages.IMPORT_OF_COMPONENT_FAILED;
ControllerUtils.throwStudiesResultException(errorMsg,
Expand Down

0 comments on commit 2e0378f

Please sign in to comment.