=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2013-08-23 15:56:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2013-11-21 09:09:33 +0000 @@ -28,16 +28,16 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.common.ListMap; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.hierarchy.HierarchyViolationException; +import org.hisp.dhis.period.PeriodType; + import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; -import org.hisp.dhis.common.ListMap; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.hierarchy.HierarchyViolationException; -import org.hisp.dhis.period.PeriodType; - /** * Defines service functionality for DataElements and DataElementGroups. * @@ -172,7 +172,7 @@ * Returns all DataElements with a given aggregantion operator. * * @param aggregationOperator the aggregation operator of the DataElements - * to return. + * to return. * @return a collection of all DataElements with the given aggregation * operator, or an empty collection if no DataElements have the * aggregation operator. @@ -188,6 +188,14 @@ Collection getDataElementsByDomainType( String domainType ); /** + * Returns all DataElements with the given domain type. + * + * @param domainType the domainType. + * @return all DataElements with the given domainType. + */ + Collection getDataElementsByDomainType( String domainType, int first, int max ); + + /** * Returns all DataElements with the given type. * * @param type the type. @@ -264,7 +272,7 @@ /** * Returns all DataElements which are assigned to any of the given DataSets. - * + * * @param dataSets the collection of DataSets. * @return all DataElements which are assigned to any of the given DataSets. */ @@ -272,7 +280,7 @@ /** * Returns all DataElements which have the given aggregation level assigned. - * + * * @param aggregationLevel the aggregation level. * @return all DataElements which have the given aggregation level assigned. */ @@ -288,15 +296,17 @@ int getDataElementCountByName( String name ); + int getDataElementCountByDomainType( String domainType ); + /** * Returns a mapping of data element uid and associated category option combo * uids. - * + * * @param dataElementUids the uids of the data elements to include in the map. * @return a ListMap. */ ListMap getDataElementCategoryOptionComboMap( Set dataElementUids ); - + Map getDataElementUidIdMap(); // ------------------------------------------------------------------------- @@ -336,7 +346,7 @@ /** * Returns a DataElementGroup. * - * @param id the id of the DataElementGroup to return. + * @param id the id of the DataElementGroup to return. * @param i18nDataElements whether to i18n the data elements of this group. * @return the DataElementGroup with the given id, or null if no match. */ @@ -352,12 +362,12 @@ /** * Returns the data element groups with the given uids. - * + * * @param uids the uid collection. * @return the data element groups with the given uids. */ - List getDataElementGroupsByUid( Collection uids ); - + List getDataElementGroupsByUid( Collection uids ); + /** * Returns the DataElementGroup with the given UID. * @@ -381,8 +391,8 @@ * no DataElementGroups exist. */ Collection getAllDataElementGroups(); - - + + /** * Returns a DataElementGroup with a given short name. * @@ -390,7 +400,7 @@ * @return the DataElementGroup with the given short name, or null if no match. */ DataElementGroup getDataElementGroupByShortName( String shortName ); - + /** * Returns a DataElementGroup with a given code. * @@ -399,12 +409,12 @@ */ DataElementGroup getDataElementGroupByCode( String code ); - + /** * Returns all DataElementGroups which contain the given DataElement. * * @param dataElement the DataElement which the DataElementGroups must - * contain. + * contain. * @return a collection of all DataElementGroups that contain the given * DataElement. */ @@ -423,7 +433,7 @@ * elements are defined as zero is in-significant. * * @param dataElementIds identifiers of data elements where zero is - * significant. + * significant. */ void setZeroIsSignificantForDataElements( Collection dataElementIds ); @@ -439,7 +449,7 @@ * Returns all DataElement which zeroIsSignificant property is true or false * * @param zeroIsSignificant is zeroIsSignificant property - * @param dataElementGroup is group contain data elements + * @param dataElementGroup is group contain data elements * @return a collection of all DataElement */ Collection getDataElementsByZeroIsSignificantAndGroup( boolean zeroIsSignificant, @@ -452,9 +462,9 @@ int getDataElementGroupCount(); int getDataElementGroupCountByName( String name ); - + Collection getDataElements( DataSet dataSet, String key, Integer max ); - + // ------------------------------------------------------------------------- // DataElementGroupSet // ------------------------------------------------------------------------- @@ -466,7 +476,7 @@ void deleteDataElementGroupSet( DataElementGroupSet groupSet ); DataElementGroupSet getDataElementGroupSet( int id ); - + DataElementGroupSet getDataElementGroupSet( int id, boolean i18nGroups ); DataElementGroupSet getDataElementGroupSet( String uid ); @@ -482,7 +492,7 @@ Collection getAllDataElementGroupSets(); Collection getDataElementGroupSets( Collection identifiers ); - + List getDataElementGroupSetsByUid( Collection uids ); Collection getDataElementGroupSetsBetween( int first, int max ); === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2013-08-23 15:56:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2013-11-21 09:09:33 +0000 @@ -93,6 +93,14 @@ Collection getDataElementsByDomainType( String domainType ); /** + * Returns all DataElements with the given domain type. + * + * @param domainType the domainType. + * @return all DataElements with the given domainType. + */ + Collection getDataElementsByDomainType( String domainType, int first, int max ); + + /** * Returns all DataElements with the given type. * * @param type the type. @@ -179,4 +187,6 @@ ListMap getDataElementCategoryOptionComboMap( Set dataElementUids ); Collection get( DataSet dataSet, String key, Integer max ); + + int getCountByDomainType( String domainType ); } === 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-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2013-11-21 09:09:33 +0000 @@ -244,6 +244,11 @@ return i18n( i18nService, dataElementStore.getDataElementsByDomainType( domainType ) ); } + public Collection getDataElementsByDomainType( String domainType, int first, int max ) + { + return i18n( i18nService, dataElementStore.getDataElementsByDomainType( domainType, first, max ) ); + } + public Collection getDataElementByCategoryCombo( DataElementCategoryCombo categoryCombo ) { return i18n( i18nService, dataElementStore.getDataElementByCategoryCombo( categoryCombo ) ); @@ -323,6 +328,12 @@ return getCountByName( i18nService, dataElementStore, name ); } + @Override + public int getDataElementCountByDomainType( String domainType ) + { + return dataElementStore.getCountByDomainType( domainType ); + } + public Collection getDataElementsBetween( int first, int max ) { return getObjectsBetween( i18nService, dataElementStore, first, max ); @@ -347,7 +358,7 @@ { return dataElementStore.getDataElementCategoryOptionComboMap( dataElementUids ); } - + public Map getDataElementUidIdMap() { Map map = new HashMap(); === 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-08-23 16:05:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2013-11-21 09:09:33 +0000 @@ -28,12 +28,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.Criteria; @@ -51,6 +45,12 @@ import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.core.RowCallbackHandler; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + /** * @author Torgeir Lorange Ostby */ @@ -59,12 +59,12 @@ implements DataElementStore { private static final Log log = LogFactory.getLog( HibernateDataElementStore.class ); - + // ------------------------------------------------------------------------- // DataElement // ------------------------------------------------------------------------- - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection searchDataElementsByName( String key ) { Session session = sessionFactory.getCurrentSession(); @@ -75,7 +75,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getAggregateableDataElements() { Session session = sessionFactory.getCurrentSession(); @@ -92,7 +92,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getAllActiveDataElements() { Session session = sessionFactory.getCurrentSession(); @@ -103,7 +103,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsByAggregationOperator( String aggregationOperator ) { Session session = sessionFactory.getCurrentSession(); @@ -114,7 +114,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsByType( String type ) { Session session = sessionFactory.getCurrentSession(); @@ -136,7 +136,21 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") + public Collection getDataElementsByDomainType( String domainType, int first, int max ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( DataElement.class ); + criteria.add( Restrictions.eq( "domainType", domainType ) ); + + criteria.setFirstResult( first ); + criteria.setMaxResults( max ); + + return criteria.list(); + } + + @SuppressWarnings("unchecked") public Collection getDataElementByCategoryCombo( DataElementCategoryCombo categoryCombo ) { Session session = sessionFactory.getCurrentSession(); @@ -147,7 +161,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsWithGroupSets() { String hql = "from DataElement d where d.groupSets.size > 0"; @@ -176,7 +190,7 @@ } } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsByZeroIsSignificant( boolean zeroIsSignificant ) { Criteria criteria = getCriteria(); @@ -187,7 +201,7 @@ return criteria.list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsWithoutGroups() { String hql = "from DataElement d where d.groups.size = 0"; @@ -195,7 +209,7 @@ return getQuery( hql ).setCacheable( true ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsWithoutDataSets() { String hql = "from DataElement d where d.dataSets.size = 0 and d.domainType =:domainType"; @@ -203,7 +217,7 @@ return getQuery( hql ).setParameter( "domainType", "aggregate" ).setCacheable( true ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsWithDataSets() { String hql = "from DataElement d where d.dataSets.size > 0"; @@ -211,7 +225,7 @@ return getQuery( hql ).setCacheable( true ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsByDataSets( Collection dataSets ) { String hql = "select distinct de from DataElement de join de.dataSets ds where ds.id in (:ids)"; @@ -220,7 +234,7 @@ .setParameterList( "ids", ConversionUtils.getIdentifiers( DataSet.class, dataSets ) ).list(); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getDataElementsByAggregationLevel( int aggregationLevel ) { String hql = "from DataElement de join de.aggregationLevels al where al = :aggregationLevel"; @@ -230,10 +244,10 @@ public ListMap getDataElementCategoryOptionComboMap( Set dataElementUids ) { - final String sql = + final String sql = "select dataelementuid, categoryoptioncombouid " + - "from _dataelementcategoryoptioncombo " + - "where dataelementuid in (" + TextUtils.getQuotedCommaDelimitedString( dataElementUids ) + ")"; + "from _dataelementcategoryoptioncombo " + + "where dataelementuid in (" + TextUtils.getQuotedCommaDelimitedString( dataElementUids ) + ")"; final ListMap map = new ListMap(); @@ -247,7 +261,7 @@ { String de = rs.getString( 1 ); String coc = rs.getString( 2 ); - + map.putValue( de, coc ); } } ); @@ -261,7 +275,7 @@ return map; } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection get( DataSet dataSet, String key, Integer max ) { String hql = "select dataElement from DataSet dataSet inner join dataSet.dataElements as dataElement where dataSet.id = :dataSetId "; @@ -277,7 +291,18 @@ { query.setMaxResults( max ); } - + return query.list(); } + + @Override + public int getCountByDomainType( String domainType ) + { + Session session = sessionFactory.getCurrentSession(); + + Criteria criteria = session.createCriteria( DataElement.class ); + criteria.add( Restrictions.eq( "domainType", domainType ) ); + + return criteria.list().size(); + } } === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementController.java 2013-08-23 16:00:30 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/dataelement/DataElementController.java 2013-11-21 09:09:33 +0000 @@ -29,17 +29,77 @@ */ import org.hisp.dhis.api.controller.AbstractCrudController; +import org.hisp.dhis.api.controller.WebMetaData; +import org.hisp.dhis.api.controller.WebOptions; +import org.hisp.dhis.common.Pager; import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + /** * @author Morten Olav Hansen */ @Controller -@RequestMapping( value = DataElementController.RESOURCE_PATH ) +@RequestMapping(value = DataElementController.RESOURCE_PATH) public class DataElementController extends AbstractCrudController { public static final String RESOURCE_PATH = "/dataElements"; + + @Autowired + private DataElementService dataElementService; + + protected List getEntityList( WebMetaData metaData, WebOptions options ) + { + List entityList; + + Date lastUpdated = options.getLastUpdated(); + + String KEY_DOMAIN_TYPE = "domainType"; + + if ( DataElement.DOMAIN_TYPE_AGGREGATE.equals( options.getOptions().get( KEY_DOMAIN_TYPE ) ) + || DataElement.DOMAIN_TYPE_PATIENT.equals( options.getOptions().get( KEY_DOMAIN_TYPE ) ) ) + { + String domainType = options.getOptions().get( KEY_DOMAIN_TYPE ); + + if ( options.hasPaging() ) + { + int count = dataElementService.getDataElementCountByDomainType( domainType ); + + Pager pager = new Pager( options.getPage(), count, options.getPageSize() ); + metaData.setPager( pager ); + + entityList = new ArrayList( dataElementService.getDataElementsByDomainType( domainType, pager.getOffset(), pager.getPageSize() ) ); + } + else + { + entityList = new ArrayList( dataElementService.getDataElementsByDomainType( domainType ) ); + } + } + else if ( lastUpdated != null ) + { + entityList = new ArrayList( manager.getByLastUpdatedSorted( getEntityClass(), lastUpdated ) ); + } + else if ( options.hasPaging() ) + { + int count = manager.getCount( getEntityClass() ); + + Pager pager = new Pager( options.getPage(), count, options.getPageSize() ); + metaData.setPager( pager ); + + entityList = new ArrayList( manager.getBetween( getEntityClass(), pager.getOffset(), pager.getPageSize() ) ); + } + else + { + entityList = new ArrayList( manager.getAllSorted( getEntityClass() ) ); + } + + return entityList; + } }