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);
}
}
}
}
}
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;
}
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;
}
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();
}
}
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());
}
Aggregations