use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class CollectionSheetServiceFacadeWebTier method saveCollectionSheet.
@Override
public CollectionSheetErrorsDto saveCollectionSheet(final SaveCollectionSheetDto saveCollectionSheet) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
final SaveCollectionSheetDto saveCollectionSheetDto = saveCollectionSheet;
UserContext userContext = new UserContextFactory().create(user);
int customerId = saveCollectionSheetDto.getSaveCollectionSheetCustomers().get(0).getCustomerId();
CustomerBO customerBO = this.customerDao.findCustomerById(customerId);
try {
personnelDao.checkAccessPermission(userContext, customerBO.getOfficeId(), customerBO.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
CollectionSheetErrorsDto collectionSheetErrorsDto = null;
try {
collectionSheetErrorsDto = collectionSheetService.saveCollectionSheet(saveCollectionSheet);
} catch (SaveCollectionSheetException e) {
throw new MifosRuntimeException(e.printInvalidSaveCollectionSheetReasons());
}
return collectionSheetErrorsDto;
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class AdminServiceFacadeWebTier method updateSavingsProduct.
@Override
public PrdOfferingDto updateSavingsProduct(SavingsProductDto savingsProductRequest) {
SavingsOfferingBO savingsProductForUpdate = this.savingsProductDao.findById(savingsProductRequest.getProductDetails().getId());
// enforced by integrity constraints on table also.
if (savingsProductForUpdate.isDifferentName(savingsProductRequest.getProductDetails().getName())) {
this.savingsProductDao.validateProductWithSameNameDoesNotExist(savingsProductRequest.getProductDetails().getName());
}
if (savingsProductForUpdate.isDifferentShortName(savingsProductRequest.getProductDetails().getShortName())) {
this.savingsProductDao.validateProductWithSameShortNameDoesNotExist(savingsProductRequest.getProductDetails().getShortName());
}
// domain rule validation - put on domain entity
if (savingsProductForUpdate.isDifferentStartDate(savingsProductRequest.getProductDetails().getStartDate())) {
validateStartDateIsNotBeforeToday(savingsProductRequest.getProductDetails().getStartDate());
validateStartDateIsNotOverOneYearFromToday(savingsProductRequest.getProductDetails().getStartDate());
validateEndDateIsPastStartDate(savingsProductRequest.getProductDetails().getStartDate(), savingsProductRequest.getProductDetails().getEndDate());
}
boolean activeOrInactiveSavingsAccountExist = this.savingsProductDao.activeOrInactiveSavingsAccountsExistForProduct(savingsProductRequest.getProductDetails().getId());
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
SavingsOfferingBO newSavingsDetails = new SavingsProductAssembler(this.loanProductDao, this.savingsProductDao, this.generalLedgerDao).fromDto(user, savingsProductRequest);
savingsProductForUpdate.updateDetails(userContext);
HibernateTransactionHelper transactionHelper = new HibernateTransactionHelperForStaticHibernateUtil();
try {
transactionHelper.startTransaction();
transactionHelper.beginAuditLoggingFor(savingsProductForUpdate);
if (activeOrInactiveSavingsAccountExist) {
LocalDate updateDate = new LocalDate();
savingsProductForUpdate.updateProductDetails(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdStatus());
savingsProductForUpdate.updateSavingsDetails(newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getMinAmntForInt(), updateDate);
} else {
savingsProductForUpdate.updateDetailsOfProductNotInUse(newSavingsDetails.getPrdOfferingName(), newSavingsDetails.getPrdOfferingShortName(), newSavingsDetails.getDescription(), newSavingsDetails.getPrdCategory(), newSavingsDetails.getStartDate(), newSavingsDetails.getEndDate(), newSavingsDetails.getPrdApplicableMaster(), newSavingsDetails.getPrdStatus());
savingsProductForUpdate.updateDetailsOfSavingsProductNotInUse(newSavingsDetails.getSavingsType(), newSavingsDetails.getRecommendedAmount(), newSavingsDetails.getRecommendedAmntUnit(), newSavingsDetails.getMaxAmntWithdrawl(), newSavingsDetails.getInterestRate(), newSavingsDetails.getInterestCalcType(), newSavingsDetails.getTimePerForInstcalc(), newSavingsDetails.getFreqOfPostIntcalc(), newSavingsDetails.getMinAmntForInt());
}
this.savingsProductDao.save(savingsProductForUpdate);
transactionHelper.commitTransaction();
return savingsProductForUpdate.toDto();
} catch (Exception e) {
transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
transactionHelper.closeSession();
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class OfficeServiceFacadeWebTier method updateOffice.
@Override
public boolean updateOffice(Short officeId, Integer versionNum, OfficeUpdateRequest officeUpdateRequest) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
boolean isParentOfficeChanged = false;
OfficeBO office = officeDao.findOfficeById(officeId);
office.validateVersion(versionNum);
OfficeBO parentOffice = null;
if (officeUpdateRequest.getParentOfficeId() != null) {
parentOffice = officeDao.findOfficeById(officeUpdateRequest.getParentOfficeId());
if (office.isDifferentParentOffice(parentOffice)) {
holidayDao.validateNoExtraFutureHolidaysApplicableOnParentOffice(office.getParentOffice().getOfficeId(), officeUpdateRequest.getParentOfficeId());
}
}
if (office.isNameDifferent(officeUpdateRequest.getOfficeName())) {
officeDao.validateOfficeNameIsNotTaken(officeUpdateRequest.getOfficeName());
}
if (office.isShortNameDifferent(officeUpdateRequest.getShortName())) {
officeDao.validateOfficeShortNameIsNotTaken(officeUpdateRequest.getShortName());
}
OfficeStatus newStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
if (!office.isStatusDifferent(newStatus)) {
if (OfficeStatus.INACTIVE.equals(officeUpdateRequest.getNewStatus())) {
officeDao.validateNoActiveChildrenExist(office.getOfficeId());
officeDao.validateNoActivePeronnelExist(office.getOfficeId());
}
if (parentOffice != null) {
if (parentOffice.isInActive()) {
throw new OfficeException(OfficeConstants.KEYPARENTNOTACTIVE);
}
}
}
StaticHibernateUtil.startTransaction();
office.update(userContext, officeUpdateRequest, parentOffice);
StaticHibernateUtil.commitTransaction();
return isParentOfficeChanged;
} catch (OfficeException e1) {
throw new BusinessRuleException(e1.getKey(), e1);
} catch (ApplicationException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e.getMessage(), e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory in project head by mifos.
the class FeeServiceFacadeWebTier method updateFee.
@Override
public void updateFee(FeeUpdateRequest feeUpdateRequest) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
try {
this.feeService.update(feeUpdateRequest, userContext);
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.accounts.servicefacade.UserContextFactory 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);
}
}
}
}
Aggregations