Search in sources :

Example 1 with ReadFileSKOS

use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.

the class AlignmentQuery method queryOpentheso.

/**
 * Cette fonction permet de récupérer les alignements présents sur Opentheso
 * pour un concept passé en paramètre et un thésaurus donné
 *
 * @param idC
 * @param idTheso
 * @param lexicalValue
 * @param lang
 * @param requete
 * @param source
 * @return
 */
public ArrayList<NodeAlignment> queryOpentheso(String idC, String idTheso, String lexicalValue, String lang, String requete, String source) {
    if (requete.trim().equals("")) {
        return null;
    }
    if (lexicalValue.trim().equals("")) {
        return null;
    }
    listeAlign = new ArrayList<>();
    // construction de la requête de type (webservices Opentheso)
    lexicalValue = lexicalValue.replaceAll(" ", "%20");
    requete = requete.replace("##lang##", lang);
    requete = requete.replace("##value##", lexicalValue);
    try {
        URL url = new URL(requete);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Accept", "application/xml");
        if (conn.getResponseCode() != 200) {
            throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
        String output;
        String xmlRecord = "";
        while ((output = br.readLine()) != null) {
            xmlRecord += output;
        }
        byte[] bytes = xmlRecord.getBytes();
        xmlRecord = new String(bytes, Charset.forName("UTF-8"));
        conn.disconnect();
        StringBuffer sb = new StringBuffer(xmlRecord);
        try {
            SKOSXmlDocument sxd = new ReadFileSKOS().readStringBuffer(sb);
            for (SKOSResource resource : sxd.getResourcesList()) {
                NodeAlignment na = new NodeAlignment();
                na.setInternal_id_concept(idC);
                na.setInternal_id_thesaurus(idTheso);
                // "Pactols");
                na.setThesaurus_target(source);
                na.setUri_target(resource.getUri());
                for (SKOSLabel label : resource.getLabelsList()) {
                    switch(label.getProperty()) {
                        case SKOSProperty.prefLabel:
                            if (label.getLanguage().equals(lang)) {
                                na.setConcept_target(label.getLabel());
                            }
                            break;
                        case SKOSProperty.altLabel:
                            if (label.getLanguage().equals(lang)) {
                                if (na.getConcept_target_alt().isEmpty()) {
                                    na.setConcept_target_alt(label.getLabel());
                                } else {
                                    na.setConcept_target_alt(na.getConcept_target_alt() + ";" + label.getLabel());
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                for (SKOSDocumentation sd : resource.getDocumentationsList()) {
                    if (sd.getProperty() == SKOSProperty.definition && sd.getLanguage().equals(lang)) {
                        na.setDef_target(sd.getText());
                    }
                }
                listeAlign.add(na);
            }
        } catch (Exception ex) {
            Logger.getLogger(AlignmentQuery.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    return listeAlign;
}
Also used : MalformedURLException(java.net.MalformedURLException) SKOSXmlDocument(skos.SKOSXmlDocument) SKOSLabel(skos.SKOSLabel) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) SAXException(org.xml.sax.SAXException) NodeAlignment(mom.trd.opentheso.bdd.helper.nodes.NodeAlignment) HttpURLConnection(java.net.HttpURLConnection) SKOSResource(skos.SKOSResource) SKOSDocumentation(skos.SKOSDocumentation) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 2 with ReadFileSKOS

use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.

the class TestImportBranch method readSkosFile.

private SKOSXmlDocument readSkosFile(HikariDataSource conn, FileInputStream file, String dateFromat, boolean useArk, String adresseSite) {
    try {
        ReadFileSKOS readFileSKOS = new ReadFileSKOS();
        readFileSKOS.readBranchFile(conn, file, dateFromat, useArk, adresseSite);
        SKOSXmlDocument sKOSXmlDocument = readFileSKOS.getThesaurus();
        return sKOSXmlDocument;
    } catch (Exception ex) {
        Logger.getLogger(TestImportBranch.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 3 with ReadFileSKOS

use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.

the class JsonHelper method readSkosDocument.

public SKOSXmlDocument readSkosDocument(StringBuffer skosStringBuffer) {
    SKOSXmlDocument sKOSXmlDocument;
    try {
        ReadFileSKOS readFileSKOS = new ReadFileSKOS();
        sKOSXmlDocument = readFileSKOS.readStringBuffer(skosStringBuffer);
        return sKOSXmlDocument;
    } catch (Exception ex) {
        Logger.getLogger(JsonHelper.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
Also used : SKOSXmlDocument(skos.SKOSXmlDocument) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS)

Example 4 with ReadFileSKOS

use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.

the class FileBean method chargeSkos.

/**
 * Cette fonction permet d'insérer un thésaurus en base de données à partir
 * d'un fichier Skos
 *
 * @param event
 */
public void chargeSkos(FileUploadEvent event) {
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
    } else {
        UploadedFile file = event.getFile();
        if (formatDate == null || formatDate.equals("") || user == null || user.getNodePreference() == null) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error2")));
        } else {
            try {
                boolean useArk = false;
                useArk = user.getNodePreference().isUseArk();
                // bundlePref.getString("cheminSite");
                String adressSite = user.getNodePreference().getCheminSite();
                int idUser = selectedTerme.getUser().getUser().getId();
                new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, idUser, langueSource);
            } catch (IOException ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            vue.setAddSkos(false);
        }
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) IOException(java.io.IOException) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS) FacesMessage(javax.faces.application.FacesMessage) IOException(java.io.IOException)

Example 5 with ReadFileSKOS

use of mom.trd.opentheso.core.imports.old.ReadFileSKOS in project opentheso by miledrousset.

the class FileBean_progress method chargeSkos.

/**
 * Cette fonction permet d'insérer un thésaurus en base de données à partir
 * d'un fichier Skos
 *
 * @param event
 */
public void chargeSkos(FileUploadEvent event) {
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
    } else {
        UploadedFile file = event.getFile();
        if (formatDate == null || formatDate.equals("")) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error2")));
        } else {
            try {
                boolean useArk = false;
                ResourceBundle bundlePref = getBundlePref();
                if (bundlePref.getString("useArk").equalsIgnoreCase("true")) {
                    useArk = true;
                }
                String adressSite = bundlePref.getString("cheminSite");
                int idUser = selectedTerme.getUser().getUser().getId();
                new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, idUser, "");
            } catch (IOException ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            vue.setAddSkos(false);
        }
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) ReadFileSKOS(mom.trd.opentheso.core.imports.old.ReadFileSKOS) FacesMessage(javax.faces.application.FacesMessage) SKOSCreationException(org.semanticweb.skos.SKOSCreationException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) IOException(java.io.IOException)

Aggregations

ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)6 SKOSXmlDocument (skos.SKOSXmlDocument)4 IOException (java.io.IOException)3 FacesMessage (javax.faces.application.FacesMessage)2 UploadedFile (org.primefaces.model.UploadedFile)2 FileNotFoundException (java.io.FileNotFoundException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ResourceBundle (java.util.ResourceBundle)1 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)1 JsonHelper (mom.trd.opentheso.core.jsonld.helper.JsonHelper)1 Test (org.junit.Test)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 SKOSCreationException (org.semanticweb.skos.SKOSCreationException)1 SAXException (org.xml.sax.SAXException)1 SKOSDocumentation (skos.SKOSDocumentation)1 SKOSLabel (skos.SKOSLabel)1 SKOSResource (skos.SKOSResource)1