Search in sources :

Example 1 with ActivityFile

use of com.autentia.tnt.businessobject.ActivityFile in project TNTConcept by autentia.

the class ActivityBean method saveExternalActivity.

public String saveExternalActivity() {
    doBeforeSaveExternalActivity();
    try {
        String fileName = null;
        if (uploadFile != null) {
            fileName = FileUtil.getFileName(uploadFile.getName());
            final ActivityFile file = new ActivityFile();
            file.setInsertDate(new Date());
            file.setUser(authManager.getCurrentPrincipal().getUser());
            file.setExternalActivity(externalActivity);
            file.setFile(fileName);
            file.setFileMime(uploadFile.getContentType());
            externalActivity.getFiles().add(file);
        }
        if (externalActivity.getId() == null) {
            externalActivityManager.insertEntity(externalActivity);
        } else {
            externalActivityManager.updateEntity(externalActivity);
        }
        if (uploadFile != null) {
            if (uploader.exists(Integer.toString(externalActivity.getId()), fileName)) {
                // el fichero ya existe y lo versionamos
                uploader.version(Integer.toString(externalActivity.getId()), fileName, uploadFile);
            } else {
                uploader.store(Integer.toString(externalActivity.getId()), uploadFile);
            }
        }
        // Calls an after save action
        String result = super.doAfterSave(NavigationResults.LIST);
        return result;
    } catch (IOException e) {
        log.error("save - exception uploading field file", e);
        FacesUtils.addErrorMessage("file", "error.fileTransfer", e.getMessage());
        return null;
    }
}
Also used : ActivityFile(com.autentia.tnt.businessobject.ActivityFile) IOException(java.io.IOException) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 2 with ActivityFile

use of com.autentia.tnt.businessobject.ActivityFile in project TNTConcept by autentia.

the class ActivityBean method deleteFile.

public String deleteFile() {
    UIData table = (UIData) FacesUtils.getComponent("activity:tabExternalActivity:list");
    ActivityFile toDelete = (ActivityFile) table.getRowData();
    externalActivity.getFiles().remove(toDelete);
    return null;
}
Also used : ActivityFile(com.autentia.tnt.businessobject.ActivityFile) UIData(javax.faces.component.UIData)

Aggregations

ActivityFile (com.autentia.tnt.businessobject.ActivityFile)2 IOException (java.io.IOException)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 UIData (javax.faces.component.UIData)1