Search in sources :

Example 21 with NodeNote

use of mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote in project opentheso by miledrousset.

the class NoteHelper method getListNotesTermAllLang.

/**
 * Cette focntion permet de retourner la liste des notes pour un Term(type
 * HistoryNote, Definition, EditotrialNote) dans toutes les langues
 *
 * @param ds
 * @param idThesaurus
 * @param idTerm
 * @return ArrayList des notes sous forme de Class NodeNote
 */
public ArrayList<NodeNote> getListNotesTermAllLang(HikariDataSource ds, String idTerm, String idThesaurus) {
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    StringPlus stringPlus = new StringPlus();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT note.id, note.notetypecode," + " note.lexicalvalue, note.created," + " note.modified, note.lang FROM note, note_type" + " WHERE note.notetypecode = note_type.code" + " and note_type.isterm = true" + " and note.id_term = '" + idTerm + "'" + " and note.id_thesaurus = '" + idThesaurus + "'";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeNote nodeNote = new NodeNote();
                    nodeNote.setId_term(idTerm);
                    nodeNote.setId_note(resultSet.getInt("id"));
                    nodeNote.setLang(resultSet.getString("lang"));
                    nodeNote.setLexicalvalue(stringPlus.normalizeStringForXml(resultSet.getString("lexicalvalue")));
                    nodeNote.setModified(resultSet.getDate("modified"));
                    nodeNote.setCreated(resultSet.getDate("created"));
                    nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                    nodeNotes.add(nodeNote);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting All Notes of Term : " + idTerm, sqle);
    }
    return nodeNotes;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) StringPlus(mom.trd.opentheso.bdd.tools.StringPlus) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 22 with NodeNote

use of mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote in project opentheso by miledrousset.

the class NoteHelper method getNoteHistoriqueFromDate.

/**
 * Cette focntion permet de retourner la liste de l'historique des notes
 * pour un concept (type CustomNote, ScopeNote, HistoryNote) à une date
 * précise
 *
 * @param ds
 * @param idConcept
 * @param idThesaurus
 * @param idTerm
 * @param idLang
 * @param date
 * @return ArrayList des notes sous forme de Class NodeNote
 */
public ArrayList<NodeNote> getNoteHistoriqueFromDate(HikariDataSource ds, String idConcept, String idThesaurus, String idTerm, String idLang, Date date) {
    ArrayList<NodeNote> nodeNotes = new ArrayList<>();
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT id, notetypecode, lexicalvalue, modified, username FROM note_historique, users" + " WHERE id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and (id_concept = '" + idConcept + "' OR id_term = '" + idTerm + "' )" + " and note_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified DESC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    boolean exist = false;
                    for (NodeNote nn : nodeNotes) {
                        if (nn.getNotetypecode().equals(resultSet.getString("notetypecode"))) {
                            if (nn.getModified().before(resultSet.getDate("modified"))) {
                                NodeNote nodeNote = new NodeNote();
                                nodeNote.setId_concept(idConcept);
                                nodeNote.setId_term(idTerm);
                                nodeNote.setId_note(resultSet.getInt("id"));
                                nodeNote.setLang(idLang);
                                nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                                nodeNote.setModified(resultSet.getDate("modified"));
                                nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                                nodeNote.setIdUser(resultSet.getString("username"));
                                nodeNotes.add(nodeNote);
                            }
                            exist = true;
                        }
                    }
                    if (!exist) {
                        NodeNote nodeNote = new NodeNote();
                        nodeNote.setId_concept(idConcept);
                        nodeNote.setId_term(idTerm);
                        nodeNote.setId_note(resultSet.getInt("id"));
                        nodeNote.setLang(idLang);
                        nodeNote.setLexicalvalue(resultSet.getString("lexicalvalue"));
                        nodeNote.setModified(resultSet.getDate("modified"));
                        nodeNote.setNotetypecode(resultSet.getString("notetypecode"));
                        nodeNote.setIdUser(resultSet.getString("username"));
                        nodeNotes.add(nodeNote);
                    }
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting date historique Notes of Concept : " + idConcept, sqle);
    }
    return nodeNotes;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 23 with NodeNote

use of mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote in project opentheso by miledrousset.

