Export von Email-Adressen

master
Markus Kreth 6 years ago
parent a93a07431d
commit f2bbb78292
  1. 2
      .settings/com.vaadin.integration.eclipse.prefs
  2. 13
      .settings/org.eclipse.wst.common.component
  3. 1
      .sts4-cache/classpath-data.json
  4. 16
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Contact.java
  5. 7
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/CreateMeldungCommand.java
  6. 10
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/RevertableCommand.java
  7. 12
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/commands/revertable/RevertableCommand.java
  8. 11
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/ContactTypeComponent.java
  9. 15
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/menu/LoggedinMenuitemState.java
  10. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperNavigation.java
  11. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ClubhelperViews.java
  12. 230
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/ExportEmails.java
  13. 8
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonFilterTest.java

@ -1,4 +1,4 @@
com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.6.4","8.8.6"] com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.6.4","8.9.2"]
com.vaadin.integration.eclipse.previousCompileAction=both com.vaadin.integration.eclipse.previousCompileAction=both
com.vaadin.integration.eclipse.useLatestNightly=false com.vaadin.integration.eclipse.useLatestNightly=false
com.vaadin.integration.eclipse.widgetsetDirty=true com.vaadin.integration.eclipse.widgetsetDirty=true

@ -14,7 +14,9 @@
<wb-module deploy-name="vaadin-clubhelper-1.2.2-SNAPSHOT">
<wb-module deploy-name="vaadin-clubhelper-1.2.3-SNAPSHOT">
@ -46,6 +48,7 @@
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
@ -62,14 +65,18 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-resources/gwt"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-resources/gwt"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
@ -86,6 +93,7 @@
<property name="context-root" value="vaadin-clubhelper"/> <property name="context-root" value="vaadin-clubhelper"/>
@ -102,6 +110,7 @@
<property name="java-output-path" value="/vaadin-clubhelper/target/classes"/> <property name="java-output-path" value="/vaadin-clubhelper/target/classes"/>
@ -118,6 +127,7 @@
</wb-module> </wb-module>
@ -134,4 +144,5 @@
</project-modules> </project-modules>

File diff suppressed because one or more lines are too long

