Search in sources :

Example 21 with Concept

use of mom.trd.opentheso.bdd.datas.Concept in project opentheso by miledrousset.

the class ConceptHelper method getConceptHisoriqueFromDate.

/**
 * Cette fonction permet de récupérer l'historique d'un concept à une date
 * précise
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param date
 * @return String idGroup
 */
public ArrayList<Concept> getConceptHisoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, java.util.Date date) {
    ArrayList<Concept> listeConcept = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT modified, status, notation, top_concept, id_group, username from concept_historique, users where id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConcept + "'" + " and concept_historique.id_user=users.id_user" + " and modified <= '" + date + "' order by modified DESC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                if (resultSet != null) {
                    while (resultSet.next()) {
                        Concept c = new Concept();
                        c.setIdConcept(idConcept);
                        c.setIdThesaurus(idThesaurus);
                        c.setModified(resultSet.getDate("modified"));
                        c.setStatus(resultSet.getString("status"));
                        c.setNotation(resultSet.getString("notation"));
                        c.setTopConcept(resultSet.getBoolean("top_concept"));
                        c.setIdGroup(resultSet.getString("id_group"));
                        c.setUserName(resultSet.getString("username"));
                        listeConcept.add(c);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting date historique of Concept : " + idConcept, sqle);
    }
    return listeConcept;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 22 with Concept

use of mom.trd.opentheso.bdd.datas.Concept in project opentheso by miledrousset.

the class ConceptHelper method desactiveConcept.

/**
 * Cette fonction permet de désactiver un concept (hidden)
 *
 * @param ds
 * @param idConcept
 * @param idTheso
 * @param idUser
 * @return
 */
public boolean desactiveConcept(HikariDataSource ds, String idConcept, String idTheso, int idUser) {
    Connection conn;
    Statement stmt;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        conn.setAutoCommit(false);
        try {
            stmt = conn.createStatement();
            try {
                Concept concept = getThisConcept(ds, idConcept, idTheso);
                concept.setStatus("hidden");
                if (!addConceptHistorique(conn, concept, idUser)) {
                    conn.rollback();
                    conn.close();
                    return false;
                }
                String query = "UPDATE concept " + "set status='hidden'" + " WHERE id_concept ='" + idConcept + "'" + " AND id_thesaurus='" + idTheso + "'";
                stmt.executeUpdate(query);
                conn.commit();
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error during desactivation of Concept : " + idConcept, sqle);
        return false;
    }
    return true;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 23 with Concept

use of mom.trd.opentheso.bdd.datas.Concept in project opentheso by miledrousset.

the class ConceptHelper method regenerateArkId.

/**
 * permet de vérifier si l'id ark existe; si oui, on ne fait rien, s'il
 * n'existe pas, on l'ajoute.
 *
 * @param ds
 * @param url
 * @param idConcept
 * @param idLang
 * @param idTheso
 * @return #MR
 */
public boolean regenerateArkId(HikariDataSource ds, String idConcept, String idLang, String idTheso) {
    String idArk;
    ArkClient ark_Client = new ArkClient();
    Concept concept = getThisConcept(ds, idConcept, idTheso);
    if (concept.getIdArk() == null) {
        // création d'un identifiant Ark
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    if (concept.getIdArk().isEmpty()) {
        // création d'un identifiant Ark
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    // ici, nous avons un  IdArk, on vérifie s'il est encore valide ?
    idArk = ark_Client.getInfosArkId(concept.getIdArk());
    // exp :  idArk = ark_Client.getInfosArkId("66666/pcrtgG3244vfqgI8");
    if (idArk == null) {
        // l'idArk n'est plus valide, il faut le créer
        return prepareToAddArkId(ds, idConcept, idLang, idTheso);
    }
    // ici l'idArk est valide, on ne fait rien.
    return true;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) ArkClient(mom.trd.opentheso.ws.ark.ArkClient)

Example 24 with Concept

use of mom.trd.opentheso.bdd.datas.Concept in project opentheso by miledrousset.

the class ConceptHelper method getThisConcept.

/**
 * deprecated by Miled Cette fonction permet d'insérrer un Concept dans la
 * table Concept avec un idConcept existant (Import)
 *
 * @param ds
 * @param concept
 * @param urlSite
 * @param isArkActive
 * @param idUser
 * @return
 */
/*   public boolean insertConceptInTable(HikariDataSource ds,
            Concept concept, String urlSite, boolean isArkActive, int idUser) {

        Connection conn;
        Statement stmt;
        boolean status = false;
        if (concept.getCreated() == null) {
            concept.setCreated(new java.util.Date());
        }
        if (concept.getModified() == null) {
            concept.setModified(new java.util.Date());
        }
        if (concept.getStatus() == null) {
            concept.setStatus("D");
        }
        try {
            // Get connection from pool
            conn = ds.getConnection();
            String query;
            try {
                conn.setAutoCommit(false);
                stmt = conn.createStatement();
                try {*/
/**
 * récupération du code Ark via WebServices
 */
/*             String idArk = "";
                    if (isArkActive) {
                        ArrayList<DcElement> dcElementsList = new ArrayList<>();
                        Ark_Client ark_Client = new Ark_Client();
                        idArk = ark_Client.getArkId(
                                new FileUtilities().getDate(),
                                urlSite + "?idc=" + concept.getIdConcept() + "&idt=" + concept.getIdThesaurus(),
                                "", "", dcElementsList, "pcrt"); // pcrt : p= pactols, crt=code DCMI pour collection
                        concept.setIdArk(idArk);
                    } else {
                        concept.setIdArk("");
                    }*/
/**
 * Ajout des informations dans la table Concept
 */
/*                   if (!addConceptHistorique(conn, concept, idUser)) {
                        conn.rollback();
                        conn.close();
                        return false;
                    }

                    if (concept.getCreated() == null || concept.getModified() == null) {
                        query = "Insert into concept "
                                + "(id_concept, id_thesaurus, id_ark, status, notation, top_concept)"
                                + " values ("
                                + "'" + concept.getIdConcept() + "'"
                                + ",'" + concept.getIdThesaurus() + "'"
                                + ",'" + concept.getIdArk() + "'"
                                + ",'" + concept.getStatus() + "'"
                                + ",'" + concept.getNotation() + "'"
                                + "," + concept.isTopConcept()
                                + "')";
                    } else {
                        query = "Insert into concept "
                                + "(id_concept, id_thesaurus, id_ark, created, modified, status, notation, top_concept)"
                                + " values ("
                                + "'" + concept.getIdConcept() + "'"
                                + ",'" + concept.getIdThesaurus() + "'"
                                + ",'" + concept.getIdArk() + "'"
                                + ",'" + concept.getCreated() + "'"
                                + ",'" + concept.getModified() + "'"
                                + ",'" + concept.getStatus() + "'"
                                + ",'" + concept.getNotation() + "'"
                                + ",'" + concept.isTopConcept()
                                + "')";
                    }

                    stmt.executeUpdate(query);
                    status = true;
                    conn.commit();

                } finally {
                    stmt.close();
                }
            } finally {
                conn.close();
            }
        } catch (SQLException sqle) {
            // Log exception
            if (!sqle.getMessage().contains("duplicate key value violates unique constraint")) {
                log.error("Error while adding Concept : " + concept.getIdConcept(), sqle);
            }
        }
        return status;
    }*/
/**
 * Cette fonction permet de récupérer un Concept par son id et son thésaurus
 * sous forme de classe Concept (sans les relations) ni le Terme
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @return Objet class Concept
 */
public Concept getThisConcept(HikariDataSource ds, String idConcept, String idThesaurus) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    Concept concept = null;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select * from concept left join concept_group_concept  on id_concept = idconcept and id_thesaurus = idthesaurus where id_thesaurus = '" + idThesaurus + "'" + " and id_concept = '" + idConcept + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                resultSet.next();
                if (resultSet.getRow() != 0) {
                    concept = new Concept();
                    concept.setIdConcept(idConcept);
                    concept.setIdThesaurus(idThesaurus);
                    concept.setIdArk(resultSet.getString("id_ark"));
                    concept.setIdHandle(resultSet.getString("id_handle"));
                    concept.setCreated(resultSet.getDate("created"));
                    concept.setModified(resultSet.getDate("modified"));
                    concept.setStatus(resultSet.getString("status"));
                    concept.setNotation(resultSet.getString("notation"));
                    concept.setTopConcept(resultSet.getBoolean("top_concept"));
                    concept.setIdGroup(resultSet.getString("idgroup"));
                }
                resultSet.close();
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting Concept : " + idConcept, sqle);
    }
    return concept;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 25 with Concept

use of mom.trd.opentheso.bdd.datas.Concept in project opentheso by miledrousset.

the class ConceptHelper method getConcept.

/**
 * Cette fonction permet de récupérer toutes les informations concernant un
 * Concept par son id et son thésaurus et la langue
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param idLang
 * @return Objet class NodeConcept
 */
public NodeConcept getConcept(HikariDataSource ds, String idConcept, String idThesaurus, String idLang) {
    NodeConcept nodeConcept = new NodeConcept();
    // récupération des BT
    RelationsHelper relationsHelper = new RelationsHelper();
    ArrayList<NodeBT> nodeListBT = relationsHelper.getListBT(ds, idConcept, idThesaurus, idLang);
    nodeConcept.setNodeBT(nodeListBT);
    // récupération du Concept
    Concept concept = getThisConcept(ds, idConcept, idThesaurus);
    nodeConcept.setConcept(concept);
    // récupération du Terme
    TermHelper termHelper = new TermHelper();
    Term term = termHelper.getThisTerm(ds, idConcept, idThesaurus, idLang);
    nodeConcept.setTerm(term);
    // récupération des termes spécifiques
    nodeConcept.setNodeNT(relationsHelper.getListNT(ds, idConcept, idThesaurus, idLang));
    // récupération des termes associés
    nodeConcept.setNodeRT(relationsHelper.getListRT(ds, idConcept, idThesaurus, idLang));
    // récupération des Non Prefered Term
    nodeConcept.setNodeEM(termHelper.getNonPreferredTerms(ds, term.getId_term(), idThesaurus, idLang));
    // récupération des traductions
    nodeConcept.setNodeTermTraductions(termHelper.getTraductionsOfConcept(ds, idConcept, idThesaurus, idLang));
    NoteHelper noteHelper = new NoteHelper();
    // récupération des notes du Concept
    nodeConcept.setNodeNotesConcept(noteHelper.getListNotesConcept(ds, idConcept, idThesaurus, idLang));
    // récupération des notes du term
    nodeConcept.setNodeNotesTerm(noteHelper.getListNotesTerm(ds, term.getId_term(), idThesaurus, idLang));
    GroupHelper groupHelper = new GroupHelper();
    nodeConcept.setNodeConceptGroup(groupHelper.getListGroupOfConcept(ds, idThesaurus, idConcept, idLang));
    return nodeConcept;
}
Also used : NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Concept(mom.trd.opentheso.bdd.datas.Concept) NodeBT(mom.trd.opentheso.bdd.helper.nodes.NodeBT) NodeConcept(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept) Term(mom.trd.opentheso.bdd.datas.Term)

Aggregations

Concept (mom.trd.opentheso.bdd.datas.Concept)30 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)18 Term (mom.trd.opentheso.bdd.datas.Term)15 SQLException (java.sql.SQLException)12 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)12 Connection (java.sql.Connection)11 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)10 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)10 NodeConcept (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConcept)10 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)10 ArrayList (java.util.ArrayList)9 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)9 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)9 RelationsHelper (mom.trd.opentheso.bdd.helper.RelationsHelper)7 PreparedStatement (java.sql.PreparedStatement)6 Statement (java.sql.Statement)6 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)5 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)5 SKOSMapping (skos.SKOSMapping)5 SKOSTopConcept (skos.SKOSTopConcept)5