dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32471
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16571: Option. Made the option code property not unique. There might be similar values, like numeric ones.
------------------------------------------------------------
revno: 16571
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-08-29 14:48:40 +0200
message:
Option. Made the option code property not unique. There might be similar values, like numeric ones.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml
dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/ValidateOptionAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm
--
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/option/OptionService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2014-08-03 07:05:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionService.java 2014-08-29 12:48:40 +0000
@@ -76,9 +76,9 @@
Option getOption( int id );
- Option getOptionByCode( String code );
-
- Option getOptionValueByName( OptionSet optionSet, String name );
-
- Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max );
+ Option getOptionByName( OptionSet optionSet, String name );
+
+ Option getOptionByCode( OptionSet optionSet, String code );
+
+ Collection<Option> getOptions( OptionSet optionSet, String option, Integer min, Integer max );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java 2014-08-03 07:05:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/option/OptionStore.java 2014-08-29 12:48:40 +0000
@@ -42,8 +42,10 @@
{
List<Option> getOptions( int optionSetId, String key, Integer max );
- Option getOptionValueByName( OptionSet optionSet, String name );
+ Option getOptionByName( OptionSet optionSet, String name );
+
+ Option getOptionByCode( OptionSet optionSet, String code );
- Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max );
+ Collection<Option> getOptions( OptionSet optionSet, String option, Integer min, Integer max );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/DefaultOptionService.java 2014-08-29 12:48:40 +0000
@@ -178,13 +178,18 @@
return i18n( i18nService, optionValueStore.getByCode( code ) );
}
- public Option getOptionValueByName( OptionSet optionSet, String name )
- {
- return i18n( i18nService, optionStore.getOptionValueByName( optionSet, name ) );
+ public Option getOptionByName( OptionSet optionSet, String name )
+ {
+ return i18n( i18nService, optionStore.getOptionByName( optionSet, name ) );
+ }
+
+ public Option getOptionByCode( OptionSet optionSet, String name )
+ {
+ return i18n( i18nService, optionStore.getOptionByName( optionSet, name ) );
}
- public Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max )
+ public Collection<Option> getOptions( OptionSet optionSet, String option, Integer min, Integer max )
{
- return i18n( i18nService, optionStore.getOptionValues( optionSet, option, min, max ) );
+ return i18n( i18nService, optionStore.getOptions( optionSet, option, min, max ) );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2014-08-29 12:04:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/option/hibernate/HibernateOptionStore.java 2014-08-29 12:48:40 +0000
@@ -74,7 +74,7 @@
return query.list();
}
- public Option getOptionValueByName( OptionSet optionSet, String name )
+ public Option getOptionByName( OptionSet optionSet, String name )
{
String hql =
"select option from OptionSet as optionset " +
@@ -87,8 +87,21 @@
return (Option) query.uniqueResult();
}
+ public Option getOptionByCode( OptionSet optionSet, String code )
+ {
+ String hql =
+ "select option from OptionSet as optionset " +
+ "join optionset.options as option where optionset = :optionSet and option.code = :code";
+
+ Query query = getQuery( hql );
+ query.setEntity( "optionSet", optionSet );
+ query.setString( "code", code );
+
+ return (Option) query.uniqueResult();
+ }
+
@SuppressWarnings( "unchecked" )
- public Collection<Option> getOptionValues( OptionSet optionSet, String option, Integer min, Integer max )
+ public Collection<Option> getOptions( OptionSet optionSet, String option, Integer min, Integer max )
{
String hql =
"select option from OptionSet as optionset " +
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml 2014-08-04 14:27:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/option/hibernate/Option.hbm.xml 2014-08-29 12:48:40 +0000
@@ -15,7 +15,7 @@
</id>
<property name="uid" column="uid" unique="true" length="11" />
- <property name="code" column="code" not-null="false" unique="true" length="230" /> <!-- Length for legacy support -->
+ <property name="code" column="code" not-null="false" unique="false" length="230" /> <!-- Length for legacy support -->
<property name="created" type="timestamp"/>
<property name="lastUpdated" type="timestamp"/>
=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2014-08-15 07:40:20 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/java/org/hisp/dhis/caseentry/action/caseentry/LoadDataEntryAction.java 2014-08-29 12:48:40 +0000
@@ -39,6 +39,7 @@
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.option.Option;
import org.hisp.dhis.option.OptionService;
+import org.hisp.dhis.option.OptionSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
@@ -370,10 +371,11 @@
for ( TrackedEntityDataValue entityInstanceDataValue : entityInstanceDataValues )
{
int key = entityInstanceDataValue.getDataElement().getId();
- if ( entityInstanceDataValue.getDataElement().getOptionSet() != null )
+ OptionSet optionSet = entityInstanceDataValue.getDataElement().getOptionSet();
+ if ( optionSet != null )
{
String value = entityInstanceDataValue.getValue();
- Option option = optionService.getOptionByCode( value );
+ Option option = optionService.getOptionByCode( optionSet, value );
TrackedEntityDataValue instanceDataValue = new TrackedEntityDataValue(entityInstanceDataValue.getProgramStageInstance(), entityInstanceDataValue.getDataElement());
instanceDataValue.setValue( option.getName() );
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java 2014-08-03 07:05:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/GetOptionListAction.java 2014-08-29 12:48:40 +0000
@@ -103,7 +103,7 @@
this.paging = createPaging( optionSet.getOptions().size() );
- options = optionService.getOptionValues( optionSet, key, paging.getStartPos(), paging.getPageSize() );
+ options = optionService.getOptions( optionSet, key, paging.getStartPos(), paging.getPageSize() );
return SUCCESS;
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/ValidateOptionAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/ValidateOptionAction.java 2014-08-29 12:04:53 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/option/ValidateOptionAction.java 2014-08-29 12:48:40 +0000
@@ -108,11 +108,11 @@
public String execute()
throws Exception
{
+ OptionSet optionSet = optionService.getOptionSet( optionSetId );
+
if ( name != null )
{
- OptionSet optionSet = optionService.getOptionSet( optionSetId );
-
- Option match = optionService.getOptionValueByName( optionSet, name );
+ Option match = optionService.getOptionByName( optionSet, name );
if ( match != null && (id == null || match.getId() != id) )
{
@@ -124,7 +124,7 @@
if ( code != null )
{
- Option match = optionService.getOptionByCode( code );
+ Option match = optionService.getOptionByCode( optionSet, code );
if ( match != null && (id == null || match.getId() != id) )
{
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm 2014-08-29 11:18:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/addOptionForm.vm 2014-08-29 12:48:40 +0000
@@ -5,7 +5,7 @@
});
checkValueIsExist( "name", "validateOption.action",{optionSetId:getFieldValue('optionSetId')});
- checkValueIsExist( "code", "validateOption.action");
+ checkValueIsExist( "code", "validateOption.action",{optionSetId:getFieldValue('optionSetId')});
});
</script>