@ -21,6 +21,22 @@ public class Contact extends BaseEntity implements Serializable {
private static final long serialVersionUID = -7631864028095077913L; private static final long serialVersionUID = -7631864028095077913L;
public static enum Type {
PHONE("Telefon"),
MOBILE("Mobile"),
EMAIL("Email");
private final String name;
private Type(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
private String type; private String type;
private String value; private String value;

@ -8,15 +8,14 @@ import com.vaadin.icons.VaadinIcons;
import com.vaadin.server.Resource; import com.vaadin.server.Resource;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung.EventMeldung;
public class CreateMeldungCommand implements ClubCommand { public class CreateMeldungCommand implements ClubCommand {
private EventBusiness business; private EventBusiness business;
private Consumer<EventMeldung> showMeldungCommand; private Consumer<String> showMeldungCommand;
public CreateMeldungCommand(ApplicationContext context, Consumer<EventMeldung> showMeldungCommand) { public CreateMeldungCommand(ApplicationContext context, Consumer<String> showMeldungCommand) {
this.business = context.getBean(EventBusiness.class); this.business = context.getBean(EventBusiness.class);
this.showMeldungCommand = showMeldungCommand; this.showMeldungCommand = showMeldungCommand;
} }
@ -33,7 +32,7 @@ public class CreateMeldungCommand implements ClubCommand {
@Override @Override
public void execute() { public void execute() {
showMeldungCommand.accept(business.createMeldung()); showMeldungCommand.accept(business.createMeldung().toString());
} }
} }

@ -1,10 +0,0 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands;
public interface RevertableCommand extends ClubCommand {
/**
* Macht das Kommando wieder Rückgängig.
*/
void revert();
}

@ -0,0 +1,12 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.revertable;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
public interface RevertableCommand extends ClubCommand {
/**
* Macht das Kommando wieder Rückgängig.
*/
void revert();
}

@ -2,12 +2,21 @@ package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components;
import com.vaadin.ui.ComboBox; import com.vaadin.ui.ComboBox;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact.Type;
public class ContactTypeComponent extends ComboBox<String> { public class ContactTypeComponent extends ComboBox<String> {
private static final long serialVersionUID = 1507070116708489598L; private static final long serialVersionUID = 1507070116708489598L;
public ContactTypeComponent() { public ContactTypeComponent() {
setItems("Telefon", "Email", "Mobile"); Type[] type = Contact.Type.values();
String[] typeNames = new String[type.length];
for (int i = 0; i < typeNames.length; i++) {
typeNames[i] = type[i].getName();
}
setItems(typeNames);
setEmptySelectionCaption("Bitte wählen"); setEmptySelectionCaption("Bitte wählen");
} }

@ -20,7 +20,6 @@ import com.vaadin.ui.Window;
import de.kreth.googleconnectors.calendar.CalendarAdapter; import de.kreth.googleconnectors.calendar.CalendarAdapter;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung.EventMeldung;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier; import de.kreth.vaadin.clubhelper.vaadinclubhelper.security.SecurityVerifier;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.commands.ClubCommand;
@ -60,6 +59,8 @@ class LoggedinMenuitemState extends LoggedOffState {
private MenuItem deleteMenuItem; private MenuItem deleteMenuItem;
private MenuItem exportEmailsMenuItem;
public LoggedinMenuitemState(ApplicationContext context, UI ui, Supplier<ZonedDateTime> startProvider, public LoggedinMenuitemState(ApplicationContext context, UI ui, Supplier<ZonedDateTime> startProvider,
Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) { Supplier<ZonedDateTime> endProvider, BiConsumer<String, JasperPrint> printConsumer) {
super(context, startProvider, endProvider, printConsumer); super(context, startProvider, endProvider, printConsumer);
@ -122,6 +123,10 @@ class LoggedinMenuitemState extends LoggedOffState {
CommandWrapper createMeldungCommand = new CommandWrapper(new CreateMeldungCommand(context, this::show)); CommandWrapper createMeldungCommand = new CommandWrapper(new CreateMeldungCommand(context, this::show));
createMeldungMenuItem = createMeldungCommand.addTo(editMenu); createMeldungMenuItem = createMeldungCommand.addTo(editMenu);
CommandWrapper exportEmails = new CommandWrapper(new SwitchViewCommand(context, "Emails exportieren",
VaadinIcons.CALENDAR, ClubhelperViews.ExportEmails));
exportEmailsMenuItem = exportEmails.addTo(editMenu);
CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent)); CommandWrapper deleeteEvent = new CommandWrapper(new DeleteEventCommand(this::deleteEvent));
deleteMenuItem = deleeteEvent.addTo(editMenu); deleteMenuItem = deleeteEvent.addTo(editMenu);
@ -144,6 +149,9 @@ class LoggedinMenuitemState extends LoggedOffState {
item.setChecked(false); item.setChecked(false);
item.setEnabled(true); item.setEnabled(true);
} }
exportEmailsMenuItem.setEnabled(false);
if (ClubhelperViews.PersonEditView == view) { if (ClubhelperViews.PersonEditView == view) {
openPersonMenuItem.setChecked(true); openPersonMenuItem.setChecked(true);
openPersonMenuItem.setEnabled(false); openPersonMenuItem.setEnabled(false);
@ -151,6 +159,7 @@ class LoggedinMenuitemState extends LoggedOffState {
else if (ClubhelperViews.MainView == view) { else if (ClubhelperViews.MainView == view) {
calendarMenuItem.setChecked(true); calendarMenuItem.setChecked(true);
calendarMenuItem.setEnabled(false); calendarMenuItem.setEnabled(false);
exportEmailsMenuItem.setEnabled(true);
} }
else if (ClubhelperViews.EventDetails.equals(view)) { else if (ClubhelperViews.EventDetails.equals(view)) {
eventDetailItem.setChecked(true); eventDetailItem.setChecked(true);
@ -158,9 +167,9 @@ class LoggedinMenuitemState extends LoggedOffState {
} }
} }
private void show(EventMeldung createMeldung) { private void show(String preformattedText) {
VerticalLayout content = new VerticalLayout(); VerticalLayout content = new VerticalLayout();
content.addComponent(new Label(createMeldung.toString(), ContentMode.PREFORMATTED)); content.addComponent(new Label(preformattedText, ContentMode.PREFORMATTED));
Window dlg = new Window("Meldung für " + eventBusiness.getCurrent().getCaption()); Window dlg = new Window("Meldung für " + eventBusiness.getCurrent().getCaption());
dlg.setContent(content); dlg.setContent(content);
dlg.center(); dlg.center();

@ -86,6 +86,7 @@ public class ClubhelperNavigation implements ApplicationContextAware {
navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personBusiness, securityGroupVerifier)); navi.addView(ClubhelperViews.LoginUI.name(), new LoginUI(personBusiness, securityGroupVerifier));
navi.addView(ClubhelperViews.PersonEditView.name(), personEdit); navi.addView(ClubhelperViews.PersonEditView.name(), personEdit);
navi.addView(ClubhelperViews.EventDetails.name(), new EventDetails(context)); navi.addView(ClubhelperViews.EventDetails.name(), new EventDetails(context));
navi.addView(ClubhelperViews.ExportEmails.name(), new ExportEmails(context));
page.addBrowserWindowResizeListener(ev -> { page.addBrowserWindowResizeListener(ev -> {
int width = ev.getWidth(); int width = ev.getWidth();

@ -9,6 +9,7 @@ public enum ClubhelperViews {
MainView, MainView,
EventDetails, EventDetails,
PersonEditView, PersonEditView,
ExportEmails,
LoginUI; LoginUI;
public static ClubhelperViews byState(String state) { public static ClubhelperViews byState(String state) {

@ -0,0 +1,230 @@
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.navigation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.context.ApplicationContext;
import com.vaadin.data.HasValue.ValueChangeEvent;
import com.vaadin.data.provider.DataProvider;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.shared.ui.ContentMode;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.SelectionMode;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.VerticalLayout;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.PersonBusiness;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Contact;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.ClubhelperMenuBar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
public class ExportEmails extends VerticalLayout implements View {
private PersonBusiness personBusiness;
private List<GroupDef> allGroups;
private Set<GroupDef> selected;
private ListDataProvider<EmailHolder> dataProvider;
private final List<EmailHolder> items;
private MenuItemStateFactory stateFactory;
private TextArea asText;
public ExportEmails(ApplicationContext context) {
this.stateFactory = context.getBean(MenuItemStateFactory.class);
this.personBusiness = context.getBean(PersonBusiness.class);
allGroups = context.getBean(GroupDao.class).listAll();
selected = new HashSet<>();
items = new ArrayList<>();
dataProvider = DataProvider.ofCollection(items);
}
@Override
public void enter(ViewChangeEvent event) {
View.super.enter(event);
ClubhelperMenuBar menubar = new ClubhelperMenuBar(stateFactory.currentState());
HorizontalLayout groupCheck = new HorizontalLayout();
for (GroupDef groupDef : allGroups) {
CheckBox box = new CheckBox(groupDef.getName());
box.setData(groupDef);
if (groupDef.hasValidId() && groupDef.getId() == 1) {
box.setValue(true);
selected.add(groupDef);
}
box.addValueChangeListener(this::groupBoxEvent);
groupCheck.addComponent(box);
}
Grid<EmailHolder> grid = new Grid<>();
grid.addColumn(EmailHolder::getPrename).setCaption("Vorname");
grid.addColumn(EmailHolder::getSurname).setCaption("Nachname");
grid.addColumn(EmailHolder::getEmail).setCaption("Emailadresse");
grid.setSelectionMode(SelectionMode.MULTI);
grid.setDataProvider(dataProvider);
asText = new TextArea("Emails als Text");
asText.setWidth(10, Unit.CM);
asText.setWordWrap(false);
asText.setRows(25);
asText.setEnabled(false);
addComponent(menubar);
addComponent(new Label("<H1>Export von Emailadressen</H1>", ContentMode.HTML));
addComponent(groupCheck);
addComponent(new HorizontalLayout(grid, asText));
refreshData();
}
private void groupBoxEvent(ValueChangeEvent<Boolean> event) {
CheckBox box = (CheckBox) event.getComponent();
GroupDef groupDef = (GroupDef) box.getData();
Boolean checked = box.getValue();
if (Boolean.TRUE.equals(checked)) {
selected.add(groupDef);
}
else {
selected.remove(groupDef);
}
refreshData();
}
private void refreshData() {
items.clear();
personBusiness.listAll().stream()
.filter(this::matchGroupSelection)
.map(this::getEmails)
.forEach(items::addAll);
dataProvider.refreshAll();
StringBuilder text = new StringBuilder();
for (EmailHolder emailHolder : items) {
if (text.length() > 0) {
text.append(",\n");
}
text.append(emailHolder.getEmail());
}
asText.setValue(text.toString());
}
private boolean matchGroupSelection(Person p) {
Set<GroupDef> personGroups = p.getGroups();
boolean contains = false;
for (GroupDef g : selected) {
if (personGroups.contains(g)) {
contains = true;
break;
}
}
return contains;
}
private Collection<EmailHolder> getEmails(Person person) {
List<Contact> emails = new ArrayList<>();
List<Contact> contacts = person.getContacts();
for (Contact contact : contacts) {
if (Contact.Type.EMAIL.getName().equals(contact.getType())) {
emails.add(contact);
}
}
Set<EmailHolder> holders = new HashSet<>();
for (Contact c : emails) {
holders.add(new EmailHolder(person, c));
}
return holders;
}
private class EmailHolder {
private final Person person;
private final Contact contact;
public EmailHolder(Person person, Contact contact) {
super();
this.person = person;
this.contact = contact;
}
public String getEmail() {
return contact.getValue();
}
public String getPrename() {
return person.getPrename();
}
public String getSurname() {
return person.getSurname();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getEnclosingInstance().hashCode();
result = prime * result + ((contact.getValue() == null) ? 0 : contact.getValue().hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
EmailHolder other = (EmailHolder) obj;
if (!getEnclosingInstance().equals(other.getEnclosingInstance())) {
return false;
}
if (contact.getValue() == null) {
if (other.contact.getValue() != null) {
return false;
}
}
else if (!contact.getValue().equals(other.contact.getValue())) {
return false;
}
return true;
}
@Override
public String toString() {
return contact.getValue();
}
private ExportEmails getEnclosingInstance() {
return ExportEmails.this;
}
}
}

@ -13,7 +13,6 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.Mock; import org.mockito.Mock;
@ -31,7 +30,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestConfiguration;
@SpringBootTest @SpringBootTest
@ContextConfiguration(classes = TestConfiguration.class) @ContextConfiguration(classes = TestConfiguration.class)
@Tag("spring") @Tag("spring")
@Disabled //@Disabled
class PersonFilterTest { class PersonFilterTest {
private PersonFilter filter; private PersonFilter filter;
@ -86,6 +85,11 @@ class PersonFilterTest {
assertEquals(groups.size(), persons.get(0).getGroups().size()); assertEquals(groups.size(), persons.get(0).getGroups().size());
} }
@Test
void noPersonAndGroupFilter() {
}
@Test @Test
void testNoFilterSet() { void testNoFilterSet() {
allPersonsAccepted(); allPersonsAccepted();

Loading…
Cancel
Save