Skip to content

Commit 03e4968

Browse files
authored
FIX: urlop wypocz. przysług. field is calculated wrongly (#217)
* FIX: https://jira.fingo.info/browse/IJ-326 urlop wypocz. przysług. field is calculated wrongly
1 parent d6a3c70 commit 03e4968

File tree

4 files changed

+88
-25
lines changed

4 files changed

+88
-25
lines changed

src/main/java/info/fingo/urlopia/config/authentication/noauth/NoAuthFilter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import info.fingo.urlopia.user.User;
88
import info.fingo.urlopia.user.UserService;
99
import lombok.RequiredArgsConstructor;
10+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1011
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
1112
import org.springframework.security.core.Authentication;
1213
import org.springframework.security.core.context.SecurityContextHolder;
@@ -21,6 +22,7 @@
2122

2223
@Component
2324
@RequiredArgsConstructor
25+
@ConditionalOnProperty(name = "ad.configuration.enabled", havingValue = "false")
2426
public class NoAuthFilter extends OncePerRequestFilter {
2527

2628
private final UserAuthoritiesProvider userAuthoritiesProvider;

src/main/java/info/fingo/urlopia/history/HistoryLogService.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.time.LocalDateTime;
2222
import java.time.YearMonth;
2323
import java.time.format.DateTimeFormatter;
24-
import java.util.ArrayList;
2524
import java.util.List;
2625
import java.util.Optional;
2726

@@ -235,12 +234,8 @@ public Float countRemainingHours(Long userId) {
235234
public float countRemainingForCurrentYear(Long userId,
236235
Integer year){
237236
var currentYearLogs = getCountForNextYearLogs(year, userId, false);
238-
var fromLastYear = getCountForNextYearLogs(year-1, userId, true);
239-
var resultLogs = new ArrayList<HistoryLog>();
240-
resultLogs.addAll(currentYearLogs);
241-
resultLogs.addAll(fromLastYear);
242237
var hours = 0f;
243-
for (var log: resultLogs){
238+
for (var log: currentYearLogs){
244239
var request = log.getRequest();
245240
if (request == null){
246241
hours += log.getHours();
@@ -252,16 +247,17 @@ public float countRemainingForCurrentYear(Long userId,
252247
private float countRemainingFromPreviousYear(Long userId,
253248
Integer year){
254249
var hours = 0f;
255-
var lastDayOfPrevYear = LocalDate.of(year-1, 12, 31);
250+
var prevYear = year - 1;
251+
var lastDayOfPrevYear = LocalDate.of(prevYear, 12, 31);
256252
var firstDay = LocalDate.of(0, 1,1);
257253
var logs = get(firstDay, lastDayOfPrevYear, userId);
258254
for (var log: logs){
259255
var request = log.getRequest();
260256
if (request == null){
261-
hours += countForPrevYearFromLogWithoutRequest(log, year);
257+
hours += countForPrevYearFromLogWithoutRequest(log, prevYear);
262258
}
263-
else if (request.isNormal()){
264-
hours += countForPrevYearFromRequest(log, request, year-1);
259+
else if (request.isNormal() && request.getStatus() == Request.Status.ACCEPTED){
260+
hours += countForPrevYearFromRequest(log, request, prevYear);
265261
}
266262
}
267263
return hours;
@@ -272,8 +268,8 @@ private float countForPrevYearFromRequest(HistoryLog historyLog,
272268
Integer year){
273269
var lastDayOfYear = LocalDate.of(year, 12, 31);
274270
if (request.getEndDate().isBefore(lastDayOfYear)){
275-
return -1 * request.getWorkingHours();
276-
}//we need to handle "next year requests"
271+
return historyLog.getHours();
272+
}
277273
else {
278274
var firstMonthOfRequest = request.getStartDate().getMonthValue();
279275
var hours = 0;
@@ -287,15 +283,11 @@ private float countForPrevYearFromRequest(HistoryLog historyLog,
287283
private float countForPrevYearFromLogWithoutRequest(HistoryLog historyLog,
288284
Integer year){
289285
var logYear = historyLog.getCreated().getYear();
290-
var logIsFromPastYear = logYear < year;
291286
var logIsFromNextYear = logYear > year;
292287
if (logIsFromNextYear){
293288
return 0;
294289
}
295-
if (!historyLog.getCountForNextYear() || logIsFromPastYear){
296-
return historyLog.getHours();
297-
}
298-
return 0;
290+
return historyLog.getHours();
299291
}
300292

301293
public float countRemainingHoursForYear(Long userId,

src/main/java/info/fingo/urlopia/request/Request.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ public Integer getWorkingDays() {
176176
return workingDays;
177177
}
178178

179-
public float getWorkingHours(){
180-
return workingDays * requester.getWorkTime();
181-
}
182-
183179
public void setWorkingDays(Integer workingDays) {
184180
this.workingDays = workingDays;
185181
}

src/test/groovy/info/fingo/urlopia/history/HistoryLogServiceSpec.groovy

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,26 @@ class HistoryLogServiceSpec extends Specification {
299299
result == 100
300300
}
301301

302-
def "countRemainingForCurrentYear WHEN log without request from prev year but countedOnNext SHOULD be added"(){
302+
def "countRemainingForCurrentYear WHEN log without request from prev year SHOULD be added"(){
303303
given:
304304
def log = Mock(HistoryLog){
305305
getHours() >> 100
306306
}
307307
def log2 = Mock(HistoryLog) {
308308
getHours() >> -20
309+
getCreated() >> LocalDateTime.of(1,1,1,1,1,1)
309310
}
310311
historyLogRepository.findAll(_ as Filter) >>> [[log], [log2], []]
311312

312313
when:
313-
def result = historyLogService.countRemainingForCurrentYear(1,1)
314+
def result = historyLogService.countRemainingForCurrentYear(1,2)
314315

315316
then:
316317
result == 80
317318
}
318319

319320

320-
def "countRemainingForCurrentYear WHEN remaining from prev year SHOULD be added"(){
321+
def "countRemainingForCurrentYear WHEN remaining from prev year from accepted request SHOULD be added"(){
321322
given:
322323
def log = Mock(HistoryLog){
323324
getHours() >> 100
@@ -328,9 +329,10 @@ class HistoryLogServiceSpec extends Specification {
328329
isNormal() >> true
329330
getEndDate() >> LocalDate.MAX
330331
getStartDate() >> LocalDate.of(2022,12,1)
332+
getStatus() >> Request.Status.ACCEPTED
331333
}
332334
}
333-
historyLogRepository.findAll(_ as Filter) >>> [[log], [], [log2]]
335+
historyLogRepository.findAll(_ as Filter) >>> [[log], [log2], []]
334336
usedHoursFromMonthCalculator.countUsedHours(_ as Integer, _ as Integer, _ as HistoryLog) >> 20
335337

336338
when:
@@ -340,6 +342,77 @@ class HistoryLogServiceSpec extends Specification {
340342
result == 80
341343
}
342344

345+
def "countRemainingForCurrentYear WHEN remaining from prev year from not accepted request SHOULD not be added"(){
346+
given:
347+
def log = Mock(HistoryLog){
348+
getHours() >> 100
349+
}
350+
def log2 = Mock(HistoryLog) {
351+
getHours() >> -20
352+
getRequest() >> Mock(Request) {
353+
isNormal() >> true
354+
getEndDate() >> LocalDate.MAX
355+
getStartDate() >> LocalDate.of(2022,12,1)
356+
getStatus() >> status
357+
}
358+
}
359+
historyLogRepository.findAll(_ as Filter) >>> [[log], [log2], []]
360+
usedHoursFromMonthCalculator.countUsedHours(_ as Integer, _ as Integer, _ as HistoryLog) >> 20
361+
362+
when:
363+
def result = historyLogService.countRemainingForCurrentYear(1,1)
364+
365+
then:
366+
result == 100
367+
368+
where:
369+
status << [Request.Status.CANCELED, Request.Status.PENDING, Request.Status.REJECTED]
370+
}
371+
372+
def "countRemainingForCurrentYear WHEN remaining from prev year without request SHOULD be added"(){
373+
given:
374+
def log = Mock(HistoryLog){
375+
getHours() >> 100
376+
}
377+
def log2 = Mock(HistoryLog) {
378+
getHours() >> -20
379+
getCreated() >> LocalDateTime.of(1,1,1,1,1,1)
380+
}
381+
historyLogRepository.findAll(_ as Filter) >>> [[log], [log2], []]
382+
usedHoursFromMonthCalculator.countUsedHours(_ as Integer, _ as Integer, _ as HistoryLog) >> 20
383+
384+
when:
385+
def result = historyLogService.countRemainingForCurrentYear(1,2)
386+
387+
then:
388+
result == 80
389+
}
390+
391+
def "countRemainingForCurrentYear WHEN remaining from prev year with special request SHOULD not be added"(){
392+
given:
393+
def log = Mock(HistoryLog){
394+
getHours() >> 100
395+
}
396+
def log2 = Mock(HistoryLog) {
397+
getHours() >> -20
398+
getCreated() >> LocalDateTime.of(1,1,1,1,1,1)
399+
getRequest() >> Mock(Request) {
400+
isNormal() >> false
401+
getEndDate() >> LocalDate.MAX
402+
getStartDate() >> LocalDate.of(2022,12,1)
403+
getStatus() >> Request.Status.ACCEPTED
404+
}
405+
}
406+
historyLogRepository.findAll(_ as Filter) >>> [[log], [log2], []]
407+
usedHoursFromMonthCalculator.countUsedHours(_ as Integer, _ as Integer, _ as HistoryLog) >> 20
408+
409+
when:
410+
def result = historyLogService.countRemainingForCurrentYear(1,2)
411+
412+
then:
413+
result == 100
414+
}
415+
343416

344417

345418
def "countRemainingForCurrentYear WHEN no logs SHOULD return 0"(){

0 commit comments

Comments
 (0)