Search in sources :

Example 1 with LookUpLabelEntity

use of org.mifos.application.master.business.LookUpLabelEntity 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 LookUpLabelEntity

use of org.mifos.application.master.business.LookUpLabelEntity 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 3 with LookUpLabelEntity

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

the class ApplicationConfigurationPersistenceIntegrationTest method testGetLookupEntities.

/*
     * Check that we can can retrieve LookupEntities and enforce the conventions: LookupEntity names cannot contain
     * whitespace LookupEntities should not have more than 1 label
     */
@Test
public void testGetLookupEntities() {
    List<LookUpEntity> entities = applicationConfigurationDao.findLookupEntities();
    Assert.assertNotNull(entities);
    // Enforce that no entity names contain whitespace
    for (LookUpEntity entity : entities) {
        Assert.assertEquals(StringUtils.deleteWhitespace(entity.getEntityType()), entity.getEntityType());
        Set<LookUpLabelEntity> labels = entity.getLookUpLabels();
        // Enforce that each entity has 0 or 1 labels and not more
        Assert.assertTrue(labels.size() <= 1);
        for (LookUpLabelEntity label : labels) {
        //                if (entity.getEntityType().equals("Client")) {
        //                    Assert.assertEquals("Client", label.getLabelText());
        //                }
        }
    }
}
Also used : LookUpEntity(org.mifos.application.master.business.LookUpEntity) LookUpLabelEntity(org.mifos.application.master.business.LookUpLabelEntity) Test(org.junit.Test)

Aggregations

LookUpEntity (org.mifos.application.master.business.LookUpEntity)3 LookUpLabelEntity (org.mifos.application.master.business.LookUpLabelEntity)3 Session (org.hibernate.Session)1 Test (org.junit.Test)1