Search in sources :

Example 6 with NodePreference

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

the class DownloadBean method conceptToFile.

/**
 * Cette fonction permet d'exporter un concept en SKOS en temps réel dans la
 * page principale
 *
 * @param idConcept
 * @param idTheso
 * @param type
 * @return
 */
public StreamedContent conceptToFile(String idConcept, String idTheso, int type) {
    RDFFormat format = null;
    String extention = "";
    switch(type) {
        case 0:
            format = RDFFormat.RDFXML;
            extention = "_skos.xml";
            break;
        case 1:
            format = RDFFormat.JSONLD;
            extention = "_json-ld.json";
            break;
        case 2:
            format = RDFFormat.TURTLE;
            extention = "_turtle.ttl";
            break;
        case 3:
            format = RDFFormat.RDFJSON;
            extention = "_turtle.ttl";
            break;
    }
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreference(connect.getPoolConnexion(), idTheso);
    if (nodePreference == null)
        return null;
    ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.setInfos(connect.getPoolConnexion(), "dd-mm-yyyy", false, idTheso, nodePreference.getCheminSite());
    exportRdf4jHelper.setNodePreference(nodePreference);
    exportRdf4jHelper.addSignleConcept(idTheso, idConcept);
    WriteRdf4j writeRdf4j = new WriteRdf4j(exportRdf4jHelper.getSkosXmlDocument());
    ByteArrayOutputStream out;
    out = new ByteArrayOutputStream();
    Rio.write(writeRdf4j.getModel(), out, format);
    file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
    return file;
// new ExportFromBDD().exportConcept(connect.getPoolConnexion(), idTheso, idC).toString();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.helper.ExportRdf4jHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayContent(org.primefaces.model.ByteArrayContent) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 7 with NodePreference

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

the class PreferencesHelper method getThesaurusPreference.

public NodePreference getThesaurusPreference(HikariDataSource ds, String idThesaurus) {
    NodePreference np = null;
    Connection conn;
    Statement stmt;
    ResultSet resultSet;
    try {
        conn = ds.getConnection();
        try {
            stmt = conn.createStatement();
            try {
                String query = "SELECT * FROM preferences where id_thesaurus = '" + idThesaurus + "'";
                resultSet = stmt.executeQuery(query);
                if (resultSet.next()) {
                    np = new NodePreference();
                    np.setSourceLang(resultSet.getString("source_lang"));
                    np.setIdentifierType(resultSet.getInt("identifier_type"));
                    // Ark
                    np.setUseArk(resultSet.getBoolean("use_ark"));
                    np.setServeurArk(resultSet.getString("server_ark"));
                    np.setIdNaan(resultSet.getString("id_naan"));
                    np.setPrefixArk(resultSet.getString("prefix_ark"));
                    np.setUserArk(resultSet.getString("user_ark"));
                    np.setPassArk(resultSet.getString("pass_ark"));
                    // Handle
                    np.setUseHandle(resultSet.getBoolean("use_handle"));
                    np.setUserHandle(resultSet.getString("user_handle"));
                    np.setPassHandle(resultSet.getString("pass_handle"));
                    np.setPathKeyHandle(resultSet.getString("path_key_handle"));
                    np.setPathCertHandle(resultSet.getString("path_cert_handle"));
                    np.setUrlApiHandle(resultSet.getString("url_api_handle"));
                    np.setPrefixIdHandle(resultSet.getString("prefix_handle"));
                    np.setPrivatePrefixHandle(resultSet.getString("private_prefix_handle"));
                    np.setPathImage(resultSet.getString("path_image"));
                    np.setDossierResize(resultSet.getString("dossier_resize"));
                    np.setBddActive(resultSet.getBoolean("bdd_active"));
                    np.setBddUseId(resultSet.getBoolean("bdd_use_id"));
                    np.setUrlBdd(resultSet.getString("url_bdd"));
                    np.setUrlCounterBdd(resultSet.getString("url_counter_bdd"));
                    np.setZ3950actif(resultSet.getBoolean("z3950actif"));
                    np.setCollectionAdresse(resultSet.getString("collection_adresse"));
                    np.setNoticeUrl(resultSet.getString("notice_url"));
                    np.setUrlEncode(resultSet.getString("url_encode"));
                    np.setPathNotice1(resultSet.getString("path_notice1"));
                    np.setPathNotice2(resultSet.getString("path_notice2"));
                    np.setCheminSite(resultSet.getString("chemin_site"));
                    np.setWebservices(resultSet.getBoolean("webservices"));
                }
            } finally {
                stmt.close();
            }
        } finally {
            conn.close();
        }
    } catch (SQLException ex) {
        Logger.getLogger(UserHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return np;
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference)

Example 8 with NodePreference

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

the class Rest method getJsonLdDatas.

private String getJsonLdDatas(String value, String idLang, String idTheso) {
    ArrayList<String> listId = getListId(value, idLang, idTheso);
    NodePreference nodePreference1 = new PreferencesHelper().getThesaurusPreference(ds, idTheso);
    if (nodePreference != null) {
        ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
        exportRdf4jHelper.setNodePreference(nodePreference1);
        exportRdf4jHelper.setInfos(ds, "dd-mm-yyyy", false, idTheso, nodePreference1.getCheminSite());
        exportRdf4jHelper.setNodePreference(nodePreference1);
        for (String idConcept : listId) {
            exportRdf4jHelper.addSignleConcept(idTheso, idConcept);
        }
        WriteRdf4j writeRdf4j = new WriteRdf4j(exportRdf4jHelper.getSkosXmlDocument());
        ByteArrayOutputStream out;
        out = new ByteArrayOutputStream();
        Rio.write(writeRdf4j.getModel(), out, RDFFormat.JSONLD);
        // System.out.println(out.toString());
        return out.toString();
    }
    return messageEmptyJson();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.helper.ExportRdf4jHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper)

Example 9 with NodePreference

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

the class ExportJsonTest method getJson.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void getJson() {
    String idConcept1 = "14767";
    String idConcept2 = "36825";
    String idTheso = "TH_1";
    int type = 3;
    RDFFormat format = null;
    String extention;
    switch(type) {
        case 0:
            format = RDFFormat.RDFXML;
            extention = "_skos.xml";
            break;
        case 1:
            format = RDFFormat.JSONLD;
            extention = "_json-ld.json";
            break;
        case 2:
            format = RDFFormat.TURTLE;
            extention = "_turtle.ttl";
            break;
        case 3:
            format = RDFFormat.RDFJSON;
            extention = "_json.json";
            break;
    }
    HikariDataSource ds;
    ConnexionTest connexionTest = new ConnexionTest();
    ds = connexionTest.getConnexionPool();
    NodePreference nodePreference = new PreferencesHelper().getThesaurusPreference(ds, idTheso);
    if (nodePreference != null) {
        ExportRdf4jHelper exportRdf4jHelper = new ExportRdf4jHelper();
        exportRdf4jHelper.setNodePreference(nodePreference);
        exportRdf4jHelper.setInfos(ds, "dd-mm-yyyy", false, idTheso, nodePreference.getCheminSite());
        exportRdf4jHelper.setNodePreference(nodePreference);
        exportRdf4jHelper.addSignleConcept(idTheso, idConcept1);
        exportRdf4jHelper.addSignleConcept(idTheso, idConcept2);
        WriteRdf4j writeRdf4j = new WriteRdf4j(exportRdf4jHelper.getSkosXmlDocument());
        ByteArrayOutputStream out;
        out = new ByteArrayOutputStream();
        Rio.write(writeRdf4j.getModel(), out, format);
        System.out.println(out.toString());
    // file = new ByteArrayContent(out.toByteArray(), "application/xml", idTheso + " " + extention);
    }
    ds.close();
}
Also used : WriteRdf4j(mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j) HikariDataSource(com.zaxxer.hikari.HikariDataSource) ConnexionTest(connexion.ConnexionTest) ExportRdf4jHelper(mom.trd.opentheso.core.exports.rdf4j.helper.ExportRdf4jHelper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NodePreference(mom.trd.opentheso.bdd.helper.nodes.NodePreference) RDFFormat(org.eclipse.rdf4j.rio.RDFFormat) PreferencesHelper(mom.trd.opentheso.bdd.helper.PreferencesHelper) ConnexionTest(connexion.ConnexionTest) Test(org.junit.Test)

Aggregations

NodePreference (mom.trd.opentheso.bdd.helper.nodes.NodePreference)9 PreferencesHelper (mom.trd.opentheso.bdd.helper.PreferencesHelper)8 ExportRdf4jHelper (mom.trd.opentheso.core.exports.rdf4j.helper.ExportRdf4jHelper)7 WriteRdf4j (mom.trd.opentheso.core.exports.rdf4j.WriteRdf4j)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)2 ByteArrayContent (org.primefaces.model.ByteArrayContent)2 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 ConnexionTest (connexion.ConnexionTest)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ExportTxtHelper (mom.trd.opentheso.core.exports.helper.ExportTxtHelper)1 WritePdf (mom.trd.opentheso.core.exports.pdf.WritePdf)1