#4-Registro-de-Información-Personal #16

Merged
alex merged 15 commits from #4-Registro-de-Información-Personal into main 2024-09-08 13:08:42 +00:00
4 changed files with 19 additions and 20 deletions
Showing only changes of commit 49dc6421f5 - Show all commits

View File

@ -1,15 +1,11 @@
package com.primefactorsolutions.model;
import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import java.time.LocalDate;
import java.util.List;
@Data
@Entity
@ -45,7 +41,7 @@
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
public void setStatus(final Status status) {
this.status = status;
}
}

View File

@ -16,11 +16,12 @@ import java.util.Collections;
public class EmployeeService {
private final EmployeeRepository employeeRepository;
public EmployeeService(EmployeeRepository employeeRepository) {
public EmployeeService(final EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
}
public List<Employee> findEmployees(int start, int pageSize, String sortProperty, boolean asc) {
public List<Employee> findEmployees(
final int start, final int pageSize, final String sortProperty, final boolean asc) {
List<Employee> employees = employeeRepository.findAll();
int end = Math.min(start + pageSize, employees.size());
@ -33,7 +34,7 @@ public class EmployeeService {
return employees.subList(start, end);
}
public List<Employee> findEmployees(int start, int pageSize) {
public List<Employee> findEmployees(final int start, final int pageSize) {
List<Employee> employees = employeeRepository.findAll();
int end = Math.min(start + pageSize, employees.size());

View File

@ -145,11 +145,11 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
setSavedHandler((SavedHandler<Employee>) employee -> {
if (validateForm()) {
final Employee saved = employeeService.createOrUpdate(employee);
Notification.show("Empleado guardado exitosamente.");
Notification.show("Employee saved successfully.");
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
setEntityWithEnabledSave(saved);
} else {
Notification.show("Acción inválida. Por favor, complete todos los campos requeridos correctamente.", 3000, Notification.Position.MIDDLE);
Notification.show("Please complete the required fields correctly.", 3000, Notification.Position.MIDDLE);
}
});

View File

@ -27,7 +27,7 @@ public class EmployeesListView extends Main {
private final EmployeeService employeeService;
private final PagingGrid<Employee> table = new PagingGrid<>(Employee.class);
public EmployeesListView(EmployeeService employeeService) {
public EmployeesListView(final EmployeeService employeeService) {
this.employeeService = employeeService;
setupView();
refreshGrid();
@ -46,17 +46,17 @@ public class EmployeesListView extends Main {
setupPagingGrid();
}
private void updateEmployeeStatus(Employee employee, boolean isActive) {
private void updateEmployeeStatus(final Employee employee, final boolean isActive) {
employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE);
employeeService.createOrUpdate(employee);
refreshGrid();
}
private void addEditButtonColumn(String label, ButtonClickHandler handler) {
private void addEditButtonColumn(final String label, final ButtonClickHandler handler) {
table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee)));
}
private Button createButton(String label, Runnable onClickAction) {
private Button createButton(final String label, final Runnable onClickAction) {
Button button = new Button(label);
button.addClickListener(event -> onClickAction.run());
return button;
@ -66,7 +66,7 @@ public class EmployeesListView extends Main {
return createButton("Add Employee", this::navigateToAddEmployeeView);
}
private void navigateToEditView(Employee employee) {
private void navigateToEditView(final Employee employee) {
getUI().ifPresent(ui -> ui.navigate(EmployeeView.class, employee.getId().toString()));
}
@ -83,7 +83,7 @@ public class EmployeesListView extends Main {
table.setPagingDataProvider((page, pageSize) -> fetchEmployees((int) page, pageSize));
}
private List<Employee> fetchEmployees(int page, int pageSize) {
private List<Employee> fetchEmployees(final int page, final int pageSize) {
int start = page * pageSize;
if (hasSortOrder()) {
return fetchSortedEmployees(start, pageSize);
@ -95,9 +95,11 @@ public class EmployeesListView extends Main {
return !table.getSortOrder().isEmpty();
}
private List<Employee> fetchSortedEmployees(int start, int pageSize) {
private List<Employee> fetchSortedEmployees(final int start, final int pageSize) {
GridSortOrder<Employee> sortOrder = table.getSortOrder().getFirst();
return employeeService.findEmployees(start, pageSize, sortOrder.getSorted().getKey(), sortOrder.getDirection() == SortDirection.ASCENDING);
return employeeService.findEmployees(start, pageSize,
sortOrder.getSorted().getKey(),
sortOrder.getDirection() == SortDirection.ASCENDING);
}
@FunctionalInterface