Commit fc5b6693 authored by Michael Menzel's avatar Michael Menzel

Added second session getter which fails if there is not session. Added...

Added second session getter which fails if there is not session. Added exception handling for those cases to the three controllers.
parent f0dc4aa6
......@@ -64,6 +64,18 @@ public final class Sessions {
return sessions.get(key);
}
/**
* Returns session by given http session key
*
* @param key - http session key
* @return Session from session list. If not session exists throws an exception
*/
public Session getSessionOrError(String key) throws Exception {
if (!sessions.containsKey(key))
throw new Exception("No session for that key available");
return sessions.get(key);
}
/**
* Returns session by given http session key
*
......
......@@ -57,15 +57,22 @@ public class DataController {
@RequestMapping(value = "/data/{hg}", method = RequestMethod.GET)
public String data(@PathVariable("hg") String assem, Model model, HttpSession httpSession) {
Sessions sessionsControll = Sessions.getInstance();
Session currentSession = sessionsControll.getSession(httpSession.getId());
Session currentSession;
Genome.Assembly assembly;
try {
Sessions sessionsControll = Sessions.getInstance();
currentSession = sessionsControll.getSessionOrError(httpSession.getId());
assembly = Genome.Assembly.valueOf(assem);
} catch (IllegalArgumentException e) {
model.addAttribute("errorMessage", "There are no tracks with the genome version " + assem + ". Try www.enhort.mni.thm.de/data/hg19");
return "error";
} catch (Exception e) {
logger.error("Exception {}", e.getMessage(), e);
model.addAttribute("errorMessage", "The calculation could not be saved, please run it again");
return "error";
}
BackendCommand command = //new BackendCommand(assembly, Command.Task.GET_TRACKS);
......
......@@ -50,7 +50,14 @@ public class ExportController {
@RequestMapping(value = "/export/csv", method = RequestMethod.GET)
@ResponseBody
public FileSystemResource downloadCSV(HttpSession httpSession) {
Session currentSession = Sessions.getInstance().getSession(httpSession.getId());
Session currentSession = null;
try {
currentSession = Sessions.getInstance().getSessionOrError(httpSession.getId());
} catch (Exception e) {
logger.error("Exception {}", e.getMessage(), e);
//TODO show error message, there is no data to download
}
//create file
File output = new File("/tmp/csv_output_" + httpSession.getId());
......
......@@ -77,7 +77,16 @@ public class WizardController {
public String wizard_get(Model model, HttpSession httpSession, @ModelAttribute InterfaceCommand interfaceCommand) {
Sessions sessionsControll = Sessions.getInstance();
Session currentSession = sessionsControll.getSession(httpSession.getId());
Session currentSession = null;
try {
currentSession = sessionsControll.getSessionOrError(httpSession.getId());
} catch (Exception e) {
logger.error("Exception {}", e.getMessage(), e);
model.addAttribute("errorMessage", "The calculation could not be saved, please run it again");
return "error";
}
if(currentSession.getCollector() != null)
interfaceCommand.setTracks(currentSession.getCollector().getTracks());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment