use of org.mifos.security.util.UserContext in project head by mifos.
the class PersonnelServiceFacadeWebTier method unLockUserAccount.
@Override
public void unLockUserAccount(String globalAccountNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
PersonnelBO personnel = this.personnelDao.findByGlobalPersonnelNum(globalAccountNum);
personnel.updateDetails(userContext);
try {
this.transactionHelper.startTransaction();
personnel.unlockPersonnel();
this.personnelDao.save(personnel);
this.transactionHelper.commitTransaction();
} catch (Exception e) {
this.transactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
}
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class GroupLoanAccountServiceFacadeWebTier method retrieveLoanInformation.
@Override
public LoanInformationDto retrieveLoanInformation(String globalAccountNum) {
MifosUser mifosUser = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(mifosUser);
LoanBO loan = this.loanDao.findByGlobalAccountNum(globalAccountNum);
try {
personnelDao.checkAccessPermission(userContext, loan.getOfficeId(), loan.getCustomer().getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
String fundName = null;
if (loan.getFund() != null) {
fundName = loan.getFund().getFundName();
}
boolean activeSurveys = false;
List<SurveyDto> accountSurveys = loanDao.getAccountSurveyDto(loan.getAccountId());
LoanSummaryDto loanSummary = generateGroupLoanSummaryDto(new ArrayList<LoanBO>(loan.getMemberAccounts()));
LoanPerformanceHistoryEntity performanceHistory = loan.getPerformanceHistory();
LoanPerformanceHistoryDto loanPerformanceHistory = new LoanPerformanceHistoryDto(performanceHistory.getNoOfPayments(), performanceHistory.getTotalNoOfMissedPayments(), performanceHistory.getDaysInArrears(), performanceHistory.getLoanMaturityDate());
Set<AccountFeesDto> accountFeesDtos = new HashSet<AccountFeesDto>();
if (!loan.getAccountFees().isEmpty()) {
for (AccountFeesEntity accountFeesEntity : loan.getAccountFees()) {
AccountFeesDto accountFeesDto = new AccountFeesDto(accountFeesEntity.getFees().getFeeFrequency().getFeeFrequencyType().getId(), (accountFeesEntity.getFees().getFeeFrequency().getFeePayment() != null ? accountFeesEntity.getFees().getFeeFrequency().getFeePayment().getId() : null), accountFeesEntity.getFeeStatus(), accountFeesEntity.getFees().getFeeName(), accountFeesEntity.getAccountFeeAmount().toString(), getMeetingRecurrence(accountFeesEntity.getFees().getFeeFrequency().getFeeMeetingFrequency(), userContext), accountFeesEntity.getFees().getFeeId());
accountFeesDtos.add(accountFeesDto);
}
}
Set<AccountPenaltiesDto> accountPenaltiesDtos = new HashSet<AccountPenaltiesDto>();
if (!loan.getAccountPenalties().isEmpty()) {
for (AccountPenaltiesEntity accountPenaltiesEntity : loan.getAccountPenalties()) {
accountPenaltiesDtos.add(new AccountPenaltiesDto(accountPenaltiesEntity.getPenalty().getPenaltyFrequency().getId(), accountPenaltiesEntity.getPenaltyStatus(), accountPenaltiesEntity.getPenalty().getPenaltyName(), accountPenaltiesEntity.getAccountPenaltyAmount().toString(), accountPenaltiesEntity.getPenalty().getPenaltyFrequency().getName(), accountPenaltiesEntity.getPenalty().getPenaltyId()));
}
}
Set<String> accountFlagNames = getAccountStateFlagEntityNames(loan.getAccountFlags());
Short accountStateId = loan.getAccountState().getId();
String accountStateName = getAccountStateName(accountStateId);
boolean disbursed = AccountState.isDisbursed(accountStateId);
String gracePeriodTypeName = getGracePeriodTypeName(loan.getGracePeriodType().getId());
Short interestType = loan.getInterestType().getId();
String interestTypeName = getInterestTypeName(interestType);
List<CustomerNoteDto> recentNoteDtos = new ArrayList<CustomerNoteDto>();
List<AccountNotesEntity> recentNotes = loan.getRecentAccountNotes();
for (AccountNotesEntity accountNotesEntity : recentNotes) {
recentNoteDtos.add(new CustomerNoteDto(accountNotesEntity.getCommentDate(), accountNotesEntity.getComment(), accountNotesEntity.getPersonnelName()));
}
CustomValueDto customValueDto = legacyMasterDao.getLookUpEntity(MasterConstants.COLLATERAL_TYPES);
List<CustomValueListElementDto> collateralTypes = customValueDto.getCustomValueListElements();
String collateralTypeName = null;
for (CustomValueListElementDto collateralType : collateralTypes) {
if (collateralType.getId() == loan.getCollateralTypeId()) {
collateralTypeName = collateralType.getName();
break;
}
}
Boolean groupLoanWithMembers = AccountingRules.isGroupLoanWithMembers();
return new LoanInformationDto(loan.getLoanOffering().getPrdOfferingName(), globalAccountNum, accountStateId, accountStateName, disbursed, accountFlagNames, loan.getDisbursementDate(), loan.isRedone(), loan.getBusinessActivityId(), loan.getAccountId(), gracePeriodTypeName, interestType, interestTypeName, loan.getCustomer().getCustomerId(), loan.getAccountType().getAccountTypeId(), loan.getOffice().getOfficeId(), loan.getPersonnel().getPersonnelId(), loan.getNextMeetingDate(), loan.getTotalAmountDue().toString(), loan.getTotalAmountInArrears().toString(), loanSummary, loan.getLoanActivityDetails().isEmpty() ? false : true, loan.getInterestRate(), loan.isInterestDeductedAtDisbursement(), loan.getLoanOffering().getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurAfter(), loan.getLoanOffering().getLoanOfferingMeeting().getMeeting().getMeetingDetails().getRecurrenceType().getRecurrenceId(), loan.getLoanOffering().isPrinDueLastInst(), loan.getNoOfInstallments(), loan.getMaxMinNoOfInstall().getMinNoOfInstall(), loan.getMaxMinNoOfInstall().getMaxNoOfInstall(), loan.getGracePeriodDuration(), fundName, loan.getCollateralTypeId(), collateralTypeName, loan.getCollateralNote(), loan.getExternalId(), accountFeesDtos, loan.getCreatedDate(), loanPerformanceHistory, loan.getCustomer().isGroup(), getRecentActivityView(globalAccountNum), activeSurveys, accountSurveys, loan.getCustomer().getDisplayName(), loan.getCustomer().getGlobalCustNum(), loan.getOffice().getOfficeName(), recentNoteDtos, accountPenaltiesDtos, groupLoanWithMembers);
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class GroupServiceFacadeWebTier method createNewGroup.
@Override
public CustomerDetailsDto createNewGroup(GroupCreationDetail groupCreationDetail, MeetingDto meetingDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
OfficeBO userOffice = this.officeDao.findOfficeById(userContext.getBranchId());
userContext.setBranchGlobalNum(userOffice.getGlobalOfficeNum());
GroupBO group;
try {
List<AccountFeesEntity> feesForCustomerAccount = convertFeeViewsToAccountFeeEntities(groupCreationDetail.getFeesToApply());
PersonnelBO formedBy = this.personnelDao.findPersonnelById(groupCreationDetail.getLoanOfficerId());
Short officeId;
String groupName = groupCreationDetail.getDisplayName();
CustomerStatus customerStatus = CustomerStatus.fromInt(groupCreationDetail.getCustomerStatus());
String externalId = groupCreationDetail.getExternalId();
boolean trained = groupCreationDetail.isTrained();
DateTime trainedOn = groupCreationDetail.getTrainedOn();
DateTime mfiJoiningDate = groupCreationDetail.getMfiJoiningDate();
DateTime activationDate = groupCreationDetail.getActivationDate();
AddressDto dto = groupCreationDetail.getAddressDto();
Address address = null;
if (dto != null) {
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
MeetingBO groupMeeting = null;
if (meetingDto != null) {
groupMeeting = new MeetingFactory().create(meetingDto);
groupMeeting.setUserContext(userContext);
}
if (ClientRules.getCenterHierarchyExists()) {
CenterBO parentCustomer = this.customerDao.findCenterBySystemId(groupCreationDetail.getParentSystemId());
// loanOfficerId = parentCustomer.getPersonnel().getPersonnelId();
officeId = parentCustomer.getOffice().getOfficeId();
groupMeeting = parentCustomer.getCustomerMeetingValue();
group = GroupBO.createGroupWithCenterAsParent(userContext, groupName, formedBy, parentCustomer, address, externalId, trained, trainedOn, customerStatus, mfiJoiningDate, activationDate);
} else {
// create group without center as parent
Short loanOfficerId = groupCreationDetail.getLoanOfficerId() != null ? groupCreationDetail.getLoanOfficerId() : userContext.getId();
officeId = groupCreationDetail.getOfficeId();
OfficeBO office = this.officeDao.findOfficeById(groupCreationDetail.getOfficeId());
PersonnelBO loanOfficer = this.personnelDao.findPersonnelById(loanOfficerId);
int numberOfCustomersInOfficeAlready = customerDao.retrieveLastSearchIdValueForNonParentCustomersInOffice(officeId);
group = GroupBO.createGroupAsTopOfCustomerHierarchy(userContext, groupName, formedBy, groupMeeting, loanOfficer, office, address, externalId, trained, trainedOn, customerStatus, numberOfCustomersInOfficeAlready, mfiJoiningDate, activationDate);
}
try {
personnelDao.checkAccessPermission(userContext, group.getOfficeId(), group.getLoanOfficerId());
} catch (AccountException e) {
throw new MifosRuntimeException("Access denied!", e);
}
this.customerService.createGroup(group, groupMeeting, feesForCustomerAccount);
return new CustomerDetailsDto(group.getCustomerId(), group.getGlobalCustNum());
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class GroupServiceFacadeWebTier method retrieveGroupDetailsForUpdate.
@Override
public CenterDto retrieveGroupDetailsForUpdate(String globalCustNum) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
List<PersonnelDto> activeLoanOfficersForBranch = new ArrayList<PersonnelDto>();
GroupBO group = this.customerDao.findGroupBySystemId(globalCustNum);
Short officeId = group.getOffice().getOfficeId();
String searchId = group.getSearchId();
Short loanOfficerId = extractLoanOfficerId(group);
boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
if (!isCenterHierarchyExists) {
CenterCreation centerCreation = new CenterCreation(officeId, userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
activeLoanOfficersForBranch = personnelDao.findActiveLoanOfficersForOffice(centerCreation);
}
List<CustomerDto> customerList = customerDao.findClientsThatAreNotCancelledOrClosed(searchId, officeId);
List<CustomerPositionDto> customerPositionDtos = generateCustomerPositionViews(group, userContext.getLocaleId());
DateTime mfiJoiningDate = new DateTime();
String mfiJoiningDateAsString = "";
if (group.getMfiJoiningDate() != null) {
mfiJoiningDate = new DateTime(group.getMfiJoiningDate());
mfiJoiningDateAsString = DateUtils.getUserLocaleDate(userContext.getPreferredLocale(), group.getMfiJoiningDate().toString());
}
AddressDto address = null;
if (group.getAddress() != null) {
address = Address.toDto(group.getAddress());
}
return new CenterDto(loanOfficerId, group.getCustomerId(), group.getGlobalCustNum(), mfiJoiningDate, mfiJoiningDateAsString, group.getExternalId(), address, customerPositionDtos, customerList, activeLoanOfficersForBranch, isCenterHierarchyExists);
}
use of org.mifos.security.util.UserContext in project head by mifos.
the class GroupServiceFacadeWebTier method transferGroupToCenter.
@Override
public CustomerDetailDto transferGroupToCenter(String groupSystemId, String centerSystemId, Integer previousGroupVersionNo) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
CenterBO transferToCenter = this.customerDao.findCenterBySystemId(centerSystemId);
transferToCenter.updateDetails(userContext);
GroupBO group = this.customerDao.findGroupBySystemId(groupSystemId);
group.updateDetails(userContext);
checkVersionMismatch(previousGroupVersionNo, group.getVersionNo());
String groupGlobalCustNum = this.customerService.transferGroupTo(group, transferToCenter);
GroupBO transferedGroup = this.customerDao.findGroupBySystemId(groupGlobalCustNum);
return transferedGroup.toCustomerDetailDto();
} catch (ApplicationException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
Aggregations