#7 Perfil de Personal Administrativo - Listado de empleados #8
@ -17,15 +17,13 @@ import java.util.List;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Employee extends BaseEntity {
|
public class Employee extends BaseEntity {
|
||||||
private String username;
|
|
||||||
private String firstName;
|
private String firstName;
|
||||||
jesus.pelaez marked this conversation as resolved
Outdated
|
|||||||
private String lastName;
|
private String lastName;
|
||||||
private LocalDate dob;
|
@Enumerated(EnumType.STRING)
|
||||||
jesus.pelaez marked this conversation as resolved
Outdated
alex
commented
definir un enum con los status ACTIVE, INACTIVE. en vez de usar un String. definir un enum con los status ACTIVE, INACTIVE. en vez de usar un String.
jesus.pelaez
commented
Cambio realizado, esperando para revisión Cambio realizado, esperando para revisión
|
|||||||
private String personalEmail;
|
private Status status;
|
||||||
@Type(JsonType.class)
|
|
||||||
@Column(columnDefinition = "json")
|
public enum Status {
|
||||||
private List<String> phoneNumbers;
|
ACTIVE,
|
||||||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "employee", cascade = {CascadeType.ALL})
|
INACTIVE
|
||||||
private List<Document> documents;
|
}
|
||||||
private Role role;
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.primefactorsolutions.service;
|
package com.primefactorsolutions.service;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.Candidate;
|
||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.repositories.EmployeeRepository;
|
import com.primefactorsolutions.repositories.EmployeeRepository;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -7,19 +8,27 @@ import org.apache.commons.lang3.NotImplementedException;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Data
|
@Data
|
||||||
public class EmployeeService {
|
public class EmployeeService {
|
||||||
private final EmployeeRepository employeeRepository;
|
private final EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
private List<Employee> getEmployees() {
|
public EmployeeService(EmployeeRepository employeeRepository) {
|
||||||
// TODO: implement
|
this.employeeRepository = employeeRepository;
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Employee createOrUpdateEmployee(final Employee employee) {
|
public Employee createOrUpdate(final Employee employee) {
|
||||||
// TODO: implement
|
final Employee saved = employeeRepository.save(employee);
|
||||||
throw new NotImplementedException();
|
return saved;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Employee> getEmployees() {
|
||||||
|
return employeeRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Employee getEmployee(final UUID id) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,20 @@ package com.primefactorsolutions.views;
|
|||||||
import com.primefactorsolutions.model.Employee;
|
import com.primefactorsolutions.model.Employee;
|
||||||
import com.primefactorsolutions.service.EmployeeService;
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
|
import com.vaadin.flow.component.textfield.EmailField;
|
||||||
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
import com.vaadin.flow.router.BeforeEvent;
|
import com.vaadin.flow.router.BeforeEvent;
|
||||||
import com.vaadin.flow.router.HasUrlParameter;
|
import com.vaadin.flow.router.HasUrlParameter;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
import org.vaadin.firitin.form.BeanValidationForm;
|
import org.vaadin.firitin.form.BeanValidationForm;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@PermitAll
|
@PermitAll
|
||||||
@ -20,22 +24,36 @@ import java.util.List;
|
|||||||
@PageTitle("Employee")
|
@PageTitle("Employee")
|
||||||
@Route(value = "/employees", layout = MainLayout.class)
|
@Route(value = "/employees", layout = MainLayout.class)
|
||||||
public class EmployeeView extends BeanValidationForm<Employee> implements HasUrlParameter<String> {
|
public class EmployeeView extends BeanValidationForm<Employee> implements HasUrlParameter<String> {
|
||||||
|
|
||||||
private final EmployeeService employeeService;
|
private final EmployeeService employeeService;
|
||||||
|
|
||||||
|
private TextField name = null;
|
||||||
|
|
||||||
public EmployeeView(final EmployeeService employeeService) {
|
public EmployeeView(final EmployeeService employeeService) {
|
||||||
super(Employee.class);
|
super(Employee.class);
|
||||||
this.employeeService = employeeService;
|
this.employeeService = employeeService;
|
||||||
}
|
name = new TextField();
|
||||||
|
name.setWidthFull();
|
||||||
|
name.setLabel("Name");
|
||||||
|
|
||||||
@Override
|
setSavedHandler((SavedHandler<Employee>) employee -> {
|
||||||
protected List<Component> getFormComponents() {
|
final Employee saved = employeeService.createOrUpdate(employee);
|
||||||
return null;
|
setEntityWithEnabledSave(saved);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
public void setParameter(final BeforeEvent beforeEvent, final String s) {
|
||||||
|
if (StringUtils.isNotBlank(s) && !"new".equals(s)) {
|
||||||
|
var employee = employeeService.getEmployee(UUID.fromString(s));
|
||||||
|
setEntityWithEnabledSave(employee);
|
||||||
|
} else {
|
||||||
|
setEntityWithEnabledSave(new Employee());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<Component> getFormComponents() {
|
||||||
|
return List.of(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,28 @@
|
|||||||
package com.primefactorsolutions.views;
|
package com.primefactorsolutions.views;
|
||||||
|
|
||||||
|
import com.primefactorsolutions.model.Employee;
|
||||||
|
import com.primefactorsolutions.service.EmployeeService;
|
||||||
|
import com.vaadin.flow.component.ClickEvent;
|
||||||
|
import com.vaadin.flow.component.Component;
|
||||||
|
import com.vaadin.flow.component.ComponentEventListener;
|
||||||
|
import com.vaadin.flow.component.button.Button;
|
||||||
|
import com.vaadin.flow.component.combobox.ComboBox;
|
||||||
|
import com.vaadin.flow.component.html.H2;
|
||||||
import com.vaadin.flow.component.html.Main;
|
import com.vaadin.flow.component.html.Main;
|
||||||
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
|
import com.vaadin.flow.data.provider.DataProvider;
|
||||||
|
import com.vaadin.flow.data.provider.DataProviderListener;
|
||||||
|
import com.vaadin.flow.data.provider.Query;
|
||||||
|
import com.vaadin.flow.function.ValueProvider;
|
||||||
import com.vaadin.flow.router.PageTitle;
|
import com.vaadin.flow.router.PageTitle;
|
||||||
import com.vaadin.flow.router.Route;
|
import com.vaadin.flow.router.Route;
|
||||||
|
import com.vaadin.flow.shared.Registration;
|
||||||
import com.vaadin.flow.spring.annotation.SpringComponent;
|
import com.vaadin.flow.spring.annotation.SpringComponent;
|
||||||
import jakarta.annotation.security.PermitAll;
|
import jakarta.annotation.security.PermitAll;
|
||||||
import org.springframework.context.annotation.Scope;
|
import org.springframework.context.annotation.Scope;
|
||||||
|
import org.vaadin.firitin.components.grid.VGrid;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@SpringComponent
|
@SpringComponent
|
||||||
@Scope("prototype")
|
@Scope("prototype")
|
||||||
@ -13,4 +30,97 @@ import org.springframework.context.annotation.Scope;
|
|||||||
@Route(value = "/employees", layout = MainLayout.class)
|
@Route(value = "/employees", layout = MainLayout.class)
|
||||||
@PermitAll
|
@PermitAll
|
||||||
public class EmployeesListView extends Main {
|
public class EmployeesListView extends Main {
|
||||||
|
private final EmployeeService employeeService;
|
||||||
|
|
||||||
|
public EmployeesListView(final EmployeeService employeeService) {
|
||||||
|
this.employeeService = employeeService;
|
||||||
|
final H2 title = new H2("Employees list");
|
||||||
|
final HorizontalLayout hl = new HorizontalLayout();
|
||||||
|
final HorizontalLayout hf = new HorizontalLayout();
|
||||||
|
final Button employeeListAscendingOrder = new Button("Employee List in Ascending Order");
|
||||||
|
employeeListAscendingOrder.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
hl.add(employeeListAscendingOrder);
|
||||||
|
final Button employeeListDescendingOrder = new Button("Employee List in Descending Order");
|
||||||
|
employeeListDescendingOrder.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
hl.add(employeeListDescendingOrder);
|
||||||
|
final VGrid<Employee> grid = new VGrid<>(Employee.class);
|
||||||
|
grid.setColumns("firstName", "lastName", "status");
|
||||||
|
grid.setAllRowsVisible(true);
|
||||||
|
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||||
|
ComboBox<String> statusComboBox = new ComboBox<>();
|
||||||
|
statusComboBox.setItems("Active", "Inactive");
|
||||||
|
return statusComboBox;
|
||||||
|
}).setHeader("Change Status");
|
||||||
|
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||||
|
final Button edit = new Button("Edit");
|
||||||
|
edit.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
return edit;
|
||||||
|
});
|
||||||
|
grid.addComponentColumn((ValueProvider<Employee, Component>) employee -> {
|
||||||
|
final Button save = new Button("Save");
|
||||||
|
save.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
return save;
|
||||||
|
});
|
||||||
|
|
||||||
|
grid.setDataProvider(new DataProvider<>() {
|
||||||
|
@Override
|
||||||
|
public boolean isInMemory() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int size(final Query<Employee, Object> query) {
|
||||||
|
return employeeService.getEmployees().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<Employee> fetch(final Query<Employee, Object> query) {
|
||||||
|
int limit = query.getLimit();
|
||||||
|
int pagerSize = query.getPageSize();
|
||||||
|
int page = query.getPage();
|
||||||
|
return employeeService.getEmployees().stream();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshItem(final Employee employee) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshAll() {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Registration addDataProviderListener(final DataProviderListener<Employee> dataProviderListener) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
final Button previous = new Button("Previous");
|
||||||
|
previous.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
hf.add(previous);
|
||||||
|
final Button next = new Button("Next");
|
||||||
|
next.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
// no-op
|
||||||
|
});
|
||||||
|
hf.add(next);
|
||||||
|
final Button addEmployee = new Button("Add Employee");
|
||||||
|
addEmployee.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
|
||||||
|
this.getUI().get().navigate(EmployeeView.class, "new");
|
||||||
|
});
|
||||||
|
hf.add(addEmployee);
|
||||||
|
|
||||||
|
add(title, hl, grid, hf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,3 +8,9 @@ insert into assessment(id, version, candidate_id) values ('46b153f4-23fd-462f-84
|
|||||||
insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', 'a7e00ff8-da41-4624-b31c-1b13c3f2e3ae');
|
insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', 'a7e00ff8-da41-4624-b31c-1b13c3f2e3ae');
|
||||||
|
|
||||||
insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', '8a4b213c-ca81-4c38-b56d-d7028c2dde88');
|
insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', '8a4b213c-ca81-4c38-b56d-d7028c2dde88');
|
||||||
|
|
||||||
|
insert into employee (id, version, first_name, last_name, status) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'Juan', 'Perez Condori', 'INACTIVE');
|
||||||
|
insert into employee (id, version, first_name, last_name, status) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'Ana', 'Garcia Rojas', 'ACTIVE');
|
||||||
|
insert into employee (id, version, first_name, last_name, status) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'Carlos', 'Lopez Mendoza', 'INACTIVE');
|
||||||
|
insert into employee (id, version, first_name, last_name, status) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'Maria', 'Fernandez Villca', 'ACTIVE');
|
||||||
|
insert into employee (id, version, first_name, last_name, status) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'Luis', 'Gutierrez Mamani', 'ACTIVE');
|
Loading…
Reference in New Issue
Block a user
mantener
firstName
para este campo para ser mas explicito.Cambio realizado, esperando para revisión