Search in sources :

Example 1 with LookUpEntity

use of org.mifos.application.master.business.LookUpEntity in project head by mifos.

the class MessageLookup method setCustomLabel.

/*
     * Set a custom label value that will override resource bundle values.
     *
     * TODO: we need to add a method for getting and/or setting a label value directly rather than having to iterate.
     * Also, we don't necessarily want to reinitialize the MifosConfiguration after each update. Ultimately, it would be
     * cleaner to just use a key-value lookup to implement these overrides.
     */
public void setCustomLabel(String labelKey, String value) throws PersistenceException {
    // only update the value if there is a change
    if (lookupLabel(labelKey).compareTo(value) != 0) {
        for (LookUpEntity entity : applicationConfigurationDao.findLookupEntities()) {
            if (entity.getEntityType().equals(labelKey)) {
                Set<LookUpLabelEntity> labels = entity.getLookUpLabels();
                for (LookUpLabelEntity label : labels) {
                    label.setLabelName(value);
                    genericDao.createOrUpdate(label);
                    StaticHibernateUtil.commitTransaction();
                    updateLookupValueInCache(labelKey, value);
                }
            }
        }
    }
}
Also used : LookUpEntity(org.mifos.application.master.business.LookUpEntity) LookUpLabelEntity(org.mifos.application.master.business.LookUpLabelEntity)

Example 2 with LookUpEntity

use of org.mifos.application.master.business.LookUpEntity in project head by mifos.

the class LegacyMasterDao method addValueListElementForLocale.

/**
     * Create a new list element for a single locale.
     *
     * It would be nicer for this to operate on objects rather than ids, but it
     * is a first step that works.
     */
public LookUpValueEntity addValueListElementForLocale(final Short lookupEnityId, final String newElementText, final String lookUpName) throws PersistenceException {
    LookUpEntity lookUpEntity = getPersistentObject(LookUpEntity.class, lookupEnityId);
    LookUpValueEntity lookUpValueEntity = new LookUpValueEntity();
    lookUpValueEntity.setLookUpEntity(lookUpEntity);
    lookUpValueEntity.setLookUpName(lookUpName);
    createOrUpdate(lookUpValueEntity);
    LookUpValueLocaleEntity lookUpValueLocaleEntity = new LookUpValueLocaleEntity();
    lookUpValueLocaleEntity.setLocaleId(Localization.ENGLISH_LOCALE_ID);
    lookUpValueLocaleEntity.setLookUpValue(newElementText);
    lookUpValueLocaleEntity.setLookUpId(lookUpValueEntity.getLookUpId());
    createOrUpdate(lookUpValueLocaleEntity);
    // MifosConfiguration.getInstance().updateKey(lookUpValueEntity,
    // newElementText);
    ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(lookUpValueEntity, newElementText);
    return lookUpValueEntity;
}
Also used : LookUpEntity(org.mifos.application.master.business.LookUpEntity) MessageLookup(org.mifos.application.master.MessageLookup) LookUpValueLocaleEntity(org.mifos.application.master.business.LookUpValueLocaleEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity)

Example 3 with LookUpEntity

use of org.mifos.application.master.business.LookUpEntity in project head by mifos.

the class ApplicationConfigurationDaoHibernate method findLookupEntities.

@SuppressWarnings("unchecked")
@Override
public List<LookUpEntity> findLookupEntities() {
    Session session = StaticHibernateUtil.getSessionTL();
    List<LookUpEntity> entities = session.getNamedQuery(NamedQueryConstants.GET_ENTITIES).list();
    for (LookUpEntity entity : entities) {
        Set<LookUpLabelEntity> labels = entity.getLookUpLabels();
        entity.getEntityType();
        for (LookUpLabelEntity label : labels) {
            label.getLabelText();
            label.getLocaleId();
        }
    }
    return entities;
}
Also used : LookUpEntity(org.mifos.application.master.business.LookUpEntity) Session(org.hibernate.Session) LookUpLabelEntity(org.mifos.application.master.business.LookUpLabelEntity)

Example 4 with LookUpEntity

use of org.mifos.application.master.business.LookUpEntity in project head by mifos.

the class OfficeHierarchyServiceImpl method updateApplicationLabels.

