Search in sources :

Example 1 with ImportSkosHelper

use of mom.trd.opentheso.core.imports.helper.ImportSkosHelper in project opentheso by miledrousset.

the class FileBean_progress method readSkos2.

/**
 * Cette fonction permet de lire un fichier Skos en utilsant le skosapi et owlapi (officiel)
 *
 * @param event
 */
public void readSkos2(FileUploadEvent event) {
    importSkosHelper = null;
    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");
                // lecture du fichier SKOS
                importSkosHelper = new ImportSkosHelper();
                importSkosHelper.setInfos(connect.getPoolConnexion(), formatDate, useArk, adressSite, selectedTerme.getUser().getUser().getIdUser(), langueSource);
                if (!importSkosHelper.readFile(file.getInputstream(), file.getFileName())) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", importSkosHelper.getMessage()));
                    return;
                }
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, langueBean.getMsg("info") + " :", importSkosHelper.getMessage()));
                desabled = false;
            }// }
             catch (IOException | OWLOntologyCreationException | SKOSCreationException ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", ex.getMessage()));
            }
        }
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) FacesMessage(javax.faces.application.FacesMessage) ImportSkosHelper(mom.trd.opentheso.core.imports.helper.ImportSkosHelper) SKOSCreationException(org.semanticweb.skos.SKOSCreationException)

Example 2 with ImportSkosHelper

use of mom.trd.opentheso.core.imports.helper.ImportSkosHelper in project opentheso by miledrousset.

the class FileBean_progress method chargeSkos2.

/**
 * Cette fonction permet d'insérer un thésaurus en base de données à partir
 * d'un fichier Skos en utilsant leskosapi et owlapi (officiel)
 *
 * @param event
 */
public void chargeSkos2(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");
                // lecture du fichier SKOS
                ImportSkosHelper importSkosHelper = new ImportSkosHelper();
                importSkosHelper.setInfos(connect.getPoolConnexion(), formatDate, useArk, adressSite, selectedTerme.getUser().getUser().getIdUser(), langueSource);
                if (!importSkosHelper.readFile(file.getInputstream(), file.getFileName())) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", importSkosHelper.getMessage()));
                    return;
                } else {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, langueBean.getMsg("info") + " :", importSkosHelper.getMessage()));
                }
                // chargement du nom du thesaurus
                if (!importSkosHelper.addThesaurus()) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Aucune information sur le thésaurus et ses domaines, un thésaurus par defaut sera créer.. " + /*langueBean.getMsg("info")*/
                    " :", importSkosHelper.getMessage()));
                    if (!importSkosHelper.addDefaultThesaurus()) {
                        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", importSkosHelper.getMessage()));
                    }
                // echec de l'ajout du nom de thésaurus
                }
                // chargement des concepts
                if (!importSkosHelper.addConcepts()) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Aucun Concept n'a été détecté dans le fichier ... " + /*langueBean.getMsg("info")*/
                    " :", importSkosHelper.getMessage()));
                // echec de l'ajout des concepts
                }
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, langueBean.getMsg("info") + " :", importSkosHelper.getMessage()));
                vue.setAddSkos2(false);
            }// }
             catch (IOException | OWLOntologyCreationException | SKOSCreationException ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", ex.getMessage()));
            }
        }
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) ResourceBundle(java.util.ResourceBundle) IOException(java.io.IOException) FacesMessage(javax.faces.application.FacesMessage) ImportSkosHelper(mom.trd.opentheso.core.imports.helper.ImportSkosHelper) SKOSCreationException(org.semanticweb.skos.SKOSCreationException)

Aggregations

IOException (java.io.IOException)2 ResourceBundle (java.util.ResourceBundle)2 FacesMessage (javax.faces.application.FacesMessage)2 ImportSkosHelper (mom.trd.opentheso.core.imports.helper.ImportSkosHelper)2 UploadedFile (org.primefaces.model.UploadedFile)2 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)2 SKOSCreationException (org.semanticweb.skos.SKOSCreationException)2