Renombrado método para actualizar especialidades.
Dialogo de confirmación al eliminar especialidades. Limpieza de formulario en interfaz tras realizar la operación CRUD.
This commit is contained in:
@@ -108,7 +108,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MedicalSpecialtyTO getSpecialty(int id, String name, String description) throws Exception {
|
||||
public MedicalSpecialtyTO updateSpecialty(int id, String name, String description) throws Exception {
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id);
|
||||
|
||||
if (ms == null) {
|
||||
@@ -136,7 +136,7 @@ public class SystemAdminFacadeBean implements SystemAdminFacadeRemote {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteSpecialty(int id, String name, String description) throws Exception {
|
||||
public void deleteSpecialty(int id) throws Exception {
|
||||
MedicalSpecialtyJPA ms = entman.find(MedicalSpecialtyJPA.class, id);
|
||||
|
||||
if (ms == null) {
|
||||
|
||||
@@ -19,11 +19,11 @@ public interface SystemAdminFacadeRemote {
|
||||
|
||||
public LoggedUserTO login(String id, String pwd);
|
||||
|
||||
public MedicalSpecialtyTO getSpecialty(int id, String name, String description) throws Exception;
|
||||
public MedicalSpecialtyTO updateSpecialty(int id, String name, String description) throws Exception;
|
||||
|
||||
public MedicalSpecialtyTO findSpecialtyByName(String name);
|
||||
|
||||
public void deleteSpecialty(int id, String name, String description) throws Exception;
|
||||
public void deleteSpecialty(int id) throws Exception;
|
||||
|
||||
public MedicalSpecialtyTO insertSpecialty(String name, String description) throws Exception;
|
||||
}
|
||||
@@ -7,21 +7,19 @@ import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.inject.Named;
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
import TO.LoggedUserTO;
|
||||
import TO.MedicalSpecialtyTO;
|
||||
import common.Constants;
|
||||
import managedbean.common.ManagedBeanBase;
|
||||
import managedbean.common.SessionUtils;
|
||||
import managedbean.common.ValidationUtils;
|
||||
|
||||
@Named("ManageSpecialities")
|
||||
@RequestScoped
|
||||
public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String description;
|
||||
@@ -45,13 +43,17 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
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.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
this.refreshFormData();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshFormData() {
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -59,7 +61,7 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -67,7 +69,7 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
@@ -76,12 +78,20 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private void setSpecialtyData(MedicalSpecialtyTO ms) {
|
||||
this.id = ms.getId();
|
||||
this.name = ms.getName();
|
||||
this.description = ms.getDescription();
|
||||
private void showSpecialtyData(MedicalSpecialtyTO ms) {
|
||||
this.medicalSpecialty = ms;
|
||||
|
||||
if (ms == null) {
|
||||
this.id = null;
|
||||
this.name = "";
|
||||
this.description = "";
|
||||
} else {
|
||||
this.id = ms.getId();
|
||||
this.name = ms.getName();
|
||||
this.description = ms.getDescription();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<MedicalSpecialtyTO> getMedicalSpecialtiesList() {
|
||||
return medicalSpecialitiesList;
|
||||
}
|
||||
@@ -93,7 +103,7 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
public void setMedicalSpecialty(MedicalSpecialtyTO value) {
|
||||
this.medicalSpecialty = value;
|
||||
}
|
||||
|
||||
|
||||
public void saveData() {
|
||||
int error = 0;
|
||||
|
||||
@@ -108,16 +118,19 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().getSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
|
||||
this.setSpecialtyData(ms);
|
||||
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().updateSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(),
|
||||
this.medicalSpecialty.getDescription());
|
||||
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void deleteData() {
|
||||
int error = 0;
|
||||
|
||||
@@ -132,9 +145,11 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
this.getRemoteManagerSystemAdmin().deleteSpecialty(this.medicalSpecialty.getId(), this.medicalSpecialty.getName(), this.medicalSpecialty.getDescription());
|
||||
this.getRemoteManagerSystemAdmin().deleteSpecialty(this.medicalSpecialty.getId());
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los especialidad se ha borrado", "Los datos de la especialidad se han borrado correctamente.");
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
@@ -152,18 +167,20 @@ public class ManageSpecialitiesMBean extends ManagedBeanBase implements Serializ
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Descripción no rellena", "Por favor, escriba una descripción.");
|
||||
error++;
|
||||
}
|
||||
|
||||
|
||||
if (this.getRemoteManagerSystemAdmin().findSpecialtyByName(name) != null) {
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_WARN, "Especialidad ya existente", "La especialidad ya se encuentra en la base de datos");
|
||||
error++;
|
||||
}
|
||||
|
||||
|
||||
if (error == 0) {
|
||||
try {
|
||||
MedicalSpecialtyTO ms = this.getRemoteManagerSystemAdmin().insertSpecialty(name, description);
|
||||
this.setSpecialtyData(ms);
|
||||
|
||||
this.showSpecialtyData(null);
|
||||
this.refreshFormData();
|
||||
|
||||
this.addFacesMessage(FacesMessage.SEVERITY_INFO, "Los datos se han guardado", "Los datos de la especialidad se han guardado correctamente.");
|
||||
this.medicalSpecialitiesList = this.getRemoteManagerCommon().listMedicalSpecialitiesPaged(0, Constants.MAX_ITEMS_AUTOCOMPLETE_SEARCH);
|
||||
} catch (Exception e) {
|
||||
this.manageException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user