dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08605
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2096: - Cleaned up some more (and messed up a bit)
------------------------------------------------------------
revno: 2096
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2010-11-18 11:38:29 +0530
message:
- Cleaned up some more (and messed up a bit)
- Reply with list of orgunits and their urls
removed:
dhis-2/dhis-web/dhis-web-api/README.txt
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileSerializable.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataSerializableProvider.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityPlanModelService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultPeriodService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityPlanService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityValueService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IPeriodService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivitiesMapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivityPlanItemMapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeanMapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeneficiaryMapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/TaskMapper.java
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataStreamSerializable.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProvider.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/test/java/org/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/
dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java
modified:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java
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/ActivityValue.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Model.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml
--
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
=== removed file 'dhis-2/dhis-web/dhis-web-api/README.txt'
--- dhis-2/dhis-web/dhis-web-api/README.txt 2010-08-10 10:35:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/README.txt 1970-01-01 00:00:00 +0000
@@ -1,39 +0,0 @@
-NOTE: WORK IN PROGRESS
-
-This module uses the jsr-311[1] implementation jersey[2] for building
-a experimental example of what a web api for the CBHIS module of DHIS2
-might look like.
-
-Requests to paths under /api/cbhis/v0.1/ will be attempted mapped to the
-resource classes in the package org.hisp.dhis2.cbhis.api.resources.
-
-The root resource handling /api/cbhis/ will resolve the logged in
-users and return an xml (xml produced with JAXB[3]) of the orgunits linked with the user, linking
-to urls for the org units activity plan.
-
-An example:
-
-Running this module with mvn jetty:run, assuming a user test_user with
-password Trivandrum1 linked to the orgunit with id 2262 in the test
-db, this request:
-
-curl -u test_user:Trivandrum1 http://localhost:8080/api/cbhis/v0.1/
-
-should give an xml with links to the orgunits activity plans, while
-
-curl -u test_user:Trivandrum1 http://localhost:8080/api/cbhis/v0.1/orgUnits/2256/activities/plan/current
-
-should result in an xml of the current activity plan*, and
-
-curl -u test_user:Trivandrum1 curl -u test_user:Trivandrum1 http://localhost:8080/api/cbhis/v0.1/orgunits/2262/activityplan -H "Accept: application/vnd.org.dhis2.cbhis.v0.1.activityplan+serialized"
-
-should return it in serialized form somewhat like openxdata uses.
-
-* Activity plan is tentatively defined as all activities in the
- current month + earlier uncompleted activities.
-
-curl -u test_user:Trivandrum1 http://localhost:8080/api/cbhis/v0.1/orgUnits/2256/activities/all
-
-[1] https://jsr311.dev.java.net/
-[2] https://jersey.dev.java.net/
-[3] http://en.wikipedia.org/wiki/Java_Architecture_for_XML_Binding
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Activity.java 2010-11-18 06:08:29 +0000
@@ -33,7 +33,7 @@
import java.util.Date;
public class Activity
- implements MobileSerializable
+ implements DataStreamSerializable
{
private Beneficiary beneficiary;
=== 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 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2010-11-18 06:08:29 +0000
@@ -33,7 +33,7 @@
import java.util.List;
public class ActivityPlan
- implements MobileSerializable
+ implements DataStreamSerializable
{
private List<Activity> activitiesList;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityValue.java 2010-11-18 06:08:29 +0000
@@ -34,7 +34,7 @@
import java.util.List;
public class ActivityValue
- implements MobileSerializable
+ implements DataStreamSerializable
{
private int programInstanceId;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2010-11-17 06:12:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Beneficiary.java 2010-11-18 06:08:29 +0000
@@ -34,7 +34,7 @@
import java.util.List;
public class Beneficiary
- implements MobileSerializable
+ implements DataStreamSerializable
{
private int id;
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataStreamSerializable.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataStreamSerializable.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataStreamSerializable.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.web.api.model;
+
+/*
+ * 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.
+ */
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+/**
+ * Interface for entities that needs to be serialized/deserialized for
+ * communication with low-bandwith mobile phones
+ */
+public interface DataStreamSerializable
+{
+
+ public void serialize( DataOutputStream dataOutputStream )
+ throws IOException;
+
+ public void deSerialize( DataInputStream dataInputStream )
+ throws IOException;
+
+}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataValue.java 2010-11-18 06:08:29 +0000
@@ -32,7 +32,7 @@
import java.io.IOException;
public class DataValue
- implements MobileSerializable
+ implements DataStreamSerializable
{
private int id;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileModel.java 2010-11-18 06:08:29 +0000
@@ -33,7 +33,7 @@
import java.util.List;
public class MobileModel
- implements MobileSerializable
+ implements DataStreamSerializable
{
private ActivityPlan activityPlan;
@@ -76,13 +76,17 @@
throws IOException
{
- if ( programs != null )
+ if ( programs == null )
{
+ dout.writeInt( 0 );
+ }
+ else {
dout.writeInt( programs.size() );
- }
- else
- {
- dout.writeInt( 0 );
+
+ for ( Program prog : programs )
+ {
+ prog.serialize( dout );
+ }
}
// Write ActivityPlans
@@ -95,14 +99,6 @@
this.activityPlan.serialize( dout );
}
- // Write Programs
- if ( programs != null || programs.size() > 0 )
- {
- for ( Program prog : programs )
- {
- prog.serialize( dout );
- }
- }
// Write DataSets
if ( datasets == null )
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileSerializable.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileSerializable.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileSerializable.java 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
-package org.hisp.dhis.web.api.model;
-
-/*
- * 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.
- */
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-
-/**
- * Interface for entities that needs to be serialized/deserialized for
- * communication with low-bandwith mobile phones
- */
-public interface MobileSerializable
-{
-
- public void serialize( DataOutputStream dataOutputStream )
- throws IOException;
-
- public void deSerialize( DataInputStream dataInputStream )
- throws IOException;
-
-}
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Model.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Model.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Model.java 2010-11-18 06:08:29 +0000
@@ -32,7 +32,7 @@
import java.io.IOException;
public class Model
- implements MobileSerializable
+ implements DataStreamSerializable
{
private int id;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ModelList.java 2010-11-18 06:08:29 +0000
@@ -34,7 +34,7 @@
import java.util.List;
public class ModelList
- implements MobileSerializable
+ implements DataStreamSerializable
{
private List<Model> models;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2010-11-16 18:26:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnit.java 2010-11-18 06:08:29 +0000
@@ -32,12 +32,20 @@
import java.io.IOException;
-public class OrgUnit implements MobileSerializable {
+public class OrgUnit implements DataStreamSerializable {
private int id;
private String name;
+ private String downloadAllUrl;
+
+ private String downloadActivityPlanUrl;
+
+ private String uploadFacilityReportUrl;
+
+ private String uploadActivityReportUrl;
+
public int getId()
{
return id;
@@ -58,20 +66,67 @@
this.name = name;
}
- @Override
+ public String getDownloadAllUrl()
+ {
+ return downloadAllUrl;
+ }
+
+ public void setDownloadAllUrl( String downloadAllUrl )
+ {
+ this.downloadAllUrl = downloadAllUrl;
+ }
+
+ public String getDownloadActivityPlanUrl()
+ {
+ return downloadActivityPlanUrl;
+ }
+
+ public void setDownloadActivityPlanUrl( String downloadActivityPlanUrl )
+ {
+ this.downloadActivityPlanUrl = downloadActivityPlanUrl;
+ }
+
+ public String getUploadFacilityReportUrl()
+ {
+ return uploadFacilityReportUrl;
+ }
+
+ public void setUploadFacilityReportUrl( String uploadFacilityReportUrl )
+ {
+ this.uploadFacilityReportUrl = uploadFacilityReportUrl;
+ }
+
+ public String getUploadActivityReportUrl()
+ {
+ return uploadActivityReportUrl;
+ }
+
+ public void setUploadActivityReportUrl( String uploadActivityReportUrl )
+ {
+ this.uploadActivityReportUrl = uploadActivityReportUrl;
+ }
+
public void serialize( DataOutputStream dataOutputStream )
throws IOException
{
- dataOutputStream.write( this.id );
+ dataOutputStream.writeInt( this.id );
dataOutputStream.writeUTF( this.name );
+ dataOutputStream.writeUTF( this.downloadAllUrl );
+ dataOutputStream.writeUTF( this.downloadActivityPlanUrl );
+ dataOutputStream.writeUTF( this.uploadFacilityReportUrl );
+ dataOutputStream.writeUTF( this.uploadActivityReportUrl );
+
}
- @Override
public void deSerialize( DataInputStream dataInputStream )
throws IOException
{
this.id = dataInputStream.readInt();
this.name = dataInputStream.readUTF();
+ this.downloadAllUrl = dataInputStream.readUTF();
+ this.downloadActivityPlanUrl = dataInputStream.readUTF();
+ this.uploadFacilityReportUrl = dataInputStream.readUTF();
+ this.uploadActivityReportUrl = dataInputStream.readUTF();
}
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/OrgUnits.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.web.api.model;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+
+
+public class OrgUnits
+ extends ArrayList<OrgUnit>
+ implements DataStreamSerializable
+{
+
+ @Override
+ public void serialize( DataOutputStream dataOutputStream )
+ throws IOException
+ {
+ dataOutputStream.writeInt( size() );
+ for ( OrgUnit unit : this )
+ {
+ unit.serialize( dataOutputStream );
+ }
+
+ }
+
+ @Override
+ public void deSerialize( DataInputStream dataInputStream )
+ throws IOException
+ {
+ this.clear();
+ int size = dataInputStream.readInt();
+
+ for ( int i = 0; i < size; i++ )
+ {
+ OrgUnit unit = new OrgUnit();
+ unit.deSerialize( dataInputStream );
+ add( unit );
+ }
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java 2010-11-17 06:12:29 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/PatientAttribute.java 2010-11-18 06:08:29 +0000
@@ -31,7 +31,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
-public class PatientAttribute implements MobileSerializable
+public class PatientAttribute implements DataStreamSerializable
{
private String name;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Task.java 2010-11-18 06:08:29 +0000
@@ -36,7 +36,7 @@
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
-public class Task implements MobileSerializable
+public class Task implements DataStreamSerializable
{
private int id;
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/ActivityPlanProvider.java 1970-01-01 00:00:00 +0000
@@ -1,77 +0,0 @@
-package org.hisp.dhis.web.api.provider;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-import org.hisp.dhis.web.api.model.ActivityPlan;
-import com.jcraft.jzlib.JZlib;
-import com.jcraft.jzlib.ZOutputStream;
-import com.sun.jersey.spi.resource.Singleton;
-
-@Provider
-@Singleton
-@Produces( "application/vnd.org.dhis2.activityplan+serialized" )
-public class ActivityPlanProvider
- implements MessageBodyWriter<ActivityPlan>
-{
-
- @Override
- public long getSize( ActivityPlan arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4 )
- {
- return -1;
- }
-
- @Override
- public boolean isWriteable( Class<?> arg0, Type arg1, Annotation[] arg2, MediaType arg3 )
- {
-
- return true;
- }
-
- @Override
- public void writeTo( ActivityPlan arg0, Class<?> arg1, Type arg2, Annotation[] arg3, MediaType arg4,
- MultivaluedMap<String, Object> arg5, OutputStream stream )
- throws IOException, WebApplicationException
- {
- serializeZipped( arg0, stream );
- }
-
- public void serializeZipped( ActivityPlan activityPlan, OutputStream os )
- throws IOException
- {
- ByteArrayOutputStream baos = serializePersistent( activityPlan );
- ZOutputStream gzip = new ZOutputStream( os, JZlib.Z_BEST_COMPRESSION );
- DataOutputStream dos = new DataOutputStream( gzip );
-
- try
- {
- dos.write( baos.toByteArray() );
- }
- finally
- {
- dos.flush();
- gzip.finish();
- }
- }
-
- public ByteArrayOutputStream serializePersistent( ActivityPlan activityPlan )
- throws IOException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream( baos );
- activityPlan.serialize( out );
- out.flush();
- return baos;
- }
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataSerializableProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataSerializableProvider.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataSerializableProvider.java 1970-01-01 00:00:00 +0000
@@ -1,106 +0,0 @@
-package org.hisp.dhis.web.api.provider;
-
-/*
- * 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.
- */
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Type;
-
-import javax.ws.rs.Produces;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.ext.MessageBodyWriter;
-import javax.ws.rs.ext.Provider;
-
-import org.hisp.dhis.web.api.model.MobileSerializable;
-
-import com.jcraft.jzlib.JZlib;
-import com.jcraft.jzlib.ZOutputStream;
-import com.sun.jersey.spi.resource.Singleton;
-
-@Provider
-@Singleton
-@Produces( "application/vnd.org.dhis2.mobile+serialized" )
-public class DataSerializableProvider
- implements MessageBodyWriter<MobileSerializable>
-{
-
- @Override
- public boolean isWriteable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType )
- {
- return true;
- }
-
- @Override
- public long getSize( MobileSerializable t, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mediaType )
- {
- return -1;
- }
-
- @Override
- public void writeTo( MobileSerializable t, Class<?> type, Type genericType, Annotation[] annotations,
- MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream )
- throws IOException, WebApplicationException
- {
- ByteArrayOutputStream baos = serializePersistent( t );
- ZOutputStream gzip = new ZOutputStream( entityStream, JZlib.Z_BEST_COMPRESSION );
- DataOutputStream dos = new DataOutputStream( gzip );
-
- try
- {
- byte[] res = baos.toByteArray();
- dos.write( res );
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- finally
- {
- dos.flush();
- gzip.finish();
- }
-
- }
-
- public ByteArrayOutputStream serializePersistent( MobileSerializable entity )
- throws IOException
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream( baos );
- entity.serialize( out );
- out.flush();
- return baos;
- }
-
-}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProvider.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProvider.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProvider.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,106 @@
+package org.hisp.dhis.web.api.provider;
+
+/*
+ * 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.
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.Produces;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+import javax.ws.rs.ext.Provider;
+
+import org.hisp.dhis.web.api.model.DataStreamSerializable;
+
+import com.jcraft.jzlib.JZlib;
+import com.jcraft.jzlib.ZOutputStream;
+import com.sun.jersey.spi.resource.Singleton;
+
+@Provider
+@Singleton
+@Produces( "application/vnd.org.dhis2.mobile+serialized" )
+public class DataStreamSerializableProvider
+ implements MessageBodyWriter<DataStreamSerializable>
+{
+
+ @Override
+ public boolean isWriteable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType )
+ {
+ return DataStreamSerializable.class.isAssignableFrom( type );
+ }
+
+ @Override
+ public long getSize( DataStreamSerializable t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType )
+ {
+ return -1;
+ }
+
+ @Override
+ public void writeTo( DataStreamSerializable t, Class<?> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream )
+ throws IOException, WebApplicationException
+ {
+ ByteArrayOutputStream baos = serializePersistent( t );
+ ZOutputStream gzip = new ZOutputStream( entityStream, JZlib.Z_BEST_COMPRESSION );
+ DataOutputStream dos = new DataOutputStream( gzip );
+
+ try
+ {
+ byte[] res = baos.toByteArray();
+ dos.write( res );
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ dos.flush();
+ gzip.finish();
+ }
+
+ }
+
+ public ByteArrayOutputStream serializePersistent( DataStreamSerializable entity )
+ throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream( baos );
+ entity.serialize( out );
+ out.flush();
+ return baos;
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-11-16 18:26:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/MobileResource.java 2010-11-18 06:08:29 +0000
@@ -27,171 +27,73 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
-import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
-import javax.ws.rs.HeaderParam;
-import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
+import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.user.User;
-import org.hisp.dhis.web.api.model.ActivityPlan;
-import org.hisp.dhis.web.api.model.ActivityValue;
-import org.hisp.dhis.web.api.model.DataSetValue;
-import org.hisp.dhis.web.api.model.MobileModel;
import org.hisp.dhis.web.api.model.OrgUnit;
-import org.hisp.dhis.web.api.service.FacilityReportingService;
-import org.hisp.dhis.web.api.service.IActivityPlanService;
-import org.hisp.dhis.web.api.service.IActivityValueService;
-import org.hisp.dhis.web.api.service.IProgramService;
+import org.hisp.dhis.web.api.model.OrgUnits;
import org.springframework.beans.factory.annotation.Required;
-@Path( "/mobile" )
+import com.sun.jersey.api.core.ResourceContext;
+
+@Path( "/" )
public class MobileResource
{
// Dependencies
- private IActivityValueService iactivityValueService;
-
- private IProgramService programService;
-
- private IActivityPlanService activityPlanService;
-
- private FacilityReportingService facilityReportingService;
-
private CurrentUserService currentUserService;
- @Required
- public void setProgramService( IProgramService programService )
- {
- this.programService = programService;
- }
-
- @Required
- public void setActivityPlanService( IActivityPlanService activityPlanService )
- {
- this.activityPlanService = activityPlanService;
- }
-
- @Required
- public void setIactivityValueService( IActivityValueService iactivityValueService )
- {
- this.iactivityValueService = iactivityValueService;
- }
-
- @Required
- public void setFacilityReportingService( FacilityReportingService facilityReportingService )
- {
- this.facilityReportingService = facilityReportingService;
- }
-
- @Required
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- // Resource methods
+ private OrganisationUnitService organisationUnitService;
+
+ @Context
+ UriInfo uriInfo;
+
+ @Context
+ private ResourceContext rc;
@GET
@Produces( MediaType.MOBILE_SERIALIZED )
- public Response getOrgUnitForUser()
+ @Path( "mobile" )
+ public OrgUnits getOrgUnitsForUser()
{
User user = currentUserService.getCurrentUser();
Collection<OrganisationUnit> units = user.getOrganisationUnits();
- if ( units.isEmpty() )
- {
- return Response.status( Status.CONFLICT ).entity( "User is not registered to a unit." ).build();
- }
- else if ( units.size() > 1 )
- {
- StringBuilder sb = new StringBuilder( "User is registered to more than one unit: " );
-
- int i = units.size();
- for ( OrganisationUnit unit : units )
- {
- sb.append( unit.getName() );
- if ( i-- > 1 )
- sb.append( ", " );
- }
-
- return Response.status( Status.CONFLICT ).entity( sb.toString() ).build();
- }
-
- OrganisationUnit unit = units.iterator().next();
- return Response.ok( getOrgUnit( unit ) ).build();
- }
-
- @GET
- @Path( "all" )
- @Produces( MediaType.MOBILE_SERIALIZED )
- public MobileModel getAllDataForUser( @HeaderParam( "accept-language" ) String locale )
- {
-
-
- MobileModel mobileWrapper = new MobileModel();
- mobileWrapper.setActivityPlan( activityPlanService.getCurrentActivityPlan( locale ) );
-
- mobileWrapper.setPrograms( programService.getAllProgramsForLocale( locale ) );
-
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
-
- if ( units.size() == 1 )
- {
- OrganisationUnit unit = units.iterator().next();
- mobileWrapper.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
- }
- else
- {
- // FIXME: Should handle multiple explicitly;
- }
-
-
- return mobileWrapper;
- }
-
- @GET
- @Path( "activities/currentplan" )
- @Produces( MediaType.ACTIVITYPLAN_SERIALIZED )
- public ActivityPlan getCurrentActivityPlan( @HeaderParam( "accept-language" ) String locale )
- {
- return activityPlanService.getCurrentActivityPlan( locale );
- }
-
- @POST
- @Path( "dataSets" )
- @Consumes( MediaType.DATASETVALUE_SERIALIZED )
- @Produces( "application/xml" )
- public String saveDataSetValues( DataSetValue dataSetValue )
- {
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
-
- if ( units.size() != 1 )
- {
- return "INVALID_REPORTING_UNIT";
- }
-
- OrganisationUnit unit = units.iterator().next();
-
- return facilityReportingService.saveDataSetValues( unit, dataSetValue );
- }
-
- @POST
- @Path( "activities" )
- @Consumes( MediaType.ACTIVITYVALUELIST_SERIALIZED )
- @Produces( "application/xml" )
- public String saveActivityReport( ActivityValue activityValue )
- {
- return iactivityValueService.saveValues( activityValue );
+ OrgUnits orgUnits = new OrgUnits();
+
+ for ( OrganisationUnit unit : units )
+ {
+ orgUnits.add( getOrgUnit( unit ) );
+ }
+
+ return orgUnits;
+ }
+
+ @Path( "orgUnits/{id}" )
+ public OrgUnitResource getOrgUnit( @PathParam( "id" ) int id )
+ {
+
+ OrgUnitResource resource = rc.getResource( OrgUnitResource.class );
+
+ resource.setOrgUnit( organisationUnitService.getOrganisationUnit( id ) );
+
+ return resource;
}
private OrgUnit getOrgUnit( OrganisationUnit unit )
@@ -201,7 +103,30 @@
m.setId( unit.getId() );
m.setName( unit.getShortName() );
+ m.setDownloadAllUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "all" ).build( unit.getId() )
+ .toString() );
+ m.setDownloadActivityPlanUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activitiyplan" )
+ .build( unit.getId() ).toString() );
+ m.setUploadFacilityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "dataSets" )
+ .build( unit.getId() ).toString() );
+ m.setUploadActivityReportUrl( uriInfo.getBaseUriBuilder().path( "/orgUnits/{id}" ).path( "activities" )
+ .build( unit.getId() ).toString() );
+
return m;
}
+ // Setters...
+
+ @Required
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ @Required
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,96 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.web.api.model.ActivityPlan;
+import org.hisp.dhis.web.api.model.ActivityValue;
+import org.hisp.dhis.web.api.model.DataSetValue;
+import org.hisp.dhis.web.api.model.MobileModel;
+import org.hisp.dhis.web.api.service.ActivityReportingService;
+import org.hisp.dhis.web.api.service.FacilityReportingService;
+import org.hisp.dhis.web.api.service.IProgramService;
+import org.springframework.beans.factory.annotation.Required;
+
+public class OrgUnitResource
+{
+
+ private IProgramService programService;
+
+ private ActivityReportingService activityReportingService;
+
+ private FacilityReportingService facilityReportingService;
+
+ // Set by parent resource
+ private OrganisationUnit unit;
+
+ public void setOrgUnit(OrganisationUnit unit) {
+ this.unit = unit;
+ }
+
+ @GET
+ @Path( "all" )
+ @Produces( MediaType.MOBILE_SERIALIZED )
+ public MobileModel getAllDataForUser( @HeaderParam( "accept-language" ) String locale )
+ {
+ MobileModel mobileModel = new MobileModel();
+
+ mobileModel.setActivityPlan( activityReportingService.getCurrentActivityPlan( unit, locale ) );
+ mobileModel.setPrograms( programService.getPrograms( unit, locale ) );
+ mobileModel.setDatasets( facilityReportingService.getMobileDataSetsForUnit( unit, locale ) );
+
+ return mobileModel;
+ }
+
+ @GET
+ @Path( "activitiyplan" )
+ @Produces( MediaType.ACTIVITYPLAN_SERIALIZED )
+ public ActivityPlan getCurrentActivityPlan( @HeaderParam( "accept-language" ) String locale )
+ {
+ return activityReportingService.getCurrentActivityPlan( unit, locale );
+ }
+
+ @POST
+ @Path( "dataSets" )
+ @Consumes( MediaType.DATASETVALUE_SERIALIZED )
+ @Produces( "application/xml" )
+ public String saveDataSetValues( DataSetValue dataSetValue )
+ {
+ return facilityReportingService.saveDataSetValues( unit, dataSetValue );
+ }
+
+ @POST
+ @Path( "activities" )
+ @Consumes( MediaType.ACTIVITYVALUELIST_SERIALIZED )
+ @Produces( "application/xml" )
+ public String saveActivityReport( ActivityValue activityValue )
+ {
+ return activityReportingService.saveActivityReport( unit, activityValue );
+ }
+
+ // Setters...
+
+ @Required
+ public void setProgramService( IProgramService programService )
+ {
+ this.programService = programService;
+ }
+
+ @Required
+ public void setActivityReportingService( ActivityReportingService activityReportingService )
+ {
+ this.activityReportingService = activityReportingService;
+ }
+
+ @Required
+ public void setFacilityReportingService( FacilityReportingService facilityReportingService )
+ {
+ this.facilityReportingService = facilityReportingService;
+ }
+
+}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityPlanModelService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityPlanModelService.java 2010-11-15 08:35:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityPlanModelService.java 1970-01-01 00:00:00 +0000
@@ -1,68 +0,0 @@
-package org.hisp.dhis.web.api.service;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.hisp.dhis.activityplan.Activity;
-import org.hisp.dhis.activityplan.ActivityPlanService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.web.api.model.ActivityPlan;
-import org.hisp.dhis.web.api.service.mapping.ActivitiesMapper;
-import org.joda.time.DateMidnight;
-import org.joda.time.DateTime;
-import org.springframework.beans.factory.annotation.Autowired;
-
-public class ActivityPlanModelService
-{
-
- private ActivityPlanService activityPlanService;
-
- public ActivityPlanService getActivityPlanService()
- {
- return activityPlanService;
- }
-
- /**
- * Gets the current activity plan for an org unit.
- * <p>The current activity plan is tentatively defined as all activities within the current month and all uncompleted activities from earlier.
- */
- public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit )
- {
- DateTime dt = new DateTime();
- DateMidnight from = dt.withDayOfMonth( 1 ).toDateMidnight();
- DateMidnight to = from.plusMonths( 1 );
-
- final Collection<Activity> allActivities = activityPlanService.getActivitiesByProvider( unit );
- Collection<Activity> activities = new ArrayList<Activity>();
- for ( Activity activity : allActivities )
- {
- long dueTime = activity.getDueDate().getTime();
- if ( to.isBefore( dueTime ) )
- {
- continue;
- }
-
- if (from.isBefore( dueTime ) || !activity.getTask().isCompleted()) {
- activities.add( activity );
- }
- }
-
- ActivityPlan plan = new ActivitiesMapper().getModel( activities );
-
- return plan;
- }
-
- public ActivityPlan getAllActivities( OrganisationUnit unit )
- {
- final Collection<Activity> activities = activityPlanService.getActivitiesByProvider( unit );
-
- return new ActivitiesMapper().getModel( activities );
- }
-
- public void setActivityPlanService( ActivityPlanService activityPlanService )
- {
- this.activityPlanService = activityPlanService;
- }
-
-}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingService.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,14 @@
+package org.hisp.dhis.web.api.service;
+
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.web.api.model.ActivityPlan;
+import org.hisp.dhis.web.api.model.ActivityValue;
+
+public interface ActivityReportingService
+{
+
+ public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit, String localeString );
+
+ public String saveActivityReport( OrganisationUnit unit, ActivityValue activityValue );
+
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/ActivityReportingServiceImpl.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,389 @@
+package org.hisp.dhis.web.api.service;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hisp.dhis.activityplan.Activity;
+import org.hisp.dhis.activityplan.ActivityPlanService;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.patient.Patient;
+import org.hisp.dhis.patient.PatientAttributeService;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
+import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
+import org.hisp.dhis.patientdatavalue.PatientDataValue;
+import org.hisp.dhis.program.ProgramStageDataElement;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.user.CurrentUserService;
+import org.hisp.dhis.web.api.model.ActivityPlan;
+import org.hisp.dhis.web.api.model.ActivityValue;
+import org.hisp.dhis.web.api.model.Beneficiary;
+import org.hisp.dhis.web.api.model.DataValue;
+import org.hisp.dhis.web.api.model.PatientAttribute;
+import org.hisp.dhis.web.api.model.Task;
+import org.hisp.dhis.web.api.model.comparator.ActivityComparator;
+import org.joda.time.DateMidnight;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Required;
+
+public class ActivityReportingServiceImpl
+ implements ActivityReportingService
+{
+
+ private ActivityComparator activityComparator = new ActivityComparator();
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private ActivityPlanService activityPlanService;
+
+ private org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService;
+
+ private PatientAttributeValueService patientAttValueService;
+
+ private PatientAttributeService patientAttService;
+
+ private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
+
+ private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService;
+
+ private CurrentUserService currentUserService;
+
+ // -------------------------------------------------------------------------
+ // MobileDataSetService
+ // -------------------------------------------------------------------------
+
+ public ActivityPlan getCurrentActivityPlan( OrganisationUnit unit, String localeString )
+ {
+ DateTime dt = new DateTime();
+ DateMidnight from = dt.withDayOfMonth( 1 ).toDateMidnight();
+ DateMidnight to = from.plusMonths( 1 );
+
+ Collection<Activity> allActivities = activityPlanService.getActivitiesByProvider( unit );
+
+ ActivityPlan plan = new ActivityPlan();
+
+ List<org.hisp.dhis.web.api.model.Activity> items = new ArrayList<org.hisp.dhis.web.api.model.Activity>();
+
+ int i = 0;
+ for ( Activity activity : allActivities )
+ {
+ // there are error on db with patientattributeid 14, so I limit the
+ // patient to be downloaded
+ if ( i > 10 )
+ {
+ break;
+ }
+
+ long dueTime = activity.getDueDate().getTime();
+ if ( to.isBefore( dueTime ) )
+ {
+ continue;
+ }
+
+ if ( from.isBefore( dueTime ) )
+ {
+ items.add( getActivityModel( activity ) );
+ i++;
+ }
+ else if ( !activity.getTask().isCompleted() )
+ {
+ org.hisp.dhis.web.api.model.Activity a = getActivityModel( activity );
+ items.add( a );
+ a.setLate( true );
+ i++;
+ }
+ }
+ if ( !items.isEmpty() )
+ {
+ Collections.sort( items, activityComparator );
+ plan.setActivitiesList( items );
+ }
+
+ return plan;
+
+ }
+
+ private org.hisp.dhis.web.api.model.Activity getActivityModel( org.hisp.dhis.activityplan.Activity activity )
+ {
+ if ( activity == null )
+ {
+ return null;
+ }
+ org.hisp.dhis.web.api.model.Activity item = new org.hisp.dhis.web.api.model.Activity();
+ Patient patient = activity.getBeneficiary();
+
+ item.setBeneficiary( getBeneficiaryModel( patient ) );
+ item.setDueDate( activity.getDueDate() );
+ item.setTask( getTask( activity.getTask() ) );
+ return item;
+ }
+
+ public Task getTask( ProgramStageInstance stageInstance )
+ {
+ if ( stageInstance == null )
+ {
+ return null;
+ }
+
+ Task task = new Task();
+
+ task.setCompleted( stageInstance.isCompleted() );
+ task.setId( stageInstance.getId() );
+ task.setProgramStageId( stageInstance.getProgramStage().getId() );
+
+ return task;
+ }
+
+ private org.hisp.dhis.web.api.model.Beneficiary getBeneficiaryModel( Patient patient )
+ {
+
+ Beneficiary beneficiary = new Beneficiary();
+
+ List<PatientAttribute> patientAtts = new ArrayList<PatientAttribute>();
+
+ beneficiary.setId( patient.getId() );
+ beneficiary.setFirstName( patient.getFirstName() );
+ beneficiary.setLastName( patient.getLastName() );
+ beneficiary.setMiddleName( patient.getMiddleName() );
+ int currentYear = new Date().getYear();
+ int age = currentYear - patient.getBirthDate().getYear();
+ beneficiary.setAge( age );
+
+ // Set attribute which is used to group beneficiary on mobile (only if
+ // there is attribute which is set to be group factor)
+ PatientAttribute beneficiaryAttribute = null;
+ org.hisp.dhis.patient.PatientAttribute patientAttribute = patientAttService.getPatientAttributeByGroupBy( true );
+
+ if ( patientAttribute != null )
+ {
+ beneficiaryAttribute = new PatientAttribute();
+ beneficiaryAttribute.setName( patientAttribute.getName() );
+ PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, patientAttribute );
+ beneficiaryAttribute.setValue( value == null ? "Unknown" : value.getValue() );
+ beneficiary.setGroupAttribute( beneficiaryAttribute );
+ }
+ patientAttribute = null;
+
+ // Set all attributes
+ org.hisp.dhis.patient.PatientAttribute houseName = patientAttService.getPatientAttributeByName( "House Name" );
+ org.hisp.dhis.patient.PatientAttribute houseNumber = patientAttService
+ .getPatientAttributeByName( "House Number" );
+ org.hisp.dhis.patient.PatientAttribute wardNumber = patientAttService.getPatientAttributeByName( "Ward Number" );
+ org.hisp.dhis.patient.PatientAttribute nearestContact = patientAttService
+ .getPatientAttributeByName( "Nearest Contact Person Name" );
+
+ PatientAttributeValue houseNameValue = patientAttValueService.getPatientAttributeValue( patient, houseName );
+ if ( houseNameValue != null )
+ {
+ patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ) );
+ }
+
+ PatientAttributeValue houseNumberValue = patientAttValueService.getPatientAttributeValue( patient, houseNumber );
+ if ( houseNumberValue != null )
+ {
+ patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ) );
+ }
+
+ PatientAttributeValue wardNumberValue = patientAttValueService.getPatientAttributeValue( patient, wardNumber );
+ if ( wardNumberValue != null )
+ {
+ patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ) );
+ }
+
+ PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient,
+ nearestContact );
+ if ( nearestContactValue != null )
+ {
+ patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ) );
+ }
+
+ beneficiary.setPatientAttValues( patientAtts );
+
+ // for ( PatientAttributeValue patientAttributeValue :
+ // patientAttValueService.getPatientAttributeValues( patient ) )
+ // {
+ // patientAttValues.add(
+ // patientAttributeValue.getPatientAttribute().getName() + " : "
+ // + patientAttributeValue.getValue() );
+ // }
+ // beneficiary.setPatientAttValues( patientAttValues );
+
+ return beneficiary;
+ }
+
+ // -------------------------------------------------------------------------
+ // DataValueService
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String saveActivityReport( OrganisationUnit unit, ActivityValue activityValue )
+ {
+
+ ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( activityValue
+ .getProgramInstanceId() );
+
+ if ( programStageInstance == null )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+
+ programStageInstance.getProgramStage();
+ Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
+
+ for ( ProgramStageDataElement de : programStageInstance.getProgramStage().getProgramStageDataElements() )
+ {
+ dataElements.add( de.getDataElement() );
+ }
+
+ programStageInstance.getProgramStage().getProgramStageDataElements();
+ Collection<Integer> dataElementIds = new ArrayList<Integer>( activityValue.getDataValues().size() );
+
+ for ( DataValue dv : activityValue.getDataValues() )
+ {
+ dataElementIds.add( dv.getId() );
+ }
+
+ if ( dataElements.size() != dataElementIds.size() )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+
+ Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
+ for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
+ {
+ if ( !dataElementIds.contains( dataElement.getId() ) )
+ {
+ return "INVALID_PROGRAM_STAGE";
+ }
+ dataElementMap.put( dataElement.getId(), dataElement );
+ }
+
+ // Set ProgramStageInstance to completed
+ programStageInstance.setCompleted( true );
+ programStageInstanceService.updateProgramStageInstance( programStageInstance );
+ // Everything is fine, hence save
+ saveDataValues( activityValue, programStageInstance, dataElementMap, unit,
+ categoryService.getDefaultDataElementCategoryOptionCombo() );
+
+ return "SUCCESS";
+
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive method
+ // -------------------------------------------------------------------------
+
+ private void saveDataValues( ActivityValue activityValue, ProgramStageInstance programStageInstance,
+ Map<Integer, DataElement> dataElementMap, OrganisationUnit orgUnit, DataElementCategoryOptionCombo optionCombo )
+ {
+
+ org.hisp.dhis.dataelement.DataElement dataElement;
+ String value;
+
+ for ( DataValue dv : activityValue.getDataValues() )
+ {
+ value = dv.getVal();
+ DataElementCategoryOptionCombo cateOptCombo = categoryService.getDataElementCategoryOptionCombo( dv
+ .getCategoryOptComboID() );
+ if ( value != null && value.trim().length() == 0 )
+ {
+ value = null;
+ }
+
+ if ( value != null )
+ {
+ value = value.trim();
+ }
+
+ dataElement = dataElementMap.get( dv.getId() );
+ PatientDataValue dataValue = dataValueService.getPatientDataValue( programStageInstance, dataElement,
+ orgUnit );
+
+ if ( dataValue == null )
+ {
+ if ( value != null )
+ {
+ if ( programStageInstance.getExecutionDate() == null )
+ {
+ programStageInstance.setExecutionDate( new Date() );
+ programStageInstanceService.updateProgramStageInstance( programStageInstance );
+ }
+
+ dataValue = new PatientDataValue( programStageInstance, dataElement, cateOptCombo, orgUnit,
+ new Date(), value, false );
+ ;
+ dataValueService.savePatientDataValue( dataValue );
+ }
+ }
+ else
+ {
+ if ( programStageInstance.getExecutionDate() == null )
+ {
+ programStageInstance.setExecutionDate( new Date() );
+ programStageInstanceService.updateProgramStageInstance( programStageInstance );
+ }
+
+ dataValue.setValue( value );
+ dataValue.setOptionCombo( optionCombo );
+ dataValue.setProvidedByAnotherFacility( false );
+ dataValue.setTimestamp( new Date() );
+
+ dataValueService.updatePatientDataValue( dataValue );
+ }
+ }
+ }
+
+ // Setters...
+
+ @Required
+ public void setProgramStageInstanceService(
+ org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService )
+ {
+ this.programStageInstanceService = programStageInstanceService;
+ }
+
+ @Required
+ public void setActivityPlanService( ActivityPlanService activityPlanService )
+ {
+ this.activityPlanService = activityPlanService;
+ }
+
+ @Required
+ public void setPatientAttValueService( PatientAttributeValueService patientAttValueService )
+ {
+ this.patientAttValueService = patientAttValueService;
+ }
+
+ @Required
+ public void setPatientAttService( PatientAttributeService patientAttService )
+ {
+ this.patientAttService = patientAttService;
+ }
+
+ @Required
+ public void setCategoryService( org.hisp.dhis.dataelement.DataElementCategoryService categoryService )
+ {
+ this.categoryService = categoryService;
+ }
+
+ @Required
+ public void setDataValueService( org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService )
+ {
+ this.dataValueService = dataValueService;
+ }
+
+ @Required
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityPlanService.java 1970-01-01 00:00:00 +0000
@@ -1,241 +0,0 @@
-package org.hisp.dhis.web.api.service;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import org.hisp.dhis.activityplan.Activity;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.patient.PatientAttributeService;
-import org.hisp.dhis.patientattributevalue.PatientAttributeValue;
-import org.hisp.dhis.patientattributevalue.PatientAttributeValueService;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.web.api.model.ActivityPlan;
-import org.hisp.dhis.web.api.model.Beneficiary;
-import org.hisp.dhis.web.api.model.PatientAttribute;
-import org.hisp.dhis.web.api.model.comparator.ActivityComparator;
-import org.hisp.dhis.web.api.service.mapping.TaskMapper;
-import org.joda.time.DateMidnight;
-import org.joda.time.DateTime;
-
-public class DefaultActivityPlanService
- implements IActivityPlanService
-{
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private org.hisp.dhis.activityplan.ActivityPlanService activityPlanService;
-
- private ActivityComparator activityComparator = new ActivityComparator();
-
- public org.hisp.dhis.activityplan.ActivityPlanService getActivityPlanService()
- {
- return activityPlanService;
- }
-
- public void setActivityPlanService( org.hisp.dhis.activityplan.ActivityPlanService activityPlanService )
- {
- this.activityPlanService = activityPlanService;
- }
-
- private PatientAttributeValueService patientAttValueService;
-
- public PatientAttributeValueService getPatientAttValueService()
- {
- return patientAttValueService;
- }
-
- public void setPatientAttValueService( PatientAttributeValueService patientAttValueService )
- {
- this.patientAttValueService = patientAttValueService;
- }
-
- private PatientAttributeService patientAttService;
-
- public PatientAttributeService getPatientAttService()
- {
- return patientAttService;
- }
-
- public void setPatientAttService( PatientAttributeService patientAttService )
- {
- this.patientAttService = patientAttService;
- }
-
- private CurrentUserService currentUserService;
-
- public CurrentUserService getCurrentUserService()
- {
- return currentUserService;
- }
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- // -------------------------------------------------------------------------
- // MobileDataSetService
- // -------------------------------------------------------------------------
-
- public ActivityPlan getCurrentActivityPlan( String localeString )
- {
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
- OrganisationUnit unit = null;
-
- if ( units.size() > 0 )
- {
- unit = units.iterator().next();
- }
- else
- {
- return null;
- }
-
- DateTime dt = new DateTime();
- DateMidnight from = dt.withDayOfMonth( 1 ).toDateMidnight();
- DateMidnight to = from.plusMonths( 1 );
-
- Collection<Activity> allActivities = activityPlanService.getActivitiesByProvider( unit );
-
- ActivityPlan plan = new ActivityPlan();
-
- List<org.hisp.dhis.web.api.model.Activity> items = new ArrayList<org.hisp.dhis.web.api.model.Activity>();
-
- int i = 0;
- for ( Activity activity : allActivities )
- {
- // there are error on db with patientattributeid 14, so I limit the
- // patient to be downloaded
- if ( i > 10 )
- {
- break;
- }
-
- long dueTime = activity.getDueDate().getTime();
- if ( to.isBefore( dueTime ) )
- {
- continue;
- }
-
- if ( from.isBefore( dueTime ) )
- {
- items.add( getActivityModel( activity ) );
- i++;
- }
- else if ( !activity.getTask().isCompleted() )
- {
- org.hisp.dhis.web.api.model.Activity a = getActivityModel( activity );
- items.add( a );
- a.setLate( true );
- i++;
- }
- }
- if ( !items.isEmpty() )
- {
- Collections.sort( items, activityComparator );
- plan.setActivitiesList( items );
- }
-
- return plan;
-
- }
-
-
-
- private org.hisp.dhis.web.api.model.Activity getActivityModel( org.hisp.dhis.activityplan.Activity activity )
- {
- if ( activity == null )
- {
- return null;
- }
- org.hisp.dhis.web.api.model.Activity item = new org.hisp.dhis.web.api.model.Activity();
- Patient patient = activity.getBeneficiary();
-
- item.setBeneficiary( getBeneficiaryModel( patient ) );
- item.setDueDate( activity.getDueDate() );
- item.setTask( new TaskMapper().getModel( activity.getTask() ) );
- return item;
- }
-
- private org.hisp.dhis.web.api.model.Beneficiary getBeneficiaryModel( Patient patient )
- {
-
- Beneficiary beneficiary = new Beneficiary();
-
- List<PatientAttribute> patientAtts = new ArrayList<PatientAttribute>();
-
- beneficiary.setId( patient.getId() );
- beneficiary.setFirstName( patient.getFirstName() );
- beneficiary.setLastName( patient.getLastName() );
- beneficiary.setMiddleName( patient.getMiddleName() );
- int currentYear = new Date().getYear();
- int age = currentYear - patient.getBirthDate().getYear();
- beneficiary.setAge( age );
-
- // Set attribute which is used to group beneficiary on mobile (only if
- // there is attribute which is set to be group factor)
- PatientAttribute beneficiaryAttribute = null;
- org.hisp.dhis.patient.PatientAttribute patientAttribute = patientAttService.getPatientAttributeByGroupBy( true );
-
- if ( patientAttribute != null )
- {
- beneficiaryAttribute = new PatientAttribute();
- beneficiaryAttribute.setName( patientAttribute.getName() );
- PatientAttributeValue value = patientAttValueService.getPatientAttributeValue( patient, patientAttribute );
- beneficiaryAttribute.setValue( value == null ? "Unknown" : value.getValue() );
- beneficiary.setGroupAttribute( beneficiaryAttribute );
- }
- patientAttribute = null;
-
- // Set all attributes
- org.hisp.dhis.patient.PatientAttribute houseName = patientAttService.getPatientAttributeByName( "House Name" );
- org.hisp.dhis.patient.PatientAttribute houseNumber = patientAttService
- .getPatientAttributeByName( "House Number" );
- org.hisp.dhis.patient.PatientAttribute wardNumber = patientAttService.getPatientAttributeByName( "Ward Number" );
- org.hisp.dhis.patient.PatientAttribute nearestContact = patientAttService
- .getPatientAttributeByName( "Nearest Contact Person Name" );
-
- PatientAttributeValue houseNameValue = patientAttValueService.getPatientAttributeValue( patient, houseName );
- if ( houseNameValue != null )
- {
- patientAtts.add( new PatientAttribute( "House Name", houseNameValue.getValue() ) );
- }
-
- PatientAttributeValue houseNumberValue = patientAttValueService.getPatientAttributeValue( patient, houseNumber );
- if ( houseNumberValue != null )
- {
- patientAtts.add( new PatientAttribute( "House Number", houseNumberValue.getValue() ) );
- }
-
- PatientAttributeValue wardNumberValue = patientAttValueService.getPatientAttributeValue( patient, wardNumber );
- if ( wardNumberValue != null )
- {
- patientAtts.add( new PatientAttribute( "Ward Number", wardNumberValue.getValue() ) );
- }
-
- PatientAttributeValue nearestContactValue = patientAttValueService.getPatientAttributeValue( patient,
- nearestContact );
- if ( nearestContactValue != null )
- {
- patientAtts.add( new PatientAttribute( "Nearest Contact", nearestContactValue.getValue() ) );
- }
-
- beneficiary.setPatientAttValues( patientAtts );
-
- // for ( PatientAttributeValue patientAttributeValue :
- // patientAttValueService.getPatientAttributeValues( patient ) )
- // {
- // patientAttValues.add(
- // patientAttributeValue.getPatientAttribute().getName() + " : "
- // + patientAttributeValue.getValue() );
- // }
- // beneficiary.setPatientAttValues( patientAttValues );
-
- return beneficiary;
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultActivityValueService.java 1970-01-01 00:00:00 +0000
@@ -1,209 +0,0 @@
-package org.hisp.dhis.web.api.service;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.hisp.dhis.program.ProgramStageDataElement;
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.patientdatavalue.PatientDataValue;
-import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.web.api.model.ActivityValue;
-import org.hisp.dhis.web.api.model.DataValue;
-
-public class DefaultActivityValueService
- implements IActivityValueService
-{
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
- private org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService;
-
- public org.hisp.dhis.program.ProgramStageInstanceService getProgramStageInstanceService()
- {
- return programStageInstanceService;
- }
-
- public void setProgramStageInstanceService(
- org.hisp.dhis.program.ProgramStageInstanceService programStageInstanceService )
- {
- this.programStageInstanceService = programStageInstanceService;
- }
-
- private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
-
- public org.hisp.dhis.dataelement.DataElementCategoryService getCategoryService()
- {
- return categoryService;
- }
-
- public void setCategoryService( org.hisp.dhis.dataelement.DataElementCategoryService categoryService )
- {
- this.categoryService = categoryService;
- }
-
- private org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService;
-
- public org.hisp.dhis.patientdatavalue.PatientDataValueService getDataValueService()
- {
- return dataValueService;
- }
-
- public void setDataValueService( org.hisp.dhis.patientdatavalue.PatientDataValueService dataValueService )
- {
- this.dataValueService = dataValueService;
- }
-
- private CurrentUserService currentUserService;
-
- public CurrentUserService getCurrentUserService()
- {
- return currentUserService;
- }
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
-
- // -------------------------------------------------------------------------
- // DataValueService
- // -------------------------------------------------------------------------
-
- @Override
- public String saveValues( ActivityValue activityValue )
- {
-
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
-
- OrganisationUnit unit = null;
-
- if ( units.size() > 0 )
- {
- unit = units.iterator().next();
- }
- else
- {
- return "INVALID_SERVICE_PROVIDING_UNIT";
- }
-
- ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( activityValue
- .getProgramInstanceId() );
-
- if ( programStageInstance == null )
- {
- return "INVALID_PROGRAM_STAGE";
- }
-
- programStageInstance.getProgramStage();
- Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
-
- for ( ProgramStageDataElement de : programStageInstance.getProgramStage().getProgramStageDataElements() )
- {
- dataElements.add( de.getDataElement() );
- }
-
- programStageInstance.getProgramStage().getProgramStageDataElements();
- Collection<Integer> dataElementIds = new ArrayList<Integer>( activityValue.getDataValues().size() );
-
- for ( DataValue dv : activityValue.getDataValues() )
- {
- dataElementIds.add( dv.getId() );
- }
-
- if ( dataElements.size() != dataElementIds.size() )
- {
- return "INVALID_PROGRAM_STAGE";
- }
-
- Map<Integer, org.hisp.dhis.dataelement.DataElement> dataElementMap = new HashMap<Integer, org.hisp.dhis.dataelement.DataElement>();
- for ( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
- {
- if ( !dataElementIds.contains( dataElement.getId() ) )
- {
- return "INVALID_PROGRAM_STAGE";
- }
- dataElementMap.put( dataElement.getId(), dataElement );
- }
-
- // Set ProgramStageInstance to completed
- programStageInstance.setCompleted( true );
- programStageInstanceService.updateProgramStageInstance( programStageInstance );
- // Everything is fine, hence save
- saveDataValues( activityValue, programStageInstance, dataElementMap, unit,
- categoryService.getDefaultDataElementCategoryOptionCombo() );
-
- return "SUCCESS";
-
- }
-
- // -------------------------------------------------------------------------
- // Supportive method
- // -------------------------------------------------------------------------
-
- private void saveDataValues( ActivityValue activityValue, ProgramStageInstance programStageInstance,
- Map<Integer, DataElement> dataElementMap, OrganisationUnit orgUnit, DataElementCategoryOptionCombo optionCombo )
- {
-
- org.hisp.dhis.dataelement.DataElement dataElement;
- String value;
-
- for ( DataValue dv : activityValue.getDataValues() )
- {
- value = dv.getVal();
- DataElementCategoryOptionCombo cateOptCombo = categoryService.getDataElementCategoryOptionCombo( dv
- .getCategoryOptComboID() );
- if ( value != null && value.trim().length() == 0 )
- {
- value = null;
- }
-
- if ( value != null )
- {
- value = value.trim();
- }
-
- dataElement = dataElementMap.get( dv.getId() );
- PatientDataValue dataValue = dataValueService.getPatientDataValue( programStageInstance, dataElement,
- orgUnit );
-
- if ( dataValue == null )
- {
- if ( value != null )
- {
- if ( programStageInstance.getExecutionDate() == null )
- {
- programStageInstance.setExecutionDate( new Date() );
- programStageInstanceService.updateProgramStageInstance( programStageInstance );
- }
-
- dataValue = new PatientDataValue( programStageInstance, dataElement, cateOptCombo, orgUnit,
- new Date(), value, false );
- ;
- dataValueService.savePatientDataValue( dataValue );
- }
- }
- else
- {
- if ( programStageInstance.getExecutionDate() == null )
- {
- programStageInstance.setExecutionDate( new Date() );
- programStageInstanceService.updateProgramStageInstance( programStageInstance );
- }
-
- dataValue.setValue( value );
- dataValue.setOptionCombo( optionCombo );
- dataValue.setProvidedByAnotherFacility( false );
- dataValue.setTimestamp( new Date() );
-
- dataValueService.updatePatientDataValue( dataValue );
- }
- }
- }
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultPeriodService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultPeriodService.java 2010-11-15 08:35:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultPeriodService.java 1970-01-01 00:00:00 +0000
@@ -1,176 +0,0 @@
-/**
- *
- */
-package org.hisp.dhis.web.api.service;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.period.DailyPeriodType;
-import org.hisp.dhis.period.MonthlyPeriodType;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.QuarterlyPeriodType;
-import org.hisp.dhis.period.WeeklyPeriodType;
-import org.hisp.dhis.period.YearlyPeriodType;
-
-/**
- * @author abyotag_adm
- *
- */
-public class DefaultPeriodService
- implements IPeriodService
-{
-
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private org.hisp.dhis.period.PeriodService periodService;
-
- public org.hisp.dhis.period.PeriodService getPeriodService()
- {
- return periodService;
- }
-
- public void setPeriodService( org.hisp.dhis.period.PeriodService periodService )
- {
- this.periodService = periodService;
- }
- // -------------------------------------------------------------------------
- // PeriodService
- // -------------------------------------------------------------------------
-
-
-
- public Period getPeriod( String periodName, DataSet dataSet )
- {
- org.hisp.dhis.period.Period period = null;
- org.hisp.dhis.period.Period persistedPeriod = null;
- if ( dataSet.getPeriodType().getName().equals( "Daily" ) )
- {
- String pattern = "yyyy-MM-dd";
- SimpleDateFormat formatter = new SimpleDateFormat( pattern );
- Date date = new Date();
-
- try
- {
-
- date = formatter.parse( periodName );
- DailyPeriodType dailyPeriodType = new DailyPeriodType();
- period = dailyPeriodType.createPeriod( date );
-
- }
- catch ( ParseException e )
- {
- e.printStackTrace();
- }
- }
- else if ( dataSet.getPeriodType().getName().equals( "Weekly" ) )
- {
- try
- {
- int week = Integer.parseInt( periodName.substring( 0, periodName.indexOf( '-' ) ) );
- int year = Integer
- .parseInt( periodName.substring( periodName.indexOf( '-' ) + 1, periodName.length() ) );
-
- Calendar cal = Calendar.getInstance();
- cal.set( Calendar.YEAR, year );
- cal.set( Calendar.WEEK_OF_YEAR, week );
- cal.setFirstDayOfWeek( Calendar.MONDAY );
-
- WeeklyPeriodType weeklyPeriodType = new WeeklyPeriodType();
- period = weeklyPeriodType.createPeriod( cal.getTime() );
-
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- else if ( dataSet.getPeriodType().getName().equals( "Monthly" ) )
- {
- try
- {
- int month = Integer.parseInt( periodName.substring( 0, periodName.indexOf( '-' ) ) );
- int year = Integer
- .parseInt( periodName.substring( periodName.indexOf( '-' ) + 1, periodName.length() ) );
-
- Calendar cal = Calendar.getInstance();
- cal.set( Calendar.YEAR, year );
- cal.set( Calendar.MONTH, month );
-
- MonthlyPeriodType monthlyPeriodType = new MonthlyPeriodType();
- period = monthlyPeriodType.createPeriod( cal.getTime() );
-
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- }
- }
-
- else if ( dataSet.getPeriodType().getName().equals( "Yearly" ) )
- {
- Calendar cal = Calendar.getInstance();
- cal.set( Calendar.YEAR, Integer.parseInt( periodName ) );
-
- YearlyPeriodType yearlyPeriodType = new YearlyPeriodType();
-
- period = yearlyPeriodType.createPeriod( cal.getTime() );
- }
- else if ( dataSet.getPeriodType().getName().equals( "Quarterly" ) )
- {
- Calendar cal = Calendar.getInstance();
-
- int month = 0;
- if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Jan" ) )
- {
- month = 1;
- }
- else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Apr" ) )
- {
- month = 4;
- }
- else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Jul" ) )
- {
- month = 6;
- }
- else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Oct" ) )
- {
- month = 10;
- }
-
- int year = Integer.parseInt( periodName.substring( periodName.lastIndexOf( " " ) + 1 ) );
-
- cal.set( Calendar.MONTH, month );
- cal.set( Calendar.YEAR, year );
-
- QuarterlyPeriodType quarterlyPeriodType = new QuarterlyPeriodType();
- if ( month != 0 )
- {
- period = quarterlyPeriodType.createPeriod( cal.getTime() );
- }
-
- }
-
- if ( period != null )
- {
- persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(),
- dataSet.getPeriodType() );
-
- if ( persistedPeriod == null )
- {
- periodService.addPeriod( period );
- persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(),
- dataSet.getPeriodType() );
- }
- }
-
- return persistedPeriod;
- }
-
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-18 06:08:29 +0000
@@ -1,6 +1,3 @@
-/**
- *
- */
package org.hisp.dhis.web.api.service;
import static org.hisp.dhis.i18n.I18nUtils.i18n;
@@ -20,11 +17,8 @@
import org.hisp.dhis.web.api.model.Program;
import org.hisp.dhis.web.api.model.ProgramStage;
import org.hisp.dhis.web.api.utils.LocaleUtil;
+import org.springframework.beans.factory.annotation.Required;
-/**
- * @author abyotag_adm
- *
- */
public class DefaultProgramService
implements IProgramService
{
@@ -34,67 +28,25 @@
private org.hisp.dhis.program.ProgramService programService;
- public org.hisp.dhis.program.ProgramService getProgramService()
- {
- return programService;
- }
-
- public void setProgramService( org.hisp.dhis.program.ProgramService programService )
- {
- this.programService = programService;
- }
-
private org.hisp.dhis.i18n.I18nService i18nService;
- public org.hisp.dhis.i18n.I18nService getI18nService()
- {
- return i18nService;
- }
-
- public void setI18nService( org.hisp.dhis.i18n.I18nService i18nService )
- {
- this.i18nService = i18nService;
- }
-
- private CurrentUserService currentUserService;
-
-
- public CurrentUserService getCurrentUserService()
- {
- return currentUserService;
- }
-
- public void setCurrentUserService( CurrentUserService currentUserService )
- {
- this.currentUserService = currentUserService;
- }
// -------------------------------------------------------------------------
// ProgramService
// -------------------------------------------------------------------------
- public List<Program> getAllProgramsForLocale( String localeString )
+
+ public List<Program> getPrograms( OrganisationUnit unit, String localeString )
{
List<Program> programs = new ArrayList<Program>();
- Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
- OrganisationUnit unit = null;
-
- if ( units.size() > 0 )
- {
- unit = units.iterator().next();
- }
- else
- {
- return null;
- }
for ( org.hisp.dhis.program.Program program : programService.getPrograms( unit ) )
{
- programs.add( getProgramForLocale( program.getId(), localeString ) );
+ programs.add( getProgram( program.getId(), localeString ) );
}
return programs;
}
- public Program getProgramForLocale( int programId, String localeString )
+ public Program getProgram( int programId, String localeString )
{
Locale locale = LocaleUtil.getLocale( localeString );
@@ -157,5 +109,16 @@
return pr;
}
+ @Required
+ public void setProgramService( org.hisp.dhis.program.ProgramService programService )
+ {
+ this.programService = programService;
+ }
+
+ @Required
+ public void setI18nService( org.hisp.dhis.i18n.I18nService i18nService )
+ {
+ this.i18nService = i18nService;
+ }
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/FacilityReportingServiceImpl.java 2010-11-18 06:08:29 +0000
@@ -29,7 +29,10 @@
import static org.hisp.dhis.i18n.I18nUtils.i18n;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -42,7 +45,13 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.comparator.DataElementSortOrderComparator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.DailyPeriodType;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.WeeklyPeriodType;
+import org.hisp.dhis.period.YearlyPeriodType;
import org.hisp.dhis.web.api.model.DataElement;
import org.hisp.dhis.web.api.model.DataSet;
import org.hisp.dhis.web.api.model.DataSetValue;
@@ -63,7 +72,7 @@
// Dependencies
// -------------------------------------------------------------------------
- private IPeriodService periodService;
+ private PeriodService periodService;
private org.hisp.dhis.dataelement.DataElementCategoryService categoryService;
@@ -224,7 +233,7 @@
return "INVALID_DATASET_ASSOCIATION";
}
- org.hisp.dhis.period.Period selectedPeriod = periodService.getPeriod( dataSetValue.getpName(), dataSet );
+ org.hisp.dhis.period.Period selectedPeriod = getPeriod( dataSetValue.getpName(), dataSet );
if ( selectedPeriod == null )
{
@@ -312,12 +321,140 @@
}
}
+ public Period getPeriod( String periodName, org.hisp.dhis.dataset.DataSet dataSet )
+ {
+ org.hisp.dhis.period.Period period = null;
+ org.hisp.dhis.period.Period persistedPeriod = null;
+ if ( dataSet.getPeriodType().getName().equals( "Daily" ) )
+ {
+ String pattern = "yyyy-MM-dd";
+ SimpleDateFormat formatter = new SimpleDateFormat( pattern );
+ Date date = new Date();
+
+ try
+ {
+
+ date = formatter.parse( periodName );
+ DailyPeriodType dailyPeriodType = new DailyPeriodType();
+ period = dailyPeriodType.createPeriod( date );
+
+ }
+ catch ( ParseException e )
+ {
+ e.printStackTrace();
+ }
+ }
+ else if ( dataSet.getPeriodType().getName().equals( "Weekly" ) )
+ {
+ try
+ {
+ int week = Integer.parseInt( periodName.substring( 0, periodName.indexOf( '-' ) ) );
+ int year = Integer
+ .parseInt( periodName.substring( periodName.indexOf( '-' ) + 1, periodName.length() ) );
+
+ Calendar cal = Calendar.getInstance();
+ cal.set( Calendar.YEAR, year );
+ cal.set( Calendar.WEEK_OF_YEAR, week );
+ cal.setFirstDayOfWeek( Calendar.MONDAY );
+
+ WeeklyPeriodType weeklyPeriodType = new WeeklyPeriodType();
+ period = weeklyPeriodType.createPeriod( cal.getTime() );
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ else if ( dataSet.getPeriodType().getName().equals( "Monthly" ) )
+ {
+ try
+ {
+ int month = Integer.parseInt( periodName.substring( 0, periodName.indexOf( '-' ) ) );
+ int year = Integer
+ .parseInt( periodName.substring( periodName.indexOf( '-' ) + 1, periodName.length() ) );
+
+ Calendar cal = Calendar.getInstance();
+ cal.set( Calendar.YEAR, year );
+ cal.set( Calendar.MONTH, month );
+
+ MonthlyPeriodType monthlyPeriodType = new MonthlyPeriodType();
+ period = monthlyPeriodType.createPeriod( cal.getTime() );
+
+ }
+ catch ( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ else if ( dataSet.getPeriodType().getName().equals( "Yearly" ) )
+ {
+ Calendar cal = Calendar.getInstance();
+ cal.set( Calendar.YEAR, Integer.parseInt( periodName ) );
+
+ YearlyPeriodType yearlyPeriodType = new YearlyPeriodType();
+
+ period = yearlyPeriodType.createPeriod( cal.getTime() );
+ }
+ else if ( dataSet.getPeriodType().getName().equals( "Quarterly" ) )
+ {
+ Calendar cal = Calendar.getInstance();
+
+ int month = 0;
+ if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Jan" ) )
+ {
+ month = 1;
+ }
+ else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Apr" ) )
+ {
+ month = 4;
+ }
+ else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Jul" ) )
+ {
+ month = 6;
+ }
+ else if ( periodName.substring( 0, periodName.indexOf( " " ) ).equals( "Oct" ) )
+ {
+ month = 10;
+ }
+
+ int year = Integer.parseInt( periodName.substring( periodName.lastIndexOf( " " ) + 1 ) );
+
+ cal.set( Calendar.MONTH, month );
+ cal.set( Calendar.YEAR, year );
+
+ QuarterlyPeriodType quarterlyPeriodType = new QuarterlyPeriodType();
+ if ( month != 0 )
+ {
+ period = quarterlyPeriodType.createPeriod( cal.getTime() );
+ }
+
+ }
+
+ if ( period != null )
+ {
+ persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(),
+ dataSet.getPeriodType() );
+
+ if ( persistedPeriod == null )
+ {
+ periodService.addPeriod( period );
+ persistedPeriod = periodService.getPeriod( period.getStartDate(), period.getEndDate(),
+ dataSet.getPeriodType() );
+ }
+ }
+
+ return persistedPeriod;
+ }
+
// -------------------------------------------------------------------------
// Dependency setters
// -------------------------------------------------------------------------
@Required
- public void setPeriodService( IPeriodService periodService )
+ public void setPeriodService( PeriodService periodService )
{
this.periodService = periodService;
}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityPlanService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityPlanService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityPlanService.java 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-package org.hisp.dhis.web.api.service;
-
-import org.hisp.dhis.web.api.model.ActivityPlan;
-
-public interface IActivityPlanService {
-
- ActivityPlan getCurrentActivityPlan( String localeString );
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityValueService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityValueService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IActivityValueService.java 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
-package org.hisp.dhis.web.api.service;
-
-import org.hisp.dhis.web.api.model.ActivityValue;
-
-public interface IActivityValueService {
-
- public String saveValues(ActivityValue activityValue);
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IPeriodService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IPeriodService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IPeriodService.java 1970-01-01 00:00:00 +0000
@@ -1,16 +0,0 @@
-/**
- *
- */
-package org.hisp.dhis.web.api.service;
-
-import org.hisp.dhis.period.Period;
-
-/**
- * @author abyotag_adm
- *
- */
-public interface IPeriodService {
-
- Period getPeriod(String periodName, org.hisp.dhis.dataset.DataSet dataSet);
-
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java 2010-11-16 16:28:41 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/IProgramService.java 2010-11-18 06:08:29 +0000
@@ -1,21 +1,14 @@
-/**
- *
- */
package org.hisp.dhis.web.api.service;
import java.util.List;
-import org.hisp.dhis.web.api.model.ModelList;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.web.api.model.Program;
-/**
- * @author abyotag_adm
- *
- */
public interface IProgramService {
- List<Program> getAllProgramsForLocale( String localeString );
+ public List<Program> getPrograms( OrganisationUnit unit, String localeString );
- Program getProgramForLocale( int programId, String localeString );
+ public Program getProgram( int programId, String localeString );
}
=== removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping'
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivitiesMapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivitiesMapper.java 2010-08-25 17:40:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivitiesMapper.java 1970-01-01 00:00:00 +0000
@@ -1,37 +0,0 @@
-package org.hisp.dhis.web.api.service.mapping;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.hisp.dhis.web.api.model.ActivityPlan;
-import org.hisp.dhis.web.api.model.Activity;
-
-public class ActivitiesMapper implements BeanMapper<Collection<org.hisp.dhis.activityplan.Activity>, ActivityPlan>
-{
-
- private ActivityPlanItemMapper activityMapper = new ActivityPlanItemMapper();
-
- @Override
- public ActivityPlan getModel( Collection<org.hisp.dhis.activityplan.Activity> activities )
- {
- ActivityPlan plan = new ActivityPlan();
-
- if ( activities == null || activities.isEmpty() )
- {
- return plan;
- }
-
- List<Activity> items = new ArrayList<Activity>();
- plan.setActivitiesList( items );
-
- for ( org.hisp.dhis.activityplan.Activity activity : activities )
- {
- items.add(activityMapper.getModel( activity));
- }
-
- return plan;
- }
-
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivityPlanItemMapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivityPlanItemMapper.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/ActivityPlanItemMapper.java 1970-01-01 00:00:00 +0000
@@ -1,25 +0,0 @@
-package org.hisp.dhis.web.api.service.mapping;
-
-import org.hisp.dhis.web.api.model.Activity;
-
-public class ActivityPlanItemMapper
- implements BeanMapper<org.hisp.dhis.activityplan.Activity, Activity>
-{
-
- @Override
- public Activity getModel( org.hisp.dhis.activityplan.Activity activity )
- {
- if ( activity == null )
- {
- return null;
- }
-
- Activity item = new Activity();
-
- item.setBeneficiary( new BeneficiaryMapper().getModel( activity.getBeneficiary()) );
- item.setDueDate( activity.getDueDate() );
- item.setTask( new TaskMapper().getModel( activity.getTask()) );
- return item;
- }
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeanMapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeanMapper.java 2010-08-25 17:40:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeanMapper.java 1970-01-01 00:00:00 +0000
@@ -1,8 +0,0 @@
-package org.hisp.dhis.web.api.service.mapping;
-
-
-
-public interface BeanMapper<S, T>
-{
- public T getModel( S entity );
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeneficiaryMapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeneficiaryMapper.java 2010-10-19 09:32:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/BeneficiaryMapper.java 1970-01-01 00:00:00 +0000
@@ -1,28 +0,0 @@
-package org.hisp.dhis.web.api.service.mapping;
-
-import org.hisp.dhis.patient.Patient;
-import org.hisp.dhis.web.api.model.Beneficiary;
-
-public class BeneficiaryMapper
- implements BeanMapper<Patient, Beneficiary>
-{
-
- @Override
- public Beneficiary getModel( Patient patient )
- {
- if ( patient == null )
- {
- return null;
- }
-
- Beneficiary beneficiary = new Beneficiary();
-
- beneficiary.setId( patient.getId() );
- beneficiary.setFirstName( patient.getFirstName() );
- beneficiary.setLastName( patient.getLastName() );
- beneficiary.setMiddleName( patient.getMiddleName() );
-
- return beneficiary;
- }
-
-}
=== removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/TaskMapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/TaskMapper.java 2010-08-25 17:40:56 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/mapping/TaskMapper.java 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
-package org.hisp.dhis.web.api.service.mapping;
-
-import org.hisp.dhis.program.ProgramStageInstance;
-import org.hisp.dhis.web.api.model.Task;
-
-public class TaskMapper
- implements BeanMapper<ProgramStageInstance, Task>
-{
-
- @Override
- public Task getModel( ProgramStageInstance stageInstance )
- {
- if (stageInstance == null) {
- return null;
- }
-
- Task task = new Task();
-
- task.setCompleted( stageInstance.isCompleted() );
- task.setId( stageInstance.getId() );
- task.setProgramStageId( stageInstance.getProgramStage().getId() );
-
- return task;
- }
-
-}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-18 04:09:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2010-11-18 06:08:29 +0000
@@ -7,69 +7,47 @@
<bean id="org.hisp.dhis.web.api.resources.MobileResource" class="org.hisp.dhis.web.api.resources.MobileResource"
scope="prototype">
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+ </bean>
+
+ <bean id="org.hisp.dhis.web.api.resources.OrgUnitResource" class="org.hisp.dhis.web.api.resources.OrgUnitResource"
+ scope="prototype">
<property name="facilityReportingService" ref="org.hisp.dhis.web.api.service.FacilityReportingService" />
- <property name="iactivityValueService" ref="org.hisp.dhis.web.api.service.IActivityValueService" />
+ <property name="activityReportingService" ref="org.hisp.dhis.web.api.service.ActivityReportingService" />
<property name="programService" ref="org.hisp.dhis.web.api.service.IProgramService" />
- <property name="activityPlanService" ref="org.hisp.dhis.web.api.service.IActivityPlanService" />
- <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
</bean>
<!-- Services -->
- <bean id="org.hisp.dhis.web.api.service.ActivityPlanModelService" class="org.hisp.dhis.web.api.service.ActivityPlanModelService">
- <property name="activityPlanService" ref="org.hisp.dhis.activityplan.ActivityPlanService" />
+ <bean id="org.hisp.dhis.web.api.service.FacilityReportingService" class="org.hisp.dhis.web.api.service.FacilityReportingServiceImpl">
+ <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+ <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
+ <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+ <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+ <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
</bean>
- <bean id="org.hisp.dhis.web.api.service.IActivityPlanService" class="org.hisp.dhis.web.api.service.DefaultActivityPlanService">
+ <bean id="org.hisp.dhis.web.api.service.ActivityReportingService" class="org.hisp.dhis.web.api.service.ActivityReportingServiceImpl">
<property name="activityPlanService" ref="org.hisp.dhis.activityplan.ActivityPlanService" />
<property name="patientAttValueService" ref="org.hisp.dhis.patientattributevalue.PatientAttributeValueService" />
<property name="patientAttService" ref="org.hisp.dhis.patient.PatientAttributeService" />
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ <property name="programStageInstanceService" ref="org.hisp.dhis.program.ProgramStageInstanceService" />
+ <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+ <property name="dataValueService" ref="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
</bean>
<bean id="org.hisp.dhis.web.api.service.IProgramService" class="org.hisp.dhis.web.api.service.DefaultProgramService">
<property name="programService" ref="org.hisp.dhis.program.ProgramService" />
<property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
- <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
- </bean>
-
- <bean id="org.hisp.dhis.web.api.service.FacilityReportingService" class="org.hisp.dhis.web.api.service.FacilityReportingServiceImpl">
- <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
- <property name="i18nService" ref="org.hisp.dhis.i18n.I18nService" />
- <property name="periodService" ref="org.hisp.dhis.web.api.service.IPeriodService" />
- <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
- <property name="dataValueService" ref="org.hisp.dhis.datavalue.DataValueService" />
- </bean>
-
- <bean id="org.hisp.dhis.web.api.service.IActivityValueService" class="org.hisp.dhis.web.api.service.DefaultActivityValueService">
- <property name="programStageInstanceService">
- <ref bean="org.hisp.dhis.program.ProgramStageInstanceService" />
- </property>
- <property name="categoryService">
- <ref bean="org.hisp.dhis.dataelement.DataElementCategoryService" />
- </property>
- <property name="dataValueService">
- <ref bean="org.hisp.dhis.patientdatavalue.PatientDataValueService" />
- </property>
- <property name="currentUserService">
- <ref bean="org.hisp.dhis.user.CurrentUserService" />
- </property>
- </bean>
-
- <bean id="org.hisp.dhis.web.api.service.IPeriodService" class="org.hisp.dhis.web.api.service.DefaultPeriodService">
- <property name="periodService">
- <ref bean="org.hisp.dhis.period.PeriodService" />
- </property>
- </bean>
-
- <!-- Serialization writers and readers -->
-
- <bean id="org.hisp.dhis.web.api.provider.DataSerializableProvider" class="org.hisp.dhis.web.api.provider.DataSerializableProvider"
+ </bean>
+
+ <!-- Jax-RS serialization writers and readers -->
+
+ <bean id="org.hisp.dhis.web.api.provider.DataSerializableProvider" class="org.hisp.dhis.web.api.provider.DataStreamSerializableProvider"
scope="singleton" />
- <bean id="org.hisp.dhis.web.api.provider.ActivityPlanProvider"
- class="org.hisp.dhis.web.api.provider.ActivityPlanProvider" scope="singleton"/>
-
<bean id="org.hisp.dhis.web.api.consumer.DataSetValueConsumer" class="org.hisp.dhis.web.api.provider.DataSetValueConsumer"
scope="singleton" />
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org'
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp'
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis'
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web'
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api'
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java'
--- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitTest.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.web.api.model;
+
+import static org.junit.Assert.*;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
+public class OrgUnitTest
+{
+
+ @Test
+ public void testSerialization()
+ throws IOException
+ {
+ OrgUnit unit = new OrgUnit();
+ unit.setId( 1 );
+ unit.setName( "name" );
+ unit.setDownloadActivityPlanUrl( "downloadActivityPlanUrl" );
+ unit.setDownloadAllUrl( "downloadAllUrl" );
+ unit.setUploadActivityReportUrl( "uploadActivityReportUrl" );
+ unit.setUploadFacilityReportUrl( "uploadFacilityReportUrl" );
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream( baos );
+ unit.serialize( dos );
+ dos.flush();
+ OrgUnit unit2 = new OrgUnit();
+ unit2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) );
+
+ assertEquals( unit.getName(), unit2.getName() );
+ assertEquals( unit.getId(), unit2.getId() );
+
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java'
--- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/model/OrgUnitsTest.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.web.api.model;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import org.hisp.dhis.web.api.model.OrgUnit;
+import org.hisp.dhis.web.api.model.OrgUnits;
+import org.junit.Test;
+
+public class OrgUnitsTest
+{
+
+ @Test
+ public void testSerialization()
+ throws IOException
+ {
+ OrgUnit unit = createOrgUnit();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream( baos );
+
+ OrgUnits units = new OrgUnits();
+ units.add( unit );
+ units.serialize( dos );
+ dos.flush();
+ OrgUnits units2 = new OrgUnits( );
+ units2.deSerialize( new DataInputStream( new ByteArrayInputStream( baos.toByteArray() ) ) );
+ assertEquals( 1, units2.size() );
+
+ OrgUnit unit2 = units2.get( 0 );
+ assertEquals( unit.getName(), unit2.getName() );
+ assertEquals( unit.getId(), unit2.getId() );
+
+ }
+
+ private OrgUnit createOrgUnit()
+ {
+ OrgUnit unit = new OrgUnit();
+ unit.setId( 1 );
+ unit.setName( "name" );
+ unit.setDownloadActivityPlanUrl( "downloadActivityPlanUrl" );
+ unit.setDownloadAllUrl( "downloadAllUrl" );
+ unit.setUploadActivityReportUrl( "uploadActivityReportUrl" );
+ unit.setUploadFacilityReportUrl( "uploadFacilityReportUrl" );
+ return unit;
+ }
+}
=== added directory 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java'
--- dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/test/java/org/hisp/dhis/web/api/provider/DataStreamSerializableProviderTest.java 2010-11-18 06:08:29 +0000
@@ -0,0 +1,16 @@
+package org.hisp.dhis.web.api.provider;
+
+import static org.junit.Assert.assertTrue;
+
+import org.hisp.dhis.web.api.model.OrgUnits;
+import org.junit.Test;
+
+public class DataStreamSerializableProviderTest
+{
+
+ @Test
+ public void testAssigning() {
+ boolean writeable = new DataStreamSerializableProvider().isWriteable( OrgUnits.class, null, null, null );
+ assertTrue( writeable );
+ }
+}