diff --git a/src/main/java/com/primefactorsolutions/model/TimeOffRequest.java b/src/main/java/com/primefactorsolutions/model/TimeOffRequest.java index 94a50c2..d8aac8d 100644 --- a/src/main/java/com/primefactorsolutions/model/TimeOffRequest.java +++ b/src/main/java/com/primefactorsolutions/model/TimeOffRequest.java @@ -7,7 +7,6 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.Date; -import java.util.List; @Data @Entity diff --git a/src/main/java/com/primefactorsolutions/service/TeamService.java b/src/main/java/com/primefactorsolutions/service/TeamService.java index b8f7f62..ed72692 100644 --- a/src/main/java/com/primefactorsolutions/service/TeamService.java +++ b/src/main/java/com/primefactorsolutions/service/TeamService.java @@ -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 diff --git a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java index eb826da..d6b2030 100644 --- a/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java +++ b/src/main/java/com/primefactorsolutions/service/TimeOffRequestService.java @@ -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 findTimeOffRequestBy(Employee employee, - Team team, - TimeOffRequestType category, - TimeOffRequest.Status state, - int start, int pageSize) { + public List findTimeOffRequestBy(final Employee employee, + final Team team, + final TimeOffRequestType category, + final TimeOffRequest.Status state, + final int start, + final int pageSize) { List timeOffRequests = timeOffRequestRepository.findAll(); if (employee != null && !"ALL".equals(employee.getFirstName())) { timeOffRequests = timeOffRequests.stream() diff --git a/src/main/java/com/primefactorsolutions/views/RequestsListView.java b/src/main/java/com/primefactorsolutions/views/RequestsListView.java index e858fbb..3d4c898 100644 --- a/src/main/java/com/primefactorsolutions/views/RequestsListView.java +++ b/src/main/java/com/primefactorsolutions/views/RequestsListView.java @@ -36,7 +36,9 @@ public class RequestsListView extends Main { private ComboBox categoryFilter; private ComboBox 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,22 +86,28 @@ 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); + return fetchTimeOffRequests((int) page, pageSize); } else { - return fetchFilteredTimeOffRequests((int)page, pageSize, employee, team, category, state); + return fetchFilteredTimeOffRequests((int) page, pageSize, employee, team, category, state); } }); 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 fetchTimeOffRequests(int page, int pageSize) { + private List 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 fetchSortedTimeOffRequests(int start, int pageSize) { + private List fetchSortedTimeOffRequests(final int start, final int pageSize) { GridSortOrder 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 fetchFilteredTimeOffRequests(int page, int pageSize, Employee employee, Team team, TimeOffRequestType category, TimeOffRequest.Status state) { + private List 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(); }