Search in sources :

Example 1 with NodeConceptArkId

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

the class TestGetSiteMap method testExportAllDatas.

/**
 * Test of Get datas for SiteMap.
 */
@org.junit.Test
public void testExportAllDatas() {
    HikariDataSource conn = openConnexionPool();
    ConceptHelper conceptHelper = new ConceptHelper();
    ArrayList<NodeConceptArkId> nodeConceptArkIds = conceptHelper.getAllConceptArkIdOfThesaurus(conn, "TH_1");
    // ArrayList<String> allIds = conceptHelper.getAllIdConceptOfThesaurus(conn, "TH_1");
    String url;
    Date actuelle = new Date();
    // * Definition du format utilise pour les dates
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    // * Donne la date au format "aaaa-mm-jj"
    String dat = dateFormat.format(actuelle);
    StringBuilder siteMap = new StringBuilder();
    siteMap.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");
    for (NodeConceptArkId nodeConceptArkId : nodeConceptArkIds) {
        // http://ark.frantiq.fr/ark:/26678/pcrtoBSSWiOt51
        // c'est l'URL qu'il faut composer.
        siteMap.append("  <url>\n");
        siteMap.append("    <loc>");
        // siteMap.append("http://pactols.frantiq.fr/opentheso/?idc=");
        // if(nodeConceptArkId.getIdArk() == null || nodeConceptArkId.getIdArk().isEmpty()){
        siteMap.append("http://pactols.frantiq.fr/opentheso/?idc=");
        siteMap.append(nodeConceptArkId.getIdConcept());
        siteMap.append("&amp;idt=TH_1");
        /*   } else {
                siteMap.append("http://ark.frantiq.fr/ark:/");
                siteMap.append(nodeConceptArkId.getIdArk());
            }*/
        // siteMap.append(url);
        siteMap.append("</loc>\n");
        if (dat != null) {
            siteMap.append("    <lastmod>");
            siteMap.append(dat);
            siteMap.append("</lastmod>\n");
            siteMap.append("    <changefreq>");
            siteMap.append("monthly");
            siteMap.append("</changefreq>\n");
            siteMap.append("    <priority>0.9</priority>\n");
        }
        siteMap.append("  </url>\n");
    }
    /*    for (String allId : allIds) { 
            // http://pactols.frantiq.fr/opentheso/?idc=13412&idt=TH_1
            // c'est l'URL qu'il faut composer.
            
            url = conceptHelper.getIdArkOfConcept(conn, allId, "TH_1");
          //  date = conceptHelper.getModifiedDateOfConcept(conn, allId, "TH_1");

            siteMap.append("  <url>\n");
            siteMap.append("    <loc>");
            siteMap.append("http://ark.frantiq.fr/ark:/");
        //    siteMap.append("http://pactols.frantiq.fr/opentheso/?idc=");
            
            
            siteMap.append(allId);
            siteMap.append("&amp;idt=TH_1");
         //   siteMap.append(url);
            siteMap.append("</loc>\n");
            
            if(dat != null) {
                siteMap.append("    <lastmod>");
                siteMap.append(dat);
                siteMap.append("</lastmod>\n");
            }
            siteMap.append("  </url>\n");
        }
        */
    siteMap.append("</urlset>");
    System.out.println(siteMap.toString());
    conn.close();
}
Also used : HikariDataSource(com.zaxxer.hikari.HikariDataSource) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) NodeConceptArkId(mom.trd.opentheso.bdd.helper.nodes.NodeConceptArkId) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with NodeConceptArkId

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

the class ConceptHelper method getAllConceptArkIdOfThesaurus.

/**
 * Cette fonction permet de récupérer la liste des Id concept d'un thésaurus
 * (cette fonction sert pour la génération des identifiants pour Wikidata)
 *
 * @param ds
 * @param idThesaurus
 * @return ArrayList
 */
public ArrayList<NodeConceptArkId> getAllConceptArkIdOfThesaurus(HikariDataSource ds, String idThesaurus) {
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    ArrayList<NodeConceptArkId> nodeConceptArkIds = new ArrayList<>();
    try {
        // Get connection from pool
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "select id_concept, id_ark from concept where id_thesaurus = '" + idThesaurus + "' order by id_concept ASC";
                stmt.executeQuery(query);
                resultSet = stmt.getResultSet();
                while (resultSet.next()) {
                    NodeConceptArkId nodeConceptArkId = new NodeConceptArkId();
                    nodeConceptArkId.setIdConcept(resultSet.getString("id_concept"));
                    nodeConceptArkId.setIdArk(resultSet.getString("id_ark"));
                    nodeConceptArkIds.add(nodeConceptArkId);
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException sqle) {
        // Log exception
        log.error("Error while getting All Id of Concept _ Ark of Thesaurus : " + idThesaurus, sqle);
    }
    return nodeConceptArkIds;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) NodeConceptArkId(mom.trd.opentheso.bdd.helper.nodes.NodeConceptArkId)

Example 3 with NodeConceptArkId

use of mom.trd.opentheso.bdd.helper.nodes.NodeConceptArkId 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)

Aggregations

NodeConceptArkId (mom.trd.opentheso.bdd.helper.nodes.NodeConceptArkId)3 HikariDataSource (com.zaxxer.hikari.HikariDataSource)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)1 NoteHelper (mom.trd.opentheso.bdd.helper.NoteHelper)1 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)1 NodeNote (mom.trd.opentheso.bdd.helper.nodes.notes.NodeNote)1 NodeTermTraduction (mom.trd.opentheso.bdd.helper.nodes.term.NodeTermTraduction)1