Search in sources :

Example 11 with UploadedFile

use of org.primefaces.model.UploadedFile in project opentheso by miledrousset.

the class FileBean_progress method chargeImage.

/*    public void chargeCsv(FileUploadEvent event) {
        ReadFileTabule readFileTabule = new ReadFileTabule();
        if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
            event.setPhaseId(PhaseId.INVOKE_APPLICATION);
            event.queue();
        } else {
            System.out.println(sepCol + " " + sepChamps + " " + sepLangue + " " + formatDate);
            UploadedFile file = event.getFile();
            if (sepCol == null || sepCol.equals("") || sepChamps == null || sepChamps.equals("") || sepLangue == null || sepLangue.equals("") || formatDate == null || formatDate.equals("")) {
                FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error3")));
            } else {
                try {
                    readFileTabule.setReadFile(file.getInputstream(), sepCol, sepChamps, sepLangue, formatDate);
                    readFileTabule.setFields();
                    readFileTabule.setDatas();
                    ArrayList<String> fields = readFileTabule.getFieldsList();
                    ArrayList<TabulateDocument> tabulateDocuments = readFileTabule.getTabulateDocumentList();
                    //new ImportTabuleIntoBDD().insertDatas(connect.getPoolConnexion(), source, tabulateDocuments, idUser);
                    System.out.println(fields);
                    System.out.println(tabulateDocuments);
                    vue.setAddSkos(false);
                } catch (Exception ex) {
                    Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
                }
                vue.setAddSkos(false);

            }
        }
    }*/
public void chargeImage(FileUploadEvent event) {
    int idUser = selectedTerme.getUser().getUser().getIdUser();
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
    } else {
        UploadedFile file = event.getFile();
        if (source == null || source.equals("")) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error1")));
        } else {
            try {
                // Traitement
                String suffix = FilenameUtils.getExtension(file.getFileName());
                InputStream input = file.getInputstream();
                String path = pathImage;
                SimpleDateFormat dateFormatDirectory = new SimpleDateFormat(" dd-MM-yyyy HH-mm-ss");
                String dateDirectory = dateFormatDirectory.format(new Date());
                File image = new File(path + selectedTerme.getIdC() + dateDirectory + "." + suffix);
                OutputStream output = new FileOutputStream(image);
                IOUtils.copy(input, output);
                IOUtils.closeQuietly(output);
                IOUtils.closeQuietly(input);
                System.out.println(image.getName());
                BufferedImage bimg = ImageIO.read(image);
                int width = bimg.getWidth();
                int height = bimg.getHeight();
                if (width > 1024 || height > 768) {
                    resizeToBigImage(image.getName());
                }
                resizeImage(image.getName());
                addFiligrane(image.getName(), source, suffix);
                addFiligrane(dossierResize + "/" + image.getName(), source, suffix);
                new ImagesHelper().addImage(connect.getPoolConnexion(), selectedTerme.getIdC(), selectedTerme.getIdTheso(), image.getName(), source, idUser);
            } catch (IOException ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            selectedTerme.setImages(new ImagesHelper().getImages(connect.getPoolConnexion(), selectedTerme.getIdC(), selectedTerme.getIdTheso()));
            vue.setAddImage(false);
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("file.info1.1") + " " + source + langueBean.getMsg("file.info1.2") + "."));
            source = "";
        }
    }
}
Also used : ImagesHelper(mom.trd.opentheso.bdd.helper.ImagesHelper) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) Date(java.util.Date) BufferedImage(java.awt.image.BufferedImage) UploadedFile(org.primefaces.model.UploadedFile) FileOutputStream(java.io.FileOutputStream) FacesMessage(javax.faces.application.FacesMessage) SimpleDateFormat(java.text.SimpleDateFormat) UploadedFile(org.primefaces.model.UploadedFile) File(java.io.File)

Example 12 with UploadedFile

