Search in sources :

Example 1 with UserHelper

use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.

the class CurrentUser method updateAlertMail.

public boolean updateAlertMail() {
    try {
        UserHelper userHelper = new UserHelper();
        Connection conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        if (!userHelper.setAlertMailForUser(connect.getPoolConnexion().getConnection(), user.getId(), alertmail)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
            conn.rollback();
            conn.close();
            return false;
        }
        conn.commit();
        conn.close();
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("conf.alertMailMessage")));
        return true;
    } catch (SQLException ex) {
        Logger.getLogger(CurrentUser.class.getName()).log(Level.SEVERE, null, ex);
    }
    return false;
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with UserHelper

use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.

the class CurrentUser method selectAuthorizedUser.

/**
 * retoure la liste des utilisateurs suivant leurs droits
 *
 * @return
 */
public ArrayList<NodeUser> selectAuthorizedUser() {
    UserHelper userHelper = new UserHelper();
    int idRoleFrom = 1;
    if (user.getIdRole() == 1) {
        // l'utilisateur est superAdmin
        return selectAllUsers();
    }
    if (user.getIdRole() == 2) {
        // l'utilisateur est admin
        idRoleFrom = 2;
    }
    if (user.getIdRole() > 2) {
        // l'utilisateur est autre
        idRoleFrom = 3;
    }
    ArrayList<NodeUser> listeUser = userHelper.getAuthorizedUsers(connect.getPoolConnexion(), idTheso, idRoleFrom);
    return listeUser;
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) NodeUser(mom.trd.opentheso.bdd.helper.nodes.NodeUser)

Example 3 with UserHelper

use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.

the class CurrentUser method renamePseudo.

public void renamePseudo() {
    if (pseudo == null || pseudo.isEmpty()) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error6")));
    } else if (new UserHelper().isPseudoExist(connect.getPoolConnexion(), pseudo)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error5")));
    } else {
        new UserHelper().updatePseudo(connect.getPoolConnexion(), user.getId(), pseudo);
        user.setName(pseudo);
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("user.info5")));
    }
    name = pseudo;
    pseudo = "";
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) FacesMessage(javax.faces.application.FacesMessage)

Example 4 with UserHelper

use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.

the class CurrentUser method getThesaurusPreferences.

/**
 * cette fonction permet de retourner les préférences d'un thésaurus, s'il y
 * en a pas, on les initialises par les valeurs par defaut
 *
 * @param idThesaurus
 * @param workLanguage
 * @return
 */
