use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class OfficeServiceFacadeWebTier method createOffice.
@Override
public ListElement createOffice(Short operationMode, OfficeDto officeDto) {
MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
UserContext userContext = new UserContextFactory().create(user);
OfficeLevel level = OfficeLevel.getOfficeLevel(officeDto.getLevelId());
OfficeBO parentOffice = officeDao.findOfficeById(officeDto.getParentId());
AddressDto addressDto = officeDto.getAddress();
Address address = new Address(addressDto.getLine1(), addressDto.getLine2(), addressDto.getLine3(), addressDto.getCity(), addressDto.getState(), addressDto.getCountry(), addressDto.getZip(), addressDto.getPhoneNumber());
try {
OfficeBO officeBO = new OfficeBO(userContext, level, parentOffice, officeDto.getCustomFields(), officeDto.getName(), officeDto.getOfficeShortName(), address, OperationMode.fromInt(operationMode.intValue()));
OfficePersistence officePersistence = new OfficePersistence();
if (officePersistence.isOfficeNameExist(officeDto.getName())) {
throw new OfficeValidationException(OfficeConstants.OFFICENAMEEXIST);
}
if (officePersistence.isOfficeShortNameExist(officeDto.getOfficeShortName())) {
throw new OfficeValidationException(OfficeConstants.OFFICESHORTNAMEEXIST);
}
String searchId = generateSearchId(parentOffice);
officeBO.setSearchId(searchId);
String globalOfficeNum = generateOfficeGlobalNo();
officeBO.setGlobalOfficeNum(globalOfficeNum);
StaticHibernateUtil.startTransaction();
this.officeDao.save(officeBO);
StaticHibernateUtil.commitTransaction();
//Shahid - this is hackish solution to return officeId and globalOfficeNum via ListElement, it should be fixed, at least
//a proper data storage class can be created
ListElement element = new ListElement(new Integer(officeBO.getOfficeId()), officeBO.getGlobalOfficeNum());
// if we are here it means office created sucessfully
// we need to update hierarchy manager cache
OfficeSearch os = new OfficeSearch(officeBO.getOfficeId(), officeBO.getSearchId(), officeBO.getParentOffice().getOfficeId());
List<OfficeSearch> osList = new ArrayList<OfficeSearch>();
osList.add(os);
EventManger.postEvent(Constants.CREATE, osList, SecurityConstants.OFFICECHANGEEVENT);
return element;
} catch (OfficeValidationException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getMessage());
} catch (PersistenceException e) {
StaticHibernateUtil.rollbackTransaction();
throw new MifosRuntimeException(e);
} catch (OfficeException e) {
StaticHibernateUtil.rollbackTransaction();
throw new BusinessRuleException(e.getKey(), e);
} finally {
StaticHibernateUtil.closeSession();
}
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class ClientCustActionStrutsTest method createAndSetClientInSession.
private void createAndSetClientInSession() throws Exception {
OfficeBO office = new OfficePersistence().getOffice(TestObjectFactory.HEAD_OFFICE);
PersonnelBO personnel = legacyPersonnelDao.getPersonnel(PersonnelConstants.TEST_USER);
meeting = getMeeting();
ClientNameDetailDto clientNameDetailDto = new ClientNameDetailDto(NameType.CLIENT.getValue(), 1, "Client", "", "1", "");
clientNameDetailDto.setNames(ClientRules.getNameSequence());
ClientNameDetailDto spouseNameDetailView = new ClientNameDetailDto(NameType.SPOUSE.getValue(), 1, "first", "middle", "last", "secondLast");
spouseNameDetailView.setNames(ClientRules.getNameSequence());
ClientPersonalDetailDto clientPersonalDetailDto = new ClientPersonalDetailDto(1, 1, 1, 1, 1, 1, Short.valueOf("1"), Short.valueOf("1"), Short.valueOf("41"));
Calendar dob = new GregorianCalendar();
dob.set(Calendar.YEAR, 1970);
client = new ClientBO(TestUtils.makeUser(), clientNameDetailDto.getDisplayName(), CustomerStatus.fromInt(new Short("1")), null, null, new Address(), getCustomFields(), null, null, personnel, office, meeting, personnel, dob.getTime(), null, null, null, YesNoFlag.NO.getValue(), clientNameDetailDto, spouseNameDetailView, clientPersonalDetailDto, null);
legacyClientDao.saveClient(client);
StaticHibernateUtil.flushAndClearSession();
client = TestObjectFactory.getClient(Integer.valueOf(client.getCustomerId()).intValue());
request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
SessionUtils.setAttribute(Constants.BUSINESS_KEY, client, request);
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class ConfigurationIntegrationTest method testAreaOfficeConfiguration.
@Test
public void testAreaOfficeConfiguration() throws Exception {
OfficeBO areaOffice = new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_AREA_OFFICE);
OfficeConfig officeConfig = configuration.getOfficeConfig(areaOffice.getOfficeId());
assertForAccountConfig(officeConfig.getAccountConfig());
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class ConfigurationIntegrationTest method testBranchOfficeConfiguration.
@Test
public void testBranchOfficeConfiguration() throws Exception {
OfficeBO branchOffice = new OfficePersistence().getOffice(TestObjectFactory.SAMPLE_BRANCH_OFFICE);
OfficeConfig officeConfig = configuration.getOfficeConfig(branchOffice.getOfficeId());
assertForAccountConfig(officeConfig.getAccountConfig());
}
use of org.mifos.customers.office.persistence.OfficePersistence in project head by mifos.
the class CenterBOIntegrationTest method testSuccessfulCreate.
@Test
public void testSuccessfulCreate() throws Exception {
String name = "Center";
String externalId = "12345";
Date mfiJoiningDate = getDate("11/12/2005");
meeting = getMeeting();
List<FeeDto> fees = getFees();
center = new CenterBO(TestUtils.makeUser(), name, null, getCustomFields(), fees, externalId, mfiJoiningDate, new OfficePersistence().getOffice(officeId), meeting, legacyPersonnelDao.getPersonnel(personnelId), new CustomerPersistence());
new CenterPersistence().saveCenter(center);
StaticHibernateUtil.flushSession();
center = TestObjectFactory.getCenter(center.getCustomerId());
Assert.assertEquals(name, center.getDisplayName());
Assert.assertEquals(externalId, center.getExternalId());
Assert.assertEquals(mfiJoiningDate, DateUtils.getDateWithoutTimeStamp(center.getMfiJoiningDate().getTime()));
Assert.assertEquals(officeId, center.getOffice().getOfficeId());
Assert.assertEquals(2, center.getCustomFields().size());
Assert.assertEquals(AccountState.CUSTOMER_ACCOUNT_ACTIVE.getValue(), center.getCustomerAccount().getAccountState().getId());
// check if values in account fees are entered.
Assert.assertNotNull(center.getCustomerAccount().getAccountFees(fees.get(0).getFeeIdValue()));
Assert.assertNotNull(center.getCustomerAccount().getAccountFees(fees.get(1).getFeeIdValue()));
}
Aggregations