dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24879
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12241: add new endpoint: /api/completeDataSetRegistrations, uses same parameters as /api/dataValueSets b...
------------------------------------------------------------
revno: 12241
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-25 16:13:04 +0200
message:
add new endpoint: /api/completeDataSetRegistrations, uses same parameters as /api/dataValueSets but returns the completeDataSetRegistration data type.
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrations.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CompleteDataSetRegistrationController.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistration.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.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/CompleteDataSetRegistration.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistration.java 2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistration.java 2013-09-25 14:13:04 +0000
@@ -28,15 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.ImportableObject;
-import org.hisp.dhis.common.view.DetailedView;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -46,7 +43,7 @@
/**
* @author Lars Helge Overland
*/
-@JacksonXmlRootElement( localName = "completeDataSetRegistration", namespace = DxfNamespaces.DXF_2_0)
+@JacksonXmlRootElement(localName = "completeDataSetRegistration", namespace = DxfNamespaces.DXF_2_0)
public class CompleteDataSetRegistration
implements ImportableObject, Serializable
{
@@ -66,7 +63,7 @@
private String storedBy;
private transient String periodName;
-
+
// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
@@ -179,8 +176,7 @@
// -------------------------------------------------------------------------
@JsonProperty
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( {DetailedView.class} )
+ @JsonSerialize(as = BaseIdentifiableObject.class)
public DataSet getDataSet()
{
return dataSet;
@@ -192,8 +188,7 @@
}
@JsonProperty
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( {DetailedView.class} )
+ @JsonSerialize(as = BaseIdentifiableObject.class)
public Period getPeriod()
{
return period;
@@ -204,9 +199,8 @@
this.period = period;
}
- @JsonProperty( value = "organisationUnit" )
- @JsonSerialize( as = BaseIdentifiableObject.class )
- @JsonView( {DetailedView.class} )
+ @JsonProperty(value = "organisationUnit")
+ @JsonSerialize(as = BaseIdentifiableObject.class)
public OrganisationUnit getSource()
{
return source;
@@ -218,7 +212,6 @@
}
@JsonProperty
- @JsonView( {DetailedView.class} )
public Date getDate()
{
return date;
@@ -230,7 +223,6 @@
}
@JsonProperty
- @JsonView( {DetailedView.class} )
public String getStoredBy()
{
return storedBy;
@@ -241,7 +233,7 @@
this.storedBy = storedBy;
}
- @JsonIgnore
+ @JsonProperty
public String getPeriodName()
{
return periodName;
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrations.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrations.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/CompleteDataSetRegistrations.java 2013-09-25 14:13:04 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.dataset;
+
+/*
+ * Copyright (c) 2004-2013, 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 com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.DxfNamespaces;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@JacksonXmlRootElement( localName = "completeDataSetRegistrations", namespace = DxfNamespaces.DXF_2_0 )
+public class CompleteDataSetRegistrations
+{
+ private List<CompleteDataSetRegistration> completeDataSetRegistrationList = new ArrayList<CompleteDataSetRegistration>();
+
+ public CompleteDataSetRegistrations()
+ {
+ }
+
+ @JsonProperty
+ @JacksonXmlElementWrapper( localName = "completeDataSetRegistrationList", namespace = DxfNamespaces.DXF_2_0 )
+ @JacksonXmlProperty( localName = "completeDataSetRegistration", namespace = DxfNamespaces.DXF_2_0 )
+ public List<CompleteDataSetRegistration> getCompleteDataSetRegistrationList()
+ {
+ return completeDataSetRegistrationList;
+ }
+
+ public void setCompleteDataSetRegistrationList( List<CompleteDataSetRegistration> completeDataSetRegistrationList )
+ {
+ this.completeDataSetRegistrationList = completeDataSetRegistrationList;
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java 2013-09-25 14:13:04 +0000
@@ -28,10 +28,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
@@ -42,7 +38,11 @@
import org.hisp.dhis.common.view.ExportView;
import org.hisp.dhis.dxf2.datavalue.DataValue;
-@JacksonXmlRootElement( localName = "dataValueSet", namespace = DxfNamespaces.DXF_2_0)
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+@JacksonXmlRootElement(localName = "dataValueSet", namespace = DxfNamespaces.DXF_2_0)
public class DataValueSet
{
//--------------------------------------------------------------------------
@@ -50,13 +50,13 @@
//--------------------------------------------------------------------------
protected String dataElementIdScheme;
-
+
protected String orgUnitIdScheme;
-
+
protected Boolean dryRun;
-
+
protected String strategy;
-
+
//--------------------------------------------------------------------------
// Properties
//--------------------------------------------------------------------------
@@ -70,7 +70,7 @@
protected String orgUnit;
protected List<DataValue> dataValues = new ArrayList<DataValue>();
-
+
//--------------------------------------------------------------------------
// Constructors
//--------------------------------------------------------------------------
@@ -78,14 +78,14 @@
public DataValueSet()
{
}
-
+
//--------------------------------------------------------------------------
// Getters and setters
//--------------------------------------------------------------------------
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getDataElementIdScheme()
{
return dataElementIdScheme;
@@ -97,8 +97,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getOrgUnitIdScheme()
{
return orgUnitIdScheme;
@@ -110,8 +110,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public Boolean getDryRun()
{
return dryRun;
@@ -123,8 +123,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getStrategy()
{
return strategy;
@@ -136,8 +136,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getDataSet()
{
return dataSet;
@@ -149,8 +149,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getCompleteDate()
{
return completeDate;
@@ -162,8 +162,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getPeriod()
{
return period;
@@ -175,8 +175,8 @@
}
@JsonProperty
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0)
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public String getOrgUnit()
{
return orgUnit;
@@ -187,10 +187,10 @@
this.orgUnit = orgUnit;
}
- @JsonProperty( value = "dataValues" )
- @JsonView( { DetailedView.class, ExportView.class } )
- @JacksonXmlElementWrapper( localName = "dataValues", namespace = DxfNamespaces.DXF_2_0)
- @JacksonXmlProperty( localName = "dataValue", namespace = DxfNamespaces.DXF_2_0)
+ @JsonProperty(value = "dataValues")
+ @JsonView({ DetailedView.class, ExportView.class })
+ @JacksonXmlElementWrapper(localName = "dataValues", namespace = DxfNamespaces.DXF_2_0)
+ @JacksonXmlProperty(localName = "dataValue", namespace = DxfNamespaces.DXF_2_0)
public List<DataValue> getDataValues()
{
return dataValues;
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CompleteDataSetRegistrationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CompleteDataSetRegistrationController.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CompleteDataSetRegistrationController.java 2013-09-25 14:13:04 +0000
@@ -0,0 +1,147 @@
+package org.hisp.dhis.api.controller;
+
+/*
+ * Copyright (c) 2004-2013, 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 org.hisp.dhis.common.IdentifiableObjectManager;
+import org.hisp.dhis.common.view.BasicView;
+import org.hisp.dhis.dataset.CompleteDataSetRegistration;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
+import org.hisp.dhis.dataset.CompleteDataSetRegistrations;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dxf2.utils.JacksonUtils;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_JSON;
+import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_XML;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( value = CompleteDataSetRegistrationController.RESOURCE_PATH )
+public class CompleteDataSetRegistrationController
+{
+ public static final String RESOURCE_PATH = "/completeDataSetRegistrations";
+
+ @Autowired
+ private CompleteDataSetRegistrationService completeDataSetRegistrationService;
+
+ @Autowired
+ private PeriodService periodService;
+
+ @Autowired
+ private IdentifiableObjectManager manager;
+
+ @Autowired
+ private OrganisationUnitService organisationUnitService;
+
+ @RequestMapping( method = RequestMethod.GET, produces = CONTENT_TYPE_XML )
+ public void getCompleteDataSetRegistrationsXml(
+ @RequestParam Set<String> dataSet,
+ @RequestParam( required = false ) String period,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
+ @RequestParam Set<String> orgUnit,
+ @RequestParam( required = false ) boolean children,
+ HttpServletResponse response ) throws IOException
+ {
+ response.setContentType( CONTENT_TYPE_XML );
+ CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations( dataSet, period, startDate, endDate, orgUnit, children );
+
+ JacksonUtils.toXmlWithView( response.getOutputStream(), completeDataSetRegistrations, BasicView.class );
+ }
+
+ @RequestMapping( method = RequestMethod.GET, produces = CONTENT_TYPE_JSON )
+ public void getCompleteDataSetRegistrationsJson(
+ @RequestParam Set<String> dataSet,
+ @RequestParam( required = false ) String period,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date startDate,
+ @RequestParam @DateTimeFormat( pattern = "yyyy-MM-dd" ) Date endDate,
+ @RequestParam Set<String> orgUnit,
+ @RequestParam( required = false ) boolean children,
+ HttpServletResponse response ) throws IOException
+ {
+ response.setContentType( CONTENT_TYPE_JSON );
+ CompleteDataSetRegistrations completeDataSetRegistrations = getCompleteDataSetRegistrations( dataSet, period, startDate, endDate, orgUnit, children );
+
+ JacksonUtils.toJsonWithView( response.getOutputStream(), completeDataSetRegistrations, BasicView.class );
+ }
+
+ private CompleteDataSetRegistrations getCompleteDataSetRegistrations( Set<String> dataSet, String period, Date startDate, Date endDate, Set<String> orgUnit, boolean children )
+ {
+ Set<Period> periods = new HashSet<Period>();
+ Set<DataSet> dataSets = new HashSet<DataSet>();
+ Set<OrganisationUnit> organisationUnits = new HashSet<OrganisationUnit>();
+
+ PeriodType periodType = periodService.getPeriodTypeByName( period );
+
+ if ( periodType != null )
+ {
+ periods.addAll( periodService.getPeriodsBetweenDates( periodType, startDate, endDate ) );
+ }
+ else
+ {
+ periods.addAll( periodService.getPeriodsBetweenDates( startDate, endDate ) );
+ }
+
+ if ( children )
+ {
+ organisationUnits.addAll( organisationUnitService.getOrganisationUnitsWithChildren( orgUnit ) );
+ }
+ else
+ {
+ organisationUnits.addAll( organisationUnitService.getOrganisationUnitsByUid( orgUnit ) );
+ }
+
+ dataSets.addAll( manager.getByUid( DataSet.class, dataSet ) );
+
+ CompleteDataSetRegistrations completeDataSetRegistrations = new CompleteDataSetRegistrations();
+ completeDataSetRegistrations.setCompleteDataSetRegistrationList( new ArrayList<CompleteDataSetRegistration>(
+ completeDataSetRegistrationService.getCompleteDataSetRegistrations( dataSets, organisationUnits, periods ) ) );
+
+ return completeDataSetRegistrations;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java 2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java 2013-09-25 14:13:04 +0000
@@ -41,7 +41,7 @@
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-@JacksonXmlRootElement( localName = "dxf2", namespace = DxfNamespaces.DXF_2_0 )
+@JacksonXmlRootElement( localName = "dataValueSets", namespace = DxfNamespaces.DXF_2_0 )
public class DataValueSets
{
private List<DataValueSet> dataValueSets = new ArrayList<DataValueSet>();