Search in sources :

Example 6 with FormFile

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

the class BirtReportsUploadAction method editThenUpload.

public ActionForward editThenUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    BirtReportsUploadActionForm uploadForm = (BirtReportsUploadActionForm) form;
    ReportsPersistence rp = new ReportsPersistence();
    ReportsCategoryBO category = rp.getPersistentObject(ReportsCategoryBO.class, Short.valueOf(uploadForm.getReportCategoryId()));
    ReportsBO reportBO = rp.getReport(Short.valueOf(uploadForm.getReportId()));
    ReportsJasperMap reportJasperMap = reportBO.getReportsJasperMap();
    if (!isReportItsSelf(uploadForm, reportBO) && isReportAlreadyExist(request, uploadForm.getReportTitle(), category)) {
        return mapping.findForward(ActionForwards.editpreview_failure.toString());
    } else if (isReportActivityIdNull(request, reportBO)) {
        return mapping.findForward(ActionForwards.create_failure.toString());
    }
    reportBO.setReportName(uploadForm.getReportTitle());
    reportBO.setIsActive(Short.valueOf(uploadForm.getIsActive()));
    reportBO.setReportsCategoryBO(category);
    rp.createOrUpdate(reportBO);
    // kim
    String activityNameHead = "Can view ";
    rp.updateLookUpValue(reportBO.getActivityId(), activityNameHead + uploadForm.getReportTitle());
    legacyRolesPermissionsDao.reparentActivityUsingHibernate(reportBO.getActivityId(), category.getActivityId());
    legacyRolesPermissionsDao.changeActivityMessage(reportBO.getActivityId(), Localization.ENGLISH_LOCALE_ID, "Can view " + reportBO.getReportName());
    FormFile formFile = uploadForm.getFile();
    if (StringUtils.isEmpty(formFile.getFileName())) {
        formFile.destroy();
    } else {
        reportJasperMap.setReportJasper(formFile.getFileName());
        rp.createOrUpdate(reportJasperMap);
        uploadFile(formFile);
    }
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : ReportsPersistence(org.mifos.reports.persistence.ReportsPersistence) ReportsCategoryBO(org.mifos.reports.business.ReportsCategoryBO) BirtReportsUploadActionForm(org.mifos.reports.struts.actionforms.BirtReportsUploadActionForm) ReportsJasperMap(org.mifos.reports.business.ReportsJasperMap) ReportsBO(org.mifos.reports.business.ReportsBO) FormFile(org.apache.struts.upload.FormFile)

Example 7 with FormFile

use of org.apache.struts.upload.FormFile in project zoj by licheng.

the class ProblemImportAction method execute.

/**
     * ProblemImportAction.
     * 
     * @param mapping
     *            action mapping
     * @param form
     *            action form
     * @param request
     *            http servlet request
     * @param response
     *            http servlet response
     * 
     * @return action forward instance
     * 
     * @throws Exception
     *             any errors happened
     */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, ContextAdapter context) throws Exception {
    // check contest
    boolean isProblemset = context.getRequest().getRequestURI().endsWith("importProblems.do");
    ActionForward forward = this.checkContestAdminPermission(mapping, context, isProblemset, false);
    if (forward != null) {
        return forward;
    }
    ProblemPackage pack = (ProblemPackage) context.getSessionAttribute("ProblemPackage");
    context.setSessionAttribute("ProblemPackage", null);
    AbstractContest contest = context.getContest();
    InputStream in = null;
    String filePath = context.getRequest().getParameter("problemFilePath");
    FormFile file = ((ProblemImportForm) form).getProblemFile();
    if (filePath != null && filePath.trim().length() > 0) {
        in = new FileInputStream(filePath);
    } else if (file != null) {
        in = file.getInputStream();
    }
    if (in != null) {
        ActionMessages messages = new ActionMessages();
        pack = ProblemManager.importProblem(in, messages);
        if (messages.size() > 0) {
            return this.handleFailure(mapping, context, messages);
        }
        context.setSessionAttribute("ProblemPackage", pack);
        return this.handleSuccess(mapping, context, "preview");
    }
    if (pack == null) {
        return this.handleSuccess(mapping, context, "selectcontest");
    }
    try {
        ProblemImportAction.createProblems(pack, contest.getId());
        /*
             * ProblemCriteria criteria = new ProblemCriteria(); criteria.setContestId(new Long(contest.getId()));
             * 
             * // remove List oldProblems = problemPersistence.searchProblems(criteria); for (Iterator it =
             * oldProblems.iterator(); it.hasNext();) { problemPersistence.deleteProblem(((Problem) it.next()).getId(),
             * 0); }
             */
        ContestManager.getInstance().refreshContest(contest.getId());
    } catch (Exception pe) {
        this.error(pe);
        ActionMessages messages = new ActionMessages();
        messages.add("message", new ActionMessage("onlinejudge.importProblems.failure"));
        this.saveErrors(context.getRequest(), messages);
        context.setAttribute("back", "editContest.do?contestId=" + contest.getId());
        return this.handleSuccess(mapping, context, "success");
    }
    ActionMessages messages = new ActionMessages();
    messages.add("message", new ActionMessage("onlinejudge.importProblems.success"));
    this.saveErrors(context.getRequest(), messages);
    context.setAttribute("back", "showContestProblems.do?contestId=" + contest.getId());
    return this.handleSuccess(mapping, context, "success");
}
Also used : AbstractContest(cn.edu.zju.acm.onlinejudge.bean.AbstractContest) ProblemImportForm(cn.edu.zju.acm.onlinejudge.form.ProblemImportForm) ProblemPackage(cn.edu.zju.acm.onlinejudge.util.ProblemPackage) ActionMessages(org.apache.struts.action.ActionMessages) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ActionMessage(org.apache.struts.action.ActionMessage) ActionForward(org.apache.struts.action.ActionForward) FileInputStream(java.io.FileInputStream) FormFile(org.apache.struts.upload.FormFile)

