Rama-Ricardo #14

Merged
alex merged 8 commits from Rama-Ricardo into main 2024-09-04 17:53:01 +00:00
3 changed files with 14 additions and 47 deletions
Showing only changes of commit 7d6955a5c3 - Show all commits

View File

@ -21,38 +21,30 @@
private String lastName; private String lastName;
private LocalDate birthday; private LocalDate birthday;
private String birthCity; private String birthCity;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private MaritalStatus maritalStatus; private MaritalStatus maritalStatus;
private String residenceAddress; private String residenceAddress;
private String phoneNumber; private String phoneNumber;
private String personalEmail; private String personalEmail;
private String emergencyCName; private String emergencyCName;
private String emergencyCAddress; private String emergencyCAddress;
private String emergencyCPhone; private String emergencyCPhone;
private String emergencyCEmail; private String emergencyCEmail;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private Status status; private Status status;
public enum Status { public enum Status {
ACTIVE, ACTIVE,
INACTIVE INACTIVE
} }
public enum MaritalStatus { public enum MaritalStatus {
SINGLE, SINGLE,
MARRIED, MARRIED,
WIDOWED, WIDOWED,
DIVORCED DIVORCED
} }
public Status getStatus() { public Status getStatus() {
return status; return status;
} }
public void setStatus(Status status) { public void setStatus(Status status) {
this.status = status; this.status = status;
} }

View File

@ -1,5 +1,4 @@
package com.primefactorsolutions.service; package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.beanutils.BeanComparator;
import com.primefactorsolutions.repositories.EmployeeRepository; import com.primefactorsolutions.repositories.EmployeeRepository;
@ -16,46 +15,33 @@ import java.util.Collections;
@Data @Data
public class EmployeeService { public class EmployeeService {
private final EmployeeRepository employeeRepository; private final EmployeeRepository employeeRepository;
private List<Employee> pagedBase;
public EmployeeService(EmployeeRepository employeeRepository) { public EmployeeService(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository; this.employeeRepository = employeeRepository;
} }
private void initializePagedBase() {
if (pagedBase == null) {
this.pagedBase = employeeRepository.findAll();
}
}
public List<Employee> findEmployees(int start, int pageSize, String sortProperty, boolean asc) { public List<Employee> findEmployees(int start, int pageSize, String sortProperty, boolean asc) {
initializePagedBase(); // Asegurarse de que pagedBase esté inicializada List<Employee> employees = employeeRepository.findAll();
System.err.println("findAll " + start + " " + pageSize + " sort " + sortProperty + " asc:" + asc );
int end = (int) (start + pageSize);
if (end > pagedBase.size()) {
end = pagedBase.size();
}
Collections.sort(pagedBase, new BeanComparator<Employee>(sortProperty));
if(!asc) { int end = Math.min(start + pageSize, employees.size());
Outdated
Review

no se puede guardar en un campo de la clase porque la clase es un singleton (si hay varios llamados van a haber problemas de concurrencia). solucion: no usar un campo en la clase y simplemente retornar toda la lista cada vez sin guardar en un campo.

no se puede guardar en un campo de la clase porque la clase es un singleton (si hay varios llamados van a haber problemas de concurrencia). solucion: no usar un campo en la clase y simplemente retornar toda la lista cada vez sin guardar en un campo.
Collections.reverse(pagedBase); employees.sort(new BeanComparator<>(sortProperty));
if (!asc) {
Collections.reverse(employees);
} }
return pagedBase.subList((int) start, end);
return employees.subList(start, end);
Outdated
Review

usar logger en vez de system println. ver lombok @Slf4j https://projectlombok.org/features/log

usar logger en vez de system println. ver lombok @Slf4j https://projectlombok.org/features/log
} }
public List<Employee> findEmployees(int start, int pageSize) { public List<Employee> findEmployees(int start, int pageSize) {
initializePagedBase(); // Asegurarse de que pagedBase esté inicializada List<Employee> employees = employeeRepository.findAll();
System.err.println("findAll " + start + " " + pageSize);
int end = (int) (start + pageSize); int end = Math.min(start + pageSize, employees.size());
if (end > pagedBase.size()) { return employees.subList(start, end);
end = pagedBase.size();
}
return pagedBase.subList((int) start, end);
} }
public Employee createOrUpdate(final Employee employee) { public Employee createOrUpdate(final Employee employee) {
final Employee saved = employeeRepository.save(employee); return employeeRepository.save(employee);
return saved;
} }
public Employee getEmployee(final UUID id) { public Employee getEmployee(final UUID id) {

View File

@ -43,22 +43,11 @@ public class EmployeesListView extends Main {
private void configureTable() { private void configureTable() {
table.setColumns("firstName", "lastName", "status"); table.setColumns("firstName", "lastName", "status");
addStatusColumn();
addEditButtonColumn("Edit", this::navigateToEditView); addEditButtonColumn("Edit", this::navigateToEditView);
addEditButtonColumn("Save", this::navigateToSaveChangeStatus); addEditButtonColumn("Save", this::navigateToSaveChangeStatus);
setupPagingGrid(); setupPagingGrid();
} }
private void addStatusColumn() {
table.addComponentColumn(this::createStatusCheckbox)
.setHeader("Change Status");
}
private Checkbox createStatusCheckbox(Employee employee) {
Checkbox statusCheckbox = new Checkbox( employee.getStatus() == Employee.Status.ACTIVE);
return statusCheckbox;
}
private void updateEmployeeStatus(Employee employee, boolean isActive) { private void updateEmployeeStatus(Employee employee, 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);