Search in sources :

Example 26 with OfficePersistence

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();
    }
}
Also used : OfficeException(org.mifos.customers.office.exceptions.OfficeException) OfficeValidationException(org.mifos.customers.office.exceptions.OfficeValidationException) Address(org.mifos.framework.business.util.Address) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) MifosUser(org.mifos.security.MifosUser) UserContextFactory(org.mifos.accounts.servicefacade.UserContextFactory) OfficeSearch(org.mifos.security.util.OfficeSearch) AddressDto(org.mifos.dto.domain.AddressDto) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeBO(org.mifos.customers.office.business.OfficeBO) ListElement(org.mifos.dto.screen.ListElement) PersistenceException(org.mifos.framework.exceptions.PersistenceException) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) OfficeLevel(org.mifos.customers.office.util.helpers.OfficeLevel) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 27 with OfficePersistence

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);
}
Also used : Address(org.mifos.framework.business.util.Address) OfficeBO(org.mifos.customers.office.business.OfficeBO) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) ClientNameDetailDto(org.mifos.dto.screen.ClientNameDetailDto) ClientPersonalDetailDto(org.mifos.dto.screen.ClientPersonalDetailDto) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ClientBO(org.mifos.customers.client.business.ClientBO) GregorianCalendar(java.util.GregorianCalendar) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence)

Example 28 with OfficePersistence

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());
}
Also used : OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 29 with OfficePersistence

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());
}
Also used : OfficeBO(org.mifos.customers.office.business.OfficeBO) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Test(org.junit.Test)

Example 30 with OfficePersistence

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()));
}
Also used : FeeDto(org.mifos.accounts.fees.business.FeeDto) CustomerPersistence(org.mifos.customers.persistence.CustomerPersistence) OfficePersistence(org.mifos.customers.office.persistence.OfficePersistence) Date(java.util.Date) CenterPersistence(org.mifos.customers.center.persistence.CenterPersistence) Test(org.junit.Test)

Aggregations

OfficePersistence (org.mifos.customers.office.persistence.OfficePersistence)37 PersistenceException (org.mifos.framework.exceptions.PersistenceException)17 OfficeBO (org.mifos.customers.office.business.OfficeBO)16 Test (org.junit.Test)11 MifosRuntimeException (org.mifos.core.MifosRuntimeException)11 OfficeException (org.mifos.customers.office.exceptions.OfficeException)11 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)8 ClientNameDetailDto (org.mifos.dto.screen.ClientNameDetailDto)8 ClientPersonalDetailDto (org.mifos.dto.screen.ClientPersonalDetailDto)8 ArrayList (java.util.ArrayList)7 CustomerException (org.mifos.customers.exceptions.CustomerException)7 ClientBO (org.mifos.customers.client.business.ClientBO)6 ProductDefinitionException (org.mifos.accounts.productdefinition.exceptions.ProductDefinitionException)5 MeetingException (org.mifos.application.meeting.exceptions.MeetingException)5 OfficeDetailsDto (org.mifos.dto.domain.OfficeDetailsDto)5 Date (java.util.Date)4 MessageLookup (org.mifos.application.master.MessageLookup)4 CustomerPersistence (org.mifos.customers.persistence.CustomerPersistence)4 Address (org.mifos.framework.business.util.Address)4 ApplicationException (org.mifos.framework.exceptions.ApplicationException)4