use of org.primefaces.model.UploadedFile 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");
                new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, selectedTerme.getUser().getUser().getIdUser(), "");
            } 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)

Example 13 with UploadedFile

use of org.primefaces.model.UploadedFile in project opentheso by miledrousset.

the class FileBean_progress method chargeCsv.

/**
 * Cette fonction permet d'insérer un thésaurus en base de données à partir
 * d'un fichier CSV
 *
 * @param event
 */
public void chargeCsv(FileUploadEvent event) {
    ImportTabulateHelper importTabulateHelper = new ImportTabulateHelper();
    if (!PhaseId.INVOKE_APPLICATION.equals(event.getPhaseId())) {
        event.setPhaseId(PhaseId.INVOKE_APPLICATION);
        event.queue();
    } else {
        System.out.println(sepCol + " " + sepChamps + " " + sepLangue + " " + formatDate);
        UploadedFile file = event.getFile();
        if (sepCol == null || sepCol.equals("") || sepChamps == null || sepChamps.equals("") || sepLangue == null || sepLangue.equals("") || formatDate == null || formatDate.equals("")) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error3")));
        } else {
            try {
                if (!importTabulateHelper.readFile(file.getInputstream(), sepCol, sepChamps, sepLangue, formatDate)) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error3")));
                }
                // ArrayList<TabulateDocument> tabulateDocuments = importTabulateHelper.getTabulateDocumentList();
                if (!importTabulateHelper.insertIntoBDD(connect.getPoolConnexion(), idTheso, selectedTerme.getUser().getUser().getIdUser())) {
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error3")));
                }
                // System.out.println(fields);
                // System.out.println(tabulateDocuments);
                vue.setAddSkos(false);
            } catch (Exception ex) {
                Logger.getLogger(FileBean.class.getName()).log(Level.SEVERE, null, ex);
            }
            vue.setAddSkos(false);
        }
    }
}
Also used : UploadedFile(org.primefaces.model.UploadedFile) ImportTabulateHelper(mom.trd.opentheso.core.imports.helper.ImportTabulateHelper) FacesMessage(javax.faces.application.FacesMessage) SKOSCreationException(org.semanticweb.skos.SKOSCreationException) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) IOException(java.io.IOException)

Example 14 with UploadedFile

use of org.primefaces.model.UploadedFile 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 || roleOnTheso.getNodePreference() == null) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, langueBean.getMsg("error") + " :", langueBean.getMsg("file.error2")));
        } else {
            try {
                boolean useArk = false;
                useArk = roleOnTheso.getNodePreference().isUseArk();
                // bundlePref.getString("cheminSite");
                String adressSite = roleOnTheso.getNodePreference().getCheminSite();
                new ReadFileSKOS().readFile(connect.getPoolConnexion(), file.getInputstream(), formatDate, useArk, adressSite, user.getUser().getIdUser(), roleOnTheso.getNodePreference().getSourceLang());
            } 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)

Aggregations

IOException (java.io.IOException)14 UploadedFile (org.primefaces.model.UploadedFile)14 FacesMessage (javax.faces.application.FacesMessage)11 File (java.io.File)5 InputStream (java.io.InputStream)4 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)4 SKOSCreationException (org.semanticweb.skos.SKOSCreationException)4 ResourceBundle (java.util.ResourceBundle)3 BufferedImage (java.awt.image.BufferedImage)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ImagesHelper (mom.trd.opentheso.bdd.helper.ImagesHelper)2 ImportSkosHelper (mom.trd.opentheso.core.imports.helper.ImportSkosHelper)2 ImportTabulateHelper (mom.trd.opentheso.core.imports.helper.ImportTabulateHelper)2 ReadFileSKOS (mom.trd.opentheso.core.imports.old.ReadFileSKOS)2 DatasetThumbnail (edu.harvard.iq.dataverse.dataset.DatasetThumbnail)1 UpdateDatasetThumbnailCommand (edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand)1 FileInputStream (java.io.FileInputStream)1