=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/comparator/OrganisationUnitByLevelComparator.java 2012-06-28 09:21:53 +0000 @@ -0,0 +1,45 @@ +package org.hisp.dhis.organisationunit.comparator; + +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.organisationunit.OrganisationUnit; + +import java.util.Comparator; + +/** + * @author Morten Olav Hansen + */ +public class OrganisationUnitByLevelComparator + implements Comparator +{ + @Override + public int compare( OrganisationUnit o1, OrganisationUnit o2 ) + { + return o1.getLevel() - o2.getLevel(); + } +} === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-27 05:24:21 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/importers/DefaultIdentifiableObjectImporter.java 2012-06-28 09:21:53 +0000 @@ -45,11 +45,10 @@ import org.hisp.dhis.expression.Expression; import org.hisp.dhis.expression.ExpressionService; import org.hisp.dhis.importexport.ImportStrategy; -import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.period.Period; import org.hisp.dhis.period.PeriodService; import org.hisp.dhis.period.PeriodType; -import org.hisp.dhis.system.util.FunctionUtils; +import org.hisp.dhis.system.util.CollectionUtils; import org.hisp.dhis.system.util.ReflectionUtils; import org.hisp.dhis.system.util.functional.Function1; import org.springframework.beans.factory.annotation.Autowired; @@ -243,7 +242,7 @@ { if ( attributeValues.size() > 0 ) { - FunctionUtils.forEach( attributeValues, new Function1() + CollectionUtils.forEach( attributeValues, new Function1() { @Override public void apply( AttributeValue attributeValue ) @@ -284,7 +283,7 @@ { Set dataElementOperands = extractDataElementOperands( object, fieldName ); - FunctionUtils.forEach( dataElementOperands, new Function1() + CollectionUtils.forEach( dataElementOperands, new Function1() { @Override public void apply( DataElementOperand dataElementOperand ) @@ -300,7 +299,7 @@ { Set attributeValues = extractAttributeValues( object ); - FunctionUtils.forEach( attributeValues, new Function1() + CollectionUtils.forEach( attributeValues, new Function1() { @Override public void apply( AttributeValue attributeValue ) @@ -624,7 +623,7 @@ final Map fieldMap = new HashMap(); final Collection fieldCollection = ReflectionUtils.collectFields( object.getClass(), idObjects ); - FunctionUtils.forEach( fieldCollection, new Function1() + CollectionUtils.forEach( fieldCollection, new Function1() { @Override public void apply( Field field ) @@ -669,7 +668,7 @@ final Map> collectionFields = new HashMap>(); final Collection fieldCollection = ReflectionUtils.collectFields( object.getClass(), idObjectCollectionsWithScanned ); - FunctionUtils.forEach( fieldCollection, new Function1() + CollectionUtils.forEach( fieldCollection, new Function1() { @Override public void apply( Field field ) @@ -695,7 +694,7 @@ Collection collection = collectionFields.get( field ); final Collection objects = ReflectionUtils.newCollectionInstance( field.getType() ); - FunctionUtils.forEach( collection, new Function1() + CollectionUtils.forEach( collection, new Function1() { @Override public void apply( Object object ) === modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/OrganisationUnitUtils.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/OrganisationUnitUtils.java 2012-06-27 05:24:21 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/OrganisationUnitUtils.java 2012-06-28 09:21:53 +0000 @@ -28,9 +28,11 @@ */ import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.system.util.functional.Predicate; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; /** === added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CollectionUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CollectionUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CollectionUtils.java 2012-06-28 09:21:53 +0000 @@ -0,0 +1,68 @@ +package org.hisp.dhis.system.util; + +/* + * Copyright (c) 2004-2012, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.system.util.functional.Function1; +import org.hisp.dhis.system.util.functional.Predicate; + +import java.util.Collection; +import java.util.Iterator; + +/** + * @author Morten Olav Hansen + */ +public class CollectionUtils +{ + public static void forEach( Collection collection, Function1 function ) + { + for ( T object : collection ) + { + if ( object == null ) + { + continue; + } + + function.apply( object ); + } + } + + public static void filter( Collection collection, Predicate predicate ) + { + Iterator iterator = collection.iterator(); + + while ( iterator.hasNext() ) + { + T object = iterator.next(); + + if ( !predicate.evaluate( object ) ) + { + iterator.remove(); + } + } + } +} === removed file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/FunctionUtils.java' --- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/FunctionUtils.java 2012-06-25 20:14:42 +0000 +++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/FunctionUtils.java 1970-01-01 00:00:00 +0000 @@ -1,51 +0,0 @@ -package org.hisp.dhis.system.util; - -/* - * Copyright (c) 2004-2012, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import org.hisp.dhis.system.util.functional.Function1; - -import java.util.Collection; - -/** - * @author Morten Olav Hansen - */ -public class FunctionUtils -{ - public static void forEach( Collection collection, Function1 function ) - { - for ( T object : collection ) - { - if(object == null) - { - continue; - } - - function.apply( object ); - } - } -} === modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm' --- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 2011-08-27 13:23:03 +0000 +++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnitTree.vm 2012-06-28 09:21:53 +0000 @@ -4,7 +4,7 @@ #if( ! $versionOnly ) ,"organisationUnits": { #foreach( $unit in $organisationUnits ) -"${unit.id}":{"id":${unit.id},"n":"$!encoder.jsonEncode( ${unit.name} )",#if( $unit.parent )"pid":${unit.parent.id},#end"c":[#foreach( $child in $unit.sortedChildren )${child.id}#if( $velocityCount < $unit.children.size() ),#end#end]} +"${unit.id}":{"id":${unit.id},"n":"$!encoder.jsonEncode( ${unit.name} )",#if( $unit.parent )"pid":${unit.parent.id},#end"c":[#foreach( $child in $unit.sortedChildren )${child.id}#if( $velocityCount < $unit.children.size() ),#end#end]} #if( $velocityCount < $organisationUnits.size() ),#end#end }#end } \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java' --- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2012-06-14 06:23:51 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2012-06-28 09:21:53 +0000 @@ -29,8 +29,12 @@ import com.opensymphony.xwork2.Action; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; +import org.hisp.dhis.configuration.ConfigurationService; import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitLevel; import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.system.util.CollectionUtils; +import org.hisp.dhis.system.util.functional.Predicate; import org.hisp.dhis.user.CurrentUserService; import org.hisp.dhis.user.User; import org.hisp.dhis.version.Version; @@ -69,6 +73,13 @@ this.versionService = versionService; } + private ConfigurationService configurationService; + + public void setConfigurationService( ConfigurationService configurationService ) + { + this.configurationService = configurationService; + } + // ------------------------------------------------------------------------- // Input & Output // ------------------------------------------------------------------------- @@ -126,10 +137,8 @@ { if ( user.getOrganisationUnits() != null && currentUserService.currentUserIsSuper() ) { - userOrganisationUnits = new ArrayList( - organisationUnitService.getRootOrganisationUnits() ); - rootOrganisationUnits = new ArrayList( - organisationUnitService.getRootOrganisationUnits() ); + userOrganisationUnits = new ArrayList( organisationUnitService.getRootOrganisationUnits() ); + rootOrganisationUnits = new ArrayList( organisationUnitService.getRootOrganisationUnits() ); } else { @@ -144,6 +153,33 @@ { organisationUnits.addAll( organisationUnitService.getOrganisationUnitWithChildren( unit.getId() ) ); } + + OrganisationUnitLevel offlineOrganisationUnitLevel = configurationService.getConfiguration().getOfflineOrganisationUnitLevel(); + + if ( offlineOrganisationUnitLevel == null ) + { + int size = organisationUnitService.getOrganisationUnitLevels().size(); + offlineOrganisationUnitLevel = organisationUnitService.getOrganisationUnitLevel( size ); + } + + int minLevel = rootOrganisationUnits.get( 0 ).getLevel(); + int total = minLevel + offlineOrganisationUnitLevel.getLevel() - 1; + + if ( total > offlineOrganisationUnitLevel.getLevel() ) + { + total = offlineOrganisationUnitLevel.getLevel(); + } + + final int finalTotal = total; + + CollectionUtils.filter( organisationUnits, new Predicate() + { + @Override + public boolean evaluate( OrganisationUnit organisationUnit ) + { + return organisationUnit.getLevel() <= finalTotal; + } + } ); } Collections.sort( rootOrganisationUnits, IdentifiableObjectNameComparator.INSTANCE ); === modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2012-06-05 22:03:24 +0000 +++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2012-06-28 09:21:53 +0000 @@ -516,6 +516,7 @@ + - - /dhis-web-commons/ajax/jsonOrganisationUnitTree.vm - + /dhis-web-commons/ajax/jsonOrganisationUnitTree.vm plainTextError === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2012-06-27 16:54:45 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/SetGeneralSettingsAction.java 2012-06-28 09:21:53 +0000 @@ -205,12 +205,12 @@ configuration.setCompletenessRecipients( userGroupService.getUserGroup( completenessRecipients ) ); } - System.err.println( "Setting offline1: " + offlineOrganisationUnitLevel ); - if ( offlineOrganisationUnitLevel != null ) { - System.err.println( "Setting offline2: " + offlineOrganisationUnitLevel ); configuration.setOfflineOrganisationUnitLevel( organisationUnitService.getOrganisationUnitLevel( offlineOrganisationUnitLevel ) ); + + // if the level is changed, we need to make sure that the version is also changed. + organisationUnitService.updateVersion(); } if ( infrastructuralDataElements != null ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2012-06-27 16:54:45 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2012-06-28 09:21:53 +0000 @@ -103,4 +103,4 @@ no_cache=No cache cache_until_6am_tomorrow=Cache until 6 AM tomorrow cache_for_two_weeks=Cache for two weeks -offline_orgunit_level=Offline Organisation Unit Level +max_levels_to_offline=Maximum Organisation Unit Levels to Offline === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2012-06-27 16:54:45 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemGeneralSettings.vm 2012-06-28 09:21:53 +0000 @@ -79,13 +79,16 @@

- -

$i18n.getString( "offline_orgunit_level" )

+ +

$i18n.getString( "max_levels_to_offline" )