WIP: Rama-Melina #4 y #5 #13

Closed
melina.gutierrez wants to merge 3 commits from Rama-Melina into main
3 changed files with 145 additions and 11 deletions

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

View File

@ -1,10 +1,8 @@
package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Candidate;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.repositories.EmployeeRepository;
import lombok.Data;
import org.apache.commons.lang3.NotImplementedException;
import org.springframework.stereotype.Service;
import java.util.List;
@ -15,7 +13,7 @@ import java.util.UUID;
public class EmployeeService {
private final EmployeeRepository employeeRepository;
public EmployeeService(EmployeeRepository employeeRepository) {
public EmployeeService(final EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
}

View File

@ -3,8 +3,16 @@ 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.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.value.ValueChangeMode;
import com.vaadin.flow.router.BeforeEvent;
import com.vaadin.flow.router.HasUrlParameter;
import com.vaadin.flow.router.PageTitle;
@ -13,6 +21,7 @@ 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.components.datepicker.VDatePicker;
import org.vaadin.firitin.form.BeanValidationForm;
import java.util.List;
@ -27,18 +36,133 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final EmployeeService employeeService;
private TextField name = null;
private TextField lastName = null;
private VDatePicker birthday = null;
private TextField birthCity = null;
private ComboBox<String> maritalStatus = null;
private TextField residenceAddress = null;
private TextField phoneNumber = null;
private EmailField personalEmail = null;
private TextField emergencyCName = null;
private TextField emergencyCAddress = null;
private TextField emergencyCPhone = null;
private EmailField emergencyCEmail = null;
private H2 mt = null;
private H3 fs = null;
private H3 ss = null;
//private final Button editButton = new Button("Edit");
public EmployeeView(final EmployeeService employeeService) {
super(Employee.class);
this.employeeService = employeeService;
name = new TextField();
mt = new H2("Información General del Empleado");
fs = new H3("Información Personal");
ss = new H3("Datos de Contacto de Emergencia");
final HorizontalLayout mainLayout = new HorizontalLayout();
final VerticalLayout sidebar = createSidebar();
final VerticalLayout contentLayout = createContentLayout();
final VerticalLayout contentLayout2 = createContentLayout();
name = new TextField("Nombres: ");
name.setWidthFull();
name.setLabel("Name");
name.setMaxLength(30);
lastName = new TextField("Apellidos");
lastName.setWidthFull();
lastName.setMaxLength(30);
birthday = new VDatePicker("Fecha de Nacimiento");
birthday.setWidthFull();
birthCity = new TextField("Ciudad y País de Nacimiento");
birthCity.setWidthFull();
birthCity.setMaxLength(20);
maritalStatus = new ComboBox<>("Estado Civil");
maritalStatus.setItems(List.of("Soltero", "Casado", "Viudo", "Divorciado"));
maritalStatus.setWidthFull();
residenceAddress = new TextField("Dirección de Residencia");
residenceAddress.setWidthFull();
residenceAddress.setMaxLength(50);
phoneNumber = new TextField("Teléfono");
phoneNumber.setWidthFull();
phoneNumber.setMaxLength(8);
phoneNumber.setValueChangeMode(ValueChangeMode.EAGER);
phoneNumber.addValueChangeListener(e -> {
if (!e.getValue().matches("\\d*")) {
phoneNumber.setErrorMessage("El teléfono debe contener solo números.");
}
});
personalEmail = new EmailField("E-mail");
personalEmail.setWidthFull();
personalEmail.setMaxLength(30);
emergencyCName = new TextField("Nombres y Apellidos de Contacto");
emergencyCName.setWidthFull();
emergencyCName.setMaxLength(50);
emergencyCAddress = new TextField("Dirección de Contacto");
emergencyCAddress.setWidthFull();
emergencyCAddress.setMaxLength(50);
emergencyCPhone = new TextField("Teléfono de Contacto");
emergencyCPhone.setWidthFull();
emergencyCPhone.setMaxLength(8);
emergencyCPhone.setValueChangeMode(ValueChangeMode.EAGER);
emergencyCPhone.addValueChangeListener(e -> {
if (!e.getValue().matches("\\d*")) {
emergencyCPhone.setErrorMessage("El teléfono debe contener solo números.");
}
});
emergencyCEmail = new EmailField("Email de Contacto");
emergencyCEmail.setWidthFull();
emergencyCEmail.setMaxLength(30);
contentLayout.add(
mt, fs, name, lastName, birthday, birthCity, maritalStatus,
residenceAddress, phoneNumber, personalEmail);
contentLayout2.add(
ss, emergencyCName, emergencyCAddress, emergencyCPhone, emergencyCEmail);
setSavedHandler((SavedHandler<Employee>) employee -> {
final Employee saved = employeeService.createOrUpdate(employee);
Review

parece que los campos de emergency contact no estan definidos en la clase model Employee. Se deberian crear esos campos para que puedan ser guardados en al DB.

podrias ir viendo de agregar campo por campo y ver si se guardan en la db cuando se hace el save.

parece que los campos de emergency contact no estan definidos en la clase model Employee. Se deberian crear esos campos para que puedan ser guardados en al DB. podrias ir viendo de agregar campo por campo y ver si se guardan en la db cuando se hace el save.
Notification.show("Empleado guardado exitosamente.");
getUI().ifPresent(ui -> ui.navigate(EmployeesListView.class));
setEntityWithEnabledSave(saved);
});
mainLayout.add(sidebar, contentLayout, contentLayout2);
addClassName("main-layout");
}
private VerticalLayout createSidebar() {
VerticalLayout sidebar = new VerticalLayout();
sidebar.setWidth("250px");
sidebar.add(new Button("Información General", e -> navigateToSection("Información General")));
sidebar.add(new Button("Detalles Profesionales", e -> navigateToSection("Detalles Profesionales")));
return sidebar;
}
private void navigateToSection(final String section) {
Notification.show("Navigating to " + section);
}
private VerticalLayout createContentLayout() {
VerticalLayout contentLayout = new VerticalLayout();
contentLayout.setWidth("100%");
return contentLayout;
}
@Override
@ -53,7 +177,23 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
@Override
protected List<Component> getFormComponents() {
return List.of(name);
}
return List.of(
mt,
fs,
name,
lastName,
birthday,
birthCity,
maritalStatus,
residenceAddress,
phoneNumber,
personalEmail,
ss,
emergencyCName,
emergencyCAddress,
emergencyCPhone,
emergencyCEmail
);
}
}