Correcciones
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m27s

This commit is contained in:
jesus.pelaez 2024-10-08 15:38:41 -04:00
parent d6dce9a4d0
commit b14e7902cc
4 changed files with 79 additions and 33 deletions

View File

@ -7,7 +7,6 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@Data
@Entity

View File

@ -1,20 +1,12 @@
package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Document;
import com.primefactorsolutions.model.DocumentType;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.Team;
import com.primefactorsolutions.repositories.DocumentRepository;
import com.primefactorsolutions.repositories.TeamRepository;
import lombok.AllArgsConstructor;
import org.apache.commons.beanutils.BeanComparator;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@AllArgsConstructor

View File

@ -6,7 +6,6 @@ import lombok.AllArgsConstructor;
import org.apache.commons.beanutils.BeanComparator;
import org.springframework.stereotype.Service;
import java.sql.Time;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -56,11 +55,12 @@ public class TimeOffRequestService {
return timeOffRequests.subList(start, end);
}
public List<TimeOffRequest> findTimeOffRequestBy(Employee employee,
Team team,
TimeOffRequestType category,
TimeOffRequest.Status state,
int start, int pageSize) {
public List<TimeOffRequest> findTimeOffRequestBy(final Employee employee,
final Team team,
final TimeOffRequestType category,
final TimeOffRequest.Status state,
final int start,
final int pageSize) {
List<TimeOffRequest> timeOffRequests = timeOffRequestRepository.findAll();
if (employee != null && !"ALL".equals(employee.getFirstName())) {
timeOffRequests = timeOffRequests.stream()

View File

@ -36,7 +36,9 @@ public class RequestsListView extends Main {
private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequest.Status> stateFilter;
public RequestsListView(TimeOffRequestService requestService, EmployeeService employeeService, TeamService teamService) {
public RequestsListView(final TimeOffRequestService requestService,
final EmployeeService employeeService,
final TeamService teamService) {
this.requestService = requestService;
this.employeeService = employeeService;
this.teamService = teamService;
@ -60,7 +62,16 @@ public class RequestsListView extends Main {
}
private void setupRequestGrid() {
requestGrid.setColumns("category", "state", "availableDays", "expiration", "startDate", "endDate", "daysToBeTake", "daysBalance");
requestGrid.setColumns(
"category",
"state",
"availableDays",
"expiration",
"startDate",
"endDate",
"daysToBeTake",
"daysBalance"
);
requestGrid.addComponentColumn(this::createEmployeeSpan).setHeader("Employee");
requestGrid.addComponentColumn(this::createTeamSpan).setHeader("Team");
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
@ -75,7 +86,10 @@ public class RequestsListView extends Main {
return new HorizontalLayout(viewButton, editButton, saveButton, closeButton);
}
private void refreshRequestGrid(Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
private void refreshRequestGrid(final Employee employee,
final Team team,
final TimeOffRequestType category,
final TimeOffRequest.Status state) {
requestGrid.setPagingDataProvider((page, pageSize) -> {
if (allFiltersAreNull(employee, team, category, state)) {
return fetchTimeOffRequests((int) page, pageSize);
@ -86,11 +100,14 @@ public class RequestsListView extends Main {
requestGrid.getDataProvider().refreshAll();
}
private boolean allFiltersAreNull(Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
private boolean allFiltersAreNull(final Employee employee,
final Team team,
final TimeOffRequestType category,
final TimeOffRequest.Status state) {
return employee == null && team == null && category == null && state == null;
}
private List<TimeOffRequest> fetchTimeOffRequests(int page, int pageSize) {
private List<TimeOffRequest> fetchTimeOffRequests(final int page, final int pageSize) {
int start = page * pageSize;
if (requestGrid.getSortOrder().isEmpty()) {
return requestService.findTimeOffRequests(start, pageSize);
@ -99,21 +116,31 @@ public class RequestsListView extends Main {
}
}
private List<TimeOffRequest> fetchSortedTimeOffRequests(int start, int pageSize) {
private List<TimeOffRequest> fetchSortedTimeOffRequests(final int start, final int pageSize) {
GridSortOrder<TimeOffRequest> sortOrder = requestGrid.getSortOrder().getFirst();
return requestService.findTimeOffRequests(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING);
return requestService.findTimeOffRequests(
start,
pageSize,
sortOrder.getSorted().getKey(),
sortOrder.getDirection() == SortDirection.ASCENDING
);
}
private List<TimeOffRequest> fetchFilteredTimeOffRequests(int page, int pageSize, Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) {
private List<TimeOffRequest> fetchFilteredTimeOffRequests(final int page,
final int pageSize,
final Employee employee,
final Team team,
final TimeOffRequestType category,
final TimeOffRequest.Status state) {
return requestService.findTimeOffRequestBy(employee, team, category, state, page, pageSize);
}
private Span createEmployeeSpan(TimeOffRequest timeOffRequest) {
private Span createEmployeeSpan(final TimeOffRequest timeOffRequest) {
Employee employee = timeOffRequest.getEmployee();
return new Span(employee.getFirstName() + " " + employee.getLastName());
}
private Span createTeamSpan(TimeOffRequest timeOffRequest) {
private Span createTeamSpan(final TimeOffRequest timeOffRequest) {
return new Span(timeOffRequest.getTeam().getName());
}
@ -124,7 +151,14 @@ public class RequestsListView extends Main {
employeeFilter.setItems(employees);
employeeFilter.setItemLabelGenerator(this::getEmployeeLabel);
employeeFilter.setValue(employees.getFirst());
employeeFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), teamFilter.getValue(), categoryFilter.getValue(), stateFilter.getValue()));
employeeFilter.addValueChangeListener(event ->
refreshRequestGrid(
event.getValue(),
teamFilter.getValue(),
categoryFilter.getValue(),
stateFilter.getValue()
)
);
return employeeFilter;
}
@ -135,7 +169,14 @@ public class RequestsListView extends Main {
teamFilter.setItems(teams);
teamFilter.setItemLabelGenerator(this::getTeamLabel);
teamFilter.setValue(teams.getFirst());
teamFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), event.getValue(), categoryFilter.getValue(), stateFilter.getValue()));
teamFilter.addValueChangeListener(event ->
refreshRequestGrid(
employeeFilter.getValue(),
event.getValue(),
categoryFilter.getValue(),
stateFilter.getValue()
)
);
return teamFilter;
}
@ -143,7 +184,14 @@ public class RequestsListView extends Main {
categoryFilter = new ComboBox<>("Category");
categoryFilter.setItems(TimeOffRequestType.values());
categoryFilter.setValue(TimeOffRequestType.values()[0]);
categoryFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), teamFilter.getValue(), event.getValue(), stateFilter.getValue()));
categoryFilter.addValueChangeListener(event ->
refreshRequestGrid(
employeeFilter.getValue(),
teamFilter.getValue(),
event.getValue(),
stateFilter.getValue()
)
);
return categoryFilter;
}
@ -151,7 +199,14 @@ public class RequestsListView extends Main {
stateFilter = new ComboBox<>("State");
stateFilter.setItems(TimeOffRequest.Status.values());
stateFilter.setValue(TimeOffRequest.Status.values()[0]);
stateFilter.addValueChangeListener(event -> refreshRequestGrid(employeeFilter.getValue(), teamFilter.getValue(), categoryFilter.getValue(), event.getValue()));
stateFilter.addValueChangeListener(event ->
refreshRequestGrid(
employeeFilter.getValue(),
teamFilter.getValue(),
categoryFilter.getValue(),
event.getValue()
)
);
return stateFilter;
}
@ -167,11 +222,11 @@ public class RequestsListView extends Main {
return allTeamsOption;
}
private String getEmployeeLabel(Employee employee) {
private String getEmployeeLabel(final Employee employee) {
return "ALL".equals(employee.getFirstName()) ? "ALL" : employee.getFirstName() + " " + employee.getLastName();
}
private String getTeamLabel(Team team) {
private String getTeamLabel(final Team team) {
return "ALL".equals(team.getName()) ? "ALL" : team.getName();
}