dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09500
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2539: [DHIS Mobile] Sort CategoryOptionCombo before send them to client
------------------------------------------------------------
revno: 2539
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Wed 2011-01-12 10:46:34 +0700
message:
[DHIS Mobile] Sort CategoryOptionCombo before send them to client
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
--
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-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-12-30 10:01:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2011-01-12 03:46:34 +0000
@@ -52,6 +52,8 @@
private org.hisp.dhis.program.ProgramService programService;
private org.hisp.dhis.i18n.I18nService i18nService;
+
+ private org.hisp.dhis.web.api.service.ModelMapping modelMapping;
// -------------------------------------------------------------------------
// ProgramService
@@ -135,7 +137,7 @@
org.hisp.dhis.dataelement.DataElement dataElement = programStagedataElement.getDataElement();
- DataElement de = ModelMapping.getDataElement( dataElement );
+ DataElement de = modelMapping.getDataElement( dataElement );
de.setCompulsory( programStagedataElement.isCompulsory() );
@@ -164,4 +166,10 @@
{
this.i18nService = i18nService;
}
+
+ @Required
+ public void setModelMapping(
+ org.hisp.dhis.web.api.service.ModelMapping modelMapping) {
+ this.modelMapping = modelMapping;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2010-12-22 04:05:46 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2011-01-12 03:46:34 +0000
@@ -61,308 +61,299 @@
import org.hisp.dhis.web.api.utils.PeriodUtil;
import org.springframework.beans.factory.annotation.Required;
-public class FacilityReportingServiceImpl
- implements FacilityReportingService
-{
- private static Log log = LogFactory.getLog( FacilityReportingServiceImpl.class );
-
- private static boolean DEBUG = log.isDebugEnabled();
-
- private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator();
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private PeriodService periodService;
-
- private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
-
- private org.hisp.dhis.datavalue.DataValueService dataValueService;
-
- private org.hisp.dhis.dataset.DataSetService dataSetService;
-
- private org.hisp.dhis.i18n.I18nService i18nService;
-
- private org.hisp.dhis.datalock.DataSetLockService dataSetLockService;
-
- // -------------------------------------------------------------------------
- // Service methods
- // -------------------------------------------------------------------------
-
- public List<DataSet> getMobileDataSetsForUnit( OrganisationUnit unit, String localeString )
- {
-
- List<DataSet> datasets = new ArrayList<DataSet>();
- Locale locale = LocaleUtil.getLocale( localeString );
-
- if (DEBUG)
- log.debug( "Getting data sets for unit " + unit.getName() );
-
- for ( org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile( unit ) )
- {
- PeriodType periodType = dataSet.getPeriodType();
- if ( periodType instanceof DailyPeriodType
- || periodType instanceof WeeklyPeriodType
- || periodType instanceof MonthlyPeriodType
- || periodType instanceof YearlyPeriodType
- || periodType instanceof QuarterlyPeriodType )
- {
- if (DEBUG)
- log.debug( "Found data set " + dataSet.getName() );
-
- datasets.add( getDataSetForLocale( dataSet.getId(), locale ) );
- }
- else
- {
- log.warn( "Dataset '" + dataSet.getName()
- + "' set to be reported from mobile, but not of a supported period type: "
- + periodType.getName() );
- }
- }
-
- return datasets;
- }
-
- public DataSet getDataSetForLocale( int dataSetId, Locale locale )
- {
- org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetId );
- dataSet = i18n( i18nService, locale, dataSet );
- Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
-
- DataSet ds = new DataSet();
-
- ds.setId( dataSet.getId() );
- // Name defaults to short name with fallback to name if empty
- String name = dataSet.getShortName();
- if (name == null || name.trim().isEmpty()) {
- name = dataSet.getName();
- }
-
- ds.setName( name );
- ds.setVersion( dataSet.getVersion() );
- ds.setPeriodType( dataSet.getPeriodType().getName() );
-
- List<Section> sectionList = new ArrayList<Section>();
- ds.setSections( sectionList );
-
- if ( sections == null || sections.size() == 0 )
- {
- List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>(
- dataSet.getDataElements() );
-
- Collections.sort( dataElements, dataElementComparator );
-
- // Fake Section to store Data Elements
- Section section = new Section();
- section.setId( 0 );
- section.setName( "" );
-
- section.setDataElements( getDataElements( locale, dataElements ) );
- sectionList.add( section );
- }
- else
- {
- for ( org.hisp.dhis.dataset.Section s : sections )
- {
- Section section = new Section();
- section.setId( s.getId() );
- section.setName( s.getName() );
-
- List<DataElement> dataElementList = getDataElements( locale, s.getDataElements() );
- section.setDataElements( dataElementList );
- sectionList.add( section );
- }
- }
-
- return ds;
- }
-
- private List<DataElement> getDataElements( Locale locale, List<org.hisp.dhis.dataelement.DataElement> dataElements )
- {
- List<DataElement> dataElementList = new ArrayList<DataElement>();
-
- for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
- {
- dataElement = i18n( i18nService, locale, dataElement );
-
- DataElement de = ModelMapping.getDataElement( dataElement );
-
- // For facility Reporting, no data elements are mandatory
- de.setCompulsory( false );
-
- dataElementList.add( de );
- }
- return dataElementList;
- }
-
- @Override
- public void saveDataSetValues( OrganisationUnit unit, DataSetValue dataSetValue ) throws NotAllowedException
- {
-
- org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetValue.getId() );
-
- if ( !dataSetService.getDataSetsBySource( unit ).contains( dataSet ) )
- {
- throw new NotAllowedException( "INVALID_DATASET_ASSOCIATION" );
- }
-
- Period selectedPeriod = getPeriod( dataSetValue.getPeriodName(), dataSet.getPeriodType() );
-
- if ( selectedPeriod == null )
- {
- throw new NotAllowedException("INVALID_PERIOD");
- }
-
- if (isDataSetLocked(unit, dataSet, selectedPeriod)){
- throw new NotAllowedException("DATASET_LOCKED");
- }
-
- Collection<org.hisp.dhis.dataelement.DataElement> dataElements = dataSet.getDataElements();
- Collection<Integer> dataElementIds = new ArrayList<Integer>( dataSetValue.getDataValues().size() );
-
- for ( DataValue dv : dataSetValue.getDataValues() )
- {
- dataElementIds.add( dv.getId() );
- }
-
- Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
- for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
- {
- if ( !dataElementIds.contains( dataElement.getId() ) )
- {
- log.info( "Dataset '" + dataSet.getName() + "' for org unit '" + unit.getName()
- + "' missing data element '" + dataElement.getName() + "'" );
- }
- dataElementMap.put( dataElement.getId(), dataElement );
- }
-
- // Everything is fine, hence save
- saveDataValues( dataSetValue, dataElementMap, selectedPeriod, unit,
- categoryService.getDefaultDataElementCategoryOptionCombo() );
-
- }
-
- // -------------------------------------------------------------------------
- // Supportive method
- // -------------------------------------------------------------------------
-
- private boolean isDataSetLocked(OrganisationUnit unit, org.hisp.dhis.dataset.DataSet dataSet, Period selectedPeriod){
- if(dataSetLockService.getDataSetLockByDataSetPeriodAndSource( dataSet, selectedPeriod, unit )!=null)
- return true;
- return false;
- }
-
-
- private void saveDataValues( DataSetValue dataSetValue,
- Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap, Period period, OrganisationUnit orgUnit,
- DataElementCategoryOptionCombo optionCombo )
- {
-
- org.hisp.dhis.dataelement.DataElement dataElement;
- String value;
-
- for ( DataValue dv : dataSetValue.getDataValues() )
- {
- value = dv.getValue();
- DataElementCategoryOptionCombo cateOptCombo = categoryService.getDataElementCategoryOptionCombo( dv
- .getCategoryOptComboID() );
- if ( value != null && value.trim().length() == 0 )
- {
- value = null;
- }
-
- if ( value != null )
- {
- value = value.trim();
- }
-
- dataElement = dataElementMap.get( dv.getId() );
- org.hisp.dhis.datavalue.DataValue dataValue = dataValueService.getDataValue( orgUnit, dataElement, period,
- cateOptCombo );
-
- if ( dataValue == null )
- {
- if ( value != null )
- {
- dataValue = new org.hisp.dhis.datavalue.DataValue( dataElement, period, orgUnit, value, "",
- new Date(), "", cateOptCombo );
- dataValueService.addDataValue( dataValue );
- }
- }
- else
- {
- if ( value != null )
- {
- dataValue.setValue( value );
- dataValue.setTimestamp( new Date() );
- dataValueService.updateDataValue( dataValue );
- }
- }
-
- }
- }
-
- public Period getPeriod( String periodName, PeriodType periodType )
- {
- Period period = PeriodUtil.getPeriod( periodName, periodType );
-
- if ( period == null )
- {
- return null;
- }
-
- Period persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType );
-
- if ( persistedPeriod == null )
- {
- periodService.addPeriod( period );
- persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(), periodType );
- }
-
- return persistedPeriod;
- }
-
- // -------------------------------------------------------------------------
- // Dependency setters
- // -------------------------------------------------------------------------
-
- @Required
- public void setPeriodService( PeriodService periodService )
- {
- this.periodService = periodService;
- }
-
- @Required
- public void setCategoryService( org.hisp.dhis.dataelement.DataElementCategoryService categoryService )
- {
- this.categoryService = categoryService;
- }
-
- @Required
- public void setDataValueService( org.hisp.dhis.datavalue.DataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
- @Required
- public void setDataSetService( org.hisp.dhis.dataset.DataSetService dataSetService )
- {
- this.dataSetService = dataSetService;
- }
-
- @Required
- public void setI18nService( org.hisp.dhis.i18n.I18nService i18nService )
- {
- this.i18nService = i18nService;
- }
-
- @Required
- public void setDataSetLockService( org.hisp.dhis.datalock.DataSetLockService dataSetLockService )
- {
- this.dataSetLockService = dataSetLockService;
- }
-
-
+public class FacilityReportingServiceImpl implements FacilityReportingService {
+ private static Log log = LogFactory
+ .getLog(FacilityReportingServiceImpl.class);
+
+ private static boolean DEBUG = log.isDebugEnabled();
+
+ private DataElementSortOrderComparator dataElementComparator = new DataElementSortOrderComparator();
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private PeriodService periodService;
+
+ private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
+
+ private org.hisp.dhis.datavalue.DataValueService dataValueService;
+
+ private org.hisp.dhis.dataset.DataSetService dataSetService;
+
+ private org.hisp.dhis.i18n.I18nService i18nService;
+
+ private org.hisp.dhis.datalock.DataSetLockService dataSetLockService;
+
+ private org.hisp.dhis.web.api.service.ModelMapping modelMapping;
+
+ // -------------------------------------------------------------------------
+ // Service methods
+ // -------------------------------------------------------------------------
+
+ public List<DataSet> getMobileDataSetsForUnit(OrganisationUnit unit,
+ String localeString) {
+
+ List<DataSet> datasets = new ArrayList<DataSet>();
+ Locale locale = LocaleUtil.getLocale(localeString);
+
+ if (DEBUG)
+ log.debug("Getting data sets for unit " + unit.getName());
+
+ for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService
+ .getDataSetsForMobile(unit)) {
+ PeriodType periodType = dataSet.getPeriodType();
+ if (periodType instanceof DailyPeriodType
+ || periodType instanceof WeeklyPeriodType
+ || periodType instanceof MonthlyPeriodType
+ || periodType instanceof YearlyPeriodType
+ || periodType instanceof QuarterlyPeriodType) {
+ if (DEBUG)
+ log.debug("Found data set " + dataSet.getName());
+
+ datasets.add(getDataSetForLocale(dataSet.getId(), locale));
+ } else {
+ log.warn("Dataset '"
+ + dataSet.getName()
+ + "' set to be reported from mobile, but not of a supported period type: "
+ + periodType.getName());
+ }
+ }
+
+ return datasets;
+ }
+
+ public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
+ org.hisp.dhis.dataset.DataSet dataSet = dataSetService
+ .getDataSet(dataSetId);
+ dataSet = i18n(i18nService, locale, dataSet);
+ Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
+
+ DataSet ds = new DataSet();
+
+ ds.setId(dataSet.getId());
+ // Name defaults to short name with fallback to name if empty
+ String name = dataSet.getShortName();
+ if (name == null || name.trim().isEmpty()) {
+ name = dataSet.getName();
+ }
+
+ ds.setName(name);
+ ds.setVersion(dataSet.getVersion());
+ ds.setPeriodType(dataSet.getPeriodType().getName());
+
+ List<Section> sectionList = new ArrayList<Section>();
+ ds.setSections(sectionList);
+
+ if (sections == null || sections.size() == 0) {
+ List<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>(
+ dataSet.getDataElements());
+
+ Collections.sort(dataElements, dataElementComparator);
+
+ // Fake Section to store Data Elements
+ Section section = new Section();
+ section.setId(0);
+ section.setName("");
+
+ section.setDataElements(getDataElements(locale, dataElements));
+ sectionList.add(section);
+ } else {
+ for (org.hisp.dhis.dataset.Section s : sections) {
+ Section section = new Section();
+ section.setId(s.getId());
+ section.setName(s.getName());
+
+ List<DataElement> dataElementList = getDataElements(locale,
+ s.getDataElements());
+ section.setDataElements(dataElementList);
+ sectionList.add(section);
+ }
+ }
+
+ return ds;
+ }
+
+ private List<DataElement> getDataElements(Locale locale,
+ List<org.hisp.dhis.dataelement.DataElement> dataElements) {
+ List<DataElement> dataElementList = new ArrayList<DataElement>();
+
+ for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) {
+ dataElement = i18n(i18nService, locale, dataElement);
+
+ DataElement de = modelMapping.getDataElement(dataElement);
+
+ // For facility Reporting, no data elements are mandatory
+ de.setCompulsory(false);
+
+ dataElementList.add(de);
+ }
+ return dataElementList;
+ }
+
+ @Override
+ public void saveDataSetValues(OrganisationUnit unit,
+ DataSetValue dataSetValue) throws NotAllowedException {
+
+ org.hisp.dhis.dataset.DataSet dataSet = dataSetService
+ .getDataSet(dataSetValue.getId());
+
+ if (!dataSetService.getDataSetsBySource(unit).contains(dataSet)) {
+ throw new NotAllowedException("INVALID_DATASET_ASSOCIATION");
+ }
+
+ Period selectedPeriod = getPeriod(dataSetValue.getPeriodName(),
+ dataSet.getPeriodType());
+
+ if (selectedPeriod == null) {
+ throw new NotAllowedException("INVALID_PERIOD");
+ }
+
+ if (isDataSetLocked(unit, dataSet, selectedPeriod)) {
+ throw new NotAllowedException("DATASET_LOCKED");
+ }
+
+ Collection<org.hisp.dhis.dataelement.DataElement> dataElements = dataSet
+ .getDataElements();
+ Collection<Integer> dataElementIds = new ArrayList<Integer>(
+ dataSetValue.getDataValues().size());
+
+ for (DataValue dv : dataSetValue.getDataValues()) {
+ dataElementIds.add(dv.getId());
+ }
+
+ Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
+ for (org.hisp.dhis.dataelement.DataElement dataElement : dataElements) {
+ if (!dataElementIds.contains(dataElement.getId())) {
+ log.info("Dataset '" + dataSet.getName() + "' for org unit '"
+ + unit.getName() + "' missing data element '"
+ + dataElement.getName() + "'");
+ }
+ dataElementMap.put(dataElement.getId(), dataElement);
+ }
+
+ // Everything is fine, hence save
+ saveDataValues(dataSetValue, dataElementMap, selectedPeriod, unit,
+ categoryService.getDefaultDataElementCategoryOptionCombo());
+
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive method
+ // -------------------------------------------------------------------------
+
+ private boolean isDataSetLocked(OrganisationUnit unit,
+ org.hisp.dhis.dataset.DataSet dataSet, Period selectedPeriod) {
+ if (dataSetLockService.getDataSetLockByDataSetPeriodAndSource(dataSet,
+ selectedPeriod, unit) != null)
+ return true;
+ return false;
+ }
+
+ private void saveDataValues(DataSetValue dataSetValue,
+ Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap,
+ Period period, OrganisationUnit orgUnit,
+ DataElementCategoryOptionCombo optionCombo) {
+
+ org.hisp.dhis.dataelement.DataElement dataElement;
+ String value;
+
+ for (DataValue dv : dataSetValue.getDataValues()) {
+ value = dv.getValue();
+ DataElementCategoryOptionCombo cateOptCombo = categoryService
+ .getDataElementCategoryOptionCombo(dv
+ .getCategoryOptComboID());
+ if (value != null && value.trim().length() == 0) {
+ value = null;
+ }
+
+ if (value != null) {
+ value = value.trim();
+ }
+
+ dataElement = dataElementMap.get(dv.getId());
+ org.hisp.dhis.datavalue.DataValue dataValue = dataValueService
+ .getDataValue(orgUnit, dataElement, period, cateOptCombo);
+
+ if (dataValue == null) {
+ if (value != null) {
+ dataValue = new org.hisp.dhis.datavalue.DataValue(
+ dataElement, period, orgUnit, value, "",
+ new Date(), "", cateOptCombo);
+ dataValueService.addDataValue(dataValue);
+ }
+ } else {
+ if (value != null) {
+ dataValue.setValue(value);
+ dataValue.setTimestamp(new Date());
+ dataValueService.updateDataValue(dataValue);
+ }
+ }
+
+ }
+ }
+
+ public Period getPeriod(String periodName, PeriodType periodType) {
+ Period period = PeriodUtil.getPeriod(periodName, periodType);
+
+ if (period == null) {
+ return null;
+ }
+
+ Period persistedPeriod = periodService.getPeriod(period.getStartDate(),
+ period.getEndDate(), periodType);
+
+ if (persistedPeriod == null) {
+ periodService.addPeriod(period);
+ persistedPeriod = periodService.getPeriod(period.getStartDate(),
+ period.getEndDate(), periodType);
+ }
+
+ return persistedPeriod;
+ }
+
+ // -------------------------------------------------------------------------
+ // Dependency setters
+ // -------------------------------------------------------------------------
+
+ @Required
+ public void setPeriodService(PeriodService periodService) {
+ this.periodService = periodService;
+ }
+
+ @Required
+ public void setCategoryService(
+ org.hisp.dhis.dataelement.DataElementCategoryService categoryService) {
+ this.categoryService = categoryService;
+ }
+
+ @Required
+ public void setDataValueService(
+ org.hisp.dhis.datavalue.DataValueService dataValueService) {
+ this.dataValueService = dataValueService;
+ }
+
+ @Required
+ public void setDataSetService(
+ org.hisp.dhis.dataset.DataSetService dataSetService) {
+ this.dataSetService = dataSetService;
+ }
+
+ @Required
+ public void setI18nService(org.hisp.dhis.i18n.I18nService i18nService) {
+ this.i18nService = i18nService;
+ }
+
+ @Required
+ public void setDataSetLockService(
+ org.hisp.dhis.datalock.DataSetLockService dataSetLockService) {
+ this.dataSetLockService = dataSetLockService;
+ }
+
+ @Required
+ public void setModelMapping(
+ org.hisp.dhis.web.api.service.ModelMapping modelMapping) {
+ this.modelMapping = modelMapping;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java 2010-12-06 06:19:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ModelMapping.java 2011-01-12 03:46:34 +0000
@@ -28,57 +28,69 @@
*/
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Set;
-
import org.hisp.dhis.web.api.model.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
import org.hisp.dhis.web.api.model.Model;
import org.hisp.dhis.web.api.model.ModelList;
-
-public class ModelMapping
-{
-
- public static DataElement getDataElement( org.hisp.dhis.dataelement.DataElement dataElement )
- {
- DataElement de = new DataElement();
- de.setId( dataElement.getId() );
-
- // Name defaults to alternative name with fallback to name if empty
- String name = dataElement.getAlternativeName();
- if (name == null || name.trim().isEmpty()) {
- name = dataElement.getName();
- }
- de.setName( name );
- de.setType( dataElement.getType() );
-
- de.setCategoryOptionCombos( getCategoryOptionCombos( dataElement ) );
- return de;
- }
-
- public static ModelList getCategoryOptionCombos( org.hisp.dhis.dataelement.DataElement dataElement )
- {
- Set<DataElementCategoryOptionCombo> deCatOptCombs = dataElement.getCategoryCombo().getOptionCombos();
-
-// if ( deCatOptCombs.size() < 2 )
-// {
-// return null;
-// }
-
- // Client DataElement
- ModelList deCateOptCombo = new ModelList();
- List<Model> listCateOptCombo = new ArrayList<Model>();
- deCateOptCombo.setModels( listCateOptCombo );
-
- for ( DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs )
- {
- Model oneCateOptCombo = new Model();
- oneCateOptCombo.setId( oneCatOptCombo.getId() );
- oneCateOptCombo.setName( oneCatOptCombo.getName() );
- listCateOptCombo.add( oneCateOptCombo );
- }
- return deCateOptCombo;
- }
-
-
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Required;
+
+public class ModelMapping {
+ private DataElementCategoryService categoryService;
+
+ @Required
+ public void setCategoryService(
+ org.hisp.dhis.dataelement.DataElementCategoryService categoryService) {
+ this.categoryService = categoryService;
+ }
+
+ public DataElement getDataElement(
+ org.hisp.dhis.dataelement.DataElement dataElement) {
+ DataElement de = new DataElement();
+ de.setId(dataElement.getId());
+
+ // Name defaults to alternative name with fallback to name if empty
+ String name = dataElement.getAlternativeName();
+ if (name == null || name.trim().isEmpty()) {
+ name = dataElement.getName();
+ }
+ de.setName(name);
+ de.setType(dataElement.getType());
+
+ de.setCategoryOptionCombos(getCategoryOptionCombos(dataElement));
+ return de;
+ }
+
+ public ModelList getCategoryOptionCombos(
+ org.hisp.dhis.dataelement.DataElement dataElement) {
+ DataElementCategoryCombo categoryCombo = dataElement.getCategoryCombo();
+ Collection<DataElementCategoryOptionCombo> deCatOptCombs = categoryService
+ .sortOptionCombos(categoryCombo);
+ // Set<DataElementCategoryOptionCombo> deCatOptCombs =
+ // dataElement.getCategoryCombo().getOptionCombos();
+
+ // if ( deCatOptCombs.size() < 2 )
+ // {
+ // return null;
+ // }
+
+ // Client DataElement
+ ModelList deCateOptCombo = new ModelList();
+ List<Model> listCateOptCombo = new ArrayList<Model>();
+ deCateOptCombo.setModels(listCateOptCombo);
+
+ for (DataElementCategoryOptionCombo oneCatOptCombo : deCatOptCombs) {
+ Model oneCateOptCombo = new Model();
+ oneCateOptCombo.setId(oneCatOptCombo.getId());
+ oneCateOptCombo.setName(oneCatOptCombo.getName());
+ listCateOptCombo.add(oneCateOptCombo);
+ }
+ return deCateOptCombo;
+ }
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-12-08 05:45:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-01-12 03:46:34 +0000
@@ -27,6 +27,7 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
<property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
+ <property name="modelMapping" ref="org.hisp.dhis.web.api.service.ModelMapping" />
</bean>
<bean id="org.hisp.dhis.web.api.service.ActivityReportingService" class="org.hisp.dhis.web.api.service.ActivityReportingServiceImpl">
@@ -42,6 +43,7 @@
<bean id="org.hisp.dhis.web.api.service.IProgramService" class="org.hisp.dhis.web.api.service.DefaultProgramService">
<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
+ <property name="modelMapping" ref="org.hisp.dhis.web.api.service.ModelMapping" />
</bean>
<!-- Jax-RS providers for (de-)serialization, exception mapping, json configuration -->
@@ -69,6 +71,13 @@
<property name="orgUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="dataElementCategoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
</bean>
-
+
+ <!-- ModelMapping beans -->
+ <bean id="org.hisp.dhis.web.api.service.ModelMapping" class="org.hisp.dhis.web.api.service.ModelMapping">
+ <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+ </bean>
+
</beans>
+
+