Skip to content

Commit

Permalink
Fixes #21 - make menu and foot fragments
Browse files Browse the repository at this point in the history
Fixes #244 - make source not found page have full menu
Fixes #243 - make person not found page have full menu
  • Loading branch information
dickschoeller committed May 19, 2017
1 parent fafb018 commit e185b82
Show file tree
Hide file tree
Showing 25 changed files with 298 additions and 323 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final String getIndexName() {
/**
* @return the GedObject
*/
protected final G getGedObject() {
public final G getGedObject() {
return gedObject;
}
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.schoellerfamily.gedbrowser.renderer;

import org.schoellerfamily.gedbrowser.datamodel.GedObject;

/**
* Provides the pattern of returning an index query. The default goes to the
* letter A.
*
* @author Dick Schoeller
* @param <T> the GedObject type to render
*/
public interface IndexHrefRenderer<T extends GedObject> {
/**
* @return the GedObject
*/
T getGedObject();


/**
* @return the href string to the index page containing this person.
*/
default String getIndexHref() {
return "surnames?db=" + getGedObject().getDbName() + "&letter=" + "A";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
/**
* @author Dick Schoeller
*/
public final class IndexRenderer extends GedRenderer<Root> {
public final class IndexRenderer extends GedRenderer<Root>
implements IndexHrefRenderer<Root> {
/** Logger. */
private final Log logger = LogFactory.getLog(getClass());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
/**
* @author Dick Schoeller
*/
public final class LivingRenderer extends GedRenderer<Root> {
public final class LivingRenderer extends GedRenderer<Root>
implements IndexHrefRenderer<Root> {
/** Logger. */
private final Log logger = LogFactory.getLog(getClass());

Expand Down Expand Up @@ -135,11 +136,4 @@ public List<PersonRenderer> getPersons() {
return persons;
}
}

/**
* @return the href string to the index page containing this person.
*/
public String getIndexHref() {
return "surnames?db=" + getGedObject().getDbName() + "&letter=" + "A";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* @author Dick Schoeller
*/
public final class PersonRenderer extends GedRenderer<Person> {
public final class PersonRenderer extends GedRenderer<Person>
implements IndexHrefRenderer<Person> {
/**
* Number of generations, including the root when rendering the tree.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
*
* @author Dick Schoeller
*/
public final class SourceRenderer extends GedRenderer<Source> {
public final class SourceRenderer extends GedRenderer<Source>
implements IndexHrefRenderer<Source> {
/**
* @param gedObject the Source that we are going to render
* @param rendererFactory the factory that creates the renderers for the
Expand Down Expand Up @@ -61,12 +62,4 @@ public List<GedRenderer<?>> getAttributes() {
}
return list;
}

/**
* @return the href string to the index page containing this person.
*/
public String getIndexHref() {
final Source source = getGedObject();
return "surnames?db=" + source.getDbName() + "&letter=A";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final String surnames(
createRenderingContext());

model.addAttribute("filename", gedbrowserHome + "/" + dbName + ".ged");
model.addAttribute("index", gedRenderer);
model.addAttribute("model", gedRenderer);
model.addAttribute("appInfo", appInfo);

logger.debug("Exiting surnames");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final String living(@RequestParam(value = "db",
createRenderingContext());

model.addAttribute("filename", gedbrowserHome + "/" + dbName + ".ged");
model.addAttribute("living", gedRenderer);
model.addAttribute("model", gedRenderer);
model.addAttribute("appInfo", appInfo);

logger.debug("Exiting living");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ public final String person(
final Model model) {
logger.debug("Entering person");

final Person person = fetchPerson(dbName, idString);

final RenderingContext context = createRenderingContext();

final Person person = fetchPerson(dbName, idString, context);

final List<PlaceInfo> places = fetchPlaces(person, context);
final Boolean showMap = !places.isEmpty();

final String filename = gedbrowserHome + "/" + dbName + ".ged";
model.addAttribute("filename", filename);
model.addAttribute("name", nameHtml(context, person));
model.addAttribute("person", personRenderer(context, person));
model.addAttribute("model", personRenderer(context, person));
model.addAttribute("places", places);
model.addAttribute("key", getMapsKey());
model.addAttribute("showMap", showMap);
Expand All @@ -77,15 +77,17 @@ public final String person(
/**
* @param dbName the name of the database
* @param idString the ID of the person
* @param context the rendering context
* @return the person
*/
private Person fetchPerson(final String dbName, final String idString) {
private Person fetchPerson(final String dbName, final String idString,
final RenderingContext context) {
final Root root = fetchRoot(dbName);
final Person person = (Person) root.find(idString);
if (person == null) {
throw new PersonNotFoundException(
"Person " + idString + " not found", idString,
root.getDbName());
root.getDbName(), context);
}
return person;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.schoellerfamily.gedbrowser.datamodel.Source;
import org.schoellerfamily.gedbrowser.renderer.GedRenderer;
import org.schoellerfamily.gedbrowser.renderer.GedRendererFactory;
import org.schoellerfamily.gedbrowser.renderer.RenderingContext;
import org.schoellerfamily.gedbrowser.renderer.application.ApplicationInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -52,18 +53,20 @@ public final String source(

final Root root = fetchRoot(dbName);

final RenderingContext context = createRenderingContext();
final Source source = (Source) root.find(idString);
if (source == null) {
throw new SourceNotFoundException(
"Source " + idString + " not found", idString, dbName);
"Source " + idString + " not found", idString, dbName,
context);
}

final GedRenderer<?> sourceRenderer = new GedRendererFactory()
.create(source, createRenderingContext());
.create(source, context);

model.addAttribute("filename", gedbrowserHome + "/" + dbName + ".ged");
model.addAttribute("sourceString", source.getString());
model.addAttribute("source", sourceRenderer);
model.addAttribute("model", sourceRenderer);
model.addAttribute("appInfo", appInfo);
logger.debug("Exiting source");
return "source";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.schoellerfamily.gedbrowser.controller.exception;

import org.schoellerfamily.gedbrowser.renderer.RenderingContext;

/**
* @author Dick Schoeller
*/
public class ObjectNotFoundException extends RuntimeException {
/** */
private static final long serialVersionUID = 3L;

/** */
private final String id;

/** */
private final String datasetName;

/** */
private final RenderingContext context;

/**
* @param message the message to display
* @param id the ID of the object not found
* @param datasetName the name of the dataset being searched
* @param context the rendering context
*/
public ObjectNotFoundException(final String message, final String id,
final String datasetName, final RenderingContext context) {
super(message);
this.id = id;
this.datasetName = datasetName;
this.context = context;
}


/**
* Get the ID of the person that was not found.
*
* @return the ID
*/
public String getId() {
return id;
}

/**
* @return get the name of the dataset being searched
*/
public String getDatasetName() {
return datasetName;
}

/**
* @return href string to the index page for surnames beginning with A.
*/
public String getIndexHref() {
return "surnames?db=" + datasetName + "&letter=" + "A";
}

/**
* Check if the user has a particular role.
*
* @param role role that we are looking for
* @return true if the user has the role
*/
public boolean hasRole(final String role) {
return context.hasRole(role);
}

/**
* @return the href string to the living estimator.
*/
public String getLivingHref() {
return "living?db=" + datasetName;
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
package org.schoellerfamily.gedbrowser.controller.exception;

import org.schoellerfamily.gedbrowser.renderer.RenderingContext;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
* @author Dick Schoeller
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Person not found")
public final class PersonNotFoundException extends RuntimeException {
public final class PersonNotFoundException extends ObjectNotFoundException {
/** */
private static final long serialVersionUID = 2L;

/** */
private final String personId;

/** */
private final String datasetName;
private static final long serialVersionUID = 3L;

/**
* @param message the message to display
* @param personId the ID of the person not found
* @param datasetName the name of the dataset being searched
* @param context the rendering context
*/
public PersonNotFoundException(final String message, final String personId,
final String datasetName) {
super(message);
this.personId = personId;
this.datasetName = datasetName;
final String datasetName, final RenderingContext context) {
super(message, personId, datasetName, context);
}

/**
Expand All @@ -35,13 +29,6 @@ public PersonNotFoundException(final String message, final String personId,
* @return the ID
*/
public String getPersonId() {
return personId;
}

/**
* @return get the name of the dataset being searched
*/
public String getDatasetName() {
return datasetName;
return super.getId();
}
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
package org.schoellerfamily.gedbrowser.controller.exception;

import org.schoellerfamily.gedbrowser.renderer.RenderingContext;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
* @author Dick Schoeller
*/
@ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "Source not found")
public final class SourceNotFoundException extends RuntimeException {
public final class SourceNotFoundException extends ObjectNotFoundException {
/** */
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
* @param context the rendering context
*/
public SourceNotFoundException(final String message, final String sourceId,
final String datasetName) {
super(message);
this.sourceId = sourceId;
this.datasetName = datasetName;
final String datasetName, final RenderingContext context) {
super(message, sourceId, datasetName, context);
}

/**
Expand All @@ -35,13 +29,6 @@ public SourceNotFoundException(final String message, final String sourceId,
* @return the ID
*/
public String getSourceId() {
return sourceId;
}

/**
* @return get the name of the dataset being searched
*/
public String getDatasetName() {
return datasetName;
return super.getId();
}
}
Loading

0 comments on commit e185b82

Please sign in to comment.