dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36315
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18602: Org unit tree. Impl feature for defining how many org unit levels to cache offline in tree per or...
------------------------------------------------------------
revno: 18602
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-03-13 19:39:40 +0100
message:
Org unit tree. Impl feature for defining how many org unit levels to cache offline in tree per org unit level. Useful for isntance for global hierarchies where you want to allow country users to cache their own country, whereas avoiding global users to load all countries.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitLevel.hbm.xml
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitlevel/SaveOrganisationUnitLevelsAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/saveOrganisationUnitLevelForm.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/organisationunit/OrganisationUnitLevel.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2015-02-05 06:53:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitLevel.java 2015-03-13 18:39:40 +0000
@@ -29,12 +29,16 @@
*/
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.schema.annotation.PropertyRange;
/**
@@ -50,6 +54,8 @@
private static final long serialVersionUID = 1599124366660090489L;
private int level;
+
+ private Integer offlineLevels;
// -------------------------------------------------------------------------
// Constructors
@@ -65,6 +71,13 @@
this.name = name;
}
+ public OrganisationUnitLevel( int level, String name, Integer offlineLevels )
+ {
+ this.level = level;
+ this.name = name;
+ this.offlineLevels = offlineLevels;
+ }
+
// -------------------------------------------------------------------------
// hashCode and equals
// -------------------------------------------------------------------------
@@ -128,6 +141,19 @@
this.level = level;
}
+ @JsonProperty
+ @JsonView( { DetailedView.class, ExportView.class } )
+ @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ public Integer getOfflineLevels()
+ {
+ return offlineLevels;
+ }
+
+ public void setOfflineLevels( Integer offlineLevels )
+ {
+ this.offlineLevels = offlineLevels;
+ }
+
@Override
public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-02-19 16:52:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2015-03-13 18:39:40 +0000
@@ -814,6 +814,7 @@
else
{
existing.setName( level.getName() );
+ existing.setOfflineLevels( level.getOfflineLevels() );
updateOrganisationUnitLevel( existing );
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitLevel.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitLevel.hbm.xml 2014-04-06 09:44:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnitLevel.hbm.xml 2015-03-13 18:39:40 +0000
@@ -18,6 +18,8 @@
<property name="name" column="name" not-null="true" unique="true" length="230" />
<property name="level" not-null="true" unique="true" />
+
+ <property name="offlineLevels" />
</class>
</hibernate-mapping>
=== 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 2015-03-13 16:08:55 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOrganisationUnitTreeAction.java 2015-03-13 18:39:40 +0000
@@ -278,14 +278,56 @@
return orgUnitVersion.getValue();
}
-
+
+ /**
+ * Returns the number of org unit levels to cache offline based on the given
+ * org unit level argument, next the org unit level from the user org unit,
+ * next the level from the configuration.
+ */
private Integer getMaxLevels()
{
- OrganisationUnitLevel offlineOrgUnitLevel = offlineLevel != null ? new OrganisationUnitLevel( offlineLevel, "" )
- : configurationService.getConfiguration().getOfflineOrganisationUnitLevel();
-
List<OrganisationUnitLevel> orgUnitLevels = organisationUnitService.getOrganisationUnitLevels();
- return ( offlineOrgUnitLevel != null && !orgUnitLevels.isEmpty() ) ? offlineOrgUnitLevel.getLevel() : null;
+ Integer levelFromUserOrgUnit = null;
+
+ if ( orgUnitLevels == null || orgUnitLevels.isEmpty() )
+ {
+ return null;
+ }
+
+ if ( offlineLevel != null )
+ {
+ return offlineLevel;
+ }
+ else if ( ( levelFromUserOrgUnit = getMaxLevelsFromUserOrgUnits() ) != null )
+ {
+ return levelFromUserOrgUnit;
+ }
+ else
+ {
+ OrganisationUnitLevel level = configurationService.getConfiguration().getOfflineOrganisationUnitLevel();
+
+ return level != null ? level.getLevel() : null;
+ }
+ }
+
+ /**
+ * Returns the number of org unit levels to cache offline based on the org unit
+ * level of the first user org unit. Returns null if not defined.
+ */
+ private Integer getMaxLevelsFromUserOrgUnits()
+ {
+ if ( !rootOrganisationUnits.isEmpty() )
+ {
+ OrganisationUnit orgUnit = rootOrganisationUnits.get( 0 );
+
+ int level = organisationUnitService.getLevelOfOrganisationUnit( orgUnit.getId() );
+
+ OrganisationUnitLevel orgUnitLevel = organisationUnitService.getOrganisationUnitLevelByLevel( level );
+
+ return orgUnitLevel != null && orgUnitLevel.getOfflineLevels() != null ? orgUnitLevel.getOfflineLevels() : null;
+ }
+
+ return null;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitlevel/SaveOrganisationUnitLevelsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitlevel/SaveOrganisationUnitLevelsAction.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunitlevel/SaveOrganisationUnitLevelsAction.java 2015-03-13 18:39:40 +0000
@@ -28,16 +28,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.MathUtils.isInteger;
+
import java.util.HashSet;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
-import java.util.Map.Entry;
+import org.apache.struts2.ServletActionContext;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.util.ContextUtils;
-import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
/**
@@ -48,6 +50,7 @@
implements Action
{
private static final String LEVEL_PARAM_PREFIX = "level";
+ private static final String OFFLINE_LEVELS_PARAM_PREFIX = "offline";
// -------------------------------------------------------------------------
// Dependencies
@@ -78,11 +81,15 @@
if ( key != null && key.startsWith( LEVEL_PARAM_PREFIX ) )
{
- if ( value != null && value.trim().length() > 0 )
+ if ( value != null && !value.isEmpty() )
{
int level = Integer.parseInt( key.substring( LEVEL_PARAM_PREFIX.length(), key.length() ) );
- organisationUnitService.addOrUpdateOrganisationUnitLevel( new OrganisationUnitLevel( level, value ) );
+ String offlineLevelsValue = params.get( OFFLINE_LEVELS_PARAM_PREFIX + level );
+
+ Integer offlineLevels = isInteger( offlineLevelsValue ) ? Integer.parseInt( offlineLevelsValue ) : null;
+
+ organisationUnitService.addOrUpdateOrganisationUnitLevel( new OrganisationUnitLevel( level, value, offlineLevels ) );
levels.add( level );
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2014-06-25 03:57:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/org/hisp/dhis/oum/i18n_module.properties 2015-03-13 18:39:40 +0000
@@ -88,6 +88,7 @@
please_select_from_tree=Please select from tree (optional)
polygon=Polygon
point=Point
+offline_levels=Offline levels
available_data_sets=Available data sets
selected_data_sets=Selected data sets
limited=Limited
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/saveOrganisationUnitLevelForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/saveOrganisationUnitLevelForm.vm 2014-10-06 17:20:27 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/saveOrganisationUnitLevelForm.vm 2015-03-13 18:39:40 +0000
@@ -20,12 +20,19 @@
<tr>
<th>$i18n.getString( "level" )</th>
<th>$i18n.getString( "name" )</th>
+ <th>$i18n.getString( "offline_levels" )</th>
<th>$i18n.getString( "operations" )</th>
</tr>
#foreach ( $level in $levels )
<tr>
<td style="text-align: center">$level.level</td>
<td><input type="text" id="level${level.level}" name="level${level.level}" value="$!level.displayName" class="uniqueFields {validate:{required:true,alphanumeric:false,unique:'uniqueFields'}}"/></td>
+ <td><select id="offline${level.level}" name="offline${level.level}" style="width:90px">
+ <option value="">$i18n.getString( "default" )</option>
+ #foreach( $l in [1..15])
+ <option value="${l}"#if( $l == $level.offlineLevels ) selected="selected"#end>$l</option>
+ #end
+ </select></td>
<td align="center"><a href="javascript:translate( 'OrganisationUnitLevel', '$level.uid' )" title="$i18n.getString( 'translation_translate' )"><img src="../images/i18n.png" alt="$i18n.getString( 'translation_translate' )"/></a></td>
</tr>
#end