use of org.mifos.security.MifosUser 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.security.MifosUser in project head by mifos.
the class CustomerServiceFacadeWebTier method search.
@Override
public CustomerSearch search(String searchString) throws ApplicationException {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
if (searchString == null) {
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
}
String normalisedSearchString = org.mifos.framework.util.helpers.SearchUtils.normalizeSearchString(searchString);
if (normalisedSearchString.equals("")) {
throw new CustomerException(CenterConstants.NO_SEARCH_STRING);
}
String officeId = userContext.getBranchId().toString();
String officeName = this.officeDao.findOfficeDtoById(userContext.getBranchId()).getName();
PersonnelBO loggedInUser = personnelDao.findPersonnelById(userContext.getId());
QueryResult searchResult = customerDao.search(normalisedSearchString, loggedInUser);
return new CustomerSearch(searchResult, searchString, officeId, officeName);
}
use of org.mifos.security.MifosUser 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.security.MifosUser in project head by mifos.
the class ClientServiceFacadeWebTier method retrieveMfiInfoForEdit.
@Override
public ClientMfiInfoDto retrieveMfiInfoForEdit(String clientSystemId) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
ClientBO client = this.customerDao.findClientBySystemId(clientSystemId);
String groupDisplayName = "";
String centerDisplayName = "";
if (client.getParentCustomer() != null) {
groupDisplayName = client.getParentCustomer().getDisplayName();
if (client.getParentCustomer().getParentCustomer() != null) {
centerDisplayName = client.getParentCustomer().getParentCustomer().getDisplayName();
}
}
List<PersonnelDto> loanOfficersList = new ArrayList<PersonnelDto>();
if (!client.isClientUnderGroup()) {
CenterCreation centerCreation = new CenterCreation(client.getOffice().getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
loanOfficersList = this.personnelDao.findActiveLoanOfficersForOffice(centerCreation);
}
CustomerDetailDto customerDetail = client.toCustomerDetailDto();
ClientDetailDto clientDetail = client.toClientDetailDto(ClientRules.isFamilyDetailsRequired());
return new ClientMfiInfoDto(groupDisplayName, centerDisplayName, loanOfficersList, customerDetail, clientDetail);
}
use of org.mifos.security.MifosUser in project head by mifos.
the class ClientServiceFacadeWebTier method removeGroupMembership.
@Override
public void removeGroupMembership(String globalCustNum, Short loanOfficerId, String comment) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(mifosUser);
ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
client.updateDetails(userContext);
PersonnelBO loanOfficer = null;
if (loanOfficerId != null) {
loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
}
PersonnelBO loggedInUser = this.personnelDao.findPersonnelById(userContext.getId());
java.sql.Date commentDate = new DateTimeService().getCurrentJavaSqlDate();
CustomerNoteEntity accountNotesEntity = new CustomerNoteEntity(comment, commentDate, loggedInUser, client);
customerService.removeGroupMembership(client, loanOfficer, accountNotesEntity, userContext.getLocaleId());
}
Aggregations