dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #40119
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20314: Introduced persisted name for category option combo. Using access=property in hibernate mapping.
------------------------------------------------------------
revno: 20314
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-23 14:23:52 +0200
message:
Introduced persisted name for category option combo. Using access=property in hibernate mapping.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionComboStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionComboStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.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/CategoryOptionComboStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionComboStore.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/CategoryOptionComboStore.java 2015-09-23 12:23:52 +0000
@@ -39,4 +39,6 @@
extends GenericIdentifiableObjectStore<DataElementCategoryOptionCombo>
{
DataElementCategoryOptionCombo getCategoryOptionCombo( DataElementCategoryCombo categoryCombo, Set<DataElementCategoryOption> categoryOptions );
+
+ void updateNames();
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2015-09-16 14:49:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryCombo.java 2015-09-23 12:23:52 +0000
@@ -28,12 +28,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.CombinationGenerator;
@@ -45,11 +43,12 @@
import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.common.view.ExportView;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
/**
* @author Abyot Aselefew
@@ -207,7 +206,6 @@
{
if ( optionCombo.getCategoryOptions() != null && optionCombo.getCategoryOptions().equals( categoryOptionSet ) )
{
- optionCombo.setName( getNameFromCategoryOptions( categoryOptions ) );
list.add( optionCombo );
continue;
}
@@ -217,27 +215,6 @@
return list;
}
- private String getNameFromCategoryOptions( List<DataElementCategoryOption> categoryOptions )
- {
- StringBuilder name = new StringBuilder();
-
- if ( categoryOptions != null && categoryOptions.size() > 0 )
- {
- Iterator<DataElementCategoryOption> iterator = categoryOptions.iterator();
-
- name.append( "(" ).append( iterator.next().getDisplayName() );
-
- while ( iterator.hasNext() )
- {
- name.append( ", " ).append( iterator.next().getDisplayName() );
- }
-
- name.append( ")" );
- }
-
- return name.toString();
- }
-
public void generateOptionCombos()
{
this.optionCombos = new HashSet<>( generateOptionCombosList() );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2015-09-23 10:48:14 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java 2015-09-23 12:23:52 +0000
@@ -301,24 +301,24 @@
StringBuilder builder = new StringBuilder();
List<DataElementCategory> categories = this.categoryCombo.getCategories();
-
+
for ( DataElementCategory category : categories )
{
- builder.append( "(" );
-
List<DataElementCategoryOption> options = category.getCategoryOptions();
- for ( DataElementCategoryOption option : this.categoryOptions )
+ optionLoop: for ( DataElementCategoryOption option : this.categoryOptions )
{
if ( options.contains( option ) )
{
builder.append( option.getDisplayName() ).append( ", " );
+
+ continue optionLoop;
}
}
-
- builder.delete( Math.max( builder.length() - 2, 0 ), builder.length() ).append( ")" );
}
+ builder.delete( Math.max( builder.length() - 2, 0 ), builder.length() );
+
return StringUtils.substring( builder.toString(), 0, 255 );
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2015-06-22 20:07:56 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/resourcetable/DefaultResourceTableService.java 2015-09-23 12:23:52 +0000
@@ -218,7 +218,7 @@
for ( DataElementCategoryOptionCombo coc : combo.getSortedOptionCombos() )
{
List<Object> values = new ArrayList<>();
-
+
values.add( coc.getId() );
values.add( coc.getName() );
values.add( coc.isIgnoreApproval() ? APPROVAL_LEVEL_HIGHEST : null );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionComboStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionComboStore.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateCategoryOptionComboStore.java 2015-09-23 12:23:52 +0000
@@ -28,9 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.List;
import java.util.Set;
import org.hibernate.Query;
+import org.hibernate.Session;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.dataelement.CategoryOptionComboStore;
import org.hisp.dhis.dataelement.DataElementCategoryCombo;
@@ -65,4 +67,24 @@
return (DataElementCategoryOptionCombo) query.uniqueResult();
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void updateNames()
+ {
+ List<DataElementCategoryOptionCombo> categoryOptionCombos = getQuery( "from DataElementCategoryOptionCombo co where co.name is null" ).list();
+ int counter = 0;
+
+ Session session = getSession();
+
+ for ( DataElementCategoryOptionCombo coc : categoryOptionCombos )
+ {
+ session.update( coc );
+
+ if ( ( counter % 400 ) == 0 )
+ {
+ session.flush();
+ }
+ }
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2015-09-23 10:50:30 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2015-09-23 12:23:52 +0000
@@ -348,7 +348,7 @@
{
session.update( organisationUnit );
- if ( (counter % 400) == 0 )
+ if ( ( counter % 400 ) == 0 )
{
dbmsManager.clearSession();
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2015-09-22 06:05:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java 2015-09-23 12:23:52 +0000
@@ -34,6 +34,7 @@
import org.amplecode.quick.StatementManager;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.dataelement.CategoryOptionComboStore;
import org.hisp.dhis.jdbc.StatementBuilder;
import org.hisp.dhis.jdbc.batchhandler.RelativePeriodsBatchHandler;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -75,6 +76,9 @@
@Autowired
private OrganisationUnitService organisationUnitService;
+ @Autowired
+ private CategoryOptionComboStore categoryOptionComboStore;
+
// -------------------------------------------------------------------------
// Execute
// -------------------------------------------------------------------------
@@ -892,6 +896,8 @@
updateNameColumnLengths();
organisationUnitService.updatePaths();
+
+ categoryOptionComboStore.updateNames();
log.info( "Tables updated" );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml 2015-09-23 10:48:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml 2015-09-23 12:23:52 +0000
@@ -15,6 +15,8 @@
</id>
&identifiableProperties;
+ <property name="name" column="name" access="property" unique="false" not-null="false" length="255" />
+
<set name="categoryOptions" table="categoryoptioncombos_categoryoptions">
<cache usage="read-write" />
<key column="categoryoptioncomboid" foreign-key="fk_categoryoptioncombos_categoryoptions_categoryoptioncomboid" />
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java 2015-09-16 18:31:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java 2015-09-23 12:23:52 +0000
@@ -525,17 +525,12 @@
}
}
- private String getOptionNamesFromCombo( DataElementCategoryOptionCombo combo )
- {
- return combo.getName().substring( 1, combo.getName().length() - 1);
- }
-
private String getStatusString( DataApprovalStatus status )
{
DataApproval da = status.getDataApproval();
String approval = da == null ? "approval=null" :
"ou=" + ( da.getOrganisationUnit() == null ? "(null)" : da.getOrganisationUnit().getName() )
- + " mechanism=" + ( da.getAttributeOptionCombo() == null ? "(null)" : getOptionNamesFromCombo( da.getAttributeOptionCombo() ) )
+ + " mechanism=" + ( da.getAttributeOptionCombo() == null ? "(null)" : da.getAttributeOptionCombo().getName() )
+ " level=" + ( da.getDataApprovalLevel() == null ? "(null)" : da.getDataApprovalLevel().getLevel() );
DataApprovalPermissions permissions = status.getPermissions();
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java 2015-09-23 10:48:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java 2015-09-23 12:23:52 +0000
@@ -88,10 +88,10 @@
categoryA = new DataElementCategory( "Gender" );
categoryB = new DataElementCategory( "Agegroup" );
- categoryA.getCategoryOptions().add( categoryOptionA );
- categoryA.getCategoryOptions().add( categoryOptionB );
- categoryB.getCategoryOptions().add( categoryOptionC );
- categoryB.getCategoryOptions().add( categoryOptionD );
+ categoryA.addDataElementCategoryOption( categoryOptionA );
+ categoryA.addDataElementCategoryOption( categoryOptionB );
+ categoryB.addDataElementCategoryOption( categoryOptionC );
+ categoryB.addDataElementCategoryOption( categoryOptionD );
categoryService.addDataElementCategory( categoryA );
categoryService.addDataElementCategory( categoryB );
@@ -99,9 +99,9 @@
categoryComboA = new DataElementCategoryCombo( "GenderAgegroup" );
categoryComboB = new DataElementCategoryCombo( "Gender" );
- categoryComboA.getCategories().add( categoryA );
- categoryComboA.getCategories().add( categoryB );
- categoryComboB.getCategories().add( categoryA );
+ categoryComboA.addDataElementCategory( categoryA );
+ categoryComboA.addDataElementCategory( categoryB );
+ categoryComboB.addDataElementCategory( categoryA );
categoryService.addDataElementCategoryCombo( categoryComboA );
categoryService.addDataElementCategoryCombo( categoryComboB );
@@ -148,7 +148,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboA.setCategoryOptions( categoryOptions );
@@ -179,7 +179,7 @@
categoryOptionComboB = new DataElementCategoryOptionCombo();
categoryOptionComboC = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboB.setCategoryCombo( categoryComboA );
@@ -223,7 +223,7 @@
categoryOptionComboB = new DataElementCategoryOptionCombo();
categoryOptionComboC = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboB.setCategoryCombo( categoryComboA );
@@ -243,4 +243,21 @@
assertNotNull( categoryOptionCombos );
assertEquals( 4, categoryOptionCombos.size() ); // Including default category option combo
}
+
+ @Test
+ public void testGetDataElementCategoryOptionComboName()
+ {
+ categoryOptionComboA = new DataElementCategoryOptionCombo();
+
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
+
+ categoryOptionComboA.setCategoryCombo( categoryComboA );
+ categoryOptionComboA.setCategoryOptions( categoryOptions );
+
+ categoryService.addDataElementCategoryOptionCombo( categoryOptionComboA );
+
+ String expected = "Male, 0-20";
+
+ assertEquals( expected, categoryOptionComboA.getName() );
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java 2015-09-23 10:48:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java 2015-09-23 12:23:52 +0000
@@ -90,10 +90,10 @@
categoryA = new DataElementCategory( "Gender" );
categoryB = new DataElementCategory( "Agegroup" );
- categoryA.getCategoryOptions().add( categoryOptionA );
- categoryA.getCategoryOptions().add( categoryOptionB );
- categoryB.getCategoryOptions().add( categoryOptionC );
- categoryB.getCategoryOptions().add( categoryOptionD );
+ categoryA.addDataElementCategoryOption( categoryOptionA );
+ categoryA.addDataElementCategoryOption( categoryOptionB );
+ categoryB.addDataElementCategoryOption( categoryOptionC );
+ categoryB.addDataElementCategoryOption( categoryOptionD );
categoryService.addDataElementCategory( categoryA );
categoryService.addDataElementCategory( categoryB );
@@ -101,9 +101,9 @@
categoryComboA = new DataElementCategoryCombo( "GenderAgegroup" );
categoryComboB = new DataElementCategoryCombo( "Gender" );
- categoryComboA.getCategories().add( categoryA );
- categoryComboA.getCategories().add( categoryB );
- categoryComboB.getCategories().add( categoryA );
+ categoryComboA.addDataElementCategory( categoryA );
+ categoryComboA.addDataElementCategory( categoryB );
+ categoryComboB.addDataElementCategory( categoryA );
categoryService.addDataElementCategoryCombo( categoryComboA );
categoryService.addDataElementCategoryCombo( categoryComboB );
@@ -118,7 +118,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboA.setCategoryOptions( categoryOptions );
@@ -137,7 +137,7 @@
{
categoryOptionComboA = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboA.setCategoryOptions( categoryOptions );
@@ -168,7 +168,7 @@
categoryOptionComboB = new DataElementCategoryOptionCombo();
categoryOptionComboC = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboB.setCategoryCombo( categoryComboA );
@@ -212,7 +212,7 @@
categoryOptionComboB = new DataElementCategoryOptionCombo();
categoryOptionComboC = new DataElementCategoryOptionCombo();
- Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );
+ Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionC );
categoryOptionComboA.setCategoryCombo( categoryComboA );
categoryOptionComboB.setCategoryCombo( categoryComboA );