Skip to content

Commit

Permalink
Merge 3ac53c0 into 4b1083a
Browse files Browse the repository at this point in the history
  • Loading branch information
dickschoeller committed Jan 25, 2017
2 parents 4b1083a + 3ac53c0 commit 7bf6a26
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.schoellerfamily.gedbrowser.Users;
import org.schoellerfamily.gedbrowser.controller.exception.DataSetNotFoundException;
import org.schoellerfamily.gedbrowser.controller.exception.PersonNotFoundException;
import org.schoellerfamily.gedbrowser.controller.exception.SourceNotFoundException;
import org.schoellerfamily.gedbrowser.renderer.RenderingContext;
import org.schoellerfamily.gedbrowser.renderer.User;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -58,15 +59,24 @@ public final ModelAndView personNotFoundError(
final HttpServletRequest request,
final PersonNotFoundException exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("personNotFound");
mav.setStatus(HttpStatus.NOT_FOUND);
final ModelAndView mav = createModelAndViewForException(
request, exception, "personNotFound", HttpStatus.NOT_FOUND);
return mav;
}

/**
* @param request the request we're processing
* @param exception the exception caught
* @return the model and view
*/
@ExceptionHandler({ SourceNotFoundException.class })
@ResponseStatus(HttpStatus.NOT_FOUND)
public final ModelAndView sourceNotFoundError(
final HttpServletRequest request,
final SourceNotFoundException exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = createModelAndViewForException(
request, exception, "sourceNotFound", HttpStatus.NOT_FOUND);
return mav;
}

Expand All @@ -81,16 +91,8 @@ public final ModelAndView dataSetNotFoundError(
final HttpServletRequest request,
final DataSetNotFoundException exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("error");
mav.setViewName("dataSetNotFound");
mav.setStatus(HttpStatus.NOT_FOUND);
final ModelAndView mav = createModelAndViewForException(
request, exception, "dataSetNotFound", HttpStatus.NOT_FOUND);
return mav;
}

Expand All @@ -102,17 +104,32 @@ public final ModelAndView dataSetNotFoundError(
@ExceptionHandler({ Throwable.class })
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView error(final HttpServletRequest request,
final DataSetNotFoundException exception) {
final Exception exception) {
logger.info("Handling exception: " + exception.getMessage());
final ModelAndView mav = createModelAndViewForException(
request, exception, "error", HttpStatus.INTERNAL_SERVER_ERROR);
return mav;
}

/**
* @param request the http request being served
* @param exception the exception that occurred
* @param viewName the view we will put up in response
* @param status the status we are reporting
* @return the model and view for displaying the page
*/
private ModelAndView createModelAndViewForException(
final HttpServletRequest request, final Exception exception,
final String viewName, final HttpStatus status) {
final ModelAndView mav = new ModelAndView();
mav.addObject("exception", exception);
mav.addObject("url", request.getRequestURL());
mav.addObject("renderingContext", renderingContext);
mav.addObject("appInfo", applicationInfo);
// TODO hard coded in several places need to refactor
mav.addObject("homeUrl", "http://www.schoellerfamily.org");
mav.setViewName("error");
mav.setStatus(HttpStatus.INTERNAL_SERVER_ERROR);
mav.setViewName(viewName);
mav.setStatus(status);
return mav;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public final String source(
final Source source = (Source) root.find(idString);
if (source == null) {
throw new SourceNotFoundException(
"Source " + idString + " not found");
"Source " + idString + " not found", idString, dbName);
}

final GedRenderer<?> gedRenderer = new GedRendererFactory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,37 @@ public final class SourceNotFoundException extends RuntimeException {
/** */
private static final long serialVersionUID = 1L;

/** */
private final String sourceId;

/** */
private final String datasetName;

/**
* @param message the message to display
* @param sourceId the ID of the source not found
* @param datasetName the name of the dataset being searched
*/
public SourceNotFoundException(final String message) {
public SourceNotFoundException(final String message, final String sourceId,
final String datasetName) {
super(message);
this.sourceId = sourceId;
this.datasetName = datasetName;
}

/**
* Get the ID of the source that was not found.
*
* @return the ID
*/
public String getSourceId() {
return sourceId;
}

/**
* @return get the name of the dataset being searched
*/
public String getDatasetName() {
return datasetName;
}
}
48 changes: 48 additions & 0 deletions gedbrowser/src/main/resources/templates/sourceNotFound.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Source not found</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link type="text/css" href="css/gedbrowser.css" rel="stylesheet" />
</head>
<body>
<div class="menubar">
<span class="left">
<span><a th:href="${homeUrl}">Home</a></span>
<!--
<span><a th:href="${source.indexHref}">Index</a></span>
<span><a th:if="${source.hasRole('ADMIN')}" th:href="${source.livingHref}">Living</a></span>
< ! - - span><a th:if="${#authorization.expression('hasRole(''ROLE_ADMIN'')')}">Living</a></span - - >
-->
</span>
<div th:if="${#httpServletRequest.remoteUser} != null" class="right">
<form th:action="@{logout}" method="post">
<input class="menubar" type="submit" th:value="'Logout ' + ${renderingContext.firstname}"/>
</form>
</div>
<span th:if="${#httpServletRequest.remoteUser} == null" class="right" th:inline="text"><a th:href="@{login}">Login</a></span>
</div>
<div class="outer">
<div class="middle">
<div class="inner">
<h1 th:utext="${exception.message}">Source</h1>
<h2 class="name"><span th:utext="${exception.sourceId}">I1</span> not found in dataset <span th:utext="${exception.datasetName}"></span></h2>
<hr class="final"/>
<table class="buttonrow">
<tr class="buttonrow">
<td class="brleft">
<p class="maintainer">Maintained by <a id="maintainerMail" th:href="'mailto:' + ${appInfo.maintainerEmail}" th:text="${appInfo.maintainerName}"></a>.<br/>
Created with <a th:href="${appInfo.applicationURL}" th:text="${appInfo.name}"></a>, version <span th:text="${appInfo.version}">2.0</span> on <span th:text="${#dates.format(#dates.createToday(),'MMMMM dd, yyyy')}"></span>.<br/>
Get the sources on <a th:href="${appInfo.applicationURL}">GitHub</a> <a th:href="${appInfo.applicationURL}"><img src="images/github-25.png" style="vertical-align:top"/></a></p>
</td>
</tr>
</table>
</div>
</div>
</div>

<!-- anywhere in your document: -->
<form th:action="@{logout}" id="logoutForm">
<!-- csrf hidden input included automagically -->
</form>
</body>
</html>

0 comments on commit 7bf6a26

Please sign in to comment.