use of org.apache.struts.upload.FormFile in project head by mifos.
the class ImportTransactionsAction method upload.
public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
final ImportTransactionsActionForm importTransactionsForm = (ImportTransactionsActionForm) form;
final FormFile importTransactionsFile = importTransactionsForm.getImportTransactionsFile();
final String importPluginClassname = importTransactionsForm.getImportPluginName();
request.getSession().setAttribute(IMPORT_PLUGIN_CLASSNAME, importPluginClassname);
final InputStream stream = importTransactionsFile.getInputStream();
final String tempFilename = saveImportAsTemporaryFile(importTransactionsFile.getInputStream());
request.getSession().setAttribute(IMPORT_TEMPORARY_FILENAME, tempFilename);
final ParseResultDto importResult = this.importTransactionsServiceFacade.parseImportTransactions(importPluginClassname, importTransactionsFile.getInputStream());
final List<String> errorsForDisplay = new ArrayList<String>();
if (!importResult.getParseErrors().isEmpty()) {
errorsForDisplay.addAll(importResult.getParseErrors());
}
int numberRowSuccessfullyParsed = importResult.getNumberRowSuccessfullyParsed();
if (numberRowSuccessfullyParsed == -1) {
numberRowSuccessfullyParsed = importResult.getSuccessfullyParsedPayments().size();
}
boolean submitButtonDisabled = false;
if (numberRowSuccessfullyParsed == 0) {
submitButtonDisabled = true;
}
if (importResult.isAmountInformationFilled() && importResult.isExtraRowInformationFilled()) {
request.setAttribute("isExtraInformationFilled", true);
request.setAttribute("numberOfErrorRows", importResult.getNumberOfErrorRows());
request.setAttribute("numberOfIgnoredRows", importResult.getNumberOfIgnoredRows());
request.setAttribute("numberOfReadRows", importResult.getNumberOfReadRows());
request.setAttribute("totalAmountOfTransactionsImported", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfTransactionsImported()).toString());
request.setAttribute("totalAmountOfTransactionsWithError", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfTransactionsWithError()).toString());
request.setAttribute("totalAmountOfDisbursementsTransactionsImported", new Money(Money.getDefaultCurrency(), importResult.getTotalAmountOfDisbursementsImported().toString()));
request.getSession().setAttribute(SESSION_ATTRIBUTE_LOG, importResult.getStatusLogFile().getBytes());
request.getSession().setAttribute(SESSION_ATTRIBUTE_LOG_FILENAME, statusLogfileName(importTransactionsFile.getFileName()));
} else {
request.setAttribute("isExtraInformationFilled", false);
}
request.setAttribute("importTransactionsErrors", errorsForDisplay);
request.setAttribute("numSuccessfulRows", numberRowSuccessfullyParsed);
request.setAttribute("submitButtonDisabled", submitButtonDisabled);
request.setAttribute("numberOfOverpayments", importResult.getNumberOfOverpayments());
stream.close();
importTransactionsFile.destroy();
return mapping.findForward("import_results");
}
use of org.apache.struts.upload.FormFile in project head by mifos.
the class BirtAdminDocumentUploadAction method editThenUpload.
@SuppressWarnings("unchecked")
@TransactionDemarcate(validateAndResetToken = true)
public ActionForward editThenUpload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
BirtAdminDocumentUploadActionForm uploadForm = (BirtAdminDocumentUploadActionForm) form;
FormFile formFile = uploadForm.getFile();
boolean newFile = false;
if (StringUtils.isEmpty(formFile.getFileName())) {
formFile.destroy();
} else {
uploadFile(formFile);
newFile = true;
}
AdminDocumentBO admindoc = legacyAdminDocumentDao.getAdminDocumentById(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
admindoc.setAdminDocumentName(uploadForm.getAdminiDocumentTitle());
admindoc.setIsActive(Short.valueOf(uploadForm.getIsActive()));
if (newFile) {
admindoc.setAdminDocumentIdentifier(formFile.getFileName());
}
legacyAdminDocumentDao.createOrUpdate(admindoc);
if (Short.valueOf(uploadForm.getAccountTypeId()).shortValue() <= 2) {
List<AccountStateEntity> masterList = (List<AccountStateEntity>) SessionUtils.getAttribute("SelectedStatus", request);
List<AdminDocAccStateMixBO> admindoclist = legacyAdminDocAccStateMixDao.getMixByAdminDocuments(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
for (AdminDocAccStateMixBO temp : admindoclist) {
legacyAdminDocAccStateMixDao.delete(temp);
}
AdminDocAccStateMixBO admindocaccstatemixBO = new AdminDocAccStateMixBO();
for (AccountStateEntity acc : masterList) {
admindocaccstatemixBO = new AdminDocAccStateMixBO();
admindocaccstatemixBO.setAccountStateID(acc);
admindocaccstatemixBO.setAdminDocumentID(admindoc);
legacyAdminDocAccStateMixDao.createOrUpdate(admindocaccstatemixBO);
}
} else {
List<AccountActionEntity> masterList = (List<AccountActionEntity>) SessionUtils.getAttribute("SelectedStatus", request);
List<AdminDocAccActionMixBO> admindoclist = legacyAdminDocAccStateMixDao.getAccActionMixByAdminDocument(Short.valueOf(SessionUtils.getAttribute("admindocId", request).toString()));
for (AdminDocAccActionMixBO temp : admindoclist) {
legacyAdminDocAccStateMixDao.delete(temp);
}
AdminDocAccActionMixBO adminDocAccActionMixBO = new AdminDocAccActionMixBO();
for (AccountActionEntity acc : masterList) {
adminDocAccActionMixBO = new AdminDocAccActionMixBO();
adminDocAccActionMixBO.setAccountAction(acc);
adminDocAccActionMixBO.setAdminDocument(admindoc);
legacyAdminDocAccStateMixDao.createOrUpdate(adminDocAccActionMixBO);
}
}
return getViewBirtAdminDocumentPage(mapping, form, request, response);
}
use of org.apache.struts.upload.FormFile in project head by mifos.
the class BirtReportsUploadAction method upload.
public ActionForward upload(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()));
if (isReportAlreadyExist(request, uploadForm.getReportTitle(), category)) {
return mapping.findForward(ActionForwards.preview_failure.toString());
}
short parentActivity = category.getActivityId();
int newActivityId;
String activityNameHead = "Can view ";
try {
newActivityId = legacyRolesPermissionsDao.calculateDynamicActivityId();
legacyRolesPermissionsDao.createActivityForReports(parentActivity, activityNameHead + uploadForm.getReportTitle());
} catch (ActivityGeneratorException ex) {
ActionErrors errors = new ActionErrors();
errors.add(ex.getKey(), new ActionMessage(ex.getKey()));
request.setAttribute(Globals.ERROR_KEY, errors);
return mapping.findForward(ActionForwards.preview_failure.toString());
}
FormFile formFile = uploadForm.getFile();
uploadFile(formFile);
ReportsBO reportBO = createOrUpdateReport(category, newActivityId, uploadForm.getReportTitle(), Short.valueOf(uploadForm.getIsActive()), formFile.getFileName(), uploadForm.getIsDW());
allowActivityPermission(reportBO, newActivityId);
request.setAttribute("report", reportBO);
return mapping.findForward(ActionForwards.create_success.toString());
}
use of org.apache.struts.upload.FormFile in project head by mifos.
the class BirtReportsUploadActionStrutsTest method testShouldCreateFailureWhenActivityIdOutOfRange.
@Test
public void testShouldCreateFailureWhenActivityIdOutOfRange() throws Exception {
ActivityEntity activityEntity = insertActivityForTest(Short.MIN_VALUE);
FormFile file = new MockFormFile("testFilename");
BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
setRequestPathInfo("/birtReportsUploadAction.do");
addRequestParameter("method", "upload");
actionForm.setFile(file);
actionForm.setReportTitle("existingTitle");
actionForm.setReportCategoryId("1");
actionForm.setIsActive("1");
setActionForm(actionForm);
actionPerform();
verifyForward("preview_failure");
String[] errors = { ReportsConstants.ERROR_NOMOREDYNAMICACTIVITYID };
verifyActionErrors(errors);
deleteActivityForTest(activityEntity);
}
use of org.apache.struts.upload.FormFile in project head by mifos.
the class BirtReportsUploadActionStrutsTest method testUpgradePathNotRuined.
@Test
public void testUpgradePathNotRuined() throws Exception {
// TODO Temporary solution to avoid unsuccessful test on some machines
// Retrieve initial activities information
List<ActivityEntity> activities = new RolesPermissionsBusinessService().getActivities();
int newActivityId = activities.get(activities.size() - 1).getId() + 1;
// Upload a report creating an activity for the report
FormFile file = new MockFormFile("testFilename.rptdesign");
BirtReportsUploadActionForm actionForm = new BirtReportsUploadActionForm();
setRequestPathInfo("/birtReportsUploadAction.do");
addRequestParameter("method", "upload");
actionForm.setFile(file);
actionForm.setReportTitle("exsitTitle");
actionForm.setReportCategoryId("1");
actionForm.setIsActive("1");
setActionForm(actionForm);
actionPerform();
Assert.assertEquals(0, getErrorSize());
Assert.assertNotNull(request.getAttribute("report"));
// Simulate an future activities upgrade
AddActivity activity = null;
try {
activity = new AddActivity((short) newActivityId, SecurityConstants.ORGANIZATION_MANAGEMENT, "no name");
activity.upgrade(StaticHibernateUtil.getSessionTL().connection());
} catch (Exception e) {
legacyRolesPermissionsDao.delete(request.getAttribute("report"));
StaticHibernateUtil.flushSession();
throw e;
}
// Undo
ReportsBO report = (ReportsBO) request.getAttribute("report");
removeReport(report.getReportId());
}
Aggregations