From d751833c182b9c9a94562e72e84f096546b03014 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Thu, 22 Aug 2024 20:37:39 -0400 Subject: [PATCH 1/5] #7 Perfil de Personal Administrativo - Listado de empleados --- .../primefactorsolutions/model/Employee.java | 12 +- .../service/EmployeeService.java | 19 ++- .../views/EmployeesListView.java | 110 ++++++++++++++++++ 3 files changed, 125 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index dcc7df0..7610a4f 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -17,15 +17,7 @@ import java.util.List; @NoArgsConstructor @EqualsAndHashCode(callSuper = true) public class Employee extends BaseEntity { - private String username; - private String firstName; + private String name; private String lastName; - private LocalDate dob; - private String personalEmail; - @Type(JsonType.class) - @Column(columnDefinition = "json") - private List phoneNumbers; - @OneToMany(fetch = FetchType.EAGER, mappedBy = "employee", cascade = {CascadeType.ALL}) - private List documents; - private Role role; + private String status; } diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 9005783..76f9521 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -7,19 +7,26 @@ import org.apache.commons.lang3.NotImplementedException; import org.springframework.stereotype.Service; import java.util.List; +import java.util.UUID; @Service @Data public class EmployeeService { private final EmployeeRepository employeeRepository; - private List getEmployees() { - // TODO: implement - throw new NotImplementedException(); + public EmployeeService(EmployeeRepository employeeRepository) { + this.employeeRepository = employeeRepository; } - private Employee createOrUpdateEmployee(final Employee employee) { - // TODO: implement - throw new NotImplementedException(); + public Employee createOrUpdate(final Employee assessment) { + return null; + } + + public List getEmployees() { + return employeeRepository.findAll(); + } + + public Employee getEmployee(final UUID id) { + return null; } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 45cab4f..1e13d4c 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -1,11 +1,28 @@ 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.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.Route; +import com.vaadin.flow.shared.Registration; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; +import org.vaadin.firitin.components.grid.VGrid; + +import java.util.stream.Stream; @SpringComponent @Scope("prototype") @@ -13,4 +30,97 @@ import org.springframework.context.annotation.Scope; @Route(value = "/employees", layout = MainLayout.class) @PermitAll 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>) buttonClickEvent -> { + // no-op + }); + hl.add(employeeListAscendingOrder); + final Button employeeListDescendingOrder = new Button("Employee List in Descending Order"); + employeeListDescendingOrder.addClickListener((ComponentEventListener>) buttonClickEvent -> { + // no-op + }); + hl.add(employeeListDescendingOrder); + final VGrid grid = new VGrid<>(Employee.class); + grid.setColumns("name", "lastName", "status"); + grid.setAllRowsVisible(true); + grid.addComponentColumn((ValueProvider) employee -> { + ComboBox statusComboBox = new ComboBox<>(); + statusComboBox.setItems("Active", "Inactive"); + return statusComboBox; + }).setHeader("Change Status"); + grid.addComponentColumn((ValueProvider) employee -> { + final Button edit = new Button("Edit"); + edit.addClickListener((ComponentEventListener>) buttonClickEvent -> { + // no-op + }); + return edit; + }); + grid.addComponentColumn((ValueProvider) employee -> { + final Button save = new Button("Save"); + save.addClickListener((ComponentEventListener>) buttonClickEvent -> { + // no-op + }); + return save; + }); + + grid.setDataProvider(new DataProvider<>() { + @Override + public boolean isInMemory() { + return false; + } + + @Override + public int size(final Query query) { + return employeeService.getEmployees().size(); + } + + @Override + public Stream fetch(final Query 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 dataProviderListener) { + return null; + } + }); + + final Button previous = new Button("Previous"); + previous.addClickListener((ComponentEventListener>) buttonClickEvent -> { + // no-op + }); + hf.add(previous); + final Button next = new Button("Next"); + next.addClickListener((ComponentEventListener>) buttonClickEvent -> { + // no-op + }); + hf.add(next); + final Button addEmployee = new Button("Add Employee"); + addEmployee.addClickListener((ComponentEventListener>) buttonClickEvent -> { + //this.getUI().get().navigate(EmployeeView.class, "new"); + }); + hf.add(addEmployee); + + add(title, hl, grid, hf); + } } -- 2.34.1 From c0e770bf758d15e500bc6e213eec59a165f771a9 Mon Sep 17 00:00:00 2001 From: "jesus.pelaez" Date: Fri, 23 Aug 2024 00:52:00 +0000 Subject: [PATCH 2/5] Actualizar src/main/resources/data.sql --- src/main/resources/data.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index cc682ab..f653182 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -7,4 +7,10 @@ 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', '8a4b213c-ca81-4c38-b56d-d7028c2dde88'); \ No newline at end of file +insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', '8a4b213c-ca81-4c38-b56d-d7028c2dde88'); + +insert into employee (id, version, name, last_name, status) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'Juan', 'Perez Condori', 'Inactivo'); +insert into employee (id, version, name, last_name, status) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'Ana', 'Garcia Rojas', 'Activo'); +insert into employee (id, version, name, last_name, status) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'Carlos', 'Lopez Mendoza', 'Inactivo'); +insert into employee (id, version, name, last_name, status) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'Maria', 'Fernandez Villca', 'Activo'); +insert into employee (id, version, name, last_name, status) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'Luis', 'Gutierrez Mamani', 'Activo'); \ No newline at end of file -- 2.34.1 From cde58ad1c3e6fd6f08636d21d38ad8010520d4bf Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Fri, 23 Aug 2024 21:54:00 -0400 Subject: [PATCH 3/5] #4 Perfil de Empleado - Redireccionamiento formulario --- .../service/EmployeeService.java | 6 ++-- .../views/EmployeeView.java | 28 +++++++++++++++---- .../views/EmployeesListView.java | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 76f9521..716827d 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,5 +1,6 @@ package com.primefactorsolutions.service; +import com.primefactorsolutions.model.Candidate; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.repositories.EmployeeRepository; import lombok.Data; @@ -18,8 +19,9 @@ public class EmployeeService { this.employeeRepository = employeeRepository; } - public Employee createOrUpdate(final Employee assessment) { - return null; + public Employee createOrUpdate(final Employee employee) { + final Employee saved = employeeRepository.save(employee); + return saved; } public List getEmployees() { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 5f5acf8..6003b76 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -3,16 +3,20 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; 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.HasUrlParameter; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; +import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.form.BeanValidationForm; import java.util.List; +import java.util.UUID; @SpringComponent @PermitAll @@ -20,22 +24,36 @@ import java.util.List; @PageTitle("Employee") @Route(value = "/employees", layout = MainLayout.class) public class EmployeeView extends BeanValidationForm implements HasUrlParameter { - private final EmployeeService employeeService; + private TextField name = null; + public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; - } + name = new TextField(); + name.setWidthFull(); + name.setLabel("Name"); - @Override - protected List getFormComponents() { - return null; + setSavedHandler((SavedHandler) employee -> { + final Employee saved = employeeService.createOrUpdate(employee); + setEntityWithEnabledSave(saved); + }); } @Override 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 getFormComponents() { + return List.of(name); } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 1e13d4c..145ff28 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -117,7 +117,7 @@ public class EmployeesListView extends Main { hf.add(next); final Button addEmployee = new Button("Add Employee"); addEmployee.addClickListener((ComponentEventListener>) buttonClickEvent -> { - //this.getUI().get().navigate(EmployeeView.class, "new"); + this.getUI().get().navigate(EmployeeView.class, "new"); }); hf.add(addEmployee); -- 2.34.1 From 6fe875d062cefa9f582196318b58938ffa91be95 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 27 Aug 2024 09:41:06 -0400 Subject: [PATCH 4/5] #7 Perfil de Personal Administrativo - Listado de empleados (CORRECCIONES) --- src/main/java/com/primefactorsolutions/model/Employee.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index 7610a4f..e65d3c8 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -17,7 +17,7 @@ import java.util.List; @NoArgsConstructor @EqualsAndHashCode(callSuper = true) public class Employee extends BaseEntity { - private String name; + private String firstName; private String lastName; - private String status; + private enum status { ACTIVE, INACTIVE}; } -- 2.34.1 From 0f63ee58a255850dce5c97b0e931954b91e4c282 Mon Sep 17 00:00:00 2001 From: ricardo051199 Date: Tue, 27 Aug 2024 11:13:11 -0400 Subject: [PATCH 5/5] #7 Perfil de Personal Administrativo - Listado de empleados (CORRECCIONES v2) --- .../java/com/primefactorsolutions/model/Employee.java | 8 +++++++- .../primefactorsolutions/views/EmployeesListView.java | 2 +- src/main/resources/data.sql | 10 +++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/primefactorsolutions/model/Employee.java b/src/main/java/com/primefactorsolutions/model/Employee.java index e65d3c8..6e883f0 100644 --- a/src/main/java/com/primefactorsolutions/model/Employee.java +++ b/src/main/java/com/primefactorsolutions/model/Employee.java @@ -19,5 +19,11 @@ import java.util.List; public class Employee extends BaseEntity { private String firstName; private String lastName; - private enum status { ACTIVE, INACTIVE}; + @Enumerated(EnumType.STRING) + private Status status; + + public enum Status { + ACTIVE, + INACTIVE + } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 145ff28..59fbb3f 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -48,7 +48,7 @@ public class EmployeesListView extends Main { }); hl.add(employeeListDescendingOrder); final VGrid grid = new VGrid<>(Employee.class); - grid.setColumns("name", "lastName", "status"); + grid.setColumns("firstName", "lastName", "status"); grid.setAllRowsVisible(true); grid.addComponentColumn((ValueProvider) employee -> { ComboBox statusComboBox = new ComboBox<>(); diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index f653182..f797344 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -9,8 +9,8 @@ insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4- insert into ASSESSMENT_QUESTIONS (assessment_id, question_id) values ('46b153f4-23fd-462f-8430-fbe67b83caab', '8a4b213c-ca81-4c38-b56d-d7028c2dde88'); -insert into employee (id, version, name, last_name, status) values ('e99b7af5-7d3a-4c0f-b8bc-e8d0388d8fc4', 1, 'Juan', 'Perez Condori', 'Inactivo'); -insert into employee (id, version, name, last_name, status) values ('f6ab3c6d-7078-45f6-9b22-4e37637bfec6', 1, 'Ana', 'Garcia Rojas', 'Activo'); -insert into employee (id, version, name, last_name, status) values ('2e2293b1-3f9a-4f3d-abc8-32639b0a5e15', 1, 'Carlos', 'Lopez Mendoza', 'Inactivo'); -insert into employee (id, version, name, last_name, status) values ('4b1c6c35-4627-4b35-b6e9-dc75c68b2c31', 1, 'Maria', 'Fernandez Villca', 'Activo'); -insert into employee (id, version, name, last_name, status) values ('afc5c741-f70a-4394-853b-39d51b118927', 1, 'Luis', 'Gutierrez Mamani', 'Activo'); \ No newline at end of file +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'); \ No newline at end of file -- 2.34.1