use of org.mifos.security.util.UserContext in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method confirmImport.
@Override
public ParseResultDto confirmImport(String importPluginClassname, String tempFileName) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
FileInputStream fileInput = null;
try {
final TransactionImport transactionImport = getInitializedImportPlugin(importPluginClassname, userContext.getId());
fileInput = new FileInputStream(tempFileName);
final ParseResultDto importResult = transactionImport.parse(fileInput);
fileInput.close();
fileInput = new FileInputStream(tempFileName);
if (importPluginClassname.equalsIgnoreCase("org.almajmoua.AudiBankXlsImporter")) {
importResult.setTrxIdsToUndo(transactionImport.storeForUndoImport(fileInput));
} else {
transactionImport.store(fileInput);
}
return importResult;
} catch (Exception e) {
throw new MifosRuntimeException(e);
} finally {
if (fileInput != null) {
try {
fileInput.close();
} catch (Exception e2) {
throw new MifosRuntimeException(e2);
}
}
}
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method undoFullImport.
@Override
public void undoFullImport(String importTransactionsFileName) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
TreeSet<String> accountsWithAdjustedPayments = new TreeSet<String>();
try {
ImportedFilesEntity filesEntity = this.importedFilesService.getImportedFileByName(importTransactionsFileName);
List<AccountTrxnEntity> trxUndo = new ArrayList<AccountTrxnEntity>(filesEntity.getImportedTrxn());
List<ImportedAccPaymentDto> accPaymentList = new ArrayList<ImportedAccPaymentDto>();
for (AccountTrxnEntity trxn : trxUndo) {
try {
validateForAdjustedPayments(trxn, accountsWithAdjustedPayments);
accPaymentList.add(new ImportedAccPaymentDto(trxn.getAccount().getGlobalAccountNum(), trxn.getAccountPayment().getPaymentId()));
} catch (BusinessRuleException e) {
//nothing to do
}
}
for (ImportedAccPaymentDto accDto : accPaymentList) {
try {
this.accountServiceFacade.applyHistoricalAdjustment(accDto.getGlobalNum(), accDto.getPaymentId(), IMPORT_UNDONE, userContext.getId(), null);
} catch (MifosRuntimeException e) {
// TODO: validation will be added with MIFOS-5779
}
}
this.importedFilesService.saveImportedFileName(filesEntity.getFileName(), filesEntity.getSubmittedBy(), null, Boolean.TRUE, filesEntity.getUndoable());
} catch (Exception e) {
throw new MifosRuntimeException(e);
}
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method saveImportedFileName.
@Override
public void saveImportedFileName(String importTransactionsFileName, String importPluginClassname, List<AccountTrxDto> idsToUndoImport) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
PersonnelBO submittedBy = this.personnelDao.findPersonnelById(userContext.getId());
Boolean undoable = Boolean.FALSE;
if (importPluginClassname.equalsIgnoreCase("org.almajmoua.AudiBankXlsImporter")) {
undoable = Boolean.TRUE;
}
importedFilesService.saveImportedFileName(importTransactionsFileName, submittedBy, idsToUndoImport, Boolean.FALSE, undoable);
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class ImportTransactionsServiceFacadeWebTier method parseImportTransactions.
@Override
public ParseResultDto parseImportTransactions(String importPluginClassname, InputStream inputStream) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
final TransactionImport ti = getInitializedImportPlugin(importPluginClassname, userContext.getId());
final ParseResultDto importResult = ti.parse(inputStream);
int numberRowSuccessfullyParsed = ti.getSuccessfullyParsedRows();
importResult.setNumberRowSuccessfullyParsed(numberRowSuccessfullyParsed);
String statusLogFile = generateStatusLogfile(importResult, ti);
importResult.setStatusLogFile(statusLogFile);
return importResult;
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class UserContextFactory method create.
public UserContext create(MifosUser user) {
Short localeId = user.getPreferredLocaleId();
Locale preferredLocale = Localization.getInstance().getLocaleById(localeId);
UserContext userContext = new UserContext();
userContext.setPreferredLocale(preferredLocale);
userContext.setLocaleId(localeId);
userContext.setBranchId(user.getBranchId());
userContext.setId((short) user.getUserId());
userContext.setName(user.getUsername());
userContext.setLevelId(user.getLevelId());
userContext.setRoles(new HashSet<Short>(user.getRoleIds()));
return userContext;
}
Aggregations