use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CustomerServiceImpl method updateCustomerMeetingSchedule.
@Override
public void updateCustomerMeetingSchedule(MeetingBO updatedMeeting, CustomerBO customer) {
try {
customer.validateIsTopOfHierarchy();
customerDao.checkPermissionForEditMeetingSchedule(updatedMeeting.getUserContext(), customer);
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(customer.getOfficeId());
this.hibernateTransactionHelper.startTransaction();
boolean scheduleUpdateRequired = false;
CustomerMeetingEntity meetingEntity = customer.getCustomerMeeting();
if (meetingEntity != null) {
MeetingBO meeting = customer.getCustomerMeetingValue();
scheduleUpdateRequired = updateMeeting(meeting, updatedMeeting);
} else {
CustomerMeetingEntity newMeetingEntity = customer.createCustomerMeeting(updatedMeeting);
customer.setCustomerMeeting(newMeetingEntity);
}
customerDao.save(customer);
if (scheduleUpdateRequired) {
handleChangeInMeetingSchedule(customer, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
this.hibernateTransactionHelper.commitTransaction();
} catch (CustomerException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (AccountException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CustomerServiceImpl method transferClientTo.
@Override
public ClientBO transferClientTo(UserContext userContext, Integer groupId, String clientGlobalCustNum, Integer previousClientVersionNo) throws CustomerException {
ClientBO client = customerDao.findClientBySystemId(clientGlobalCustNum);
client.validateVersion(previousClientVersionNo);
client.validateIsSameGroup(groupId);
client.updateDetails(userContext);
GroupBO receivingGroup = (GroupBO) customerDao.findCustomerById(groupId);
client.validateReceivingGroup(receivingGroup);
client.validateForActiveAccounts();
client.validateForPeriodicFees();
if (client.getOfficeId() != receivingGroup.getOfficeId()) {
customerDao.checkPermissionforEditingClientOfficeMembership(client.getUserContext(), client);
}
CustomerBO oldParent = client.getParentCustomer();
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(client);
boolean regenerateSchedules = client.transferTo(receivingGroup);
if (oldParent != null) {
client.resetPositions(oldParent);
oldParent.updateDetails(client.getUserContext());
if (oldParent.getParentCustomer() != null) {
CustomerBO center = oldParent.getParentCustomer();
client.resetPositions(center);
center.setUserContext(client.getUserContext());
}
customerDao.save(oldParent);
}
receivingGroup.updateDetails(client.getUserContext());
customerDao.save(receivingGroup);
client.updateDetails(userContext);
customerDao.save(client);
hibernateTransactionHelper.flushAndClearSession();
if (regenerateSchedules) {
client = customerDao.findClientBySystemId(clientGlobalCustNum);
CalendarEvent calendarEvents = holidayDao.findCalendarEventsForThisYearAndNext(client.getOfficeId());
handleChangeInMeetingSchedule(client, calendarEvents.getWorkingDays(), calendarEvents.getHolidays());
}
hibernateTransactionHelper.commitTransaction();
return client;
} catch (ApplicationException e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} catch (Exception e) {
this.hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
this.hibernateTransactionHelper.closeSession();
}
}
use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CustomerServiceImpl method updateClientPersonalInfo.
@Override
public final void updateClientPersonalInfo(UserContext userContext, ClientPersonalInfoUpdate personalInfo) throws CustomerException {
ClientBO client = (ClientBO) this.customerDao.findCustomerById(personalInfo.getCustomerId());
client.validateVersion(personalInfo.getOriginalClientVersionNumber());
client.updateDetails(userContext);
LocalDate currentDOB = new LocalDate(client.getDateOfBirth());
LocalDate newDOB = currentDOB;
try {
// updating Date of birth
// doesn''t sound normal but it can be required in certain cases
// see http://mifosforge.jira.com/browse/MIFOS-4368
newDOB = new LocalDate(DateUtils.getDateAsSentFromBrowser(personalInfo.getDateOfBirth()));
} catch (InvalidDateException e) {
throw new MifosRuntimeException(e);
}
if (!currentDOB.isEqual(newDOB)) {
customerDao.validateClientForDuplicateNameOrGovtId(personalInfo.getClientDisplayName(), newDOB.toDateMidnight().toDate(), null);
}
try {
hibernateTransactionHelper.startTransaction();
hibernateTransactionHelper.beginAuditLoggingFor(client);
client.updatePersonalInfo(personalInfo);
clientPhotoService.update(personalInfo.getCustomerId().longValue(), personalInfo.getPicture());
customerDao.save(client);
hibernateTransactionHelper.commitTransaction();
} catch (ApplicationException e) {
hibernateTransactionHelper.rollbackTransaction();
throw new CustomerException(e.getKey(), e);
} catch (Exception e) {
hibernateTransactionHelper.rollbackTransaction();
throw new MifosRuntimeException(e);
} finally {
hibernateTransactionHelper.commitTransaction();
}
}
use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CenterPersistence method saveCenter.
/**
* @deprecated use {@link CustomerDao#save(org.mifos.customers.business.CustomerBO)}.
*/
@Deprecated
public void saveCenter(CenterBO center) throws CustomerException {
try {
createOrUpdate(center);
center.generateGlobalCustomerNumber();
createOrUpdate(center);
} catch (PersistenceException e) {
throw new CustomerException(CustomerConstants.CREATE_FAILED_EXCEPTION, e);
}
}
use of org.mifos.customers.exceptions.CustomerException in project head by mifos.
the class CustomerDaoHibernate method validateCenterNameIsNotTakenForOffice.
@SuppressWarnings("unchecked")
@Override
public void validateCenterNameIsNotTakenForOffice(String displayName, Short officeId) throws CustomerException {
if (StringUtils.isBlank(displayName)) {
throw new CustomerException(CustomerConstants.INVALID_NAME, new Object[] { displayName });
}
Map<String, Object> queryParameters = new HashMap<String, Object>();
queryParameters.put(CustomerConstants.DISPLAY_NAME, displayName);
queryParameters.put(CustomerConstants.OFFICE_ID, officeId);
List queryResult = this.genericDao.executeNamedQuery("Customer.getCenterCount", queryParameters);
if (Integer.valueOf(queryResult.get(0).toString()) > 0) {
throw new CustomerException(CustomerConstants.ERRORS_DUPLICATE_CUSTOMER, new Object[] { displayName });
}
}
Aggregations