dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20748
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9632: Translation for formname of data entry form.
------------------------------------------------------------
revno: 9632
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-01-28 15:50:29 +0700
message:
Translation for formname of data entry form.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2013-01-27 20:34:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2013-01-28 08:50:29 +0000
@@ -73,6 +73,8 @@
public class DataElement
extends BaseNameableObject
{
+ public static final String[] I18N_PROPERTIES = { "name", "shortName", "description", "formName" };
+
/**
* Determines if a de-serialized file is compatible with this class.
*/
@@ -114,7 +116,12 @@
* The name to appear in forms.
*/
private String formName;
-
+
+ /**
+ * The i18n variant of the display name. Should not be persisted.
+ */
+ protected transient String displayFormName;
+
/**
* If this DataElement is active or not (enabled or disabled).
*/
@@ -413,7 +420,17 @@
*/
public String getFormNameFallback()
{
- return formName != null && !formName.isEmpty() ? formName : getDisplayName();
+ return formName != null && !formName.isEmpty() ? getDisplayFormName() : getDisplayName();
+ }
+
+ public String getDisplayFormName()
+ {
+ return ( displayFormName != null && !displayFormName.trim().isEmpty() ) ? displayFormName : formName;
+ }
+
+ public void setDisplayFormName( String displayFormName )
+ {
+ this.displayFormName = displayFormName;
}
/**
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2013-01-11 13:12:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2013-01-28 08:50:29 +0000
@@ -79,7 +79,8 @@
private GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore;
- public void setDataElementGroupSetStore( GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore )
+ public void setDataElementGroupSetStore(
+ GenericIdentifiableObjectStore<DataElementGroupSet> dataElementGroupSetStore )
{
this.dataElementGroupSetStore = dataElementGroupSetStore;
}
@@ -142,7 +143,7 @@
}
} );
}
-
+
public List<DataElement> getDataElementsByUid( Collection<String> uids )
{
return dataElementStore.getByUid( uids );
@@ -328,29 +329,29 @@
{
return i18n( i18nService, dataElementStore.getDataElementsByAggregationLevel( aggregationLevel ) );
}
-
+
public Map<String, Set<String>> getDataElementCategoryOptionCombos()
{
return dataElementStore.getDataElementCategoryOptionCombos();
}
-
+
public Map<String, Integer> getDataElementUidIdMap()
{
Map<String, Integer> map = new HashMap<String, Integer>();
-
+
for ( DataElement dataElement : getAllDataElements() )
{
map.put( dataElement.getUid(), dataElement.getId() );
}
-
+
return map;
}
-
+
public Collection<DataElement> getDataElements( DataSet dataSet, String key, Integer max )
{
- return dataElementStore.get( dataSet, key, max );
+ return i18n( i18nService, dataElementStore.get( dataSet, key, max ) );
}
-
+
// -------------------------------------------------------------------------
// DataElementGroup
// -------------------------------------------------------------------------
@@ -376,19 +377,19 @@
{
return i18n( i18nService, dataElementGroupStore.get( id ) );
}
-
+
public DataElementGroup getDataElementGroup( int id, boolean i18nDataElements )
{
DataElementGroup group = getDataElementGroup( id );
-
+
if ( i18nDataElements )
{
i18n( i18nService, group.getMembers() );
}
-
+
return group;
}
-
+
public Collection<DataElementGroup> getDataElementGroups( final Collection<Integer> identifiers )
{
Collection<DataElementGroup> groups = getAllDataElementGroups();
@@ -401,7 +402,7 @@
}
} );
}
-
+
public Collection<DataElementGroup> getDataElementGroupsByUid( Collection<String> uids )
{
return dataElementGroupStore.getByUid( uids );
@@ -487,16 +488,16 @@
{
return i18n( i18nService, dataElementGroupSetStore.get( id ) );
}
-
+
public DataElementGroupSet getDataElementGroupSet( int id, boolean i18nGroups )
{
DataElementGroupSet groupSet = getDataElementGroupSet( id );
-
+
if ( i18nGroups )
{
i18n( i18nService, groupSet.getDataElements() );
}
-
+
return groupSet;
}
@@ -571,7 +572,7 @@
}
} );
}
-
+
public List<DataElementGroupSet> getDataElementGroupSetsByUid( Collection<String> uids )
{
return dataElementGroupSetStore.getByUid( uids );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2013-01-05 15:22:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2013-01-28 08:50:29 +0000
@@ -212,28 +212,26 @@
{
String hql = "select distinct de from DataElement de join de.dataSets ds where ds.id in (:ids)";
- return sessionFactory.getCurrentSession().createQuery( hql ).setParameterList( "ids",
- ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list();
+ return sessionFactory.getCurrentSession().createQuery( hql )
+ .setParameterList( "ids", ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list();
}
@SuppressWarnings( "unchecked" )
public Collection<DataElement> getDataElementsByAggregationLevel( int aggregationLevel )
{
String hql = "from DataElement de join de.aggregationLevels al where al = :aggregationLevel";
-
+
return getQuery( hql ).setInteger( "aggregationLevel", aggregationLevel ).list();
}
public Map<String, Set<String>> getDataElementCategoryOptionCombos()
{
- final String sql =
- "select de.uid, coc.uid " +
- "from dataelement de " +
- "join categorycombos_optioncombos cc on de.categorycomboid = cc.categorycomboid " +
- "join categoryoptioncombo coc on cc.categoryoptioncomboid = coc.categoryoptioncomboid";
-
+ final String sql = "select de.uid, coc.uid " + "from dataelement de "
+ + "join categorycombos_optioncombos cc on de.categorycomboid = cc.categorycomboid "
+ + "join categoryoptioncombo coc on cc.categoryoptioncomboid = coc.categoryoptioncomboid";
+
final Map<String, Set<String>> sets = new HashMap<String, Set<String>>();
-
+
jdbcTemplate.query( sql, new RowCallbackHandler()
{
@Override
@@ -242,30 +240,33 @@
{
String dataElement = rs.getString( 1 );
String categoryOptionCombo = rs.getString( 2 );
-
+
Set<String> set = sets.get( dataElement ) != null ? sets.get( dataElement ) : new HashSet<String>();
-
- set.add( categoryOptionCombo );
+
+ set.add( categoryOptionCombo );
sets.put( dataElement, set );
}
} );
-
+
return sets;
}
-
+
@SuppressWarnings( "unchecked" )
public Collection<DataElement> get( DataSet dataSet, String key, Integer max )
{
String hql = "select dataElement from DataSet dataSet inner join dataSet.dataElements as dataElement where dataSet.id = :dataSetId ";
-
- if( key != null )
+
+ if ( key != null )
{
hql += " and lower(dataElement.name) like lower('%" + key + "%') ";
}
-
+
Query query = getQuery( hql );
query.setInteger( "dataSetId", dataSet.getId() );
- query.setMaxResults( max );
+ if ( max != null )
+ {
+ query.setMaxResults( max );
+ }
return query.list();
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-26 11:40:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2013-01-28 08:50:29 +0000
@@ -46,6 +46,7 @@
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.NameableObject;
+import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.system.util.LocaleUtils;
import org.hisp.dhis.translation.Translation;
import org.hisp.dhis.translation.TranslationService;
@@ -86,20 +87,20 @@
for ( String string : localeStrings )
{
Locale locale = LocaleUtils.getLocale( string );
-
+
if ( locale != null )
{
locales.add( locale );
}
}
-
+
Collections.sort( locales, new Comparator<Locale>()
+ {
+ public int compare( Locale l1, Locale l2 )
{
- public int compare( Locale l1, Locale l2 )
- {
- return l1.getDisplayName().compareTo( l2.getDisplayName() );
- }
- } );
+ return l1.getDisplayName().compareTo( l2.getDisplayName() );
+ }
+ } );
}
// -------------------------------------------------------------------------
@@ -136,18 +137,18 @@
{
return;
}
-
+
List<String> properties = getObjectPropertyNames( object );
-
+
Collection<Translation> translations = translationService.getTranslations( getClassName( object ),
getId( object ), locale );
-
+
Map<String, String> translationMap = convertTranslations( translations );
-
+
for ( String property : properties )
{
String value = translationMap.get( property );
-
+
if ( value != null && !value.isEmpty() )
{
setProperty( object, "display", property, value );
@@ -161,21 +162,21 @@
{
return;
}
-
+
Object peek = objects.iterator().next();
List<String> properties = getObjectPropertyNames( peek );
-
+
Collection<Translation> translations = translationService.getTranslations( getClassName( peek ), locale );
for ( Object object : objects )
{
Map<String, String> translationMap = getTranslationsForObject( translations, getId( object ) );
-
+
for ( String property : properties )
{
String value = translationMap.get( property );
-
+
if ( value != null && !value.isEmpty() )
{
setProperty( object, "display", property, value );
@@ -183,31 +184,37 @@
}
}
}
-
+
public Map<String, String> getObjectPropertyValues( Object object )
{
List<String> properties = getObjectPropertyNames( object );
-
+
Map<String, String> translations = new HashMap<String, String>();
-
+
for ( String property : properties )
{
translations.put( property, getProperty( object, property ) );
}
-
+
return translations;
}
public List<String> getObjectPropertyNames( Object object )
{
- if ( !( object instanceof IdentifiableObject ) )
+ if ( !(object instanceof IdentifiableObject) )
{
throw new IllegalArgumentException( "I18n object must be identifiable: " + object );
}
- return ( object instanceof NameableObject ) ? Arrays.asList( NameableObject.I18N_PROPERTIES ) : Arrays.asList( IdentifiableObject.I18N_PROPERTIES );
+ if ( object instanceof DataElement )
+ {
+ return Arrays.asList( DataElement.I18N_PROPERTIES );
+ }
+
+ return (object instanceof NameableObject) ? Arrays.asList( NameableObject.I18N_PROPERTIES ) : Arrays
+ .asList( IdentifiableObject.I18N_PROPERTIES );
}
-
+
// -------------------------------------------------------------------------
// Object
// -------------------------------------------------------------------------
@@ -232,9 +239,9 @@
{
String key = translationEntry.getKey();
String value = translationEntry.getValue();
-
+
Translation translation = translationService.getTranslation( className, id, locale, key );
-
+
if ( value != null && !value.trim().isEmpty() )
{
if ( translation != null )
@@ -260,33 +267,33 @@
{
return getTranslations( className, id, getCurrentLocale() );
}
-
+
public Map<String, String> getTranslations( String className, int id, Locale locale )
{
if ( locale != null && className != null )
{
return convertTranslations( translationService.getTranslations( className, id, locale ) );
}
-
+
return new HashMap<String, String>();
}
// -------------------------------------------------------------------------
// Locale
// -------------------------------------------------------------------------
-
+
public Locale getCurrentLocale()
{
return (Locale) userSettingService.getUserSetting( UserSettingService.KEY_DB_LOCALE );
}
-
+
public boolean currentLocaleIsBase()
{
return getCurrentLocale() == null;
}
-
+
public List<Locale> getAvailableLocales()
- {
+ {
return locales;
}
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2013-01-04 18:10:25 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadFormAction.java 2013-01-28 08:50:29 +0000
@@ -227,7 +227,8 @@
{
DataSet dataSet = dataSetService.getDataSet( dataSetId, true, false, false );
- List<DataElement> dataElements = new ArrayList<DataElement>( dataSet.getDataElements() );
+ List<DataElement> dataElements = new ArrayList<DataElement>( dataElementService.getDataElements( dataSet, null,
+ null ) );
if ( dataElements.isEmpty() )
{
@@ -306,7 +307,13 @@
String displayMode = dataSet.getDataSetType();
- if ( multiOrganisationUnit != null && multiOrganisationUnit != 0 ) // for multiOrg, we only support section forms
+ if ( multiOrganisationUnit != null && multiOrganisationUnit != 0 ) // for
+ // multiOrg,
+ // we
+ // only
+ // support
+ // section
+ // forms
{
OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( multiOrganisationUnit );
List<OrganisationUnit> organisationUnitChildren = new ArrayList<OrganisationUnit>();
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties 2012-11-07 14:39:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties 2013-01-28 08:50:29 +0000
@@ -196,4 +196,5 @@
long_text = Long text
text_type = Text type
legend_set=Legend set
-skip_total_in_reports=Skip category total in reports
\ No newline at end of file
+skip_total_in_reports=Skip category total in reports
+translation_label_formName = Form name
\ No newline at end of file