Skip to content

Commit

Permalink
https://jira.fingo.info/browse/IJ-308 Add posibility to start countin…
Browse files Browse the repository at this point in the history
…g monthly report by activate event (#181)
  • Loading branch information
DaDudek authored Dec 7, 2022
1 parent 70957cf commit 69722c5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/main/java/info/fingo/urlopia/api/v2/reports/ReportService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import info.fingo.urlopia.api.v2.reports.holidays.UserHolidaysReportFactory;
import info.fingo.urlopia.api.v2.user.UserFilterFactory;
import info.fingo.urlopia.config.persistance.filter.Filter;
import info.fingo.urlopia.history.HistoryLog;
import info.fingo.urlopia.history.HistoryLogService;
import info.fingo.urlopia.history.UserDetailsChangeEvent;
import info.fingo.urlopia.reports.ReportTemplateLoader;
Expand Down Expand Up @@ -121,9 +122,19 @@ List<User> findEmployeesNeededToBeInAttendanceList(Integer year,
var employees = userService.get(filter);
employees.addAll(findInactiveUsersNeededToBeInReport(year ,month));
employees.addAll(findUsersThatChangedToB2BAndNeededToBeInReport(year, month));
employees.removeAll(findAllUserThatWasNotActiveYet(year, month));
return employees;
}

private List<User> findAllUserThatWasNotActiveYet(Integer year,
Integer month) {
var nextMonth = YearMonth.of(year,month).plusMonths(1);
var logsWithActivationEventFromFuture = historyLogService.getBy(nextMonth, UserDetailsChangeEvent.USER_ACTIVATED);
return logsWithActivationEventFromFuture.stream()
.map(HistoryLog::getUser)
.toList();
}

private List<User> findInactiveUsersNeededToBeInReport(Integer year,
Integer month) {
var filter = userFilterFactory.getInactiveECUsersFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public class HistoryLogFilterCreator {
private static final String EVENT_FILTER = "userDetailsChangeEvent";


public static Filter filterBy(UserDetailsChangeEvent changeEvent,
YearMonth minYearMonth){
var firstDayOfMonth = minYearMonth.atDay(1);
var startOfFirstDay = LocalDateTime.of(firstDayOfMonth, LocalTime.MIN);

return Filter.newBuilder()
.and(CREATED_FIELD_FILTER, Operator.GREATER_OR_EQUAL, DATE_FORMATTER.format(startOfFirstDay))
.and(EVENT_FILTER, Operator.EQUAL, changeEvent.name())
.build();
}

public static Filter filterBy(UserDetailsChangeEvent changeEvent,
YearMonth yearMonth,
Long userId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public Page<HistoryLogExcerptProjection> get(Long userId,
}


public List<HistoryLog> getBy(YearMonth yearMonth,
UserDetailsChangeEvent userDetailsChangeEvent){
var filter = HistoryLogFilterCreator.filterBy(userDetailsChangeEvent, yearMonth);
return historyLogRepository.findAll(filter);
}

public HistoryLogOutput updateCountingYear(UpdateLogCountingYearInput updateLogCountingYearInput){
var optionalLog = historyLogRepository.findById(updateLogCountingYearInput.historyLogId());
var historyLog = optionalLog.orElseThrow(NoSuchHistoryLogException::invalidId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import info.fingo.urlopia.api.v2.reports.attendance.MonthlyAttendanceListReportF
import info.fingo.urlopia.api.v2.reports.holidays.UserHolidaysReportFactory
import info.fingo.urlopia.api.v2.user.UserFilterFactory
import info.fingo.urlopia.config.persistance.filter.Filter
import info.fingo.urlopia.history.HistoryLog
import info.fingo.urlopia.history.HistoryLogExcerptProjection
import info.fingo.urlopia.history.HistoryLogService
import info.fingo.urlopia.history.UserDetailsChangeEvent
Expand Down Expand Up @@ -87,6 +88,7 @@ class ReportServiceSpec extends Specification{
def requiredUsers = [activeECUser]
def undesirableUsers = [inactiveECUser, activeB2BUser]
historyLogService.get(_ as Long, _ as YearMonth, _ as UserDetailsChangeEvent) >> []
historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)
Expand All @@ -103,7 +105,7 @@ class ReportServiceSpec extends Specification{
def undesirableUsers = [activeB2BUser]
presenceConfirmationService.hasPresenceByUserAndDateInterval(_ as LocalDate, _ as LocalDate, inactiveECUser.getId()) >> true
historyLogService.get(_ as Long, _ as YearMonth, _ as UserDetailsChangeEvent) >> []

historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)
Expand All @@ -119,7 +121,7 @@ class ReportServiceSpec extends Specification{
def undesirableUsers = [activeB2BUser]
requestService.hasAcceptedByDateIntervalAndUser(_ as LocalDate, _ as LocalDate, _ as Long) >> true
historyLogService.get(_ as Long, _ as YearMonth, _ as UserDetailsChangeEvent) >> []

historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)
Expand All @@ -135,6 +137,7 @@ class ReportServiceSpec extends Specification{
def undesirableUsers = [inactiveECUser]
presenceConfirmationService.hasPresenceByUserAndDateInterval(_ as LocalDate, _ as LocalDate, activeB2BUser.getId()) >> true
historyLogService.get(_ as Long, _ as YearMonth, _ as UserDetailsChangeEvent) >> []
historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)
Expand All @@ -149,6 +152,7 @@ class ReportServiceSpec extends Specification{
def requiredUsers = [activeECUser, activeB2BUser]
presenceConfirmationService.hasPresenceByUserAndDateInterval(_ as LocalDate, _ as LocalDate, activeB2BUser.getId()) >> false
historyLogService.get(_ as Long, _ as YearMonth, UserDetailsChangeEvent.USER_CHANGE_TO_B2B) >> [Mock(HistoryLogExcerptProjection)]
historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)
Expand All @@ -157,6 +161,33 @@ class ReportServiceSpec extends Specification{
result.containsAll(requiredUsers)
}

def "findEmployeesNeededToBeInAttendanceList() WHEN user has activation event after given month SHOULD be removed from list"(){
given:
historyLogService.get(_ as Long, _ as YearMonth, UserDetailsChangeEvent.USER_CHANGE_TO_B2B) >> []
def logMock = Mock(HistoryLog){
getUser() >> activeECUser
}
historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> [logMock]

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)

then:
!result.contains(activeECUser)
}

def "findEmployeesNeededToBeInAttendanceList() WHEN user not has activation event after given month SHOULD not be removed from list"(){
given:
historyLogService.get(_ as Long, _ as YearMonth, UserDetailsChangeEvent.USER_CHANGE_TO_B2B) >> []
historyLogService.getBy(_ as YearMonth, UserDetailsChangeEvent.USER_ACTIVATED) >> []

when:
def result = reportService.findEmployeesNeededToBeInAttendanceList(1, 1)

then:
result.contains(activeECUser)
}


def "getWorkTimeEvidenceReportName() WHEN called with id and year SHOULD return formatted file name string"(){
given: "valid EvidenceReportModel"
Expand Down

0 comments on commit 69722c5

Please sign in to comment.