@Override
public void updateApplicationLabels(List<OfficeLevelEntity> changedOfficeLabels, List<LookUpEntity> lookupEntities, List<GracePeriodTypeEntity> gracePeriods, List<LookUpValueEntity> accountStatuses) {
    try {
        transactionHelper.startTransaction();
        for (OfficeLevelEntity entity : changedOfficeLabels) {
            officeDao.save(entity);
            LookUpValueEntity lookupValue = entity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
        }
        for (GracePeriodTypeEntity entity : gracePeriods) {
            applicationConfigurationDao.save(entity);
            LookUpValueEntity lookupValue = entity.getLookUpValue();
            String messageText = lookupValue.getMessageText();
            if (StringUtils.isBlank(messageText)) {
                messageText = ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookupValue.getPropertiesKey());
            }
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getLookUpValue().getLookUpName(), messageText);
        }
        for (LookUpEntity entity : lookupEntities) {
            applicationConfigurationDao.save(entity);
            ApplicationContextProvider.getBean(MessageLookup.class).updateLookupValueInCache(entity.getEntityType(), entity.findLabel());
        }
        for (LookUpValueEntity entity : accountStatuses) {
            applicationConfigurationDao.save(entity);
        }
        transactionHelper.commitTransaction();
        if (!accountStatuses.isEmpty()) {
            MenuRepository.getInstance().removeMenuForAllLocale();
        }
    } catch (BusinessRuleException e) {
        transactionHelper.rollbackTransaction();
        throw e;
    } catch (Exception e) {
        transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } finally {
        transactionHelper.closeSession();
    }
}
Also used : BusinessRuleException(org.mifos.service.BusinessRuleException) LookUpEntity(org.mifos.application.master.business.LookUpEntity) MessageLookup(org.mifos.application.master.MessageLookup) GracePeriodTypeEntity(org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException) BusinessRuleException(org.mifos.service.BusinessRuleException) OfficeLevelEntity(org.mifos.customers.office.business.OfficeLevelEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 5 with LookUpEntity

use of org.mifos.application.master.business.LookUpEntity in project head by mifos.

the class AccountActionEntityIntegrationTest method testBasics.

@Test
public void testBasics() throws Exception {
    AccountActionEntity action = (AccountActionEntity) session.get(AccountActionEntity.class, AccountActionTypes.PAYMENT.getValue());
    LookUpValueEntity lookUpValue = action.getLookUpValue();
    Assert.assertEquals("AccountAction-Payment", lookUpValue.getLookUpName());
    Assert.assertEquals(new Integer(191), lookUpValue.getLookUpId());
    LookUpEntity lookUpEntity = lookUpValue.getLookUpEntity();
    Assert.assertEquals(LookUpEntity.ACCOUNT_ACTION, lookUpEntity.getEntityId().shortValue());
    Assert.assertEquals("AccountAction", lookUpEntity.getEntityType());
    Set<LookUpValueLocaleEntity> valueLocales = lookUpValue.getLookUpValueLocales();
    Assert.assertEquals(1, valueLocales.size());
    LookUpValueLocaleEntity valueLocale = valueLocales.iterator().next();
    Assert.assertEquals(1, (int) valueLocale.getLocaleId());
    Assert.assertEquals("Payment", ApplicationContextProvider.getBean(MessageLookup.class).lookup(lookUpValue));
    Assert.assertEquals("Payment", action.getName());
}
Also used : LookUpEntity(org.mifos.application.master.business.LookUpEntity) LookUpValueLocaleEntity(org.mifos.application.master.business.LookUpValueLocaleEntity) LookUpValueEntity(org.mifos.application.master.business.LookUpValueEntity) Test(org.junit.Test)

Aggregations

LookUpEntity (org.mifos.application.master.business.LookUpEntity)14 LookUpValueEntity (org.mifos.application.master.business.LookUpValueEntity)8 Test (org.junit.Test)5 MessageLookup (org.mifos.application.master.MessageLookup)3 LookUpLabelEntity (org.mifos.application.master.business.LookUpLabelEntity)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)3 Session (org.hibernate.Session)2 LookUpValueLocaleEntity (org.mifos.application.master.business.LookUpValueLocaleEntity)2 HashMap (java.util.HashMap)1 Ignore (org.junit.Ignore)1 GracePeriodTypeEntity (org.mifos.accounts.productdefinition.business.GracePeriodTypeEntity)1 MifosRuntimeException (org.mifos.core.MifosRuntimeException)1 OfficeLevelEntity (org.mifos.customers.office.business.OfficeLevelEntity)1 RoleBO (org.mifos.security.rolesandpermission.business.RoleBO)1 BusinessRuleException (org.mifos.service.BusinessRuleException)1