dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12301
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3746: [DHISMobile] Limit search results by mobile client (too many results can hang the phone)
------------------------------------------------------------
revno: 3746
committer: Long <thanhlongngo1988>
branch nick: dhis2
timestamp: Thu 2011-05-26 11:03:58 +0700
message:
[DHISMobile] Limit search results by mobile client (too many results can hang the phone)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.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/program/comparator/ProgramStageDataElementSortOrderComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java 2011-05-19 03:18:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/comparator/ProgramStageDataElementSortOrderComparator.java 2011-05-26 04:03:58 +0000
@@ -1,3 +1,30 @@
+/*
+ * Copyright (c) 2004-2010, 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.program.comparator;
import java.util.Comparator;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-04-28 07:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-05-26 04:03:58 +0000
@@ -194,6 +194,7 @@
@GET
@Path( "search" )
public ActivityPlan search( @HeaderParam( "identifier" ) String identifier )
+ throws NotAllowedException
{
return activityReportingService.getActivitiesByIdentifier( identifier );
}
@@ -216,8 +217,7 @@
.toString() );
orgUnit.setChangeUpdateDataSetLangUrl( getOrgUnitUrlBuilder( uriInfo ).path( "changeLanguageDataSet" )
.build( unit.getId() ).toString() );
- orgUnit.setSearchUrl( getOrgUnitUrlBuilder( uriInfo ).path( "search" )
- .build( unit.getId() ).toString() );
+ orgUnit.setSearchUrl( getOrgUnitUrlBuilder( uriInfo ).path( "search" ).build( unit.getId() ).toString() );
return orgUnit;
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java 2011-04-28 07:10:33 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java 2011-05-26 04:03:58 +0000
@@ -36,7 +36,7 @@
public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit, String localeString );
- public ActivityPlan getActivitiesByIdentifier( String keyword );
+ public ActivityPlan getActivitiesByIdentifier( String keyword ) throws NotAllowedException;
public void saveActivityReport( OrganisationUnit unit, ActivityValue activityValue )
throws NotAllowedException;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2011-05-10 08:37:38 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2011-05-26 04:03:58 +0000
@@ -143,6 +143,7 @@
@Override
public ActivityPlan getActivitiesByIdentifier( String keyword )
+ throws NotAllowedException
{
long time = PeriodType.createCalendarInstance().getTime().getTime();
@@ -154,33 +155,46 @@
Collection<Patient> patients = patientIdentifierService.getPatientsByIdentifier( keyword, 0,
patientIdentifierService.countGetPatientsByIdentifier( keyword ) );
- if ( patients != null )
- {
- Iterator<Patient> iterator = patients.iterator();
+ // Prevent the case that there are so many result (will hang the mobile
+ // phone ) because user just enter one or two number
- while ( iterator.hasNext() )
+ if ( patients.size() > 10 )
+ {
+ throw NotAllowedException.NEED_MORE_SPECIFIC;
+ }
+ else
+ {
+ if ( patients != null )
{
- Patient patient = iterator.next();
-
- List<ProgramStageInstance> programStageInstances = programStageInstanceService
- .getProgramStageInstances( patient, false );
-
- for ( int i = 0; i < programStageInstances.size(); i++ )
+ Iterator<Patient> iterator = patients.iterator();
+
+ while ( iterator.hasNext() )
{
- ProgramStageInstance programStageInstance = programStageInstances.get( i );
-
- expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(),
- programStageInstance.getProgramInstance().getProgram().getMaxDaysAllowedInputData() ) );
-
- if ( programStageInstance.getDueDate().getTime() <= time && expiredDate.getTimeInMillis() > time )
+ Patient patient = iterator.next();
+
+ List<ProgramStageInstance> programStageInstances = programStageInstanceService
+ .getProgramStageInstances( patient, false );
+
+ for ( int i = 0; i < programStageInstances.size(); i++ )
{
- items.add( getActivity( programStageInstance,
- programStageInstance.getDueDate().getTime() < time ) );
+ ProgramStageInstance programStageInstance = programStageInstances.get( i );
+
+ expiredDate.setTime( DateUtils.getDateAfterAddition( programStageInstance.getDueDate(),
+ programStageInstance.getProgramInstance().getProgram().getMaxDaysAllowedInputData() ) );
+
+ if ( programStageInstance.getDueDate().getTime() <= time
+ && expiredDate.getTimeInMillis() > time )
+ {
+ items.add( getActivity( programStageInstance,
+ programStageInstance.getDueDate().getTime() < time ) );
+ }
}
}
}
+
+ return new ActivityPlan( items );
}
- return new ActivityPlan( items );
+
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java 2011-05-05 21:15:45 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/NotAllowedException.java 2011-05-26 04:03:58 +0000
@@ -45,6 +45,7 @@
public static final NotAllowedException NO_USER = new NotAllowedException( "NO_USER", "No user is logged in." );
+ public static final NotAllowedException NEED_MORE_SPECIFIC = new NotAllowedException( "NEED_MORE_SPECIFIC", "So many result. Please be more specific" );
private String reason;