dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08300
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1981: Fix: cannot get datasets which dont have sections.
------------------------------------------------------------
revno: 1981
committer: Tran Ng Minh Luan <Luan@MinhLuan-PC>
branch nick: dhis2
timestamp: Mon 2010-11-01 13:32:22 +0700
message:
Fix: cannot get datasets which dont have sections.
Change: get only datasets with certain user.
added:
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ProgramResource.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.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/DataSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java 2010-09-24 11:12:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetService.java 2010-11-01 06:32:22 +0000
@@ -197,7 +197,7 @@
/**
* Returns all DataSets that can be collected through mobile.
*/
- Collection<DataSet> getDataSetsForMobile();
+ Collection<DataSet> getDataSetsForMobile(Source source);
// -------------------------------------------------------------------------
// FrequencyOverrideAssociation
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-10-22 06:50:26 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSetStore.java 2010-11-01 06:32:22 +0000
@@ -118,7 +118,7 @@
/**
* Returns all DataSets that can be collected through mobile.
*/
- Collection<DataSet> getDataSetsForMobile();
+ Collection<DataSet> getDataSetsForMobile(Source source);
Collection<DataSet> getDataSetsBySources( Collection<? extends Source> sources );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-10-22 06:52:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/DefaultDataSetService.java 2010-11-01 06:32:22 +0000
@@ -275,9 +275,9 @@
return i18n( i18nService, dataSet.getDataElements() );
}
- public Collection<DataSet> getDataSetsForMobile()
+ public Collection<DataSet> getDataSetsForMobile(Source source)
{
- return i18n( i18nService, dataSetStore.getDataSetsForMobile() );
+ return i18n( i18nService, dataSetStore.getDataSetsForMobile(source) );
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataset/hibernate/HibernateDataSetStore.java 2010-11-01 06:32:22 +0000
@@ -41,6 +41,7 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.source.Source;
import org.hisp.dhis.system.util.ConversionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* @author Kristian Nordal
@@ -178,14 +179,14 @@
}
@SuppressWarnings( "unchecked" )
- public Collection<DataSet> getDataSetsForMobile() {
-
- Session session = sessionFactory.getCurrentSession();
-
- Criteria criteria = session.createCriteria( DataSet.class );
- criteria.add( Restrictions.eq( "mobile", true ) );
-
- return criteria.list();
+ public Collection<DataSet> getDataSetsForMobile(Source source) {
+ System.out.println("received Source: "+source.getName());
+ String hql = "from DataSet d where :source in elements(d.sources) and d.mobile = true";
+ Query query = sessionFactory.getCurrentSession().createQuery( hql );
+ query.setEntity( "source", source );
+
+ return query.list();
+
}
// -------------------------------------------------------------------------
=== 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-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/ActivityPlan.java 2010-11-01 06:32:22 +0000
@@ -56,28 +56,22 @@
for(int i=0; i<activitiesList.size(); i++)
{
Activity activity = (Activity)activitiesList.get(i);
-
dout.writeLong(activity.getDueDate().getTime());
-
- System.out.println("add beneficiary");
Beneficiary b = activity.getBeneficiary();
dout.writeInt(b.getId());
dout.writeUTF(b.getFirstName());
dout.writeUTF(b.getMiddleName());
dout.writeUTF(b.getLastName());
dout.writeBoolean(activity.isLate());
- System.out.println("add beneficiary att");
Set<String> atts = b.getPatientAttValues();
dout.writeInt( atts.size() );
for(String att : atts){
dout.writeUTF( att );
}
- System.out.println("add task");
Task t = activity.getTask();
dout.writeInt(t.getId()); dout.writeInt(t.getProgramStageId()); dout.writeBoolean(t.isCompleted());
}
}
-
bout.flush();
bout.writeTo(out);
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2010-10-29 12:19:15 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/DataSet.java 2010-11-01 06:32:22 +0000
@@ -1,15 +1,19 @@
package org.hisp.dhis.web.api.model;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
-import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlAccessType;
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 2010-10-28 09:25:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/MobileWrapper.java 2010-11-01 06:32:22 +0000
@@ -60,7 +60,6 @@
}else{
this.activityPlan.serialize( dout );
}
- System.out.println("finish serialize ActivityPlan");
//Write Programs
if(programs != null || programs.size() > 0){
@@ -68,7 +67,6 @@
prog.serialize( dout );
}
}
- System.out.println("finish serialize Programs");
//Write DataSets
if(datasets == null){
@@ -80,7 +78,6 @@
}
}
- System.out.println("finish serialize Datasets");
bout.flush();
bout.writeTo(out);
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java 2010-10-20 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/model/Program.java 2010-11-01 06:32:22 +0000
@@ -47,11 +47,9 @@
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
- System.out.println("add program info");
dout.writeInt(this.getId());
dout.writeUTF(this.getName());
dout.writeInt(programStages.size());
- System.out.println("add program stages");
for(int i=0; i<programStages.size(); i++)
{
ProgramStage programStage = (ProgramStage)programStages.get(i);
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ActivityPlanResource.java 2010-11-01 06:32:22 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Produces;
+
+import org.hisp.dhis.web.api.model.ActivityPlan;
+import org.hisp.dhis.web.api.model.ActivityValue;
+import org.hisp.dhis.web.api.service.IActivityPlanService;
+import org.hisp.dhis.web.api.service.IActivityValueService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Path("/activityplan")
+public class ActivityPlanResource {
+
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private IActivityPlanService activityPlanService;
+
+ @Autowired
+ private IActivityValueService iactivityValueService;
+
+
+ // -------------------------------------------------------------------------
+ // Resources
+ // -------------------------------------------------------------------------
+
+ @GET
+ @Path( "current" )
+ @Produces( "application/vnd.org.dhis2.activityplan+serialized" )
+ public ActivityPlan getCurrentActivityPlan(@HeaderParam("accept-language") String locale)
+ {
+ return activityPlanService.getCurrentActivityPlan( locale );
+ }
+
+ @POST
+ @Path( "values" )
+ @Consumes( "application/vnd.org.dhis2.activityvaluelist+serialized" )
+ @Produces("application/xml")
+ public String getValues(ActivityValue activityValue)
+ {
+ return iactivityValueService.saveValues(activityValue);
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2010-11-01 06:32:22 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Produces;
+
+import org.hisp.dhis.web.api.model.AbstractModelList;
+import org.hisp.dhis.web.api.model.DataSet;
+import org.hisp.dhis.web.api.model.DataSetValue;
+import org.hisp.dhis.web.api.service.IDataSetService;
+import org.hisp.dhis.web.api.service.IDataValueService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Path("/mobile-datasets")
+public class DataSetResource {
+
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private IDataSetService idataSetService;
+
+ @Autowired
+ private IDataValueService idataValueService;
+
+
+ // -------------------------------------------------------------------------
+ // Resources
+ // -------------------------------------------------------------------------
+
+ @GET
+ @Produces( "application/vnd.org.dhis2.abstractmodellist+serialized" )
+ public AbstractModelList getAllMobileDataSets(@HeaderParam("accept-language") String locale)
+ {
+ return null;
+// return idataSetService.getAllMobileDataSetsForLocale( locale );
+ }
+
+ @GET
+ @Path("{datasetid}")
+ @Produces( "application/vnd.org.dhis2.dataset+serialized" )
+ public DataSet getSelectedDataSet(
+ @PathParam("datasetid") int datasetid,
+ @HeaderParam("accept-language") String locale
+ )
+ {
+ return null;
+// return idataSetService.getDataSetForLocale( datasetid, locale );
+ }
+
+ @POST
+ @Path( "values" )
+ @Consumes( "application/vnd.org.dhis2.datasetvalue+serialized" )
+ @Produces("application/xml")
+ public String getValues(DataSetValue dataSetValue)
+ {
+ return idataValueService.saveValues(dataSetValue);
+ }
+}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ProgramResource.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ProgramResource.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ProgramResource.java 2010-11-01 06:32:22 +0000
@@ -0,0 +1,47 @@
+package org.hisp.dhis.web.api.resources;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.Produces;
+
+import org.hisp.dhis.web.api.model.AbstractModelList;
+import org.hisp.dhis.web.api.model.Program;
+import org.hisp.dhis.web.api.service.IProgramService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@Path("/programs")
+public class ProgramResource {
+
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private IProgramService iprogramService;
+
+ // -------------------------------------------------------------------------
+ // Resources
+ // -------------------------------------------------------------------------
+
+ @GET
+ @Produces( "application/vnd.org.dhis2.abstractmodellist+serialized" )
+ public AbstractModelList getAllMobileDataSets(@HeaderParam("accept-language") String locale)
+ {
+// return iprogramService.getAllProgramsForLocale( locale );
+ return null;
+ }
+
+ @GET
+ @Path("{programid}")
+ @Produces( "application/vnd.org.dhis2.program+serialized" )
+ public Program getSelectedProgram(
+ @PathParam("programid") int programid,
+ @HeaderParam("accept-language") String locale
+ )
+ {
+ return iprogramService.getProgramForLocale( programid, locale );
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java 2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultDataSetService.java 2010-11-01 06:32:22 +0000
@@ -3,10 +3,14 @@
import static org.hisp.dhis.i18n.I18nUtils.i18n;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Set;
+import org.hisp.dhis.order.manager.DataElementOrderManagerException;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.web.api.model.DataElement;
import org.hisp.dhis.web.api.model.DataSet;
import org.hisp.dhis.web.api.model.Section;
@@ -25,19 +29,37 @@
@Autowired
private org.hisp.dhis.i18n.I18nService i18nService;
+ @Autowired
+ private org.hisp.dhis.order.manager.DataElementOrderManager dataElementOrderManager ;
+
+ @Autowired
+ private CurrentUserService currentUserService;
// -------------------------------------------------------------------------
// MobileDataSetService
// -------------------------------------------------------------------------
public List<DataSet> getAllMobileDataSetsForLocale(String localeString) {
-
+ Collection<OrganisationUnit> units = currentUserService.getCurrentUser().getOrganisationUnits();
+ OrganisationUnit unit = null;
+
+ if( units.size() > 0 )
+ {
+ unit = units.iterator().next();
+ }
+ else
+ {
+ return null;
+ }
+
+
+
List<DataSet> datasets = new ArrayList<DataSet>();
Locale locale = LocaleUtil.getLocale(localeString);
// AbstractModelList abstractModelList = new AbstractModelList();
//
// List<AbstractModel> abstractModels = new ArrayList<AbstractModel>();
//
- for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile())
+ for (org.hisp.dhis.dataset.DataSet dataSet : dataSetService.getDataSetsForMobile(unit))
{
if( dataSet.getPeriodType().getName().equals( "Daily") ||
dataSet.getPeriodType().getName().equals( "Weekly") ||
@@ -54,7 +76,6 @@
}
public DataSet getDataSetForLocale(int dataSetId, Locale locale) {
- System.out.println("DefaultDataSetService: transform dataset");
org.hisp.dhis.dataset.DataSet dataSet = dataSetService.getDataSet( dataSetId );
dataSet = i18n( i18nService, locale, dataSet );
Set<org.hisp.dhis.dataset.Section> sections = dataSet.getSections();
@@ -66,40 +87,64 @@
ds.setId( dataSet.getId() );
ds.setName( dataSet.getName() );
- System.out.println("DefaultDataSetService: create DataSet "+ ds.getName());
ds.setPeriodType( dataSet.getPeriodType().getName() );
//Mobile
List<Section> sectionList = new ArrayList<Section>();
ds.setSections(sectionList);
- for(org.hisp.dhis.dataset.Section each : sections){
- List<org.hisp.dhis.dataelement.DataElement> dataElements = each.getDataElements();
-
- Section section = new Section();
- section.setId(each.getId());
- section.setName(each.getName());
- //Mobile
- List<DataElement> dataElementList = new ArrayList<DataElement>();
- section.setDes(dataElementList);
-
-
- for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
- {
- dataElement = i18n( i18nService, locale, dataElement );
-
- DataElement de = new DataElement();
- de.setId( dataElement.getId() );
- de.setName( dataElement.getName() );
- de.setType( dataElement.getType() );
- dataElementList.add( de );
- System.out.println("add dataelement:"+de.getName());
+ if(sections.size() == 0 || sections == null){
+ Collection<org.hisp.dhis.dataelement.DataElement> dataElements = new ArrayList<org.hisp.dhis.dataelement.DataElement>();
+ try {
+ dataElements = dataElementOrderManager.getOrderedDataElements(dataSet);
+ } catch (DataElementOrderManagerException e) {
+ e.printStackTrace();
+ }
+ //Fake Section to store Data Elements
+ Section section = new Section();
+
+ sectionList.add(section);
+ section.setId(0);
+ section.setName("");
+
+ List<DataElement> dataElementList = new ArrayList<DataElement>();
+ section.setDes(dataElementList);
+
+ for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
+ {
+ dataElement = i18n( i18nService, locale, dataElement );
+
+ DataElement de = new DataElement();
+ de.setId( dataElement.getId() );
+ de.setName( dataElement.getName() );
+ de.setType( dataElement.getType() );
+ dataElementList.add( de );
+ }
+ }else{
+ for(org.hisp.dhis.dataset.Section each : sections){
+ List<org.hisp.dhis.dataelement.DataElement> dataElements = each.getDataElements();
+
+ Section section = new Section();
+ section.setId(each.getId());
+ section.setName(each.getName());
+ //Mobile
+ List<DataElement> dataElementList = new ArrayList<DataElement>();
+ section.setDes(dataElementList);
+
+
+ for( org.hisp.dhis.dataelement.DataElement dataElement : dataElements )
+ {
+ dataElement = i18n( i18nService, locale, dataElement );
+
+ DataElement de = new DataElement();
+ de.setId( dataElement.getId() );
+ de.setName( dataElement.getName() );
+ de.setType( dataElement.getType() );
+ dataElementList.add( de );
+ }
+ sectionList.add(section);
}
-
- sectionList.add(section);
- System.out.println("add section:"+section.getName());
- }
-// ds.setDataElements(des);
+ }
return ds;
}
=== 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-10-20 15:56:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/service/DefaultProgramService.java 2010-11-01 06:32:22 +0000
@@ -106,14 +106,10 @@
public Program getProgramForLocale(int programId, String localeString)
{
-
- System.out.println("The id is: " + programId + " and locale is: " + localeString);
Locale locale = LocaleUtil.getLocale(localeString);
org.hisp.dhis.program.Program program = programService.getProgram( programId );
- System.out.println("Fetched .... " + program.getId() );
-
program = i18n( i18nService, locale, program );
Program pr = new Program();