Error handling

master
Markus Kreth 7 years ago
parent deefacbb49
commit 99cc213ef1
  1. 5
      .classpath
  2. 1
      .settings/org.eclipse.core.resources.prefs
  3. 13
      .settings/org.eclipse.wst.common.component
  4. 3
      pom.xml
  5. 15
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ClubhelperException.java
  6. 18
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java
  7. 7
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/PersonDaoImpl.java
  8. 28
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/ClubEvent.java
  9. 38
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/ClubhelperErrorDialog.java
  10. 16
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  11. 36
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/HeadView.java
  12. 6
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/LoginUI.java
  13. 25
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/MainView.java
  14. 22
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessSpringTest.java
  15. 6
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/ThrowingRunnable.java

@ -35,5 +35,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="target/generated-resources/gwt">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

@ -5,4 +5,5 @@ encoding//src/main/resources/jasper/calendar_month.jrxml=UTF-8
encoding//src/main/resources/jasper/calendar_year.jrxml=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding//target/generated-resources/gwt=UTF-8
encoding/<project>=UTF-8

@ -7,7 +7,9 @@
<wb-module deploy-name="vaadin-clubhelper-1.0.6-SNAPSHOT">
<wb-module deploy-name="vaadin-clubhelper-1.1.1-SNAPSHOT">
@ -25,6 +27,7 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
@ -34,6 +37,7 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
@ -43,6 +47,7 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -52,7 +57,10 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-resources/gwt"/>
@ -70,6 +78,7 @@
<property name="java-output-path" value="/vaadin-clubhelper/target/classes"/>
@ -79,6 +88,7 @@
</wb-module>
@ -88,4 +98,5 @@
</project-modules>

@ -4,7 +4,7 @@
<groupId>de.kreth.vaadin.clubhelper</groupId>
<artifactId>vaadin-clubhelper</artifactId>
<version>1.1.0</version>
<version>1.1.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>vaadin-clubhelper</name>
@ -345,6 +345,5 @@
<url>https://github.com/markuskreth/vaadin-clubhelper.git</url>
<connection>scm:git:git@github.com:markuskreth/vaadin-clubhelper.git</connection>
<developerConnection>scm:git:git@github.com:markuskreth/vaadin-clubhelper.git</developerConnection>
<tag>vaadin-clubhelper-1.1.0</tag>
</scm>
</project>

@ -0,0 +1,15 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper;
public class ClubhelperException extends Exception {
private static final long serialVersionUID = 8677112373849590712L;
public ClubhelperException(String message, Throwable cause) {
super(message, cause);
}
public ClubhelperException(String message) {
super(message);
}
}

@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ClubhelperException;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung.EventMeldung;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao;
@ -44,15 +45,19 @@ public class EventBusiness {
this.current = ev;
}
public void changePersons(Set<Person> selected) {
public void changePersons(Set<Person> selected) throws ClubhelperException {
if (current != null) {
try {
clubEventDao.addPersons(current, selected);
log.info("Updated {}, {} with participants: {}", current.getCaption(), current.getStart(), selected);
} catch (Exception e) {
log.error("Unable to update Event {}, {}, {} with participants: {}", current.getId(),
current.getCaption(), current.getStart(), selected, e);
throw e;
}
catch (Exception e) {
StringBuilder errorMessage = new StringBuilder("Unable to update Event ");
errorMessage.append(current.getId());
errorMessage.append(", ").append(current.getCaption());
errorMessage.append(", ").append(current.getStart());
errorMessage.append(" with participants: ").append(selected);
throw new ClubhelperException(errorMessage.toString(), e);
}
}
}
@ -70,7 +75,8 @@ public class EventBusiness {
return el;
}
}
} else {
}
else {
altersgruppen.add(e);
e.setClubEvent(current);
}

