use of org.mifos.security.MifosUser in project head by mifos.
the class ClientServiceFacadeWebTier method previewClient.
@Override
public ProcessRulesDto previewClient(String governmentId, DateTime dateOfBirth, String clientName, boolean defaultFeeRemoval, Short officeId, Short loanOfficerId) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
boolean clientPendingApprovalStateEnabled = ProcessFlowRules.isClientPendingApprovalStateEnabled();
boolean governmentIdValidationFailing = false;
boolean duplicateNameOnClosedClient = false;
boolean duplicateNameOnBlackListedClient = false;
boolean governmentIdValidationUnclosedFailing = false;
boolean duplicateNameOnClient = false;
List<ClientBO> matchedClients = new ArrayList<ClientBO>();
List<ClientBO> temp;
if (defaultFeeRemoval) {
customerDao.checkPermissionForDefaultFeeRemoval(userContext, officeId, loanOfficerId);
}
if (StringUtils.isNotBlank(governmentId)) {
temp = this.customerDao.validateGovernmentIdForUnclosedClient(governmentId);
if (temp != null) {
matchedClients.addAll(temp);
}
governmentIdValidationUnclosedFailing = temp != null && temp.size() > 0;
if (!governmentIdValidationUnclosedFailing) {
temp = this.customerDao.validateGovernmentIdForClient(governmentId);
if (temp != null) {
matchedClients.addAll(temp);
}
governmentIdValidationFailing = temp != null && temp.size() > 0;
}
}
if (!governmentIdValidationFailing && !governmentIdValidationUnclosedFailing) {
temp = this.customerDao.validateForBlackListedClientsOnNameAndDob(clientName, dateOfBirth);
if (temp != null) {
matchedClients.addAll(temp);
}
duplicateNameOnBlackListedClient = temp != null && temp.size() > 0;
if (!duplicateNameOnBlackListedClient) {
temp = this.customerDao.validateForClosedClientsOnNameAndDob(clientName, dateOfBirth);
if (temp != null) {
matchedClients.addAll(temp);
}
duplicateNameOnClosedClient = temp != null && temp.size() > 0;
if (!duplicateNameOnClosedClient) {
temp = this.customerDao.validateForClientsOnName(clientName);
if (temp != null) {
matchedClients.addAll(temp);
}
duplicateNameOnClient = temp != null && temp.size() > 0;
}
}
}
List<MatchedClientDto> matched = new ArrayList<MatchedClientDto>();
for (ClientBO client : matchedClients) {
matched.add(new MatchedClientDto(client.getGlobalCustNum(), client.getDisplayName(), client.getAddress().getPhoneNumber(), client.getGovernmentId(), client.getDisplayAddress(), client.getOffice().getOfficeName(), client.getOffice().getGlobalOfficeNum()));
}
return new ProcessRulesDto(clientPendingApprovalStateEnabled, governmentIdValidationFailing, duplicateNameOnClosedClient, duplicateNameOnBlackListedClient, governmentIdValidationUnclosedFailing, duplicateNameOnClient, matched);
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.security.MifosUser in project head by mifos.
the class ClientServiceFacadeWebTier method updateFamilyInfo.
@Override
public void updateFamilyInfo(ClientFamilyInfoUpdate clientFamilyInfoUpdate) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
try {
this.customerService.updateClientFamilyInfo(userContext, clientFamilyInfoUpdate);
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.security.MifosUser in project head by mifos.
the class ClientServiceFacadeWebTier method retreiveClientDetailsForRemovalFromGroup.
@Override
public ClientRemovalFromGroupDto retreiveClientDetailsForRemovalFromGroup(String globalCustNum) {
try {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = toUserContext(user);
ClientBO client = this.customerDao.findClientBySystemId(globalCustNum);
client.updateDetails(userContext);
client.checkIfClientIsATitleHolder();
List<OfficeDetailsDto> activeBranches = this.officeDao.findActiveBranches(userContext.getBranchId());
boolean isCenterHierarchyExists = ClientRules.getCenterHierarchyExists();
boolean isActive = client.isActive();
Short loanOfficerId = client.getPersonnel().getPersonnelId();
CenterCreation clientDetails = new CenterCreation(client.getOfficeId(), userContext.getId(), userContext.getLevelId(), userContext.getPreferredLocale());
List<PersonnelDto> loanOfficers = this.personnelDao.findActiveLoanOfficersForOffice(clientDetails);
return new ClientRemovalFromGroupDto(client.getGlobalCustNum(), isActive, isCenterHierarchyExists, loanOfficerId, loanOfficers, activeBranches);
} catch (CustomerException e) {
throw new BusinessRuleException(e.getKey(), e);
}
}
use of org.mifos.security.MifosUser in project head by mifos.
the class OfficeServiceFacadeWebTier method retrieveAllNonBranchOfficesApplicableToLoggedInUser.
@Override
public List<OfficeDto> retrieveAllNonBranchOfficesApplicableToLoggedInUser() {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
OfficeDto office = officeDao.findOfficeDtoById(user.getBranchId());
return officeDao.findNonBranchesOnlyWithParentsMatching(office.getSearchId());
}
use of org.mifos.security.MifosUser 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();
}
}
Aggregations