Search in sources :

Example 1 with CollaboratorSearch

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;
}
Also used : CollaboratorSearch(com.autentia.tnt.dao.search.CollaboratorSearch) SortCriteria(com.autentia.tnt.dao.SortCriteria)

Aggregations

SortCriteria (com.autentia.tnt.dao.SortCriteria)1 CollaboratorSearch (com.autentia.tnt.dao.search.CollaboratorSearch)1