use of com.autentia.tnt.dao.search.CollaboratorSearch in project TNTConcept by autentia.
the class CollaboratorBean method doBeforeSave.
public String doBeforeSave() {
// comprobacion de que solo se ha seleccionado o un usuario, o un contacto o una organizacion
int numRefs = 0;
if (collaborator.getUser() != null) {
numRefs++;
CollaboratorSearch collaboratorSearch = new CollaboratorSearch();
collaboratorSearch.setUser(this.getUser());
if (!CollaboratorManager.getDefault().getAllEntities(collaboratorSearch, new SortCriteria("id")).isEmpty()) {
FacesUtils.addErrorMessage(null, "collaborator.error.duplicateUserCollaborator");
return "Fail";
}
}
if (collaborator.getContact() != null) {
numRefs++;
CollaboratorSearch collaboratorSearch = new CollaboratorSearch();
collaboratorSearch.setContact(this.getContact());
if (!CollaboratorManager.getDefault().getAllEntities(collaboratorSearch, new SortCriteria("id")).isEmpty()) {
FacesUtils.addErrorMessage(null, "collaborator.error.duplicateContactCollaborator");
return "Fail";
}
}
if (collaborator.getOrganization() != null) {
numRefs++;
CollaboratorSearch collaboratorSearch = new CollaboratorSearch();
collaboratorSearch.setOrganization(this.getOrganization());
if (!CollaboratorManager.getDefault().getAllEntities(collaboratorSearch, new SortCriteria("id")).isEmpty()) {
FacesUtils.addErrorMessage(null, "collaborator.error.duplicateOrganizationCollaborator");
return "Fail";
}
}
if (numRefs != 1) {
FacesUtils.addErrorMessage(null, "collaborator.error.justOne");
return "Fail";
}
return null;
}
Aggregations