use of org.mifos.customers.office.util.helpers.OfficeStatus 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.customers.office.util.helpers.OfficeStatus in project head by mifos.
the class OffAction method officeUpdateRequestFrom.
private OfficeUpdateRequest officeUpdateRequestFrom(OffActionForm offActionForm) throws OfficeException {
OfficeStatus newStatus = null;
if (getShortValue(offActionForm.getOfficeStatus()) != null) {
newStatus = OfficeStatus.getOfficeStatus(getShortValue(offActionForm.getOfficeStatus()));
}
OfficeLevel newlevel = OfficeLevel.getOfficeLevel(getShortValue(offActionForm.getOfficeLevel()));
Short parentOfficeId = getShortValue(offActionForm.getParentOfficeId());
Address address = offActionForm.getAddress();
AddressDto addressDto = null;
if (address != null) {
addressDto = Address.toDto(address);
}
return new OfficeUpdateRequest(offActionForm.getOfficeName(), offActionForm.getShortName(), newStatus.getValue(), newlevel.getValue(), parentOfficeId, addressDto);
}
use of org.mifos.customers.office.util.helpers.OfficeStatus in project head by mifos.
the class OfficeBO method update.
public void update(UserContext userContext, OfficeUpdateRequest officeUpdateRequest, OfficeBO newParentOffice) throws OfficeException {
updateDetails(userContext);
OfficeStatus officeStatus = OfficeStatus.getOfficeStatus(officeUpdateRequest.getNewStatus());
OfficeLevel officeLevel = OfficeLevel.getOfficeLevel(officeUpdateRequest.getNewlevel());
Address address = null;
AddressDto dto = officeUpdateRequest.getAddress();
if (dto != null) {
address = new Address(dto.getLine1(), dto.getLine2(), dto.getLine3(), dto.getCity(), dto.getState(), dto.getCountry(), dto.getZip(), dto.getPhoneNumber());
}
update(officeUpdateRequest.getOfficeName(), officeUpdateRequest.getShortName(), officeStatus, officeLevel, newParentOffice, address, new ArrayList<CustomFieldDto>());
}
Aggregations