@ -33,6 +33,7 @@ public class PersonDaoImpl extends AbstractDaoImpl<Person> implements PersonDao
super.save(obj);
}
@Transactional
public void checkSubEntities(Person obj) {
Startpass startPass = obj.getStartpass();
if (startPass != null) {
@ -58,7 +59,8 @@ public class PersonDaoImpl extends AbstractDaoImpl<Person> implements PersonDao
c.setChanged(now);
if (entityManager.contains(c) || c.hasValidId()) {
entityManager.merge(c);
} else {
}
else {
c.setCreated(now);
entityManager.persist(c);
}
@ -95,7 +97,8 @@ public class PersonDaoImpl extends AbstractDaoImpl<Person> implements PersonDao
if (r[1].equals(ignoring)) {
p = entityManager.find(Person.class, r[2]);
relation = r[3].toString();
} else if (r[2].equals(ignoring)) {
}
else if (r[2].equals(ignoring)) {
p = entityManager.find(Person.class, r[1]);
relation = r[4].toString();
}

@ -21,20 +21,30 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.CompetitionType.Type;
// Entity must not be used, this class is persisted by ClubEvent.hbm.xml
@Entity
/**
* Calendar Event item corresponding to google calendar events.
* @author markus
*
*/
public class ClubEvent extends BasicItem implements EntityAccessor {
private static final long serialVersionUID = -3600971939167437577L;
@Id
private String id;
private String location;
private String iCalUID;
private String organizerDisplayName;
@ManyToMany
private Set<Person> persons;
@OneToMany
private Set<Altersgruppe> altersgruppen;
@OneToOne
@JoinColumn(name = "id", nullable = true)
private CompetitionType competitionType;
@ -99,7 +109,8 @@ public class ClubEvent extends BasicItem implements EntityAccessor {
public Type getType() {
if (competitionType != null) {
return competitionType.getType();
} else {
}
else {
return null;
}
}
@ -196,25 +207,29 @@ public class ClubEvent extends BasicItem implements EntityAccessor {
if (iCalUID == null) {
if (other.iCalUID != null)
return false;
} else if (!iCalUID.equals(other.iCalUID)) {
}
else if (!iCalUID.equals(other.iCalUID)) {
return false;
}
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id)) {
}
else if (!id.equals(other.id)) {
return false;
}
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location)) {
}
else if (!location.equals(other.location)) {
return false;
}
if (organizerDisplayName == null) {
if (other.organizerDisplayName != null)
return false;
} else if (!organizerDisplayName.equals(other.organizerDisplayName)) {
}
else if (!organizerDisplayName.equals(other.organizerDisplayName)) {
return false;
}
return true;
@ -224,7 +239,8 @@ public class ClubEvent extends BasicItem implements EntityAccessor {
if (parse != null) {
Instant instant = parse.toInstant();
return ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
} else {
}
else {
return null;
}
}

@ -0,0 +1,38 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui;
import java.io.PrintWriter;
import java.io.StringWriter;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
public class ClubhelperErrorDialog {
private final Window errorDlg = new Window("Fehler");
public ClubhelperErrorDialog(String errormessage, Exception exception) {
VerticalLayout layout = new VerticalLayout();
layout.addComponent(new Label(errormessage));
layout.addComponent(new Label(exception.getMessage()));
StringWriter out = new StringWriter();
PrintWriter writer = new PrintWriter(out);
exception.printStackTrace(writer);
layout.addComponent(toComponent(out));
layout.addComponent(new Button("Schließen", event -> errorDlg.close()));
errorDlg.setContent(layout);
}
public Label toComponent(StringWriter out) {
Label label = new Label(out.toString());
label.setContentMode(ContentMode.PREFORMATTED);
return label;
}
public void show(UI ui) {
ui.addWindow(errorDlg);
}
}

@ -24,11 +24,14 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
public class CalendarComponent extends CustomComponent {
private static final long serialVersionUID = -9152173211931554059L;
private transient final Logger log = LoggerFactory.getLogger(getClass());
private final transient Logger log = LoggerFactory.getLogger(getClass());
private final transient List<Consumer<ZonedDateTime>> dateUpdateEvents;
private final ClubEventProvider dataProvider;
private Calendar<ClubEvent> calendar;
private List<Consumer<ZonedDateTime>> dateUpdateEvents;
private final Calendar<ClubEvent> calendar;
public CalendarComponent(ClubEventProvider dataProvider) {
@ -40,7 +43,7 @@ public class CalendarComponent extends CustomComponent {
calendar.setCaption("Events");
calendar.setSizeFull();
calendar.addListener(ev -> calendarEvent(ev));
calendar.addListener(this::calendarEvent);
setCompositionRoot(calendar);
}
@ -75,6 +78,11 @@ public class CalendarComponent extends CustomComponent {
calendar.markAsDirty();
}
/**
* {@link ClubEvent} provider for vaadin calendar addon.
* @author markus
*
*/
public static class ClubEventProvider extends BasicItemProvider<ClubEvent> {
private static final long serialVersionUID = -5415397258827236704L;

@ -48,6 +48,7 @@ public class HeadView extends HorizontalLayout {
private static final long serialVersionUID = -7915475211371903028L;
protected transient final Logger log = LoggerFactory.getLogger(getClass());
protected transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uuuu");
private final ClubEventProvider dataProvider;
@ -55,9 +56,11 @@ public class HeadView extends HorizontalLayout {
private int monthItemId;
private final Button personLabel;
protected final Label monthName;
private final Function<Component, ZonedDateTime> startTime;
private final Function<Component, ZonedDateTime> endTime;
private final ClubNavigator navigator;
@ -104,7 +107,8 @@ public class HeadView extends HorizontalLayout {
Person loggedinPerson = securityVerifier.getLoggedinPerson();
if (loggedinPerson != null) {
personLabel.setCaption(loggedinPerson.getSurname() + ", " + loggedinPerson.getPrename());
} else {
}
else {
personLabel.setCaption("");
}
}
@ -133,7 +137,8 @@ public class HeadView extends HorizontalLayout {
securityVerifier.setLoggedinPerson(null);
navigator.navigateTo(ClubhelperViews.MainView.name());
});
} else {
}
else {
contextMenu.addItem("Anmelden", ev1 -> navigator.navigateTo(ClubhelperViews.LoginUI.name()));
}
int width = getUI().getPage().getBrowserWindowWidth();
@ -156,7 +161,8 @@ public class HeadView extends HorizontalLayout {
start = startTime.apply(source);
end = endTime.apply(source);
items = dataProvider.getItems(start, end);
} else {
}
else {
start = startTime.apply(source).withDayOfYear(1);
end = start.withMonth(12).withDayOfMonth(31);
items = dataProvider.getItems(start, end);
@ -180,7 +186,8 @@ public class HeadView extends HorizontalLayout {
if (values.containsKey(day)) {
content = values.get(day);
content.append("\n");
} else {
}
else {
content = new StringBuilder();
values.put(day, content);
}
@ -194,7 +201,8 @@ public class HeadView extends HorizontalLayout {
String calendarMonth;
if (monthOnly) {
calendarMonth = dfMonth.format(start);
} else {
}
else {
calendarMonth = "Jahr " + start.getYear();
}
@ -202,7 +210,8 @@ public class HeadView extends HorizontalLayout {
JasperPrint print;
if (monthOnly) {
print = CalendarCreator.createCalendar(new Date(start.toInstant().toEpochMilli()), values, holidays);
} else {
}
else {
print = CalendarCreator.createYearCalendar(start.getYear(), values, holidays);
}
log.trace("Created Jasper print for {}", calendarMonth);
@ -215,12 +224,10 @@ public class HeadView extends HorizontalLayout {
window.setHeight("90%");
personLabel.getUI().addWindow(window);
log.trace("Added pdf window for {}", calendarMonth);
} catch (JRException e) {
}
catch (JRException | IOException | RuntimeException e) {
log.error("Error Creating Jasper Report for {}", calendarMonth, e);
Notification.show("Fehler bei PDF: " + e);
} catch (IOException e1) {
log.error("Error Creating Jasper Report for {}", calendarMonth, e1);
Notification.show("Fehler bei PDF: " + e1);
}
}
@ -239,13 +246,16 @@ public class HeadView extends HorizontalLayout {
exec.execute(() -> {
try {
JasperExportManager.exportReportToPdfStream(print, out);
} catch (JRException e) {
}
catch (JRException e) {
log.error("Error on Export to Pdf.", e);
throw new RuntimeException(e);
} finally {
}
finally {
try {
out.close();
} catch (IOException e) {
}
catch (IOException e) {
log.warn("Error closing Jasper output stream.", e);
}
}

@ -18,9 +18,11 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
public class LoginUI extends VerticalLayout implements View {
private static final long serialVersionUID = 4339018452507960084L;
private final Logger logger = LoggerFactory.getLogger(getClass());
private Navigator navigator;
private String parameters;
public LoginUI(PersonDao personDao, SecurityVerifier securityGroupVerifier) {
@ -35,8 +37,8 @@ public class LoginUI extends VerticalLayout implements View {
Person loggedin = personDao.findLoginUser(username, password);
securityGroupVerifier.setLoggedinPerson(loggedin);
navigator.navigateTo(ClubhelperViews.MainView.name() + '/' + parameters);
} catch (final Exception ex) {
ex.printStackTrace();
}
catch (final Exception ex) {
logger.error("Error on login for User={}", e.getLoginParameter("username"), ex);
String message = "Incorrect user or password for " + e.getLoginParameter("username") + "\n"
+ ex.getMessage();

@ -11,12 +11,14 @@ import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.VerticalLayout;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ClubhelperException;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.ClubhelperErrorDialog;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.PersonGrid;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.SingleEventView;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavigation.ClubNavigator;
@ -24,14 +26,19 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation.ClubhelperNavig
public abstract class MainView extends VerticalLayout implements View {
private static final long serialVersionUID = 4831071242146146399L;
protected final Logger LOGGER = LoggerFactory.getLogger(getClass());
private final PersonDao personDao;
private final GroupDao groupDao;
protected final EventBusiness eventBusiness;
protected final SecurityVerifier securityVerifier;
protected PersonGrid personGrid;
protected SingleEventView eventView;
protected ClubNavigator navigator;
@ -49,16 +56,19 @@ public abstract class MainView extends VerticalLayout implements View {
if (this.navigator == null) {
initUI(event);
LOGGER.info("Loaded UI and started fetch of Events");
} else {
}
else {
if (securityVerifier.isLoggedin()) {
LOGGER.info("{} already initialized - opening Person View.", getClass().getName());
ClubEvent current = eventBusiness.getCurrent();
openDetailForEvent(current);
} else {
}
else {
LOGGER.info("{} already initialized - but not loggedin.", getClass().getName());
detailClosed();
}
}
}
public void initUI(ViewChangeEvent event) {
@ -79,7 +89,16 @@ public abstract class MainView extends VerticalLayout implements View {
private void personSelectionChange(SelectionEvent<Person> ev) {
Set<Person> selected = ev.getAllSelectedItems();
LOGGER.debug("Selection changed to: {}", selected);
eventBusiness.changePersons(selected);
try {
eventBusiness.changePersons(selected);
}
catch (ClubhelperException e) {
LOGGER.error("Error storing Persons.", e);
String text = "Fehler beim Speichern der Personen dieser Veranstaltung";
new ClubhelperErrorDialog(text, e).show(getUI());
}
}
public void detailClosed() {

@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ClubhelperException;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.TestDatabaseHelper;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubeventHasPerson;
@ -31,6 +32,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
class EventBusinessSpringTest {
private List<Person> persons;
private ClubEvent event;
@Autowired
@ -94,11 +96,27 @@ class EventBusinessSpringTest {
@Disabled
void testAddPersonsToEvent() {
assertEquals(0, all.getResultList().size());
testDatabaseHelper.transactional(() -> eventBusiness.changePersons(new HashSet<>(persons.subList(0, 1))));
testDatabaseHelper.transactional(() -> eventBusiness.changePersons(new HashSet<>(persons.subList(0, 2))));
try {
transactional(() -> eventBusiness.changePersons(new HashSet<>(persons.subList(0, 1))));
transactional(() -> eventBusiness.changePersons(new HashSet<>(persons.subList(0, 2))));
}
catch (Exception e) {
}
List<ClubeventHasPerson> result = all.getResultList();
assertEquals(2, result.size());
}
private void transactional(ThrowingRunnable<ClubhelperException> object) {
testDatabaseHelper.transactional(() -> {
try {
object.run();
}
catch (ClubhelperException e) {
throw new RuntimeException(e);
}
});
}
}

@ -0,0 +1,6 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.business;
public interface ThrowingRunnable<E extends Exception> {
void run() throws E;
}
Loading…
Cancel
Save