public NodePreference getThesaurusPreferences(String idThesaurus, String workLanguage) {
    if (user.getId() == 1) {
        // superAdmin
        authorizedTheso = new ThesaurusHelper().getAllIdOfThesaurus(connect.getPoolConnexion());
    } else {
        authorizedTheso = new UserHelper().getAuthorizedThesaurus(connect.getPoolConnexion(), user.getId());
    }
    PreferencesHelper preferencesHelper = new PreferencesHelper();
    if (connect.getPoolConnexion() != null) {
        nodePreference = preferencesHelper.getThesaurusPreference(connect.getPoolConnexion(), idThesaurus);
        if (nodePreference == null) {
            // cas où il n'y a pas de préférence pour ce thésaurus, il faut les créer
            preferencesHelper.initPreferences(connect.getPoolConnexion(), idThesaurus, workLanguage);
            nodePreference = preferencesHelper.getThesaurusPreference(connect.getPoolConnexion(), idThesaurus);
        } else {
            langSourceEdit = nodePreference.getSourceLang();
            // alertNbCdtEdit = nodePreference.getNbAlertCdt();
            // alertCdtEdit = nodePreference.isAlertCdt();
            selectedThesaurus = new ArrayList<>();
            selectedThesaurus.add(idTheso);
        }
        idTheso = idThesaurus;
        versionOfOpentheso = new BaseDeDoneesHelper().getVersionOfOpentheso(connect.getPoolConnexion());
        return nodePreference;
    }
    return null;
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) BaseDeDoneesHelper(mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 5 with UserHelper

use of mom.trd.opentheso.bdd.helper.UserHelper in project opentheso by miledrousset.

the class CurrentUser method addUser.

public void addUser() throws SQLException {
    if (pwdEdit1 == null || pwdEdit1.equals("") || pwdEdit2 == null || pwdEdit2.equals("") || nameEdit == null || nameEdit.equals("") || mailEdit.equals("") || mailEdit == null) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error2")));
    } else if (!pwdEdit1.equals(pwdEdit2)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error3")));
    } else if (new UserHelper().isUserLoginExist(connect.getPoolConnexion(), nameEdit)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.error5")));
    } else {
        UserHelper userHelper = new UserHelper();
        Connection conn;
        conn = connect.getPoolConnexion().getConnection();
        conn.setAutoCommit(false);
        int idUser = -1;
        if (userHelper.isUserMailExist(conn, mailEdit)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("user.info7")));
        } else {
            try {
                // Cas de création de SuperAdmin
                if (user.getIdRole() == 1) {
                    // ajout de l'utilisateur
                    if (!userHelper.addUser(conn, nameEdit, mailEdit, MD5Password.getEncodedPassword(pwdEdit1), roleEdit)) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                    // récupération de l'Id du User
                    idUser = userHelper.getIdUser(conn, nameEdit);
                    if (idUser == -1) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                    // ajout du role
                    if (!userHelper.addRole(conn, idUser, roleEdit, idTheso, "")) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                }
                // Cas de création d'admin (par thésaurus)
                if (user.getIdRole() == 2) {
                    // ajout de l'utilisateur
                    if (!userHelper.addUser(conn, nameEdit, mailEdit, MD5Password.getEncodedPassword(pwdEdit1), roleEdit)) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                    // récupération de l'Id du User
                    idUser = userHelper.getIdUser(conn, nameEdit);
                    if (idUser == -1) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                    // ajout du role
                    if (!userHelper.addRole(conn, idUser, roleEdit, idTheso, "")) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                        conn.rollback();
                        conn.close();
                        return;
                    }
                }
                // mise à jour des alerts mails pour l'utilisateur
                if (alertmail) {
                    if (idUser != -1)
                        if (!userHelper.setAlertMailForUser(conn, idUser, true)) {
                            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
                            conn.rollback();
                            conn.close();
                            return;
                        }
                }
                userHelper.updateAddUserHistorique(conn, nameEdit);
                conn.commit();
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(CurrentUser.class.getName()).log(Level.SEVERE, null, ex);
            }
            mailEdit = "";
            pwdEdit1 = "";
            pwdEdit2 = "";
            nameEdit = "";
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("user.info3")));
        }
    }
}
Also used : UserHelper(mom.trd.opentheso.bdd.helper.UserHelper) SQLException(java.sql.SQLException) Connection(java.sql.Connection) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)19 FacesMessage (javax.faces.application.FacesMessage)10 Connection (java.sql.Connection)8 SQLException (java.sql.SQLException)8 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)6 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)2 BaseDeDoneesHelper (mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper)2 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)2 NodeUser (mom.trd.opentheso.bdd.helper.nodes.NodeUser)2 FacesContext (javax.faces.context.FacesContext)1 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)1 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)1 SKOSCreator (mom.trd.opentheso.skosapi.SKOSCreator)1 SKOSLabel (mom.trd.opentheso.skosapi.SKOSLabel)1 SKOSRelation (mom.trd.opentheso.skosapi.SKOSRelation)1 SKOSResource (mom.trd.opentheso.skosapi.SKOSResource)1 SKOSConceptScheme (skos.SKOSConceptScheme)1 SKOSLabel (skos.SKOSLabel)1 SKOSResource (skos.SKOSResource)1 SKOSTopConcept (skos.SKOSTopConcept)1