the class GetAllArkTest method testExportAllDatas.

/**
 * Test of Get datas for SiteMap.
 */
@org.junit.Test
public void testExportAllDatas() {
    HikariDataSource conn = openConnexionPool();
    String idTheso = "TH_1";
    ConceptHelper conceptHelper = new ConceptHelper();
    ArrayList<NodeConceptArkId> allIds = conceptHelper.getAllConceptArkIdOfThesaurus(conn, idTheso);
    StringBuilder file = new StringBuilder();
    TermHelper termHelper = new TermHelper();
    NoteHelper noteHelper = new NoteHelper();
    ArrayList<NodeTermTraduction> nodeTermTraductions;
    String idTerme;
    ArrayList<NodeNote> nodeNote;
    boolean passed = false;
    boolean notePassed = false;
    String note = "";
    for (NodeConceptArkId ids : allIds) {
        file.append(ids.getIdConcept());
        file.append("\t");
        if (ids.getIdArk() == null || ids.getIdArk().isEmpty()) {
            file.append("");
        } else {
            file.append(ids.getIdArk().substring(ids.getIdArk().indexOf("/") + 1));
        }
        nodeTermTraductions = termHelper.getAllTraductionsOfConcept(conn, ids.getIdConcept(), idTheso);
        if (!nodeTermTraductions.isEmpty()) {
            for (NodeTermTraduction nodeTermTraduction : nodeTermTraductions) {
                if (nodeTermTraduction.getLang().equalsIgnoreCase("fr")) {
                    file.append("\t");
                    file.append(nodeTermTraduction.getLexicalValue());
                // file.append("(");
                // file.append(nodeTermTraduction.getLang());
                // file.append(")");
                }
            }
        }
        idTerme = termHelper.getIdTermOfConcept(conn, ids.getIdConcept(), idTheso);
        nodeNote = noteHelper.getListNotesTerm(conn, idTerme, idTheso, "fr");
        for (NodeNote nodeNote1 : nodeNote) {
            if (nodeNote1.getLang().equalsIgnoreCase("fr")) {
                if (nodeNote1.getNotetypecode().equalsIgnoreCase("definition")) {
                    note = nodeNote1.getLexicalvalue().replace('\r', ' ');
                    note = note.replace('\n', ' ');
                    if (!notePassed) {
                        file.append("\t");
                    } else {
                        file.append(" ## ");
                    }
                    file.append(note);
                    passed = true;
                    notePassed = true;
                }
            }
        }
        if (!passed) {
            file.append("\t");
            file.append(" ");
        }
        passed = false;
        notePassed = false;
        file.append("\n");
    }
    System.out.println(file.toString());
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) NoteHelper(mom.trd.opentheso.bdd.helper.NoteHelper) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) NodeConceptArkId(mom.trd.opentheso.bdd.helper.nodes.NodeConceptArkId) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) TermHelper(mom.trd.opentheso.bdd.helper.TermHelper)

Example 24 with NodeNote

use of mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote in project opentheso by miledrousset.

the class ExportRdf4jHelper method addNoteGiven.

private void addNoteGiven(ArrayList<NodeNote> nodeNotes, SKOSResource resource) {
    for (NodeNote note : nodeNotes) {
        int prop;
        switch(note.getNotetypecode()) {
            case "scopeNote":
                prop = SKOSProperty.scopeNote;
                break;
            case "historyNote":
                prop = SKOSProperty.historyNote;
                break;
            case "definition":
                prop = SKOSProperty.definition;
                break;
            case "editorialNote":
                prop = SKOSProperty.editorialNote;
                break;
            default:
                prop = SKOSProperty.note;
                break;
        }
        resource.addDocumentation(note.getLexicalvalue(), note.getLang(), prop);
    }
}
Also used : NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)

Example 25 with NodeNote

use of mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote in project opentheso by miledrousset.

the class ExportRdf4jHelper method writeConceptInfo.

