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");
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);
}
}
}
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().getId())) {
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);
}
}
}
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().getId();
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().getImage(connect.getPoolConnexion(), selectedTerme.getIdC(), selectedTerme.getIdTheso(), idUser));
vue.setAddImage(false);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(langueBean.getMsg("info") + " :", langueBean.getMsg("file.info1.1") + " " + source + langueBean.getMsg("file.info1.2") + "."));
source = "";
}
}
}
Aggregations