Rama-Ricardo #14

Merged
alex merged 8 commits from Rama-Ricardo into main 2024-09-04 17:53:01 +00:00
4 changed files with 19 additions and 20 deletions
Showing only changes of commit 49dc6421f5 - Show all commits

View File

@ -1,16 +1,12 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
Review

quitar espacios blancos al inicio de cada linea

quitar espacios blancos al inicio de cada linea
import io.hypersistence.utils.hibernate.type.json.JsonType;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.hibernate.annotations.Type;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
@Data @Data
@Entity @Entity
@AllArgsConstructor @AllArgsConstructor
@ -45,7 +41,7 @@
public Status getStatus() { public Status getStatus() {
return status; return status;
} }
public void setStatus(Status status) { public void setStatus(final Status status) {
this.status = status; this.status = status;
} }
} }

View File

@ -16,11 +16,12 @@ import java.util.Collections;
public class EmployeeService { public class EmployeeService {
private final EmployeeRepository employeeRepository; private final EmployeeRepository employeeRepository;
public EmployeeService(EmployeeRepository employeeRepository) { public EmployeeService(final EmployeeRepository employeeRepository) {
this.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(); List<Employee> employees = employeeRepository.findAll();
int end = Math.min(start + pageSize, employees.size()); int end = Math.min(start + pageSize, employees.size());
@ -33,7 +34,7 @@ public class EmployeeService {
return employees.subList(start, end); 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(); List<Employee> employees = employeeRepository.findAll();
int end = Math.min(start + pageSize, employees.size()); 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 -> { setSavedHandler((SavedHandler<Employee>) employee -> {
if (validateForm()) { if (validateForm()) {
final Employee saved = employeeService.createOrUpdate(employee); final Employee saved = employeeService.createOrUpdate(employee);
Notification.show("Empleado guardado exitosamente."); Notification.show("Employee saved successfully.");
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class)); getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
setEntityWithEnabledSave(saved); setEntityWithEnabledSave(saved);
} else { } 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 EmployeeService employeeService;
private final PagingGrid<Employee> table = new PagingGrid<>(Employee.class); private final PagingGrid<Employee> table = new PagingGrid<>(Employee.class);
public EmployeesListView(EmployeeService employeeService) { public EmployeesListView(final EmployeeService employeeService) {
this.employeeService = employeeService; this.employeeService = employeeService;
setupView(); setupView();
refreshGrid(); refreshGrid();
@ -46,17 +46,17 @@ public class EmployeesListView extends Main {
setupPagingGrid(); 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); employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE);
employeeService.createOrUpdate(employee); employeeService.createOrUpdate(employee);
refreshGrid(); 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))); 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 button = new Button(label);
button.addClickListener(event -> onClickAction.run()); button.addClickListener(event -> onClickAction.run());
return button; return button;
@ -66,7 +66,7 @@ public class EmployeesListView extends Main {
return createButton("Add Employee", this::navigateToAddEmployeeView); 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())); 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)); 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; int start = page * pageSize;
if (hasSortOrder()) { if (hasSortOrder()) {
return fetchSortedEmployees(start, pageSize); return fetchSortedEmployees(start, pageSize);
@ -95,9 +95,11 @@ public class EmployeesListView extends Main {
return !table.getSortOrder().isEmpty(); 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(); 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 @FunctionalInterface