Gestión de especialidades con paginado.
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
package managedbean.systemAdmin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.view.ViewScoped;
|
||||
import javax.inject.Named;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import org.primefaces.event.RowEditEvent;
|
||||
import org.primefaces.model.LazyDataModel;
|
||||
import org.primefaces.model.SortOrder;
|
||||
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import managedbean.common.ManagedBeanBase;
|
||||
import managedbean.common.SessionUtils;
|
||||
|
||||
@Named("ManageSpecialities")
|
||||
@RequestScoped
|
||||
@ViewScoped
|
||||
public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -23,34 +28,29 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
private String name;
|
||||
private String description;
|
||||
private MedicalSpecialtyTO medicalSpecialty;
|
||||
private List<MedicalSpecialtyTO> medicalSpecialtiesList;
|
||||
private LazyDataModel<MedicalSpecialtyTO> lazyDataModelSpecialtiesList;
|
||||
|
||||
public ManageSpecialitiesMBean() {
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (this.medicalSpecialty == null) {
|
||||
this.medicalSpecialty = new MedicalSpecialtyTO();
|
||||
}
|
||||
// Recuperamos el usuario logeado actual
|
||||
LoggedUserTO usr = null;
|
||||
try {
|
||||
usr = SessionUtils.getloggedOnUser();
|
||||
this.lazyDataModelSpecialtiesList = new LazyDataModel<MedicalSpecialtyTO>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
if (usr == null)
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "Sesión no válida",
|
||||
"Su sesión actual no es válida, por favor cierre su sesión y vuelva a logearse en el sistema.");
|
||||
else {
|
||||
this.refreshFormData();
|
||||
@Override
|
||||
public List<MedicalSpecialtyTO> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
|
||||
Long totalRowCount = getRemoteManagerSystemAdmin().getSpecialtiesCount();
|
||||
this.setRowCount(totalRowCount.intValue());
|
||||
|
||||
return getRemoteManagerSystemAdmin().listSpecialtiesPaged((first / pageSize), pageSize);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private void refreshFormData() {
|
||||
this.medicalSpecialtiesList = this.getRemoteManagerCommon().listAllMedicalSpecialties();
|
||||
public LazyDataModel<MedicalSpecialtyTO> getlazyDataModelSpecialtiesList() {
|
||||
return lazyDataModelSpecialtiesList;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
@@ -91,10 +91,6 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
}
|
||||
}
|
||||
|
||||
public List<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
|
||||
return medicalSpecialtiesList;
|
||||
}
|
||||
|
||||
public MedicalSpecialtyTO getMedicalSpecialty() {
|
||||
return medicalSpecialty;
|
||||
}
|
||||
@@ -102,62 +98,68 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
public void setMedicalSpecialty(MedicalSpecialtyTO value) {
|
||||
this.medicalSpecialty = value;
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
|
||||
public void onRowEdit(RowEditEvent event) {
|
||||
int error = 0;
|
||||
|
||||
if (this.medicalSpecialty.getName() == null || this.medicalSpecialty.getName().trim().length() == 0) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre de especialidad.");
|
||||
String newName = ((MedicalSpecialtyTO) event.getObject()).getName();
|
||||
String newDescription = ((MedicalSpecialtyTO) event.getObject()).getDescription();
|
||||
|
||||
if (newName == null || newName.trim().length() == 0) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre para la especialidad.");
|
||||
error++;
|
||||
}
|
||||
if (this.medicalSpecialty.getDescription() == null || this.medicalSpecialty.getDescription().trim().length() == 0) {
|
||||
|
||||
if (newDescription == null || newDescription.trim().length() == 0) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción.");
|
||||
error++;
|
||||
}
|
||||
|
||||
|
||||
if (this.getRemoteManagerSystemAdmin().findSpecialtyByName(newName) != null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad ya existente", "La especialidad ya se encuentra en la base de datos");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
this.getRemoteManagerSystemAdmin().updateSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
this.getRemoteManagerSystemAdmin().updateSpecialty(((MedicalSpecialtyTO) event.getObject()).getId(),
|
||||
((MedicalSpecialtyTO) event.getObject()).getName(), ((MedicalSpecialtyTO) event.getObject()).getDescription());
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
|
||||
this.showSpecialtyData(null);
|
||||
|
||||
FacesMessage msg = new FacesMessage("Especialidad editada", ((MedicalSpecialtyTO) event.getObject()).getName());
|
||||
FacesContext.getCurrentInstance().addMessage(null, msg);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteData() {
|
||||
|
||||
public void onRowCancel(RowEditEvent event) {
|
||||
FacesMessage msg = new FacesMessage("Edición cancelada", ((MedicalSpecialtyTO) event.getObject()).getName());
|
||||
FacesContext.getCurrentInstance().addMessage(null, msg);
|
||||
}
|
||||
|
||||
public void deleteDataById(Integer id) throws IOException {
|
||||
int error = 0;
|
||||
try {
|
||||
if (this.getRemoteManagerMedicalTest().getSpecialistDoctorByMedicalSpecialtyCount(id) > 0) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "No se puede eliminar esta especialidad",
|
||||
"Existen especialistas que tienen asignada esta especialidad médica, por lo cual no puede ser eliminada. Asigne los especialista a otra especialidad para proceder a eliminar la especialidad a continuación.");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (this.medicalSpecialty.getName() == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Nombre no relleno", "Por favor, escriba un nombre de especialidad.");
|
||||
error++;
|
||||
}
|
||||
if (this.medicalSpecialty.getDescription() == null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción.");
|
||||
error++;
|
||||
}
|
||||
if (this.getRemoteManagerMedicalTest().getSpecialistDoctorByMedicalSpecialtyCount(this.medicalSpecialty.getId()) > 0) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_ERROR, "No se puede eliminar esta especialidad",
|
||||
"Existen especialistas que tienen asignada esta especialidad médica, por lo cual no puede ser eliminada. Asigne los especialista a otra especialidad para proceder a eliminar la especialidad a continuación.");
|
||||
error++;
|
||||
}
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
this.getRemoteManagerSystemAdmin().deleteSpecialty(this.medicalSpecialty.getId());
|
||||
if (error == 0) {
|
||||
this.getRemoteManagerSystemAdmin().deleteSpecialty(id);
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "La especialidad se ha borrado", "Los datos de la especialidad se han borrado correctamente.");
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void insertData() {
|
||||
int error = 0;
|
||||
|
||||
@@ -179,7 +181,6 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
try {
|
||||
this.getRemoteManagerSystemAdmin().insertSpecialty(name, description);
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user