Search in sources :

Example 1 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class PictureFormFile method addFile.

@TransactionDemarcate(joinToken = true)
public ActionForward addFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    FormFile file = actionForm.getSelectedFile();
    String fileName = actionForm.getSelectedFile().getFileName();
    String fileContentType = actionForm.getSelectedFile().getContentType();
    Integer fileSize = actionForm.getSelectedFile().getFileSize();
    String fileDescription = actionForm.getSelectedFileDescription();
    if (file != null) {
        actionForm.getFiles().add(file);
        actionForm.getFilesMetadata().add(new UploadedFileDto(fileName, fileContentType, fileSize, fileDescription));
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) FormFile(org.apache.struts.upload.FormFile) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 2 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class ClientCustActionForm method clearMostButNotAllFieldsOnActionForm.

public void clearMostButNotAllFieldsOnActionForm() {
    setDefaultFees(new ArrayList<ApplicableAccountFeeDto>());
    setAdditionalFees(new ArrayList<ApplicableAccountFeeDto>());
    setCustomFields(new ArrayList<CustomFieldDto>());
    setFamilyNames(new ArrayList<ClientNameDetailDto>());
    setFamilyDetails(new ArrayList<ClientFamilyDetailDto>());
    setFamilyRelationship(new ArrayList<Short>());
    setFamilyFirstName(new ArrayList<String>());
    setFamilyMiddleName(new ArrayList<String>());
    setFamilyLastName(new ArrayList<String>());
    setFamilySecondLastName(new ArrayList<String>());
    setFamilyDateOfBirthDD(new ArrayList<String>());
    setFamilyDateOfBirthMM(new ArrayList<String>());
    setFamilyDateOfBirthYY(new ArrayList<String>());
    setFamilyGender(new ArrayList<Short>());
    setFamilyLivingStatus(new ArrayList<Short>());
    initializeFamilyMember();
    addFamilyMember();
    setAddress(new Address());
    setDisplayName(null);
    setDateOfBirthDD(null);
    setDateOfBirthMM(null);
    setDateOfBirthYY(null);
    setGovernmentId(null);
    setMfiJoiningDate(null);
    setGlobalCustNum(null);
    setCustomerId(null);
    setExternalId(null);
    setLoanOfficerId(null);
    setLoanOfficerName("");
    setFormedByPersonnel(null);
    setTrained(null);
    setTrainedDate(null);
    setClientName(new ClientNameDetailDto());
    setSpouseName(new ClientNameDetailDto());
    setClientDetailView(new ClientPersonalDetailDto());
    setNextOrPreview("next");
    setQuestionGroups(null);
    for (int i = 0; i < getSelectedOfferings().size(); i++) {
        getSelectedOfferings().set(i, null);
    }
    setFiles(new ArrayList<FormFile>());
    setFilesMetadata(new ArrayList<UploadedFileDto>());
}
Also used : Address(org.mifos.framework.business.util.Address) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) ApplicableAccountFeeDto(org.mifos.dto.domain.ApplicableAccountFeeDto) FormFile(org.apache.struts.upload.FormFile) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto)

Example 3 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtAdminDocumentUploadAction method upload.

