Skip to content

Commit

Permalink
[Gepardec/mega#750] change model, dto and mapper of time warning
Browse files Browse the repository at this point in the history
  • Loading branch information
gattrCh committed Jun 4, 2024
1 parent 1b31b0d commit f3827cf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 24 deletions.
14 changes: 7 additions & 7 deletions src/main/java/com/gepardec/mega/domain/model/MonthlyWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

public class MonthlyWarning {
private final String name;
private final List<String> dateValuesWhenWarningsOccurred;
private final List<String> datesWhenWarningOccurred;

private MonthlyWarning(Builder builder) {
this.name = builder.name;
this.dateValuesWhenWarningsOccurred = builder.dateValuesWhenWarningsOccurred;
this.datesWhenWarningOccurred = builder.datesWhenWarningOccurred;
}

public String getName() {
return name;
}

public List<String> getDateValuesWhenWarningsOccurred() {
return dateValuesWhenWarningsOccurred;
public List<String> getDatesWhenWarningOccurred() {
return datesWhenWarningOccurred;
}

public static Builder builder() {return Builder.aMonthlyWarning();}

public static class Builder {
private String name;
private List<String> dateValuesWhenWarningsOccurred;
private List<String> datesWhenWarningOccurred;

private Builder() {}

Expand All @@ -34,8 +34,8 @@ public Builder name(String name) {
return this;
}

public Builder dateValuesWhenWarningsOccurred(List<String> dateValuesWhenWarningsOccurred) {
this.dateValuesWhenWarningsOccurred = dateValuesWhenWarningsOccurred;
public Builder datesWhenWarningOccurred(List<String> datesWhenWarningOccurred) {
this.datesWhenWarningOccurred = datesWhenWarningOccurred;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ public class MonthlyWarningMapper implements DtoMapper<MonthlyWarning, MonthlyWa
public MonthlyWarningDto mapToDto(MonthlyWarning object) {
return MonthlyWarningDto.builder()
.name(object.getName())
.dateValuesWhenWarningsOccurred(object.getDateValuesWhenWarningsOccurred())
.datesWhenWarningOccurred(object.getDatesWhenWarningOccurred())
.build();
}

@Override
public MonthlyWarning mapToDomain(MonthlyWarningDto object) {
return MonthlyWarning.builder()
.name(object.getName())
.dateValuesWhenWarningsOccurred(object.getDateValuesWhenWarningsOccurred())
.datesWhenWarningOccurred(object.getDatesWhenWarningOccurred())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@

public class MonthlyWarningDto {
private final String name;
private final List<String> dateValuesWhenWarningsOccurred;
private final List<String> datesWhenWarningOccurred;

private MonthlyWarningDto(Builder builder) {
this.name = builder.name;
this.dateValuesWhenWarningsOccurred = builder.dateValuesWhenWarningsOccurred;
this.datesWhenWarningOccurred = builder.datesWhenWarningOccurred;
}

public String getName() {
return name;
}

public List<String> getDateValuesWhenWarningsOccurred() {
return dateValuesWhenWarningsOccurred;
public List<String> getDatesWhenWarningOccurred() {
return datesWhenWarningOccurred;
}

public static Builder builder() {return Builder.aMonthlyWarningDto();}

public static class Builder {
private String name;
private List<String> dateValuesWhenWarningsOccurred;
private List<String> datesWhenWarningOccurred;

private Builder() {}

Expand All @@ -34,8 +34,8 @@ public Builder name(String name) {
return this;
}

public Builder dateValuesWhenWarningsOccurred(List<String> dateValuesWhenWarningsOccurred) {
this.dateValuesWhenWarningsOccurred = dateValuesWhenWarningsOccurred;
public Builder datesWhenWarningOccurred(List<String> datesWhenWarningOccurred) {
this.datesWhenWarningOccurred = datesWhenWarningOccurred;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
import com.gepardec.mega.domain.model.monthlyreport.ProjectEntryWarning;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarning;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarningType;
import com.gepardec.mega.domain.model.monthlyreport.WarningType;
import com.gepardec.mega.domain.utils.DateUtils;
import com.gepardec.mega.service.api.TimeWarningService;
import com.gepardec.mega.service.helper.WarningCalculatorsManager;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
Expand Down Expand Up @@ -51,7 +49,7 @@ public class TimeWarningServiceImpl implements TimeWarningService {
EXCESS_WORKING_TIME_PRESENT
);

private static final List<WarningType> journeyWarningTypes = List.of(
private static final List<JourneyWarningType> journeyWarningTypes = List.of(
JourneyWarningType.BACK_MISSING,
JourneyWarningType.TO_MISSING,
JourneyWarningType.INVALID_WORKING_LOCATION
Expand All @@ -68,7 +66,14 @@ public List<MonthlyWarning> getAllTimeWarningsForEmployeeAndMonth(List<AbsenceTi

timeWarningTypes.forEach(warningType -> {
MonthlyWarning warningEntry = createMonthlyTimeWarning(timeWarnings, warningType);
if(warningEntry != null){
if (warningEntry != null) {
monthlyWarnings.add(warningEntry);
}
});

journeyWarningTypes.forEach(warningType -> {
MonthlyWarning warningEntry = createMonthlyJourneyWarning(journeyWarnings, warningType);
if (warningEntry != null) {
monthlyWarnings.add(warningEntry);
}
});
Expand All @@ -80,8 +85,7 @@ private MonthlyWarning createMonthlyTimeWarning(List<TimeWarning> timeWarnings,
List<String> datesWhenWarningsOccurred = new ArrayList<>();

for (TimeWarning timeWarning : timeWarnings) {
boolean test = timeWarning.getWarningTypes().contains(warningType);
if (test) {
if (timeWarning.getWarningTypes().contains(warningType)) {
if (name.isEmpty()) {
name = switch (warningType) {
case TIME_OVERLAP -> "Zeiten überschneiden sich";
Expand All @@ -96,14 +100,44 @@ private MonthlyWarning createMonthlyTimeWarning(List<TimeWarning> timeWarnings,
case EXCESS_WORKING_TIME_PRESENT -> "Zu viel Arbeitszeit gebucht";
};
}
datesWhenWarningsOccurred.add(DateUtils.formatDate(timeWarning.getDate()));
if (timeWarning.getDate() != null) {
datesWhenWarningsOccurred.add(DateUtils.formatDate(timeWarning.getDate()));
}
}
}

if (!name.isEmpty()) {
return MonthlyWarning.builder()
.name(name)
.datesWhenWarningOccurred(datesWhenWarningsOccurred)
.build();
}
return null;
}

private MonthlyWarning createMonthlyJourneyWarning(List<JourneyWarning> journeyWarnings, JourneyWarningType warningType) {
String name = "";
List<String> datesWhenWarningsOccurred = new ArrayList<>();

for (JourneyWarning journeyWarning : journeyWarnings) {
if (journeyWarning.getWarningTypes().contains(warningType)) {
if (name.isEmpty()) {
name = switch (warningType) {
case BACK_MISSING -> "Rückreise fehlt oder ist nach dem Zeitraum";
case TO_MISSING -> "Hinreise fehlt oder ist vor dem Zeitraum";
case INVALID_WORKING_LOCATION -> "Ungültiger Arbeitsort während einer Reise";
};
}
if(journeyWarning.getDate() != null) {
datesWhenWarningsOccurred.add(DateUtils.formatDate(journeyWarning.getDate()));
}
}
}

if(!name.isEmpty()) {
return MonthlyWarning.builder()
.name(name)
.dateValuesWhenWarningsOccurred(datesWhenWarningsOccurred)
.datesWhenWarningOccurred(datesWhenWarningsOccurred)
.build();
}
return null;
Expand Down

0 comments on commit f3827cf

Please sign in to comment.