Search in sources :

Example 21 with UserHelper2

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

the class CsvImportHelper method createTheso.

/**
 * Cette fonction permet de créer un thésaurus avec ses traductions (Import)
 * elle retourne l'identifiant du thésaurus, sinon Null
 *
 * @return
 */
private String createTheso(HikariDataSource ds, String thesoName) {
    try {
        Thesaurus thesaurus = new Thesaurus();
        thesaurus.setCreator("");
        thesaurus.setContributor("");
        ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
        thesaurusHelper.setIdentifierType("2");
        Connection conn = ds.getConnection();
        conn.setAutoCommit(false);
        String idTheso1;
        if (thesaurus.getLanguage() == null) {
            thesaurus.setLanguage(langueSource);
        }
        if ((idTheso1 = thesaurusHelper.addThesaurusRollBack(conn, "", false)) == null) {
            conn.rollback();
            conn.close();
            return null;
        }
        thesaurus.setId_thesaurus(idTheso1);
        if (thesoName.isEmpty()) {
            thesoName = "theso_" + idTheso1;
        }
        thesaurus.setTitle(thesoName);
        if (!thesaurusHelper.addThesaurusTraductionRollBack(conn, thesaurus)) {
            conn.rollback();
            conn.close();
            return null;
        }
        // ajouter le thésaurus dans le group de l'utilisateur
        if (idGroupUser != -1) {
            // si le groupeUser = - 1, c'est le cas d'un SuperAdmin, alors on n'intègre pas le thésaurus dans un groupUser
            UserHelper2 userHelper = new UserHelper2();
            if (!userHelper.addThesoToGroup(conn, thesaurus.getId_thesaurus(), idGroupUser)) {
                conn.rollback();
                conn.close();
                return null;
            }
        }
        conn.commit();
        conn.close();
        return idTheso1;
    } catch (SQLException ex) {
        Logger.getLogger(CsvImportHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) SQLException(java.sql.SQLException) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) Connection(java.sql.Connection) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2)

Example 22 with UserHelper2

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

the class RoleOnThesoBean method setOwnerThesos.

/**
 * fonction pour sortir une liste (sous forme de hashMap ) de thesaurus
 * correspondant à l'utilisateur connecté
 * permet de charger les thésaurus autorisés pour l'utilisateur en cours
 * on récupère les id puis les tradcutions (ceci permet de récupérer les thésaurus non traduits)
 * #MR
 */
private void setOwnerThesos() {
    if (user.getUser() == null) {
        this.listTheso = new HashMap();
        return;
    }
    authorizedTheso = new ArrayList<>();
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    UserHelper2 userHelper = new UserHelper2();
    if (user.getUser().isIsSuperAdmin()) {
        boolean withPrivateTheso = true;
        authorizedTheso = thesaurusHelper.getAllIdOfThesaurus(connect.getPoolConnexion(), withPrivateTheso);
    } else {
        authorizedTheso = userHelper.getThesaurusOfUser(connect.getPoolConnexion(), user.getUser().getIdUser());
    }
    addAuthorizedThesoToHM();
    // permet de définir le role de l'utilisateur sur le group
    if (authorizedTheso.isEmpty())
        setUserRoleGroup();
// setUserRoleOnThisTheso();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) AccessThesaurusHelper(mom.trd.opentheso.bdd.helper.AccessThesaurusHelper) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2)

Example 23 with UserHelper2

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

the class UserHelperTest method getLabelGroup.

@Test
public void getLabelGroup() {
    UserHelper2 userHelper2 = new UserHelper2();
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource conn = connexionTest.getConnexionPool();
    String label = userHelper2.getGroupName(conn, 1);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Example 24 with UserHelper2

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

the class UserHelperTest method getUser.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void getUser() {
    int idUser = 15;
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource conn = connexionTest.getConnexionPool();
    UserHelper2 userHelper2 = new UserHelper2();
    NodeUser2 nodeUser = userHelper2.getUser(conn, idUser);
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2) NodeUser2(mom.trd.opentheso.bdd.helper.nodes.NodeUser2) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Example 25 with UserHelper2

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

the class UserHelperTest method getAuthorizedRoles.

@Test
public void getAuthorizedRoles() {
    UserHelper2 userHelper2 = new UserHelper2();
    ConnexionTest connexionTest = new ConnexionTest();
    HikariDataSource conn = connexionTest.getConnexionPool();
    ArrayList<Map.Entry<String, String>> authorizedRols = userHelper2.getAuthorizedRoles(conn, 3);
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) UserHelper2(mom.trd.opentheso.bdd.helper.UserHelper2) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Aggregations

UserHelper2 (mom.trd.opentheso.bdd.helper.UserHelper2)48 FacesMessage (javax.faces.application.FacesMessage)19 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)8 ThesaurusHelper (mom.trd.opentheso.bdd.helper.ThesaurusHelper)6 HikariDataSource (com.zaxxer.hikari.HikariDataSource)5 ConnexionTest (connexion.ConnexionTest)5 Thesaurus (mom.trd.opentheso.bdd.datas.Thesaurus)5 Test (org.junit.Test)5 AccessThesaurusHelper (mom.trd.opentheso.bdd.helper.AccessThesaurusHelper)3 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)3 LinkedHashMap (java.util.LinkedHashMap)2 CandidateHelper (mom.trd.opentheso.bdd.helper.CandidateHelper)2 NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)2 NodeUserRoleGroup (mom.trd.opentheso.bdd.helper.nodes.NodeUserRoleGroup)2 PrimeFaces (org.primefaces.PrimeFaces)2 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)1 NodeUser2 (mom.trd.opentheso.bdd.helper.nodes.NodeUser2)1