@SuppressWarnings("unchecked")
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    BirtAdminDocumentUploadActionForm uploadForm = (BirtAdminDocumentUploadActionForm) form;
    FormFile formFile = uploadForm.getFile();
    uploadFile(formFile);
    AdminDocumentBO admindocBO = createOrUpdateAdminDocument(uploadForm.getAdminiDocumentTitle(), Short.valueOf("1"), formFile.getFileName());
    AdminDocAccStateMixBO admindocaccstatemixBO = new AdminDocAccStateMixBO();
    if (Short.valueOf(uploadForm.getAccountTypeId()).shortValue() <= 2) {
        List<AccountStateEntity> masterList = (List<AccountStateEntity>) SessionUtils.getAttribute("SelectedStatus", request);
        for (AccountStateEntity acc : masterList) {
            admindocaccstatemixBO = new AdminDocAccStateMixBO();
            admindocaccstatemixBO.setAccountStateID(acc);
            admindocaccstatemixBO.setAdminDocumentID(admindocBO);
            legacyAdminDocAccStateMixDao.createOrUpdate(admindocaccstatemixBO);
        }
    } else {
        List<AccountActionEntity> masterList = (List<AccountActionEntity>) SessionUtils.getAttribute("SelectedStatus", request);
        for (AccountActionEntity accountActionEntity : masterList) {
            AdminDocAccActionMixBO adminDocAccActionMixBO = new AdminDocAccActionMixBO();
            adminDocAccActionMixBO.setAccountAction(accountActionEntity);
            adminDocAccActionMixBO.setAdminDocument(admindocBO);
            legacyAdminDocumentDao.createOrUpdate(adminDocAccActionMixBO);
        }
    }
    request.setAttribute("report", admindocBO);
    return getViewBirtAdminDocumentPage(mapping, form, request, response);
}
Also used : AdminDocumentBO(org.mifos.reports.admindocuments.business.AdminDocumentBO) BirtAdminDocumentUploadActionForm(org.mifos.reports.admindocuments.struts.actionforms.BirtAdminDocumentUploadActionForm) ArrayList(java.util.ArrayList) List(java.util.List) AdminDocAccActionMixBO(org.mifos.reports.admindocuments.business.AdminDocAccActionMixBO) AdminDocAccStateMixBO(org.mifos.reports.admindocuments.business.AdminDocAccStateMixBO) AccountStateEntity(org.mifos.accounts.business.AccountStateEntity) AccountActionEntity(org.mifos.accounts.business.AccountActionEntity) FormFile(org.apache.struts.upload.FormFile) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 4 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtAdminDocumentUploadAction method uploadFile.

private void uploadFile(FormFile formFile) throws FileNotFoundException, IOException {
    File dir = new File(viewOrganizationSettingsServiceFacade.getAdminDocumentStorageDirectory());
    dir.mkdirs();
    File file = new File(dir, formFile.getFileName());
    InputStream is = formFile.getInputStream();
    OutputStream os;
    /*
         * for test purposes, if the real path does not exist (if we're operating outside a deployed environment) the
         * file is just written to a ByteArrayOutputStream which is not actually stored. !! This does not produce any
         * sort of file that can be retirieved. !! it only allows us to perform the upload action.
         */
    if (getServletRoot(getServlet()) != null) {
        os = new FileOutputStream(file);
    } else {
        os = new ByteArrayOutputStream();
    }
    byte[] buffer = new byte[4096];
    int bytesRead = 0;
    while ((bytesRead = is.read(buffer, 0, 4096)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    os.close();
    is.close();
    formFile.destroy();
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FormFile(org.apache.struts.upload.FormFile) File(java.io.File)

Example 5 with FormFile

use of org.apache.struts.upload.FormFile in project head by mifos.

the class BirtReportsUploadAction method uploadFile.

private void uploadFile(FormFile formFile) throws FileNotFoundException, IOException {
    File dir = new File(getCustomReportStorageDirectory());
    dir.mkdirs();
    File file = new File(dir, formFile.getFileName());
    InputStream is = formFile.getInputStream();
    OutputStream os;
    /*
         * for test purposes, if the real path does not exist (if we're
         * operating outside a deployed environment) the file is just written to
         * a ByteArrayOutputStream which is not actually stored. !! This does
         * not produce any sort of file that can be retirieved. !! it only
         * allows us to perform the upload action.
         */
    if (getServletRoot(getServlet()) != null) {
        os = new FileOutputStream(file);
    } else {
        os = new ByteArrayOutputStream();
    }
    byte[] buffer = new byte[4096];
    int bytesRead = 0;
    while ((bytesRead = is.read(buffer, 0, 4096)) != -1) {
        os.write(buffer, 0, bytesRead);
    }
    os.close();
    is.close();
    formFile.destroy();
}
Also used : InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FormFile(org.apache.struts.upload.FormFile) File(java.io.File)

Aggregations

FormFile (org.apache.struts.upload.FormFile)16 TransactionDemarcate (org.mifos.framework.util.helpers.TransactionDemarcate)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)4 ClientCustActionForm (org.mifos.customers.client.struts.actionforms.ClientCustActionForm)4 BirtReportsUploadActionForm (org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)3 UploadedFileDto (org.mifos.dto.screen.UploadedFileDto)3 ReportsBO (org.mifos.reports.business.ReportsBO)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 List (java.util.List)2 ActionMessage (org.apache.struts.action.ActionMessage)2 Test (org.junit.Test)2 AccountActionEntity (org.mifos.accounts.business.AccountActionEntity)2 AccountStateEntity (org.mifos.accounts.business.AccountStateEntity)2 CustomFieldDto (org.mifos.dto.domain.CustomFieldDto)2