private void writeConceptInfo(ConceptHelper conceptHelper, SKOSResource sKOSResource, String idThesaurus, String idOfConceptChildren, DownloadBean downloadBean, List<NodeLang> selectedLanguages) {
    NodeConceptExport nodeConcept = conceptHelper.getConceptForExport(ds, idOfConceptChildren, idThesaurus, false);
    if (nodeConcept == null) {
        return;
    }
    sKOSResource.setUri(getUri(nodeConcept));
    sKOSResource.setProperty(SKOSProperty.Concept);
    // prefLabel
    for (NodeTermTraduction traduction : nodeConcept.getNodeTermTraductions()) {
        boolean isInselectedLanguages = false;
        for (NodeLang nodeLang : selectedLanguages) {
            if (nodeLang.getCode().equals(traduction.getLang())) {
                isInselectedLanguages = true;
                break;
            }
        }
        if (isInselectedLanguages) {
            sKOSResource.addLabel(traduction.getLexicalValue(), traduction.getLang(), SKOSProperty.prefLabel);
        }
    }
    // altLabel
    for (NodeEM nodeEM : nodeConcept.getNodeEM()) {
        boolean isInselectedLanguages = false;
        for (NodeLang nodeLang : selectedLanguages) {
            if (nodeLang.getCode().equals(nodeEM.getLang())) {
                isInselectedLanguages = true;
                break;
            }
        }
        if (isInselectedLanguages) {
            sKOSResource.addLabel(nodeEM.getLexical_value(), nodeEM.getLang(), SKOSProperty.altLabel);
        }
    }
    ArrayList<NodeNote> nodeNotes = nodeConcept.getNodeNoteConcept();
    nodeNotes.addAll(nodeConcept.getNodeNoteTerm());
    addNoteGiven(nodeNotes, sKOSResource, selectedLanguages);
    addGPSGiven(nodeConcept.getNodeGps(), sKOSResource);
    addAlignementGiven(nodeConcept.getNodeAlignmentsList(), sKOSResource);
    addRelationGiven(nodeConcept.getNodeListOfBT(), nodeConcept.getNodeListOfNT(), nodeConcept.getNodeListIdsOfRT(), sKOSResource, nodeConcept.getConcept().getIdThesaurus());
    String notation = nodeConcept.getConcept().getNotation();
    String created = nodeConcept.getConcept().getCreated().toString();
    String modified = nodeConcept.getConcept().getModified().toString();
    if (notation != null && !notation.equals("null")) {
        sKOSResource.addNotation(notation);
    }
    if (created != null) {
        sKOSResource.addDate(created, SKOSProperty.created);
    }
    if (modified != null) {
        sKOSResource.addDate(modified, SKOSProperty.modified);
    }
    sKOSResource.addRelation(getUriFromId(idTheso), SKOSProperty.inScheme);
    sKOSResource.addIdentifier(nodeConcept.getConcept().getIdConcept(), SKOSProperty.identifier);
    downloadBean.setProgress_abs(downloadBean.getProgress_abs() + 1);
    double progress = (downloadBean.getProgress_abs() / downloadBean.getSizeOfTheso()) * 100;
    if (progress > 100) {
        progress = 100;
    }
    downloadBean.setProgress_per_100((int) progress);
    skosXmlDocument.addconcept(sKOSResource);
}
Also used : NodeConceptExport(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptExport) NodeLang(mom.trd.opentheso.bdd.helper.nodes.NodeLang) NodeTermTraduction(mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction) NodeNote(mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote) NodeEM(mom.trd.opentheso.bdd.helper.nodes.NodeEM)

Aggregations

NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)34 NodeEM (mom.trd.opentheso.bdd.helper.nodes.NodeEM)17 ArrayList (java.util.ArrayList)14 SQLException (java.sql.SQLException)12 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)12 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)12 Connection (java.sql.Connection)11 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)11 Term (mom.trd.opentheso.bdd.datas.Term)10 Concept (mom.trd.opentheso.bdd.datas.Concept)9 NodeTerm (mom.trd.opentheso.bdd.helper.nodes.term.NodeTerm)9 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)9 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)8 AlignmentHelper (mom.trd.opentheso.bdd.helper.AlignmentHelper)8 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)7 SKOSMapping (skos.SKOSMapping)5 SKOSTopConcept (skos.SKOSTopConcept)5 HierarchicalRelationship (mom.trd.opentheso.bdd.datas.HierarchicalRelationship)4 NodeLang (mom.trd.opentheso.bdd.helper.nodes.NodeLang)4