← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21125: attributeValueStore, get all by attribute and value

 

------------------------------------------------------------
revno: 21125
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-19 12:41:44 +0700
message:
  attributeValueStore, get all by attribute and value
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.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/attribute/AttributeService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java	2015-11-19 05:37:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeService.java	2015-11-19 05:41:44 +0000
@@ -275,6 +275,8 @@
 
     List<AttributeValue> getAllAttributeValuesByAttribute( Attribute attribute );
 
+    List<AttributeValue> getAllByAttributeAndValue( Attribute attribute, String value );
+
     /**
      * Gets the number of attribute values.
      *

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java	2015-11-19 05:37:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/attribute/AttributeValueStore.java	2015-11-19 05:41:44 +0000
@@ -39,4 +39,6 @@
     extends GenericStore<AttributeValue>
 {
     List<AttributeValue> getAllByAttribute( Attribute attribute );
+
+    List<AttributeValue> getAllByAttributeAndValue( Attribute attribute, String value );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java	2015-11-19 05:37:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/DefaultAttributeService.java	2015-11-19 05:41:44 +0000
@@ -303,6 +303,12 @@
     }
 
     @Override
+    public List<AttributeValue> getAllByAttributeAndValue( Attribute attribute, String value )
+    {
+        return attributeValueStore.getAllByAttributeAndValue( attribute, value );
+    }
+
+    @Override
     public int getAttributeValueCount()
     {
         return attributeValueStore.getCount();

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java	2015-11-19 05:37:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/attribute/hibernate/HibernateAttributeValueStore.java	2015-11-19 05:41:44 +0000
@@ -49,4 +49,14 @@
     {
         return getCriteria().add( Restrictions.eq( "attribute", attribute ) ).list();
     }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public List<AttributeValue> getAllByAttributeAndValue( Attribute attribute, String value )
+    {
+        return getCriteria()
+            .add( Restrictions.eq( "attribute", attribute ) )
+            .add( Restrictions.eq( "value", value ) )
+            .list();
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java	2015-11-19 05:37:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/attribute/AttributeValueStoreTest.java	2015-11-19 05:41:44 +0000
@@ -95,4 +95,12 @@
     {
         assertEquals( 2, attributeValueStore.getAllByAttribute( atA ).size() );
     }
+
+    @Test
+    public void testGetAllByAttributeAndValue()
+    {
+        assertEquals( 0, attributeValueStore.getAllByAttributeAndValue( atA, "null" ).size() );
+        assertEquals( 1, attributeValueStore.getAllByAttributeAndValue( atA, "value 1" ).size() );
+        assertEquals( 1, attributeValueStore.getAllByAttributeAndValue( atA, "value 2" ).size() );
+    }
 }