WIP: verder uitbreiden model
This commit is contained in:
@@ -18,6 +18,19 @@
|
|||||||
<groupId>com.google.ortools</groupId>
|
<groupId>com.google.ortools</groupId>
|
||||||
<artifactId>ortools-java</artifactId>
|
<artifactId>ortools-java</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.datafaker</groupId>
|
||||||
|
<artifactId>datafaker</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package nl.agilecc.agiledancers;
|
|
||||||
|
|
||||||
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
|
|
||||||
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
|
|
||||||
public class Main {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
|
|
||||||
// to see how IntelliJ IDEA suggests fixing it.
|
|
||||||
System.out.printf("Hello and welcome!");
|
|
||||||
|
|
||||||
for (int i = 1; i <= 5; i++) {
|
|
||||||
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
|
|
||||||
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
|
|
||||||
System.out.println("i = " + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@EqualsAndHashCode
|
||||||
|
@ToString
|
||||||
|
@NoArgsConstructor
|
||||||
|
public abstract class AbstractEntity {
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
protected <T> void addNullSafe(Set<T> set, T t) {
|
||||||
|
emptyIfNull(set).add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> Set<T> emptyIfNull(Set<T> set) {
|
||||||
|
return set == null ?
|
||||||
|
new HashSet<>() :
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected <T> Set<T> unmodifiableNullSafe(Set<T> set) {
|
||||||
|
return set == null ? Collections.emptySet() : Collections.unmodifiableSet(set);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
package nl.agilecc.agiledancers.model;
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
public class Coach {
|
import lombok.*;
|
||||||
private Long id;
|
|
||||||
private String name;
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@Builder
|
||||||
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
|
public class Coach extends AbstractEntity {
|
||||||
|
@ToString.Include
|
||||||
|
private final String name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,46 @@
|
|||||||
package nl.agilecc.agiledancers.model;
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
import nl.agilecc.agiledancers.model.specifications.DanceGroupStyle;
|
import nl.agilecc.agiledancers.model.specifications.DanceGroupStyle;
|
||||||
import nl.agilecc.agiledancers.model.specifications.DanceGroupType;
|
import nl.agilecc.agiledancers.model.specifications.DanceGroupType;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class DanceGroup {
|
@Getter
|
||||||
private Long id;
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
private String category;
|
@Builder
|
||||||
private DanceGroupType type;
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
private int startAge;
|
public class DanceGroup extends AbstractEntity {
|
||||||
private int endAge;
|
@ToString.Include
|
||||||
|
private final String category;
|
||||||
|
@ToString.Include
|
||||||
|
private final DanceGroupType type;
|
||||||
|
@ToString.Include
|
||||||
|
private final int startAge;
|
||||||
|
@ToString.Include
|
||||||
|
private final int endAge;
|
||||||
|
@ToString.Include
|
||||||
private Set<Dancer> dancers;
|
private Set<Dancer> dancers;
|
||||||
|
@ToString.Include
|
||||||
private Set<DanceGroupStyle> styles;
|
private Set<DanceGroupStyle> styles;
|
||||||
|
@ToString.Include
|
||||||
private Coach coach;
|
private Coach coach;
|
||||||
|
|
||||||
|
public Set<Dancer> getDancers() {
|
||||||
|
return super.unmodifiableNullSafe(dancers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDancer(Dancer dancer) {
|
||||||
|
super.addNullSafe(dancers, dancer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<DanceGroupStyle> getStyles() {
|
||||||
|
return super.unmodifiableNullSafe(styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addStyle(DanceGroupStyle style) {
|
||||||
|
super.addNullSafe(styles, style);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@Builder
|
||||||
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
|
public class DanceSchool extends AbstractEntity {
|
||||||
|
private final String name;
|
||||||
|
private final Set<Dancer> dancers;
|
||||||
|
private final Set<DanceGroup> danceGroups;
|
||||||
|
private final Set<Show> shows;
|
||||||
|
private final Set<Coach> coaches;
|
||||||
|
|
||||||
|
public Set<Dancer> getDancers() {
|
||||||
|
return super.unmodifiableNullSafe(dancers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<DanceGroup> getDanceGroups() {
|
||||||
|
return super.unmodifiableNullSafe(danceGroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Show> getShows() {
|
||||||
|
return super.unmodifiableNullSafe(shows);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Coach> getCoaches() {
|
||||||
|
return super.unmodifiableNullSafe(coaches);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDancer(Dancer dancer) {
|
||||||
|
super.addNullSafe(dancers, dancer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDanceGroup(DanceGroup danceGroup) {
|
||||||
|
super.addNullSafe(danceGroups, danceGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addShow(Show show) {
|
||||||
|
super.addNullSafe(shows, show);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCoach(Coach coach) {
|
||||||
|
super.addNullSafe(coaches, coach);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,21 @@
|
|||||||
package nl.agilecc.agiledancers.model;
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
public class Dancer {
|
import lombok.*;
|
||||||
private Long id;
|
|
||||||
private String name;
|
import java.time.LocalDate;
|
||||||
private int age;
|
import java.time.Period;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@Builder
|
||||||
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
|
public class Dancer extends AbstractEntity {
|
||||||
|
@ToString.Include
|
||||||
|
private final String name;
|
||||||
|
@ToString.Include
|
||||||
|
private LocalDate birthDate;
|
||||||
|
|
||||||
|
public int age() {
|
||||||
|
return Period.between(birthDate, LocalDate.now()).getYears();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package nl.agilecc.agiledancers.model;
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
import nl.agilecc.agiledancers.model.specifications.DayPartType;
|
import nl.agilecc.agiledancers.model.specifications.DayPartType;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DayPart {
|
@Getter
|
||||||
private Long id;
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
@Builder
|
||||||
private DayPartType type;
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
private List<DanceGroup> danceGroups;
|
public class DayPart extends AbstractEntity {
|
||||||
|
@ToString.Include
|
||||||
|
private final DayPartType type;
|
||||||
|
@ToString.Include
|
||||||
|
private final List<DanceGroup> danceGroups;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
package nl.agilecc.agiledancers.model;
|
package nl.agilecc.agiledancers.model;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Show {
|
@Getter
|
||||||
private Long id;
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
private List<DayPart> dayParts;
|
@Builder
|
||||||
|
@ToString(onlyExplicitlyIncluded = true)
|
||||||
|
public class Show extends AbstractEntity {
|
||||||
|
@ToString.Include
|
||||||
|
private final List<DayPart> dayParts;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.AbstractEntity;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public abstract class AbstractRepository<T extends AbstractEntity> {
|
||||||
|
private long sequence = 0L;
|
||||||
|
|
||||||
|
protected Map<Long, T> entities = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
public T add(T entity) {
|
||||||
|
if (entity.getId() == null) {
|
||||||
|
entity.setId(sequence++);
|
||||||
|
}
|
||||||
|
entities.put(entity.getId(), entity);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<T> findAll() {
|
||||||
|
return List.copyOf(entities.values());
|
||||||
|
}
|
||||||
|
|
||||||
|
public T findById(long id) {
|
||||||
|
return entities.get(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Coach;
|
||||||
|
|
||||||
|
public class CoachRepository extends AbstractRepository<Coach> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.DanceGroup;
|
||||||
|
|
||||||
|
public class DanceGroupRepository extends AbstractRepository<DanceGroup> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.DanceSchool;
|
||||||
|
|
||||||
|
public class DanceSchoolRepository extends AbstractRepository<DanceSchool> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Dancer;
|
||||||
|
|
||||||
|
public class DancerRepository extends AbstractRepository<Dancer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.DayPart;
|
||||||
|
|
||||||
|
public class DayPartRepository extends AbstractRepository<DayPart> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package nl.agilecc.agiledancers.repository;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Show;
|
||||||
|
|
||||||
|
public class ShowRepository extends AbstractRepository<Show> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package nl.agilecc.agiledancers.service;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Coach;
|
||||||
|
import nl.agilecc.agiledancers.repository.CoachRepository;
|
||||||
|
|
||||||
|
public class CoachService {
|
||||||
|
private CoachRepository coachRepository = new CoachRepository();
|
||||||
|
|
||||||
|
public Coach addCoach(String name, Coach coach) {
|
||||||
|
return coachRepository.add(Coach.builder().name(name).build());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package nl.agilecc.agiledancers.service;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Coach;
|
||||||
|
import nl.agilecc.agiledancers.model.DanceGroup;
|
||||||
|
import nl.agilecc.agiledancers.model.Dancer;
|
||||||
|
import nl.agilecc.agiledancers.model.specifications.DanceGroupStyle;
|
||||||
|
import nl.agilecc.agiledancers.model.specifications.DanceGroupType;
|
||||||
|
import nl.agilecc.agiledancers.repository.DanceGroupRepository;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class DanceGroupService {
|
||||||
|
private final DanceGroupRepository danceGroupRepository = new DanceGroupRepository();
|
||||||
|
|
||||||
|
public DanceGroup add(String category, DanceGroupType type, int startAge, int endAge, Set<Dancer> dancers, Set<DanceGroupStyle> styles, Coach coach) {
|
||||||
|
DanceGroup danceGroup = DanceGroup.builder()
|
||||||
|
.category(category)
|
||||||
|
.type(type)
|
||||||
|
.startAge(startAge)
|
||||||
|
.endAge(endAge)
|
||||||
|
.dancers(dancers)
|
||||||
|
.styles(styles)
|
||||||
|
.coach(coach).build();
|
||||||
|
|
||||||
|
return danceGroupRepository.add(danceGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package nl.agilecc.agiledancers.service;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.*;
|
||||||
|
import nl.agilecc.agiledancers.repository.DanceSchoolRepository;
|
||||||
|
|
||||||
|
public class DanceSchoolService {
|
||||||
|
private final DanceSchoolRepository danceSchoolRepository = new DanceSchoolRepository();
|
||||||
|
|
||||||
|
public DanceSchool add(String name) {
|
||||||
|
DanceSchool danceSchool = DanceSchool.builder().name(name).build();
|
||||||
|
return danceSchoolRepository.add(danceSchool);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDancer(Long danceSchoolId, Dancer dancer) {
|
||||||
|
danceSchoolRepository.findById(danceSchoolId).addDancer(dancer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDanceGroup(Long danceSchoolId, DanceGroup danceGroup) {
|
||||||
|
danceSchoolRepository.findById(danceSchoolId).addDanceGroup(danceGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCoach(Long danceSchoolId, Coach coach) {
|
||||||
|
danceSchoolRepository.findById(danceSchoolId).addCoach(coach);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addShow(Long danceSchoolId, Show show) {
|
||||||
|
danceSchoolRepository.findById(danceSchoolId).addShow(show);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package nl.agilecc.agiledancers.service;
|
||||||
|
|
||||||
|
import nl.agilecc.agiledancers.model.Dancer;
|
||||||
|
import nl.agilecc.agiledancers.repository.DancerRepository;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public class DancerService {
|
||||||
|
private final DancerRepository dancerRepository = new DancerRepository();
|
||||||
|
|
||||||
|
public Dancer addDancer(String name, LocalDate birthDate) {
|
||||||
|
Dancer dancer = Dancer.builder().name(name).birthDate(birthDate).build();
|
||||||
|
return dancerRepository.add(dancer);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
agiledancers-be/src/test/java/sit/DanceSchoolSit.java
Normal file
26
agiledancers-be/src/test/java/sit/DanceSchoolSit.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package sit;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
import nl.agilecc.agiledancers.model.DanceSchool;
|
||||||
|
import nl.agilecc.agiledancers.service.DanceSchoolService;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class DanceSchoolSit {
|
||||||
|
Faker faker = new Faker();
|
||||||
|
int numberOfDanceGroups = 42;
|
||||||
|
|
||||||
|
int aantalDansersTm5 = 10;
|
||||||
|
int aantalDansers6tm10 = 30;
|
||||||
|
int aantalDansers11tot14 = 70;
|
||||||
|
int aantalDansers14tm17 = 140;
|
||||||
|
int aantalDansers18Plus = 100;
|
||||||
|
|
||||||
|
private DanceSchoolService danceSchoolService = new DanceSchoolService();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDanceSchoolModel() {
|
||||||
|
DanceSchool danceSchool = danceSchoolService.add("24 Dance Studio");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
19
pom.xml
19
pom.xml
@@ -26,6 +26,10 @@
|
|||||||
|
|
||||||
<ortools-java.version>9.12.4544</ortools-java.version>
|
<ortools-java.version>9.12.4544</ortools-java.version>
|
||||||
<lombok.version>1.18.38</lombok.version>
|
<lombok.version>1.18.38</lombok.version>
|
||||||
|
|
||||||
|
<!-- test dependencies -->
|
||||||
|
<datafaker.version>2.4.3</datafaker.version>
|
||||||
|
<junit-jupiter.version>5.12.2</junit-jupiter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<!-- dependencies that can be included by child-project - without stating the version -->
|
<!-- dependencies that can be included by child-project - without stating the version -->
|
||||||
@@ -36,6 +40,21 @@
|
|||||||
<artifactId>ortools-java</artifactId>
|
<artifactId>ortools-java</artifactId>
|
||||||
<version>${ortools-java.version}</version>
|
<version>${ortools-java.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- test dependencies -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.datafaker</groupId>
|
||||||
|
<artifactId>datafaker</artifactId>
|
||||||
|
<version>${datafaker.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>${junit-jupiter.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user