Skip to content

Commit

Permalink
Merge pull request #62 from Gepardec/feature/727-zep-rest
Browse files Browse the repository at this point in the history
Feature/727 zep rest
  • Loading branch information
Ollitod authored Jun 7, 2024
2 parents 23ce3a7 + d7931cb commit 81c8169
Show file tree
Hide file tree
Showing 192 changed files with 10,135 additions and 737 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,7 @@ $RECYCLE.BIN/
# Secrets
.env

# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,intellij+all,maven,git,patch,vim,notepadpp,java
#IntelliJ
*.http

# End of https://www.toptal.com/developers/gitignore/api/windows,linux,macos,intellij+all,maven,git,patch,vim,notepadpp,java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ public class ZepConfig {
@ConfigProperty(name = "mega.zep.soap-path")
String soapPath;

@Inject
@ConfigProperty(name = "mega.zep.rest-token")
String restToken;


public String getRestBearerToken() {
return restToken;
}

public String getUrlAsString() {
return String.format("%s%s", origin.toString(), soapPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private List<ValidationViolation> createResponseEntityForConstraintViolationExce
}
return violations.stream()
.map(this::createValidationViolationForConstraintViolation)
.collect(Collectors.toList());
.toList();
}

private ValidationViolation createValidationViolationForConstraintViolation(final ConstraintViolation<?> violation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package com.gepardec.mega.db.entity.common;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Optional;
import java.util.stream.Stream;

public enum PaymentMethodType {

@JsonProperty("Firma")
COMPANY (0, "Firma"),

@JsonProperty("privat")
PRIVATE (1, "privat");

final int paymentMethodId;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.gepardec.mega.db.entity.common;

// used to avoid hard coded numbers when retrieving doctor's visiting hours
public enum ProjectTaskType {
PROJECT_INTERNAL(3, "Intern"),
TASK_DOCTOR_VISIT(233, "Arztbesuch");

final int id;
final String name;

ProjectTaskType(int id, String name) {
this.id = id;
this.name = name;
}

public int getId() {
return id;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public List<JourneyWarning> calculate(List<ProjectEntry> projectTimeEntries) {
.filter(entry -> Task.isJourney(entry.getTask()))
.map(JourneyTimeEntry.class::cast)
.sorted(Comparator.comparing(ProjectEntry::getFromTime).thenComparing(ProjectEntry::getToTime))
.collect(Collectors.toList());
.toList();

final List<JourneyWarning> warnings = new ArrayList<>();
final JourneyDirectionValidator journeyDirectionValidator = new JourneyDirectionValidator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class InvalidWorkingLocationInJourneyCalculator implements WarningCalcula
public List<JourneyWarning> calculate(List<ProjectEntry> projectTimeEntries) {
final List<ProjectEntry> groupedProjectTimeEntries = projectTimeEntries.stream()
.sorted(Comparator.comparing(ProjectEntry::getFromTime).thenComparing(ProjectEntry::getToTime))
.collect(Collectors.toList());
.toList();

final List<JourneyWarning> warnings = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public List<TimeWarning> calculate(List<ProjectEntry> projectEntries) {
final List<ProjectTimeEntry> projectTimeEntries = projectEntries.stream()
.filter(projectEntry -> projectEntry.getClass() == ProjectTimeEntry.class)
.map(ProjectTimeEntry.class::cast)
.collect(Collectors.toList());
.toList();


LocalTime projectEntryFromTime, projectEntryToTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.gepardec.mega.domain.model.monthlyreport.ProjectEntry;
import com.gepardec.mega.domain.model.monthlyreport.Task;
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 java.time.LocalDate;
import java.util.ArrayList;
Expand Down Expand Up @@ -48,7 +50,7 @@ private TimeWarning createTimeWarning(final LocalDate date, final double workDur
TimeWarning timeWarning = new TimeWarning();
timeWarning.setDate(date);
timeWarning.setExcessWorkTime(workDurationOfDay - MAX_HOURS_A_DAY);

timeWarning.setWarningTypes(List.of(TimeWarningType.EXCESS_WORKING_TIME_PRESENT));
return timeWarning;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gepardec.mega.domain.model.monthlyreport.ProjectTimeEntry;
import com.gepardec.mega.domain.model.monthlyreport.Task;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarning;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarningType;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand Down Expand Up @@ -92,6 +93,7 @@ private TimeWarning createTimeWarning(final LocalDate date, final double breakTi
.subtract(BigDecimal.valueOf(breakTime))
.setScale(2, RoundingMode.HALF_EVEN)
.doubleValue());
timeWarning.getWarningTypes().add(TimeWarningType.MISSING_BREAK_TIME);
return timeWarning;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gepardec.mega.domain.model.monthlyreport.ProjectTimeEntry;
import com.gepardec.mega.domain.model.monthlyreport.Task;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarning;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarningType;

import java.math.BigDecimal;
import java.math.RoundingMode;
Expand Down Expand Up @@ -59,7 +60,7 @@ private List<ProjectEntry> filterForTaskAndSortByFromDate(final List<ProjectEntr
return projectTimeEntries.stream()
.filter(filterTask.or(filterActiveTravelTime))
.sorted(Comparator.comparing(ProjectEntry::getFromTime).thenComparing(ProjectEntry::getToTime))
.collect(Collectors.toList());
.toList();
}

private ProjectEntry getNextEntryOrNull(final int idx, final List<ProjectEntry> projectTimeEntries) {
Expand All @@ -85,7 +86,7 @@ private TimeWarning createTimeWarning(final ProjectEntry nextEntry, final double
.subtract(BigDecimal.valueOf(restHours))
.setScale(2, RoundingMode.HALF_EVEN)
.doubleValue());

timeWarning.getWarningTypes().add(TimeWarningType.MISSING_REST_TIME);
return timeWarning;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.gepardec.mega.domain.calculation.time;

import com.gepardec.mega.domain.calculation.AbstractTimeWarningCalculationStrategy;
import com.gepardec.mega.domain.model.AbsenceTime;
import com.gepardec.mega.domain.model.Employee;
import com.gepardec.mega.domain.model.monthlyreport.AbsenteeType;
import com.gepardec.mega.domain.model.monthlyreport.ProjectEntry;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarning;
import com.gepardec.mega.domain.model.monthlyreport.TimeWarningType;
import com.gepardec.mega.notification.mail.dates.OfficeCalendarUtil;
import de.provantis.zep.FehlzeitType;
import jakarta.validation.constraints.NotNull;

import java.time.LocalDate;
Expand All @@ -20,7 +20,7 @@

public class NoEntryCalculator extends AbstractTimeWarningCalculationStrategy {

public List<TimeWarning> calculate(@NotNull Employee employee, @NotNull List<ProjectEntry> projectEntries, @NotNull List<FehlzeitType> absenceEntries) {
public List<TimeWarning> calculate(@NotNull Employee employee, @NotNull List<ProjectEntry> projectEntries, @NotNull List<AbsenceTime> absenceEntries) {
if (projectEntries.isEmpty()) {
TimeWarning timeWarning = new TimeWarning();
timeWarning.getWarningTypes().add(TimeWarningType.EMPTY_ENTRY_LIST);
Expand Down Expand Up @@ -56,7 +56,7 @@ public List<TimeWarning> calculate(@NotNull Employee employee, @NotNull List<Pro
List<LocalDate> nonPaidVacationDays = filterAbsenceTypesAndCompileLocalDateList(AbsenteeType.NON_PAID_VACATION_DAYS.getType(), absenceEntries);
List<LocalDate> bookedDays = projectEntries.stream()
.map(ProjectEntry::getDate)
.collect(Collectors.toList());
.toList();

return businessDays.stream()
.filter(date -> !compensatoryDays.contains(date))
Expand All @@ -75,7 +75,7 @@ public List<TimeWarning> calculate(@NotNull Employee employee, @NotNull List<Pro
.filter(date -> !futureDays.contains(date))
.map(this::createTimeWarning)
.distinct()
.collect(Collectors.toList());
.toList();
}

private List<LocalDate> getBusinessDaysOfMonth(int year, int month) {
Expand Down Expand Up @@ -108,7 +108,7 @@ private List<LocalDate> getRegularWorkingHours0Dates(Employee employee, int year
private List<LocalDate> getFutureDays() {
LocalDate today = LocalDate.now();
return today.datesUntil(today.with(TemporalAdjusters.firstDayOfNextMonth()))
.collect(Collectors.toList());
.toList();
}

private TimeWarning createTimeWarning(final LocalDate date) {
Expand All @@ -119,14 +119,14 @@ private TimeWarning createTimeWarning(final LocalDate date) {
return timeWarning;
}

private List<LocalDate> filterAbsenceTypesAndCompileLocalDateList(String type, List<FehlzeitType> absenceEntries) {
private List<LocalDate> filterAbsenceTypesAndCompileLocalDateList(String type, List<AbsenceTime> absenceEntries) {
return absenceEntries.stream()
.filter(fzt -> fzt.getFehlgrund().equals(type))
.filter(fzt -> fzt.reason().equals(type))
.flatMap(this::extractFehlzeitenDateRange)
.collect(Collectors.toList());
.toList();
}

private Stream<LocalDate> extractFehlzeitenDateRange(FehlzeitType fzt) {
return LocalDate.parse(fzt.getStartdatum()).datesUntil(LocalDate.parse(fzt.getEnddatum()).plusDays(1));
private Stream<LocalDate> extractFehlzeitenDateRange(AbsenceTime fzt) {
return fzt.fromDate().datesUntil(fzt.toDate().plusDays(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private List<LocalDate> getWeekEndDays(LocalDate startDate, LocalDate endDate) {
endDate = endDate.plusDays(1);
return startDate.datesUntil(endDate)
.filter(isWeekend)
.collect(Collectors.toList());
.toList();
}

private boolean isWeekEndDay(LocalDate date, List<LocalDate> listOfWeekendDays) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface EntityMapper<D, E> {
default List<E> mapListToEntity(List<D> objects) {
return objects.stream()
.map(this::mapToEntity)
.collect(Collectors.toList());
.toList();
}

default List<D> mapListToDomain(List<E> objects) {
return objects.stream()
.map(this::mapToDomain)
.collect(Collectors.toList());
.toList();
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/gepardec/mega/domain/model/AbsenceTime.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.gepardec.mega.domain.model;

import java.time.LocalDate;

public record AbsenceTime (
String userId,
LocalDate fromDate,
LocalDate toDate,
String reason,
Boolean accepted
) {
public AbsenceTime(Builder builder) {
this(
builder.userId,
builder.fromDate,
builder.toDate,
builder.reason,
builder.accepted
);
}

public static Builder builder() {
return new Builder();
}

public static final class Builder {
private String userId;
private LocalDate fromDate;
private LocalDate toDate;
private String reason;
private Boolean accepted;

public Builder userId(String userId) {
this.userId = userId;
return this;
}

public Builder fromDate(LocalDate fromDate) {
this.fromDate = fromDate;
return this;
}

public Builder toDate(LocalDate toDate) {
this.toDate = toDate;
return this;
}

public Builder reason(String reason) {
this.reason = reason;
return this;
}

public Builder accepted(Boolean accepted) {
this.accepted = accepted;
return this;
}

public AbsenceTime build() {
return new AbsenceTime(this);
}
}
}
14 changes: 12 additions & 2 deletions src/main/java/com/gepardec/mega/domain/model/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class Employee {

private final String language;

private final Map<DayOfWeek, Duration> regularWorkingHours;
private Map<DayOfWeek, Duration> regularWorkingHours;

private final boolean active;
private boolean active;

/**
* Austrittsdatum, wird durch Aufruf von employeeService.getAllEmployeesConsideringExitDate befüllt,
Expand Down Expand Up @@ -103,6 +103,14 @@ public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public void setRegularWorkingHours(Map<DayOfWeek, Duration> regularWorkingHours) {
this.regularWorkingHours = regularWorkingHours;
}

public LocalDate getExitDate() {
return exitDate;
}
Expand All @@ -111,6 +119,8 @@ public void setExitDate(LocalDate exitDate) {
this.exitDate = exitDate;
}



@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Loading

0 comments on commit 81c8169

Please sign in to comment.