diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java index 56c0f41..27a5251 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java @@ -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.business.meldung.EventMeldung; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.AltersgruppeDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.ClubEventDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Altersgruppe; diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventMeldung.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/EventMeldung.java similarity index 58% rename from src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventMeldung.java rename to src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/EventMeldung.java index 2fc90fc..df2a1af 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventMeldung.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/EventMeldung.java @@ -1,4 +1,4 @@ -package de.kreth.vaadin.clubhelper.vaadinclubhelper.business; +package de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung; import java.util.ArrayList; import java.util.Collections; @@ -47,19 +47,7 @@ public class EventMeldung { @Override public String toString() { - StringBuilder txt = new StringBuilder(); - txt.append("\n\n für den Wettkampf "); - txt.append(event.getCaption()).append(" am ").append(event.getStart().toLocalDate().toString()) - .append(" melden wir für den MTV Groß-Buchholz folgende Starter:"); - List groupList = new ArrayList<>(groups.keySet()); - groupList.sort((o1, o2) -> Integer.compare(o2.getStart(), o1.getStart())); - for (Altersgruppe g : groupList) { - txt.append("\n\n").append(g.getBezeichnung()); - for (Person p : groups.get(g)) { - txt.append("\n").append(p.getPrename()).append(" ").append(p.getSurname()).append("\t") - .append(p.getBirth().getYear()).append("\t").append(g.getPflicht().getName()); - } - } - return txt.toString(); + return MeldungGeneratorFactory.forType(event.getType()).printMeldung(event, groups).toString(); } + } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungEinzelWettkampfGenerator.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungEinzelWettkampfGenerator.java new file mode 100644 index 0000000..1b1798e --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungEinzelWettkampfGenerator.java @@ -0,0 +1,36 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Altersgruppe; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; + +class MeldungEinzelWettkampfGenerator implements MeldungGenerator { + + /* + * (non-Javadoc) + * + * @see de.kreth.vaadin.clubhelper.vaadinclubhelper.business.MeldungGenerator# + * printMeldung() + */ + @Override + public CharSequence printMeldung(ClubEvent event, Map> groups) { + StringBuilder txt = new StringBuilder(); + txt.append("\n\n für den Wettkampf "); + txt.append(event.getCaption()).append(" am ").append(event.getStart().toLocalDate().toString()) + .append(" melden wir für den MTV Groß-Buchholz folgende Starter:"); + List groupList = new ArrayList<>(groups.keySet()); + groupList.sort((o1, o2) -> Integer.compare(o2.getStart(), o1.getStart())); + for (Altersgruppe g : groupList) { + txt.append("\n\n").append(g.getBezeichnung()); + for (Person p : groups.get(g)) { + txt.append("\n").append(p.getPrename()).append(" ").append(p.getSurname()).append("\t") + .append(p.getBirth().getYear()).append("\t").append(g.getPflicht().getName()); + } + } + return txt; + } +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGenerator.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGenerator.java new file mode 100644 index 0000000..2857031 --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGenerator.java @@ -0,0 +1,14 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung; + +import java.util.List; +import java.util.Map; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Altersgruppe; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; + +public interface MeldungGenerator { + + CharSequence printMeldung(ClubEvent event, Map> groups); + +} \ No newline at end of file diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGeneratorFactory.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGeneratorFactory.java new file mode 100644 index 0000000..f82c81d --- /dev/null +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/meldung/MeldungGeneratorFactory.java @@ -0,0 +1,23 @@ +package de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung; + +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.CompetitionType; + +public class MeldungGeneratorFactory { + + public static MeldungGenerator forType(CompetitionType.Type type) { + switch (type) { + case DOPPELMINI: +// break; + case LIGA: +// break; + case MANNSCHAFT: +// break; + case SYNCHRON: +// break; + case EINZEL: + default: + return new MeldungEinzelWettkampfGenerator(); + + } + } +} diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java index 6a8bdcd..ba9ec4f 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/EventDetails.java @@ -12,7 +12,7 @@ import com.vaadin.ui.VerticalLayout; import com.vaadin.ui.Window; import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventBusiness; -import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.EventMeldung; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.meldung.EventMeldung; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.GroupDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PflichtenDao; diff --git a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java index f28ce0b..b64a69c 100644 --- a/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java +++ b/src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusinessTest.java @@ -11,17 +11,20 @@ import java.time.ZonedDateTime; import java.util.Arrays; import java.util.HashSet; import java.util.List; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +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; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Altersgruppe; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEventBuilder; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Gender; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestAltersgruppen; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.tests.TestPersonGenerator; @@ -58,6 +61,8 @@ class EventBusinessTest { for (Person p : personen) { p.setEvents(new HashSet<>(Arrays.asList(ev))); p.setBirth(LocalDate.of(1993 + (count * 3), count, count + 2)); + int modulo = count % 2 + 1; + p.setGender(Gender.valueOf(modulo)); count++; } @@ -67,6 +72,7 @@ class EventBusinessTest { eventBusiness.setSelected(ev); EventMeldung meldung = eventBusiness.createMeldung(); assertNotNull(meldung); + Map> groups = meldung.getGroups(); }