------------------------------------------------------------ revno: 5788 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Mon 2012-01-23 12:02:10 +0530 message: (mobile) refactor to prepare for auto-selecting ou, ds, period modified: dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.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-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java 2012-01-04 12:55:23 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetDataSetsAction.java 2012-01-23 06:32:10 +0000 @@ -27,21 +27,16 @@ package org.hisp.dhis.light.dataentry.action; +import com.opensymphony.xwork2.Action; +import org.apache.commons.lang.Validate; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.light.utils.FormUtils; + import java.util.ArrayList; import java.util.List; -import org.apache.commons.lang.Validate; -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.user.CurrentUserService; -import org.hisp.dhis.user.UserCredentials; -import org.springframework.beans.factory.annotation.Required; - -import com.opensymphony.xwork2.Action; - /** - * @author mortenoh + * @author Morten Olav Hansen <[email protected]> */ public class GetDataSetsAction implements Action @@ -50,19 +45,16 @@ // Dependencies // ------------------------------------------------------------------------- - private CurrentUserService currentUserService; + private FormUtils formUtils; - @Required - public void setCurrentUserService( CurrentUserService currentUserService ) + public void setFormUtils( FormUtils formUtils ) { - this.currentUserService = currentUserService; + this.formUtils = formUtils; } - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + public FormUtils getFormUtils() { - this.organisationUnitService = organisationUnitService; + return formUtils; } // ------------------------------------------------------------------------- @@ -97,18 +89,8 @@ { Validate.notNull( organisationUnitId ); - OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); - - dataSets = new ArrayList<DataSet>( organisationUnit.getDataSets() ); - - UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials(); - - if ( !userCredentials.isSuper() ) - { - dataSets.retainAll( userCredentials.getAllDataSets() ); - } + dataSets = formUtils.getDataSetsForCurrentUser( organisationUnitId ); return SUCCESS; } - } === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetOrganisationUnitsAction.java 2012-01-23 06:32:10 +0000 @@ -28,19 +28,14 @@ package org.hisp.dhis.light.dataentry.action; import com.opensymphony.xwork2.Action; -import org.apache.commons.lang.Validate; import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; -import org.hisp.dhis.user.CurrentUserService; -import org.hisp.dhis.user.User; import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** - * @author mortenoh + * @author Morten Olav Hansen <[email protected]> */ public class GetOrganisationUnitsAction implements Action @@ -49,13 +44,6 @@ // Dependencies // ------------------------------------------------------------------------- - private CurrentUserService currentUserService; - - public void setCurrentUserService( CurrentUserService currentUserService ) - { - this.currentUserService = currentUserService; - } - private FormUtils formUtils; public void setFormUtils( FormUtils formUtils ) @@ -86,11 +74,7 @@ @Override public String execute() { - User user = currentUserService.getCurrentUser(); - Validate.notNull( user ); - - organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() ); - Collections.sort( organisationUnits, new OrganisationUnitNameComparator() ); + organisationUnits = formUtils.getSortedOrganisationUnitsForCurrentUser(); return SUCCESS; } === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java 2012-01-16 18:30:37 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/GetPeriodsAction.java 2012-01-23 06:32:10 +0000 @@ -35,23 +35,22 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.i18n.I18nFormat; +import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.period.CalendarPeriodType; import org.hisp.dhis.period.Period; -import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter; -import org.hisp.dhis.system.util.FilterUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /** - * @author mortenoh + * @author Morten Olav Hansen <[email protected]> */ public class GetPeriodsAction implements Action { - private static final int MAX_PERIODS = 10; - // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- @@ -84,6 +83,18 @@ this.registrationService = registrationService; } + private FormUtils formUtils; + + public void setFormUtils( FormUtils formUtils ) + { + this.formUtils = formUtils; + } + + public FormUtils getFormUtils() + { + return formUtils; + } + private I18nFormat format; public void setFormat( I18nFormat format ) @@ -190,15 +201,7 @@ dataSet = dataSetService.getDataSet( dataSetId ); - CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType(); - periods = periodType.generateLast5Years( new Date() ); - FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() ); - Collections.reverse( periods ); - - if ( periods.size() > MAX_PERIODS ) - { - periods = periods.subList( 0, MAX_PERIODS ); - } + periods = formUtils.getPeriodsForDataSet( dataSetId ); markLockedDataSets( organisationUnit, dataSet, periods ); === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/MarkComplete.java 2012-01-23 06:32:10 +0000 @@ -1,3 +1,30 @@ +/* + * 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. + */ + package org.hisp.dhis.light.dataentry.action; import com.opensymphony.xwork2.Action; === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java' --- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/FormUtils.java 2012-01-23 06:32:10 +0000 @@ -28,24 +28,34 @@ package org.hisp.dhis.light.utils; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.Validate; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.dataanalysis.DataAnalysisService; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; import org.hisp.dhis.datavalue.DataValue; import org.hisp.dhis.datavalue.DataValueService; import org.hisp.dhis.datavalue.DeflatedDataValue; import org.hisp.dhis.expression.ExpressionService; +import org.hisp.dhis.i18n.I18nFormat; import org.hisp.dhis.minmax.MinMaxDataElement; import org.hisp.dhis.minmax.MinMaxDataElementService; import org.hisp.dhis.minmax.validation.MinMaxValuesGenerationService; import org.hisp.dhis.options.SystemSettingManager; import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator; +import org.hisp.dhis.period.CalendarPeriodType; import org.hisp.dhis.period.Period; import org.hisp.dhis.system.filter.OrganisationUnitWithDataSetsFilter; +import org.hisp.dhis.system.filter.PastAndCurrentPeriodFilter; import org.hisp.dhis.system.util.FilterUtils; import org.hisp.dhis.system.util.ListUtils; +import org.hisp.dhis.user.CurrentUserService; +import org.hisp.dhis.user.User; +import org.hisp.dhis.user.UserCredentials; import org.hisp.dhis.validation.ValidationResult; import org.hisp.dhis.validation.ValidationRule; import org.hisp.dhis.validation.ValidationRuleService; @@ -55,14 +65,30 @@ import java.util.*; /** - * @author mortenoh + * @author Morten Olav Hansen <[email protected]> */ public class FormUtils { + public static final Integer DEFAULT_MAX_PERIODS = 10; + // ------------------------------------------------------------------------- // Dependencies // ------------------------------------------------------------------------- + private CurrentUserService currentUserService; + + public void setCurrentUserService( CurrentUserService currentUserService ) + { + this.currentUserService = currentUserService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + private DataValueService dataValueService; public void setDataValueService( DataValueService dataValueService ) @@ -70,6 +96,13 @@ this.dataValueService = dataValueService; } + private DataSetService dataSetService; + + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + private DataAnalysisService stdDevOutlierAnalysisService; public void setStdDevOutlierAnalysisService( DataAnalysisService stdDevOutlierAnalysisService ) @@ -119,6 +152,13 @@ this.expressionService = expressionService; } + private I18nFormat format; + + public void setFormat( I18nFormat format ) + { + this.format = format; + } + // ------------------------------------------------------------------------- // Utils // ------------------------------------------------------------------------- @@ -211,6 +251,59 @@ return ous; } + public List<OrganisationUnit> getSortedOrganisationUnitsForCurrentUser() + { + User user = currentUserService.getCurrentUser(); + Validate.notNull( user ); + + List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( user.getOrganisationUnits() ); + Collections.sort( organisationUnits, new OrganisationUnitNameComparator() ); + + return organisationUnits; + } + + public List<DataSet> getDataSetsForCurrentUser( Integer organisationUnitId ) + { + Validate.notNull( organisationUnitId ); + + OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( organisationUnitId ); + + List<DataSet> dataSets = new ArrayList<DataSet>( organisationUnit.getDataSets() ); + + UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials(); + + if ( !userCredentials.isSuper() ) + { + dataSets.retainAll( userCredentials.getAllDataSets() ); + } + + return dataSets; + } + + public List<Period> getPeriodsForDataSet( Integer dataSetId ) + { + return getPeriodsForDataSet( dataSetId, 0, DEFAULT_MAX_PERIODS ); + } + + public List<Period> getPeriodsForDataSet( Integer dataSetId, int first, int max ) + { + Validate.notNull( dataSetId ); + + DataSet dataSet = dataSetService.getDataSet( dataSetId ); + + CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType(); + List<Period> periods = periodType.generateLast5Years( new Date() ); + FilterUtils.filter( periods, new PastAndCurrentPeriodFilter() ); + Collections.reverse( periods ); + + if ( periods.size() > (first + max) ) + { + periods = periods.subList( first, max ); + } + + return periods; + } + // ------------------------------------------------------------------------- // Static Utils // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/resources/META-INF/dhis/beans.xml 2012-01-23 06:32:10 +0000 @@ -15,7 +15,10 @@ <!-- data entry --> <bean id="org.hisp.dhis.light.dataentry.utils.FormUtils" class="org.hisp.dhis.light.utils.FormUtils"> + <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" /> + <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" /> + <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" /> <property name="stdDevOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.StdDevOutlierAnalysisService" /> <property name="minMaxOutlierAnalysisService" ref="org.hisp.dhis.dataanalysis.MinMaxOutlierAnalysisService" /> <property name="minMaxValuesGenerationService" @@ -29,20 +32,19 @@ <bean id="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction" class="org.hisp.dhis.light.dataentry.action.GetOrganisationUnitsAction" scope="prototype"> - <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> </bean> <bean id="org.hisp.dhis.light.dataentry.action.GetDataSetsAction" class="org.hisp.dhis.light.dataentry.action.GetDataSetsAction" scope="prototype"> - <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" /> - <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" /> + <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> </bean> <bean id="org.hisp.dhis.light.dataentry.action.GetPeriodsAction" class="org.hisp.dhis.light.dataentry.action.GetPeriodsAction" scope="prototype"> + <property name="formUtils" ref="org.hisp.dhis.light.dataentry.utils.FormUtils" /> <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" /> <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" /> <property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" /> === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/dataEntryOverview.vm 2012-01-23 06:32:10 +0000 @@ -6,10 +6,10 @@ #end <div class="header-box" align="center"> - <h3 style="text-align: left; background-color: #667b99; border-color: #667b99; color: white;">$dataSetName</h3> + <h3 style="text-align: left; background-color: #719953; border-color: #719953; color: white;">$dataSetName</h3> <p style="text-align: left;"> - $period.name <br /> - $organisationUnit.name + $organisationUnit.name <br /> + $period.name </p> </div> === modified file 'dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm' --- dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm 2012-01-22 19:37:21 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/main/webapp/dhis-web-light/menu.vm 2012-01-23 06:32:10 +0000 @@ -9,9 +9,9 @@ <div class="header-box" align="center"> <h3 style="text-align: left; background-color: #719953; border-color: #719953; color: white;">$i18n.getString("completed")</h3> <p style="text-align: left;"> + $organisationUnit.name <br /> $dataSetName <br /> - $period.name <br /> - $organisationUnit.name + $period.name </p> </div> #end === modified file 'dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java' --- dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java 2011-12-08 16:02:16 +0000 +++ dhis-2/dhis-web/dhis-web-light/src/test/java/org/hisp/dhis/light/dataentry/action/GetDataSetsActionTest.java 2012-01-23 06:32:10 +0000 @@ -8,6 +8,7 @@ import java.util.Set; import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.light.utils.FormUtils; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.user.CurrentUserService; @@ -36,12 +37,16 @@ Set<DataSet> unitDataSets = createUnitDataSets(); Set<DataSet> userDataSets = createUserDataSets(); + OrganisationUnitService organisationUnitService = mock( OrganisationUnitService.class ); + CurrentUserService currentUserService = mock( CurrentUserService.class ); + + FormUtils formUtils = new FormUtils(); + formUtils.setCurrentUserService( currentUserService ); + formUtils.setOrganisationUnitService( organisationUnitService ); + // Initializing action getDataSetsAction.setOrganisationUnitId( 1 ); - CurrentUserService currentUserService = mock( CurrentUserService.class ); - getDataSetsAction.setCurrentUserService( currentUserService ); - OrganisationUnitService organisationUnitService = mock( OrganisationUnitService.class ); - getDataSetsAction.setOrganisationUnitService( organisationUnitService ); + getDataSetsAction.setFormUtils( formUtils ); // Populating mocks OrganisationUnit unit = new OrganisationUnit();
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

