dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39410
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19948: add service methods to get DE by valueType(s)
------------------------------------------------------------
revno: 19948
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-03 11:03:56 +0700
message:
add service methods to get DE by valueType(s)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.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
--
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/DataElementService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2015-08-25 07:52:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementService.java 2015-09-03 04:03:56 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.hierarchy.HierarchyViolationException;
import org.hisp.dhis.period.PeriodType;
@@ -114,7 +115,7 @@
*
* @param key the name of the DataElement to return.
* @return List of DataElements with a given key, or all dataelements if no
- * match.
+ * match.
*/
List<DataElement> searchDataElementsByName( String key );
@@ -130,7 +131,7 @@
* Returns all DataElements.
*
* @return a list of all DataElements, or an empty list if there
- * are no DataElements.
+ * are no DataElements.
*/
List<DataElement> getAllDataElements();
@@ -166,8 +167,8 @@
* @param aggregationOperator the aggregation operator of the DataElements
* to return.
* @return a list of all DataElements with the given aggregation
- * operator, or an empty collection if no DataElements have the
- * aggregation operator.
+ * operator, or an empty collection if no DataElements have the
+ * aggregation operator.
*/
List<DataElement> getDataElementsByAggregationOperator( String aggregationOperator );
@@ -193,10 +194,25 @@
* @param type the type.
* @return all DataElements with the given type.
*/
-
List<DataElement> getDataElementsByType( String type );
/**
+ * Returns all DataElements with the given value types.
+ *
+ * @param valueTypes The value types.
+ * @return all DataElements with the given value types.
+ */
+ List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes );
+
+ /**
+ * Returns all DataElements with the given type.
+ *
+ * @param valueType The value type.
+ * @return all DataElements with the given value type.
+ */
+ List<DataElement> getDataElementsByValueType( ValueType valueType );
+
+ /**
* Returns the DataElements with the given PeriodType.
*
* @param periodType the PeriodType.
@@ -237,7 +253,7 @@
* DataElementGroupSets.
*
* @return all DataElements which are associated with one or more
- * DataElementGroupSets.
+ * DataElementGroupSets.
*/
List<DataElement> getDataElementsWithGroupSets();
@@ -380,7 +396,7 @@
* Returns all DataElementGroups.
*
* @return a collection of all DataElementGroups, or an empty collection if
- * no DataElementGroups exist.
+ * no DataElementGroups exist.
*/
List<DataElementGroup> getAllDataElementGroups();
=== 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 2015-06-11 11:38:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementStore.java 2015-09-03 04:03:56 +0000
@@ -28,17 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.hisp.dhis.common.GenericDimensionalObjectStore;
+import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.ValueType;
+import org.hisp.dhis.dataset.DataSet;
+
import java.util.Collection;
import java.util.List;
import java.util.Set;
-import org.hisp.dhis.common.GenericDimensionalObjectStore;
-import org.hisp.dhis.common.ListMap;
-import org.hisp.dhis.dataset.DataSet;
-
/**
* Defines the functionality for persisting DataElements and DataElementGroups.
- *
+ *
* @author Torgeir Lorange Ostby
*/
public interface DataElementStore
@@ -52,7 +53,7 @@
/**
* Returns List of DataElements with a given key.
- *
+ *
* @param key the name of the DataElement to return.
* @return List of DataElements with a given key, or all dataelements if no match.
*/
@@ -61,25 +62,25 @@
/**
* Returns all DataElements with types that are possible to aggregate. The
* types are currently INT and BOOL.
- *
+ *
* @return all DataElements with types that are possible to aggregate.
*/
List<DataElement> getAggregateableDataElements();
/**
* Returns all DataElements with a given aggregation 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.
+ * operator, or an empty collection if no DataElements have the
+ * aggregation operator.
*/
List<DataElement> getDataElementsByAggregationOperator( String aggregationOperator );
/**
* Returns all DataElements with the given domain type.
- *
+ *
* @param domainType the domainType.
* @return all DataElements with the given domainType.
*/
@@ -95,16 +96,31 @@
/**
* Returns all DataElements with the given type.
- *
+ *
* @param type the type.
* @return all DataElements with the given type.
*/
-
List<DataElement> getDataElementsByType( String type );
/**
+ * Returns all DataElements with the given value types.
+ *
+ * @param valueTypes The value types.
+ * @return all DataElements with the given value types.
+ */
+ List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes );
+
+ /**
+ * Returns all DataElements with the given value type.
+ *
+ * @param valueType The value type.
+ * @return all DataElements with the given value type.
+ */
+ List<DataElement> getDataElementsByValueType( ValueType valueType );
+
+ /**
* Returns all DataElements with the given category combo.
- *
+ *
* @param categoryCombo the DataElementCategoryCombo.
* @return all DataElements with the given category combo.
*/
@@ -113,58 +129,59 @@
/**
* Returns all DataElements which are associated with one or more
* DataElementGroupSets.
- *
+ *
* @return all DataElements which are associated with one or more
- * DataElementGroupSets.
+ * DataElementGroupSets.
*/
List<DataElement> getDataElementsWithGroupSets();
/**
- * Defines the given data elements as zero is significant.
- *
+ * Defines the given data elements as zero is significant.
+ *
* @param dataElementIds identifiers of data elements where zero is significant.
*/
void setZeroIsSignificantForDataElements( Collection<Integer> dataElementIds );
-
+
/**
* Returns all DataElement which zeroIsSignificant property is true or false
- * @param zeroIsSignificant is zeroIsSignificant property
+ *
+ * @param zeroIsSignificant is zeroIsSignificant property
* @return a collection of all DataElement
*/
List<DataElement> getDataElementsByZeroIsSignificant( boolean zeroIsSignificant );
-
+
/**
* Returns all DataElements which are not member of any DataElementGroups.
- *
+ *
* @return all DataElements which are not member of any DataElementGroups.
*/
List<DataElement> getDataElementsWithoutGroups();
-
+
/**
* Returns all DataElements which are not assigned to any DataSets.
- *
+ *
* @return all DataElements which are not assigned to any DataSets.
*/
List<DataElement> getDataElementsWithoutDataSets();
-
+
/**
* Returns all DataElements which are assigned to at least one DataSet.
- *
+ *
* @return all DataElements which are assigned to at least one DataSet.
*/
List<DataElement> getDataElementsWithDataSets();
-
+
/**
* 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.
*/
List<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets );
-
+
/**
* 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.
*/
@@ -173,12 +190,12 @@
/**
* 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<String, String> getDataElementCategoryOptionComboMap( Set<String> dataElementUids );
-
+
List<DataElement> get( DataSet dataSet, String key, Integer max );
int getCountByDomainType( DataElementDomain 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 2015-08-25 08:45:42 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementService.java 2015-09-03 04:03:56 +0000
@@ -28,11 +28,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.i18n.I18nUtils.getCountByName;
-import static org.hisp.dhis.i18n.I18nUtils.getObjectsBetween;
-import static org.hisp.dhis.i18n.I18nUtils.getObjectsBetweenByName;
-import static org.hisp.dhis.i18n.I18nUtils.getObjectsByName;
-import static org.hisp.dhis.i18n.I18nUtils.i18n;
+import org.hisp.dhis.common.GenericDimensionalObjectStore;
+import org.hisp.dhis.common.GenericNameableObjectStore;
+import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.ValueType;
+import org.hisp.dhis.dataelement.comparator.DataElementCategoryComboSizeComparator;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.period.PeriodType;
+import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,14 +48,7 @@
import java.util.Set;
import java.util.stream.Collectors;
-import org.hisp.dhis.common.GenericDimensionalObjectStore;
-import org.hisp.dhis.common.GenericNameableObjectStore;
-import org.hisp.dhis.common.ListMap;
-import org.hisp.dhis.dataelement.comparator.DataElementCategoryComboSizeComparator;
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.i18n.I18nService;
-import org.hisp.dhis.period.PeriodType;
-import org.springframework.transaction.annotation.Transactional;
+import static org.hisp.dhis.i18n.I18nUtils.*;
/**
* @author Kristian Nordal
@@ -169,7 +166,7 @@
public Set<DataElement> getDataElementsByZeroIsSignificantAndGroup( boolean zeroIsSignificant, DataElementGroup dataElementGroup )
{
Set<DataElement> dataElements = new HashSet<>( dataElementGroup.getMembers() );
-
+
return dataElements.stream().filter( p -> p.isZeroIsSignificant() ).collect( Collectors.toSet() );
}
@@ -219,6 +216,18 @@
}
@Override
+ public List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes )
+ {
+ return i18n( i18nService, dataElementStore.getDataElementsByValueTypes( valueTypes ) );
+ }
+
+ @Override
+ public List<DataElement> getDataElementsByValueType( ValueType valueType )
+ {
+ return i18n( i18nService, dataElementStore.getDataElementsByValueType( valueType ) );
+ }
+
+ @Override
public List<DataElement> getDataElementsByPeriodType( final PeriodType periodType )
{
return getAllDataElements().stream().filter( p -> p.getPeriodType() != null && p.getPeriodType().equals( periodType ) ).collect( Collectors.toList() );
=== 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 2015-09-02 05:15:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2015-09-03 04:03:56 +0000
@@ -28,15 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Criteria;
@@ -44,16 +35,26 @@
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
+import org.hisp.dhis.commons.util.TextUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
import org.hisp.dhis.dataelement.DataElementDomain;
import org.hisp.dhis.dataelement.DataElementStore;
import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.commons.util.TextUtils;
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.List;
+import java.util.Set;
+
+import static org.hisp.dhis.common.IdentifiableObjectUtils.getIdentifiers;
+
/**
* @author Torgeir Lorange Ostby
*/
@@ -68,14 +69,14 @@
// -------------------------------------------------------------------------
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> searchDataElementsByName( String key )
{
return getCriteria( Restrictions.ilike( "name", "%" + key + "%" ) ).list();
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getAggregateableDataElements()
{
Set<String> types = new HashSet<>();
@@ -87,14 +88,14 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByAggregationOperator( String aggregationOperator )
{
return getCriteria( Restrictions.eq( "aggregationOperator", aggregationOperator ) ).list();
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByType( String type )
{
return getCriteria( Restrictions.eq( "type", type ) ).list();
@@ -102,13 +103,27 @@
@Override
@SuppressWarnings( "unchecked" )
+ public List<DataElement> getDataElementsByValueTypes( List<ValueType> valueTypes )
+ {
+ return getCriteria( Restrictions.in( "vtype", valueTypes ) ).list();
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public List<DataElement> getDataElementsByValueType( ValueType valueType )
+ {
+ return getCriteria( Restrictions.eq( "vtype", valueType ) ).list();
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByDomainType( DataElementDomain domainType )
{
return getCriteria( Restrictions.eq( "domainType", domainType ) ).list();
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByDomainType( DataElementDomain domainType, int first, int max )
{
Criteria criteria = getCriteria();
@@ -122,14 +137,14 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementByCategoryCombo( DataElementCategoryCombo categoryCombo )
{
return getCriteria( Restrictions.eq( "categoryCombo", categoryCombo ) ).list();
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsWithGroupSets()
{
String hql = "from DataElement d where d.groupSets.size > 0";
@@ -160,7 +175,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByZeroIsSignificant( boolean zeroIsSignificant )
{
Criteria criteria = getCriteria();
@@ -171,7 +186,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsWithoutGroups()
{
String hql = "from DataElement d where d.groups.size = 0";
@@ -180,7 +195,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsWithoutDataSets()
{
String hql = "from DataElement d where d.dataSets.size = 0 and d.domainType =:domainType";
@@ -189,7 +204,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsWithDataSets()
{
String hql = "from DataElement d where d.dataSets.size > 0";
@@ -198,7 +213,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByDataSets( Collection<DataSet> dataSets )
{
String hql = "select distinct de from DataElement de join de.dataSets ds where ds.id in (:ids)";
@@ -207,7 +222,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<DataElement> getDataElementsByAggregationLevel( int aggregationLevel )
{
String hql = "from DataElement de join de.aggregationLevels al where al = :aggregationLevel";
@@ -250,7 +265,7 @@
}
@Override
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
public List<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 ";