Search in sources :

Example 1 with BaseDeDoneesHelper

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

the class BaseDeDonnesBean method maJBdd.

/**
 * permet de faire la mise à jour de la BDD
 */
public void maJBdd() {
    String ownerName = "";
    InputStream inputStream = this.getClass().getResourceAsStream("/install/maj_bdd_current.sql");
    BaseDeDoneesHelper baseDeDoneesHelper = new BaseDeDoneesHelper();
    ownerName = baseDeDoneesHelper.getNameOwner(connect.getPoolConnexion(), getNameOfBdd());
    if (!baseDeDoneesHelper.insertDonnees(connect.getPoolConnexion(), inputStream, ownerName)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("bdd.error")));
    } else {
        baseDeDoneesHelper.updateVersionBdd(connect.getPoolConnexion());
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("bdd.fait")));
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BaseDeDoneesHelper(mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper) FacesMessage(javax.faces.application.FacesMessage)

Example 2 with BaseDeDoneesHelper

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

the class BaseDeDonnesBean method newDB.

/**
 * @throws SQLException
 * @throws IOException
 * @throws ClassNotFoundException
 */
public void newDB() throws SQLException, IOException, ClassNotFoundException {
    InputStream inputStream = this.getClass().getResourceAsStream("/install/opentheso_dist_4.1.sql");
    BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
    if (dbName != null) {
        BaseDeDoneesHelper basedonne = new BaseDeDoneesHelper();
        if (!basedonne.createBdD(connect.getPoolConnexion(), dbName, "")) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("error")));
        }
        if (!basedonne.insertDonnees(connect.getPoolConnexion(), inputStream, "")) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("error")));
        }
    } else {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("bdd.name")));
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BaseDeDoneesHelper(mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper) BufferedReader(java.io.BufferedReader) FacesMessage(javax.faces.application.FacesMessage)

Example 3 with BaseDeDoneesHelper

use of mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper 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 4 with BaseDeDoneesHelper

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

the class AutoInstall method createBdd.

/**
 * Permet de créer la BDD à partir du fichier opentheso_current.sql;
 * @return
 */
public boolean createBdd() {
    if (!validateConf()) {
        return false;
    }
    // on fait la connexion avec le parametres donées
    messages = "-> Connexion en cours !!!!!";
    if (!openConnexionPoolInstall()) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("inst.Err1")));
        messages = langueBean.getMsg("inst.Err1");
        return false;
    }
    BaseDeDoneesHelper baseDeDoneesHelper = new BaseDeDoneesHelper();
    // on fait la comprobation de que l'user n'exist pas
    // Si exist ne le creer pas
    messages += "<br>";
    messages += "-> Connexion établie";
    if (!baseDeDoneesHelper.isUserExist(poolConnexionInstall, nomAdmin)) {
        if (!baseDeDoneesHelper.createUser(poolConnexionInstall, nomAdmin, passwordAdmin)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("isnt.Err2")));
            messages += "<br>";
            messages += "-" + langueBean.getMsg("isnt.Err2");
            return false;
        }
        messages += "<br>";
        messages += "-> Utilisateur créé";
    }
    // si exists tout c'est fini, on ne continue pas ERROR!!
    if (!baseDeDoneesHelper.isBddExist(poolConnexionInstall, databaseName)) {
        if (!baseDeDoneesHelper.createBdD(poolConnexionInstall, databaseName, nomAdmin)) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("isnt.Err3")));
            messages += "<br>";
            messages += "-> " + langueBean.getMsg("isnt.Err3");
            return false;
        }
        messages += "<br>";
        messages += "-> Bdd installée";
    } else {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("inst.Err4")));
        messages += "<br>" + "-> " + langueBean.getMsg("inst.Err4");
        return false;
    }
    closeConnexion();
    // on refait la connexion avec la nouvelle base de données
    localDatabaseName = databaseName;
    if (!openConnexionPoolInstall()) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("inst.Err1")));
        return false;
    }
    // injection des tables et initialisation des données dans la base
    messages += "<br>";
    messages += "-> Connexion en cours à la nouvelle BDD !!!!!";
    messages += "<br>";
    // on prendre tout l'information à partir du fichier current
    InputStream inputStream = this.getClass().getResourceAsStream("/install/opentheso_current.sql");
    if (!baseDeDoneesHelper.insertDonnees(poolConnexionInstall, inputStream, nomAdmin)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("inst.Err1")));
        messages += "<br>";
        messages += "-> Erreur lors de l'insertion des tables et données primaires ???";
        return false;
    }
    // on rempli la table de la BDD pour avoir l'infomation enregistré
    if (!baseDeDoneesHelper.insertVersionBdd(poolConnexionInstall)) {
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("error") + " :", langueBean.getMsg("inst.Err1")));
        messages += "<br>";
        messages += "-Error update VersionBdd!!!!!";
    }
    // On ecrit le fichier hikari.properties la configuration pour redemarrer
    createPropertiesFile();
    messages += "<br>";
    messages += "-> Installation réussie !!!!!";
    messages += "<br><br>";
    messages += "-> n'oubliez pas de re-démarrer Tomcat !!!!!";
    return true;
}
Also used : BaseDeDoneesHelper(mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper) InputStream(java.io.InputStream) FacesMessage(javax.faces.application.FacesMessage)

Example 5 with BaseDeDoneesHelper

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

the class BaseDeDonnesBean method loadinfoDB.

/**
 * Function que prepare l'information pour le montres apres
 * @return
 * @throws SQLException
 * @throws IOException
 */
public ArrayList<BaseDeDoneesHelper> loadinfoDB() throws SQLException, IOException {
    BaseDeDoneesHelper basedone = new BaseDeDoneesHelper();
    info = basedone.info_out(connect.getPoolConnexion());
    return info;
}
Also used : BaseDeDoneesHelper(mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper)

Aggregations

BaseDeDoneesHelper (mom.trd.opentheso.bdd.helper.BaseDeDoneesHelper)6 FacesMessage (javax.faces.application.FacesMessage)4 InputStream (java.io.InputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)2 UserHelper (mom.trd.opentheso.bdd.helper.UserHelper)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 SQLException (java.sql.SQLException)1 FacesContext (javax.faces.context.FacesContext)1 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)1 NodeUser (mom.trd.opentheso.bdd.helper.nodes.NodeUser)1