Example 8 with FormFile

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

the class PictureFormFile method editPersonalInfo.

@TransactionDemarcate(joinToken = true)
public ActionForward editPersonalInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    actionForm.clearMostButNotAllFieldsOnActionForm();
    ClientBO clientFromSession = getClientFromSession(request);
    final String clientSystemId = clientFromSession.getGlobalCustNum();
    ClientBO client = this.customerDao.findClientBySystemId(clientSystemId);
    short loanOfficerId = client.getCreatedBy();
    String clientStatus = client.getCustomerStatus().getName();
    ClientPersonalInfoDto personalInfo = this.clientServiceFacade.retrieveClientPersonalInfoForUpdate(clientSystemId, clientStatus, loanOfficerId);
    SessionUtils.setCollectionAttribute(ClientConstants.SALUTATION_ENTITY, personalInfo.getClientDropdowns().getSalutations(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.GENDER_ENTITY, personalInfo.getClientDropdowns().getGenders(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.MARITAL_STATUS_ENTITY, personalInfo.getClientDropdowns().getMaritalStatuses(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.CITIZENSHIP_ENTITY, personalInfo.getClientDropdowns().getCitizenship(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.ETHNICITY_ENTITY, personalInfo.getClientDropdowns().getEthnicity(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.EDUCATION_LEVEL_ENTITY, personalInfo.getClientDropdowns().getEducationLevels(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.BUSINESS_ACTIVITIES_ENTITY, personalInfo.getClientDropdowns().getBusinessActivity(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.POVERTY_STATUS, personalInfo.getClientDropdowns().getPoverty(), request);
    SessionUtils.setCollectionAttribute(ClientConstants.HANDICAPPED_ENTITY, personalInfo.getClientDropdowns().getHandicapped(), request);
    UserContext userContext = getUserContext(request);
    List<SpouseFatherLookupEntity> spouseFather = legacyMasterDao.findMasterDataEntitiesWithLocale(SpouseFatherLookupEntity.class);
    SessionUtils.setCollectionAttribute(ClientConstants.SPOUSE_FATHER_ENTITY, spouseFather, request);
    SessionUtils.setAttribute("CanEditPhoneNumber", ActivityMapper.getInstance().isEditPhoneNumberPermitted(userContext, userContext.getBranchId()), request);
    InformationOrderServiceFacade informationOrderServiceFacade = ApplicationContextProvider.getBean(InformationOrderServiceFacade.class);
    SessionUtils.setCollectionAttribute("personalInformationOrder", informationOrderServiceFacade.getInformationOrder("CreateClient"), request);
    boolean isFamilyDetailsRequired = personalInfo.getClientRules().isFamilyDetailsRequired();
    SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_REQUIRED, isFamilyDetailsRequired, request);
    if (isFamilyDetailsRequired) {
        SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_MANDATORY, isFamilyDetailsMandatory(), request);
        SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_HIDDEN, false, request);
    } else {
        SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_MANDATORY, isSpouseFatherInformationMandatory(), request);
        SessionUtils.setAttribute(ClientConstants.ARE_FAMILY_DETAILS_HIDDEN, isSpouseFatherInformationHidden(), request);
    }
    SessionUtils.setCollectionAttribute(CustomerConstants.CUSTOM_FIELDS_LIST, new ArrayList<CustomFieldDto>(), request);
    // customer specific
    actionForm.setCustomerId(personalInfo.getCustomerDetail().getCustomerId().toString());
    actionForm.setLoanOfficerId(personalInfo.getCustomerDetail().getLoanOfficerIdAsString());
    actionForm.setGlobalCustNum(personalInfo.getCustomerDetail().getGlobalCustNum());
    actionForm.setExternalId(personalInfo.getCustomerDetail().getExternalId());
    actionForm.setAddress(Address.toAddress(client.getAddress()));
    // client specific
    actionForm.setGovernmentId(personalInfo.getClientDetail().getGovernmentId());
    actionForm.setDateOfBirth(personalInfo.getClientDetail().getDateOfBirth());
    actionForm.setClientDetailView(personalInfo.getClientDetail().getCustomerDetail());
    ClientNameDetailDto clientName = personalInfo.getClientDetail().getClientName();
    clientName.setNames(ClientRules.getNameSequence());
    actionForm.setClientName(clientName);
    String photoDelete = request.getParameter("photoDelete");
    if (photoDelete != null && photoDelete.equals("true")) {
        ApplicationContextProvider.getBean(ClientPhotoService.class).delete(client.getCustomerId().longValue());
    }
    boolean isPhotoFieldHidden = FieldConfig.getInstance().isFieldHidden("Client.Photo");
    SessionUtils.setAttribute(ClientConstants.IS_PHOTO_FIELD_HIDDEN, isPhotoFieldHidden, request);
    if (!isPhotoFieldHidden) {
        ClientPhotoDto clientPhotoDto = this.clientServiceFacade.getClientPhoto(client.getCustomerId().longValue());
        if (clientPhotoDto != null) {
            FormFile formFile = new PictureFormFile(clientPhotoDto.getContentType(), clientPhotoDto.getOut(), client.getCustomerId().toString(), clientPhotoDto.getContentLength().intValue());
            actionForm.setPicture(formFile);
        } else {
            actionForm.setPicture(null);
        }
    } else {
        actionForm.setPicture(null);
    }
    ClientNameDetailDto spouseName = personalInfo.getClientDetail().getSpouseName();
    if (spouseName != null) {
        spouseName.setNames(ClientRules.getNameSequence());
        actionForm.setSpouseName(spouseName);
    }
    actionForm.setSpouseName(spouseName);
    actionForm.setCustomFields(new ArrayList<CustomFieldDto>());
    SessionUtils.removeThenSetAttribute(Constants.BUSINESS_KEY, client, request);
    return mapping.findForward(ActionForwards.editPersonalInfo_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) ClientPhotoService(org.mifos.framework.image.service.ClientPhotoService) UserContext(org.mifos.security.util.UserContext) ClientBO(org.mifos.customers.client.business.ClientBO) CustomFieldDto(org.mifos.dto.domain.CustomFieldDto) FormFile(org.apache.struts.upload.FormFile) InformationOrderServiceFacade(org.mifos.platform.questionnaire.service.InformationOrderServiceFacade) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) SpouseFatherLookupEntity(org.mifos.application.master.business.SpouseFatherLookupEntity) ClientPersonalInfoDto(org.mifos.dto.screen.ClientPersonalInfoDto) ClientPhotoDto(org.mifos.dto.screen.ClientPhotoDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 9 with FormFile

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

the class PictureFormFile method create.

@TransactionDemarcate(validateAndResetToken = true)
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    MeetingBO meeting = (MeetingBO) SessionUtils.getAttribute(CustomerConstants.CUSTOMER_MEETING, request);
    List<SavingsDetailDto> allowedSavingProducts = getSavingsOfferingsFromSession(request);
    if (ClientRules.isFamilyDetailsRequired()) {
        actionForm.setFamilyDateOfBirth();
        actionForm.constructFamilyDetails();
    }
    List<Short> selectedSavingProducts = actionForm.getSelectedOfferings();
    String clientName = actionForm.getClientName().getDisplayName();
    Short clientStatus = actionForm.getStatusValue().getValue();
    java.sql.Date mfiJoiningDate = DateUtils.getDateAsSentFromBrowser(actionForm.getMfiJoiningDate());
    String externalId = actionForm.getExternalId();
    AddressDto address = null;
    if (actionForm.getAddress() != null) {
        address = Address.toDto(actionForm.getAddress());
    }
    Short formedBy = actionForm.getFormedByPersonnelValue();
    java.sql.Date dateOfBirth = DateUtils.getDateAsSentFromBrowser(actionForm.getDateOfBirth());
    String governmentId = actionForm.getGovernmentId();
    boolean trained = isTrained(actionForm.getTrainedValue());
    java.sql.Date trainedDate = DateUtils.getDateAsSentFromBrowser(actionForm.getTrainedDate());
    Short groupFlagValue = actionForm.getGroupFlagValue();
    ClientNameDetailDto clientNameDetailDto = actionForm.getClientName();
    ClientPersonalDetailDto clientPersonalDetailDto = actionForm.getClientDetailView();
    ClientNameDetailDto spouseFatherName = actionForm.getSpouseName();
    InputStream picture = actionForm.getCustomerPicture();
    String parentGroupId = actionForm.getParentGroupId();
    List<ClientNameDetailDto> familyNames = actionForm.getFamilyNames();
    List<ClientFamilyDetailDto> familyDetails = actionForm.getFamilyDetails();
    Short loanOfficerId = actionForm.getLoanOfficerIdValue();
    Short officeId = actionForm.getOfficeIdValue();
    // only applies when status is active
    LocalDate activationDateAsToday = new LocalDate();
    ClientCreationDetail clientCreationDetail = new ClientCreationDetail(selectedSavingProducts, clientName, clientStatus, mfiJoiningDate, externalId, address, formedBy, dateOfBirth, governmentId, trained, trainedDate, groupFlagValue, clientNameDetailDto, clientPersonalDetailDto, spouseFatherName, picture, actionForm.getFeesToApply(), parentGroupId, familyNames, familyDetails, loanOfficerId, officeId, activationDateAsToday);
    MeetingDto meetingDto = null;
    if (meeting != null) {
        meetingDto = meeting.toDto();
    }
    CustomerDetailsDto clientDetails = this.clientServiceFacade.createNewClient(clientCreationDetail, meetingDto, allowedSavingProducts);
    List<FormFile> formFiles = actionForm.getFiles();
    List<UploadedFileDto> filesMetadata = actionForm.getFilesMetadata();
    for (int i = 0; i < formFiles.size(); i++) {
        if (formFiles.get(i).getFileSize() != 0) {
            InputStream inputStream = formFiles.get(i).getInputStream();
            UploadedFileDto fileMetadata = filesMetadata.get(i);
            clientServiceFacade.uploadFile(clientDetails.getId(), inputStream, fileMetadata);
        }
    }
    actionForm.setCustomerId(clientDetails.getId().toString());
    actionForm.setGlobalCustNum(clientDetails.getGlobalCustNum());
    actionForm.setEditFamily("notEdit");
    createClientQuestionnaire.saveResponses(request, actionForm, clientDetails.getId());
    return mapping.findForward(ActionForwards.create_success.toString());
}
Also used : MeetingBO(org.mifos.application.meeting.business.MeetingBO) LocalDate(org.joda.time.LocalDate) FormFile(org.apache.struts.upload.FormFile) ClientCreationDetail(org.mifos.dto.domain.ClientCreationDetail) ClientFamilyDetailDto(org.mifos.dto.screen.ClientFamilyDetailDto) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) CustomerDetailsDto(org.mifos.dto.domain.CustomerDetailsDto) UploadedFileDto(org.mifos.dto.screen.UploadedFileDto) ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) SavingsDetailDto(org.mifos.dto.domain.SavingsDetailDto) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) AddressDto(org.mifos.dto.domain.AddressDto) Date(java.sql.Date) MeetingDto(org.mifos.dto.domain.MeetingDto) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

Example 10 with FormFile

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

the class PictureFormFile method deleteFile.

@TransactionDemarcate(joinToken = true)
public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    ClientCustActionForm actionForm = (ClientCustActionForm) form;
    String fileName = request.getParameter("fileName");
    if (fileName != null) {
        int index = 0;
        for (FormFile formFile : actionForm.getFiles()) {
            if (formFile.getFileName().equals(fileName)) {
                index = actionForm.getFiles().indexOf(formFile);
                break;
            }
        }
        if (index >= 0) {
            actionForm.getFiles().remove(index);
            actionForm.getFilesMetadata().remove(index);
        }
    }
    return mapping.findForward(ActionForwards.load_success.toString());
}
Also used : ClientCustActionForm(org.mifos.customers.client.struts.actionforms.ClientCustActionForm) FormFile(org.apache.struts.upload.FormFile) TransactionDemarcate(org.mifos.framework.util.helpers.TransactionDemarcate)

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