← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3273: Small refactoring (duplicated code)

 

------------------------------------------------------------
revno: 3273
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-04-04 13:46:41 +0200
message:
  Small refactoring (duplicated code)
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.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-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java	2011-01-12 09:13:36 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java	2011-04-04 11:46:41 +0000
@@ -53,6 +53,16 @@
         this.activitiesList = activitiesList;
     }
 
+    public ActivityPlan( )
+    {
+    }
+
+    
+    public ActivityPlan( List<Activity> activitiesList )
+    {
+        this.activitiesList = activitiesList;
+    }
+
     @Override
     public void serialize( DataOutputStream dout )
         throws IOException

=== 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-03-24 17:19:59 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java	2011-04-04 11:46:41 +0000
@@ -103,35 +103,11 @@
 
         List<Activity> items = new ArrayList<Activity>();
 
-        Collection<org.hisp.dhis.activityplan.Activity> activities;
-
-        activities = activityPlanService.getCurrentActivitiesByProvider( unit );
-
-        for ( org.hisp.dhis.activityplan.Activity each : activities )
+        for ( org.hisp.dhis.activityplan.Activity activity : activityPlanService.getCurrentActivitiesByProvider( unit ) )
         {
-            Date expiredDate = DateUtils.getDateAfterAddition( each.getTask().getDueDate(), each.getTask()
-                .getProgramInstance().getProgram().getMaxDaysAllowedInputData() );
-
-            Activity activity = new Activity();
-            Patient patient = each.getBeneficiary();
-
-            activity.setBeneficiary( getBeneficiaryModel( patient ) );
-
-            activity.setDueDate( each.getDueDate() );
-
-            Task task = new Task();
-            task.setCompleted( each.getTask().isCompleted() );
-            task.setId( each.getTask().getId() );
-            task.setProgramStageId( each.getTask().getProgramStage().getId() );
-            task.setProgramId( each.getTask().getProgramInstance().getProgram().getId() );
-            activity.setTask( task );
-            
-            activity.setLate( each.getDueDate().getTime() < time );
-
-            activity.setExpireDate( expiredDate );
-
-            items.add( activity );
+            items.add( getActivity( activity.getTask(), activity.getDueDate().getTime() < time ) );
         }
+
         if ( items.isEmpty() )
         {
             return null;
@@ -139,15 +115,11 @@
 
         Collections.sort( items, activityComparator );
 
-        ActivityPlan plan = new ActivityPlan();
-
-        plan.setActivitiesList( items );
-
         if ( DEBUG )
             log.debug( "Found " + items.size() + " current activities in " + (System.currentTimeMillis() - time)
                 + " ms." );
 
-        return plan;
+        return new ActivityPlan( items );
     }
 
     // -------------------------------------------------------------------------
@@ -213,10 +185,6 @@
 
     private Activity getActivity( ProgramStageInstance instance, boolean late )
     {
-        if ( instance == null )
-        {
-            return null;
-        }
         Activity activity = new Activity();
         Patient patient = instance.getProgramInstance().getPatient();
 
@@ -230,20 +198,16 @@
         return activity;
     }
 
-    private Task getTask( ProgramStageInstance stageInstance )
+    private Task getTask( ProgramStageInstance instance )
     {
-        if ( stageInstance == null )
-        {
+        if ( instance == null )
             return null;
-        }
 
         Task task = new Task();
-
-        task.setCompleted( stageInstance.isCompleted() );
-        task.setId( stageInstance.getId() );
-        task.setProgramStageId( stageInstance.getProgramStage().getId() );
-        task.setProgramId( stageInstance.getProgramInstance().getProgram().getId() );
-
+        task.setCompleted( instance.isCompleted() );
+        task.setId( instance.getId() );
+        task.setProgramStageId( instance.getProgramStage().getId() );
+        task.setProgramId( instance.getProgramInstance().getProgram().getId() );
         return task;
     }