Search in sources :

Example 6 with FacesMessage

use of javax.faces.application.FacesMessage 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 7 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class CurrentUser method editAllPref.

public void editAllPref() {
    // nodePreference.setAlertCdt(alertCdtEdit);
    nodePreference.setSourceLang(langSourceEdit);
    if (!new PreferencesHelper().updateAllPreferenceUser(connect.getPoolConnexion(), nodePreference, idTheso)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("error.BDD")));
        return;
    }
    initUserNodePref(idTheso);
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("user.info6")));
}
Also used : FacesMessage(javax.faces.application.FacesMessage) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 8 with FacesMessage

use of javax.faces.application.FacesMessage 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)

Example 9 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class Soap method openConnexionPool.

private HikariDataSource openConnexionPool(Properties properties) {
    HikariConfig config = new HikariConfig();
    config.setMinimumIdle(Integer.parseInt(properties.getProperty("minimumIdle")));
    config.setMaximumPoolSize(Integer.parseInt(properties.getProperty("setMaximumPoolSize")));
    config.setAutoCommit(true);
    config.setIdleTimeout(Integer.parseInt(properties.getProperty("idleTimeout")));
    config.setConnectionTimeout(Integer.parseInt(properties.getProperty("connectionTimeout")));
    config.setConnectionTestQuery(properties.getProperty("connectionTestQuery"));
    config.setDataSourceClassName(properties.getProperty("dataSourceClassName"));
    config.addDataSourceProperty("user", properties.getProperty("dataSource.user"));
    config.addDataSourceProperty("password", properties.getProperty("dataSource.password"));
    config.addDataSourceProperty("databaseName", properties.getProperty("dataSource.databaseName"));
    config.addDataSourceProperty("serverName", properties.getProperty("dataSource.serverName"));
    config.addDataSourceProperty("portNumber", properties.getProperty("dataSource.serverPort"));
    HikariDataSource poolConnexion1 = new HikariDataSource(config);
    try {
        Connection conn = poolConnexion1.getConnection();
        if (conn == null)
            return null;
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_FATAL, ex.getClass().getName(), ex.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
        poolConnexion1.close();
        return null;
    }
    return poolConnexion1;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) Connection(java.sql.Connection) HikariConfig(com.zaxxer.hikari.HikariConfig) Connexion(mom.trd.opentheso.bdd.helper.Connexion) FacesMessage(javax.faces.application.FacesMessage)

Example 10 with FacesMessage

use of javax.faces.application.FacesMessage in project opentheso by miledrousset.

the class Connexion method openConnexionPool.

private HikariDataSource openConnexionPool() {
    HikariConfig config = new HikariConfig();
    ResourceBundle resourceBundle = getBundlePool();
    if (resourceBundle == null) {
        // retour pour installation
        return null;
    }
    config.setMinimumIdle(Integer.parseInt(resourceBundle.getString("minimumIdle")));
    config.setMaximumPoolSize(Integer.parseInt(resourceBundle.getString("setMaximumPoolSize")));
    config.setAutoCommit(true);
    // config.setIdleTimeout(Integer.parseInt(getBundlePool().getString("idleTimeout")));
    // config.setConnectionTimeout(Integer.parseInt(getBundlePool().getString("connectionTimeout")));
    // config.setJdbc4ConnectionTest(false);
    config.setConnectionTestQuery(resourceBundle.getString("connectionTestQuery"));
    config.setDataSourceClassName(resourceBundle.getString("dataSourceClassName"));
    config.addDataSourceProperty("user", resourceBundle.getString("dataSource.user"));
    config.addDataSourceProperty("password", resourceBundle.getString("dataSource.password"));
    config.addDataSourceProperty("databaseName", resourceBundle.getString("dataSource.databaseName"));
    config.addDataSourceProperty("serverName", resourceBundle.getString("dataSource.serverName"));
    config.addDataSourceProperty("portNumber", resourceBundle.getString("dataSource.serverPort"));
    HikariDataSource poolConnexion1 = new HikariDataSource(config);
    try {
        poolConnexion1.getConnection();
    } catch (SQLException ex) {
        Logger.getLogger(Connexion.class.getName()).log(Level.SEVERE, null, ex);
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_FATAL, ex.getClass().getName(), ex.getMessage());
        FacesContext.getCurrentInstance().addMessage(null, message);
        poolConnexion1.close();
        return null;
    }
    return poolConnexion1;
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SQLException(java.sql.SQLException) ResourceBundle(java.util.ResourceBundle) HikariConfig(com.zaxxer.hikari.HikariConfig) FacesMessage(javax.faces.application.FacesMessage)

Aggregations

FacesMessage (javax.faces.application.FacesMessage)370 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)43 SQLException (java.sql.SQLException)40 Connection (java.sql.Connection)34 FacesContext (javax.faces.context.FacesContext)25 ArrayList (java.util.ArrayList)24 UIInput (javax.faces.component.UIInput)24 ValidatorException (javax.faces.validator.ValidatorException)24 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)22 NodeAutoCompletion (mom.trd.opentheso.bdd.helper.nodes.NodeAutoCompletion)22 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)19 UserHelper2 (mom.trd.opentheso.bdd.helper.UserHelper2)19 IOException (java.io.IOException)16 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)15 Test (org.junit.Test)13 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)12 Term (mom.trd.opentheso.bdd.datas.Term)11 UploadedFile (org.primefaces.model.UploadedFile)11 HikariDataSource (com.zaxxer.hikari.HikariDataSource)10 Date (java.util.Date)10