dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15061
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5288: WIP on integrating maps into the web api framework (should have been several commits, but..)
------------------------------------------------------------
revno: 5288
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-12-05 13:21:38 +0100
message:
WIP on integrating maps into the web api framework (should have been several commits, but..)
- Made mapview an identifiable object
- Tried to integrate maps into the web api framework (wip)
- Moved link population to jaxb marshalling (not json views yet)
- Enforcing session factory on hibernate generic store
- Detached JdbcAggregatedDataValueStore from generic store (only needs a template)
- Simplified Web link listener (probably conflicting with dxf branch)
added:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Maps.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2Utils.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/MapGenerationView.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/map.xsl
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java
dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulatorListener.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml
dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/list.xsl
dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/model2html.xsl
--
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/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2011-12-01 16:08:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2011-12-05 12:21:38 +0000
@@ -27,6 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.indicator.Indicator;
@@ -41,11 +49,12 @@
* @author Jan Henrik Overland
* @version $Id$
*/
+@XmlRootElement( name = "map", namespace = Dxf2Namespace.NAMESPACE )
+@XmlAccessorType( XmlAccessType.NONE )
public class MapView
+ extends BaseIdentifiableObject
{
- private int id;
-
- private String name;
+ private static final long serialVersionUID = 1866358818802275436L;
private User user;
@@ -175,26 +184,8 @@
// Getters and setters
// -------------------------------------------------------------------------
- public int getId()
- {
- return id;
- }
-
- public void setId( int id )
- {
- this.id = id;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName( String name )
- {
- this.name = name;
- }
-
+ @XmlElement
+ @JsonProperty
public User getUser()
{
return user;
@@ -205,6 +196,8 @@
this.user = user;
}
+ @XmlElement
+ @JsonProperty
public String getMapValueType()
{
return mapValueType;
@@ -215,6 +208,8 @@
this.mapValueType = mapValueType;
}
+ @XmlElement
+ @JsonProperty
public IndicatorGroup getIndicatorGroup()
{
return indicatorGroup;
@@ -225,6 +220,8 @@
this.indicatorGroup = indicatorGroup;
}
+ @XmlElement
+ @JsonProperty
public Indicator getIndicator()
{
return indicator;
@@ -235,6 +232,8 @@
this.indicator = indicator;
}
+ @XmlElement
+ @JsonProperty
public DataElementGroup getDataElementGroup()
{
return dataElementGroup;
@@ -245,6 +244,8 @@
this.dataElementGroup = dataElementGroup;
}
+ @XmlElement
+ @JsonProperty
public DataElement getDataElement()
{
return dataElement;
@@ -255,6 +256,8 @@
this.dataElement = dataElement;
}
+ @XmlElement
+ @JsonProperty
public String getMapDateType()
{
return mapDateType;
@@ -265,6 +268,8 @@
this.mapDateType = mapDateType;
}
+ @XmlElement
+ @JsonProperty
public PeriodType getPeriodType()
{
return periodType;
@@ -275,6 +280,8 @@
this.periodType = periodType;
}
+ @XmlElement
+ @JsonProperty
public Period getPeriod()
{
return period;
@@ -285,6 +292,8 @@
this.period = period;
}
+ @XmlElement
+ @JsonProperty
public OrganisationUnit getParentOrganisationUnit()
{
return parentOrganisationUnit;
@@ -295,6 +304,8 @@
this.parentOrganisationUnit = parentOrganisationUnit;
}
+ @XmlElement
+ @JsonProperty
public OrganisationUnitLevel getOrganisationUnitLevel()
{
return organisationUnitLevel;
@@ -305,6 +316,8 @@
this.organisationUnitLevel = organisationUnitLevel;
}
+ @XmlElement
+ @JsonProperty
public String getMapLegendType()
{
return mapLegendType;
@@ -315,6 +328,8 @@
this.mapLegendType = mapLegendType;
}
+ @XmlElement
+ @JsonProperty
public Integer getMethod()
{
return method;
@@ -325,6 +340,8 @@
this.method = method;
}
+ @XmlElement
+ @JsonProperty
public Integer getClasses()
{
return classes;
@@ -335,6 +352,8 @@
this.classes = classes;
}
+ @XmlElement
+ @JsonProperty
public String getBounds()
{
return bounds;
@@ -345,6 +364,8 @@
this.bounds = bounds;
}
+ @XmlElement
+ @JsonProperty
public String getColorLow()
{
return colorLow;
@@ -355,6 +376,8 @@
this.colorLow = colorLow;
}
+ @XmlElement
+ @JsonProperty
public String getColorHigh()
{
return colorHigh;
@@ -365,6 +388,8 @@
this.colorHigh = colorHigh;
}
+ @XmlElement
+ @JsonProperty
public MapLegendSet getMapLegendSet()
{
return mapLegendSet;
@@ -375,6 +400,8 @@
this.mapLegendSet = mapLegendSet;
}
+ @XmlElement
+ @JsonProperty
public Integer getRadiusLow()
{
return radiusLow;
@@ -385,6 +412,8 @@
this.radiusLow = radiusLow;
}
+ @XmlElement
+ @JsonProperty
public Integer getRadiusHigh()
{
return radiusHigh;
@@ -395,6 +424,8 @@
this.radiusHigh = radiusHigh;
}
+ @XmlElement
+ @JsonProperty
public String getLongitude()
{
return longitude;
@@ -405,6 +436,8 @@
this.longitude = longitude;
}
+ @XmlElement
+ @JsonProperty
public String getLatitude()
{
return latitude;
@@ -415,6 +448,8 @@
this.latitude = latitude;
}
+ @XmlElement
+ @JsonProperty
public Integer getZoom()
{
return zoom;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2011-12-01 16:08:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingService.java 2011-12-05 12:21:38 +0000
@@ -142,6 +142,8 @@
MapView getMapView( int id );
+ MapView getMapView( String uid );
+
MapView getMapViewByName( String name );
Collection<MapView> getAllMapViews();
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java 2011-01-26 00:07:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MappingStore.java 2011-12-05 12:21:38 +0000
@@ -29,6 +29,8 @@
import java.util.Collection;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.user.User;
/**
@@ -36,6 +38,7 @@
* @version $Id$
*/
public interface MappingStore
+ extends GenericIdentifiableObjectStore<MapView>
{
String ID = MappingStore.class.getName();
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Maps.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Maps.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/Maps.java 2011-12-05 12:21:38 +0000
@@ -0,0 +1,64 @@
+package org.hisp.dhis.mapping;
+
+import java.util.ArrayList;
+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.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.common.BaseLinkableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+
+/*
+ * Copyright (c) 2011, 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.
+ */
+
+@XmlRootElement( name = "maps", namespace = Dxf2Namespace.NAMESPACE )
+@XmlAccessorType( value = XmlAccessType.NONE )
+public class Maps extends BaseLinkableObject
+{
+
+ private List<MapView> maps = new ArrayList<MapView>();
+
+ private String link;
+
+ @XmlElement( name = "map" )
+ @JsonProperty( value = "maps" )
+ public List<MapView> getMaps()
+ {
+ return maps;
+ }
+
+ public void setMaps( List<MapView> maps )
+ {
+ this.maps = maps;
+ }
+
+}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java 2011-12-01 19:39:40 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/aggregation/jdbc/JdbcAggregatedDataValueStore.java 2011-12-05 12:21:38 +0000
@@ -48,14 +48,12 @@
import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
import org.hisp.dhis.aggregation.AggregatedMapValue;
import org.hisp.dhis.aggregation.StoreIterator;
-import org.hisp.dhis.caseaggregation.CaseAggregationCondition;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOption;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DeflatedDataValue;
-import org.hisp.dhis.hibernate.HibernateGenericStore;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
import org.hisp.dhis.period.Period;
@@ -65,12 +63,13 @@
import org.hisp.dhis.system.objectmapper.AggregatedIndicatorValueRowMapper;
import org.hisp.dhis.system.objectmapper.DataValueRowMapper;
import org.hisp.dhis.system.objectmapper.DeflatedDataValueRowMapper;
+import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author Lars Helge Overland
*/
public class JdbcAggregatedDataValueStore
- extends HibernateGenericStore<CaseAggregationCondition> implements AggregatedDataValueStore
+ implements AggregatedDataValueStore
{
private int FETCH_SIZE = 1000; // Number of rows to fetch from db for large resultset
@@ -87,6 +86,13 @@
this.statementManager = statementManager;
}
+ protected JdbcTemplate jdbcTemplate;
+
+ public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
+ {
+ this.jdbcTemplate = jdbcTemplate;
+ }
+
// -------------------------------------------------------------------------
// AggregatedDataValue
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2011-11-23 18:07:35 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java 2011-12-05 12:21:38 +0000
@@ -52,7 +52,7 @@
private static String[] tables = { "chart", "constant", "attribute", "indicatortype", "indicatorgroupset", "indicator",
"indicatorgroup", "datadictionary", "validationrulegroup", "validationrule", "dataset", "orgunitlevel",
"organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup",
- "dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo" };
+ "dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo", "mapview" };
// -------------------------------------------------------------------------
// Dependencies
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2011-12-01 17:08:55 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2011-12-05 12:21:38 +0000
@@ -480,13 +480,27 @@
{
MapView mapView = mappingStore.getMapView( id );
+ setMapViewLevel( mapView );
+
+ return mapView;
+ }
+
+ public MapView getMapView( String uid )
+ {
+ MapView mapView = mappingStore.getByUid( uid );
+
+ setMapViewLevel( mapView );
+
+ return mapView;
+ }
+
+ private void setMapViewLevel( MapView mapView )
+ {
if ( mapView != null )
{
mapView.getParentOrganisationUnit().setLevel(
organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit() ) );
}
-
- return mapView;
}
public MapView getMapViewByName( String name )
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java 2011-01-27 18:30:34 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/hibernate/HibernateMappingStore.java 2011-12-05 12:21:38 +0000
@@ -31,9 +31,9 @@
import org.hibernate.Criteria;
import org.hibernate.Session;
-import org.hibernate.SessionFactory;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
+import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
import org.hisp.dhis.mapping.MapLayer;
import org.hisp.dhis.mapping.MapLegend;
import org.hisp.dhis.mapping.MapLegendSet;
@@ -46,18 +46,8 @@
* @version $Id$
*/
public class HibernateMappingStore
- implements MappingStore
+ extends HibernateIdentifiableObjectStore<MapView> implements MappingStore
{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private SessionFactory sessionFactory;
-
- public void setSessionFactory( SessionFactory sessionFactory )
- {
- this.sessionFactory = sessionFactory;
- }
// -------------------------------------------------------------------------
// MapLegend
@@ -183,16 +173,12 @@
public int addMapView( MapView view )
{
- Session session = sessionFactory.getCurrentSession();
-
- return (Integer) session.save( view );
+ return save( view );
}
public void updateMapView( MapView view )
{
- Session session = sessionFactory.getCurrentSession();
-
- session.update( view );
+ update( view );
}
public void deleteMapView( MapView view )
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 2011-12-01 15:43:25 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/META-INF/dhis/beans.xml 2011-12-05 12:21:38 +0000
@@ -34,6 +34,7 @@
<bean id="org.hisp.dhis.mapping.MappingStore"
class="org.hisp.dhis.mapping.hibernate.HibernateMappingStore">
+ <property name="clazz" value="org.hisp.dhis.mapping.MapView" />
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml 2011-12-01 16:08:37 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml 2011-12-05 12:21:38 +0000
@@ -1,7 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
+ "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"
+ [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+>
<hibernate-mapping>
<class name="org.hisp.dhis.mapping.MapView" table="mapview">
@@ -9,8 +11,7 @@
<id name="id" column="mapviewid">
<generator class="native" />
</id>
-
- <property name="name" />
+ &identifiableProperties;
<many-to-one name="user" class="org.hisp.dhis.user.User" column="userid" foreign-key="fk_mapview_userid" />
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2011-11-22 15:48:30 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2011-12-05 12:21:38 +0000
@@ -39,6 +39,7 @@
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.GenericNameableObjectStore;
+import org.springframework.beans.factory.annotation.Required;
import org.springframework.jdbc.core.JdbcTemplate;
/**
@@ -50,6 +51,7 @@
{
protected SessionFactory sessionFactory;
+ @Required
public void setSessionFactory( SessionFactory sessionFactory )
{
this.sessionFactory = sessionFactory;
@@ -75,6 +77,7 @@
/**
* Could be injected through container.
*/
+ @Required
public void setClazz( Class<T> clazz )
{
this.clazz = clazz;
@@ -133,7 +136,12 @@
*/
protected final Criteria getCriteria()
{
- return sessionFactory.getCurrentSession().createCriteria( getClazz() ).setCacheable( cacheable );
+ return getClazzCriteria().setCacheable( cacheable );
+ }
+
+ protected Criteria getClazzCriteria()
+ {
+ return sessionFactory.getCurrentSession().createCriteria( getClazz() );
}
/**
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 2011-12-03 18:00:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 2011-12-05 12:21:38 +0000
@@ -27,8 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.hisp.dhis.api.utils.IdentifiableObjectParams;
-import org.hisp.dhis.api.utils.WebLinkPopulatorListener;
+import java.util.ArrayList;
+
+import javax.servlet.http.HttpServletRequest;
+
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.ChartService;
import org.hisp.dhis.chart.Charts;
@@ -39,9 +41,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
-import javax.servlet.http.HttpServletRequest;
-import java.util.ArrayList;
-
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
@@ -53,33 +52,21 @@
private ChartService chartService;
@RequestMapping( method = RequestMethod.GET )
- public String getCharts( IdentifiableObjectParams params, Model model, HttpServletRequest request )
+ public String getCharts( Model model, HttpServletRequest request )
{
Charts charts = new Charts();
charts.setCharts( new ArrayList<Chart>( chartService.getAllCharts() ) );
- if ( params.hasLinks() )
- {
- WebLinkPopulatorListener listener = new WebLinkPopulatorListener( request );
- listener.beforeMarshal( charts );
- }
-
model.addAttribute( "model", charts );
return "charts";
}
@RequestMapping( value = "/{uid}", method = RequestMethod.GET )
- public String getChart( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
+ public String getChart( @PathVariable( "uid" ) String uid, Model model, HttpServletRequest request )
{
Chart chart = chartService.getChart( uid );
- if ( params.hasLinks() )
- {
- WebLinkPopulatorListener listener = new WebLinkPopulatorListener( request );
- listener.beforeMarshal( chart );
- }
-
model.addAttribute( "model", chart );
return "chart";
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java 2011-12-03 10:15:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MapController.java 2011-12-05 12:21:38 +0000
@@ -1,19 +1,47 @@
package org.hisp.dhis.api.controller;
-import java.awt.image.BufferedImage;
+/*
+ * Copyright (c) 2011, 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.IOException;
-
-import javax.imageio.ImageIO;
-import javax.servlet.http.HttpServletResponse;
-
-import org.hisp.dhis.mapgeneration.Map;
+import java.util.ArrayList;
+
+import javax.servlet.http.HttpServletRequest;
+
import org.hisp.dhis.mapgeneration.MapGenerationService;
import org.hisp.dhis.mapping.MapView;
import org.hisp.dhis.mapping.MappingService;
+import org.hisp.dhis.mapping.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping( value = "/maps" )
@@ -25,14 +53,29 @@
@Autowired
MappingService mappingService;
- @RequestMapping( value = "/{id}" )
- public void getMapImage(@PathVariable( "id" ) int id, HttpServletResponse response )
- throws IOException
- {
- MapView mapView = mappingService.getMapView( id );
- BufferedImage image = mapGenerationService.generateMapImage( new Map( mapView ) );
-
- ImageIO.write( image, "PNG", response.getOutputStream() );
+ @RequestMapping( method = RequestMethod.GET )
+ public String getMaps( Model model, HttpServletRequest request ) throws IOException
+ {
+ Maps maps = new Maps();
+ maps.setMaps( new ArrayList<MapView>( mappingService.getAllMapViews() ) );
+
+ model.addAttribute( "model", maps );
+
+ return "maps";
+ }
+
+ @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+ public String getChart( @PathVariable String uid, Model model, HttpServletRequest request )
+ {
+ MapView mapView = mappingService.getMapView( uid );
+
+ if (mapView == null) {
+ throw new IllegalArgumentException("No map with id " + uid);
+ }
+
+ model.addAttribute( "model", mapView );
+
+ return "map";
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulatorListener.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulatorListener.java 2011-12-03 20:35:31 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulatorListener.java 2011-12-05 12:21:38 +0000
@@ -27,32 +27,60 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.bind.Marshaller;
+
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.attribute.Attributes;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.Charts;
import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.dataelement.*;
+import org.hisp.dhis.common.BaseLinkableObject;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategories;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryCombos;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombos;
+import org.hisp.dhis.dataelement.DataElementCategoryOptions;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
+import org.hisp.dhis.dataelement.DataElementGroupSets;
+import org.hisp.dhis.dataelement.DataElementGroups;
+import org.hisp.dhis.dataelement.DataElements;
import org.hisp.dhis.dataset.CompleteDataSetRegistration;
import org.hisp.dhis.dataset.CompleteDataSetRegistrations;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSets;
-import org.hisp.dhis.indicator.*;
-import org.hisp.dhis.organisationunit.*;
+import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.indicator.IndicatorGroup;
+import org.hisp.dhis.indicator.IndicatorGroupSet;
+import org.hisp.dhis.indicator.IndicatorGroupSets;
+import org.hisp.dhis.indicator.IndicatorGroups;
+import org.hisp.dhis.indicator.IndicatorType;
+import org.hisp.dhis.indicator.IndicatorTypes;
+import org.hisp.dhis.indicator.Indicators;
+import org.hisp.dhis.mapping.MapView;
+import org.hisp.dhis.mapping.Maps;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupSets;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroups;
+import org.hisp.dhis.organisationunit.OrganisationUnits;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.Users;
-import org.springframework.web.util.UrlPathHelper;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.xml.bind.Marshaller;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
-public class WebLinkPopulatorListener extends Marshaller.Listener
+public class WebLinkPopulatorListener
+ extends Marshaller.Listener
{
private HttpServletRequest request;
@@ -68,6 +96,9 @@
resourcePaths.put( Charts.class, "charts" );
resourcePaths.put( Chart.class, "charts" );
+ resourcePaths.put( Maps.class, "maps" );
+ resourcePaths.put( MapView.class, "maps" );
+
resourcePaths.put( CompleteDataSetRegistrations.class, "completeDataSetRegistrations" );
resourcePaths.put( CompleteDataSetRegistration.class, "completeDataSetRegistrations" );
@@ -118,494 +149,17 @@
@Override
public void beforeMarshal( Object source )
{
- if ( source instanceof Charts )
- {
- populateCharts( (Charts) source, true );
- }
- else if ( source instanceof Chart )
- {
- populateChart( (Chart) source, true );
- }
- else if ( source instanceof DataSets )
- {
- populateDataSets( (DataSets) source, true );
- }
- else if ( source instanceof DataSet )
- {
- populateDataSet( (DataSet) source, true );
- }
- else if ( source instanceof OrganisationUnits )
- {
- populateOrganisationUnits( (OrganisationUnits) source, true );
- }
- else if ( source instanceof OrganisationUnit )
- {
- populateOrganisationUnit( (OrganisationUnit) source, true );
- }
- else if ( source instanceof OrganisationUnitGroups )
- {
- populateOrganisationUnitGroups( (OrganisationUnitGroups) source, true );
- }
- else if ( source instanceof OrganisationUnitGroup )
- {
- populateOrganisationUnitGroup( (OrganisationUnitGroup) source, true );
- }
- else if ( source instanceof OrganisationUnitGroupSets )
- {
- populateOrganisationUnitGroupSets( (OrganisationUnitGroupSets) source, true );
- }
- else if ( source instanceof OrganisationUnitGroupSet )
- {
- populateOrganisationUnitGroupSet( (OrganisationUnitGroupSet) source, true );
- }
- else if ( source instanceof Indicators )
- {
- populateIndicators( (Indicators) source, true );
- }
- else if ( source instanceof Indicator )
- {
- populateIndicator( (Indicator) source, true );
- }
- else if ( source instanceof IndicatorGroups )
- {
- populateIndicatorGroups( (IndicatorGroups) source, true );
- }
- else if ( source instanceof IndicatorGroup )
- {
- populateIndicatorGroup( (IndicatorGroup) source, true );
- }
- else if ( source instanceof IndicatorGroupSets )
- {
- populateIndicatorGroupSets( (IndicatorGroupSets) source, true );
- }
- else if ( source instanceof IndicatorGroupSet )
- {
- populateIndicatorGroupSet( (IndicatorGroupSet) source, true );
- }
- else if ( source instanceof DataElements )
- {
- populateDataElements( (DataElements) source, true );
- }
- else if ( source instanceof DataElement )
- {
- populateDataElement( (DataElement) source, true );
- }
- else if ( source instanceof DataElementGroups )
- {
- populateDataElementGroups( (DataElementGroups) source, true );
- }
- else if ( source instanceof DataElementGroup )
- {
- populateDataElementGroup( (DataElementGroup) source, true );
- }
- else if ( source instanceof DataElementGroupSets )
- {
- populateDataElementGroupSets( (DataElementGroupSets) source, true );
- }
- else if ( source instanceof DataElementGroupSet )
- {
- populateDataElementGroupSet( (DataElementGroupSet) source, true );
- }
- else if ( source instanceof DataElementCategories )
- {
- populateDataElementCategories( (DataElementCategories) source, true );
- }
- else if ( source instanceof DataElementCategory )
- {
- populateDataElementCategory( (DataElementCategory) source, true );
- }
- else if ( source instanceof DataElementCategoryCombos )
- {
- populateDataElementCategoryCombos( (DataElementCategoryCombos) source, true );
- }
- else if ( source instanceof DataElementCategoryCombo )
- {
- populateDataElementCategoryCombo( (DataElementCategoryCombo) source, true );
- }
- else if ( source instanceof DataElementCategoryOptions )
- {
- populateDataElementCategoryOptions( (DataElementCategoryOptions) source, true );
- }
- else if ( source instanceof DataElementCategoryOption )
- {
- populateDataElementCategoryOption( (DataElementCategoryOption) source, true );
- }
- else if ( source instanceof DataElementCategoryOptionCombos )
- {
- populateDataElementCategoryOptionCombos( (DataElementCategoryOptionCombos) source, true );
- }
- else if ( source instanceof DataElementCategoryOptionCombo )
- {
- populateDataElementCategoryOptionCombo( (DataElementCategoryOptionCombo) source, true );
- }
- }
-
- private void populateDataElementCategories( DataElementCategories dataElementCategories, boolean root )
- {
- dataElementCategories.setLink( getBasePath( DataElementCategories.class ) );
-
- if ( root )
- {
- for ( DataElementCategory dataElementCategory : dataElementCategories.getDataElementCategories() )
- {
- populateDataElementCategory( dataElementCategory, false );
- }
- }
- }
-
- private void populateDataElementCategory( DataElementCategory dataElementCategory, boolean root )
- {
- dataElementCategory.setLink( getPathWithUid( dataElementCategory ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementCategory.getCategoryOptions() );
- }
- }
-
- private void populateDataElementCategoryCombos( DataElementCategoryCombos dataElementCategoryCombos, boolean root )
- {
- dataElementCategoryCombos.setLink( getBasePath( DataElementCategoryCombos.class ) );
-
- if ( root )
- {
- for ( DataElementCategoryCombo dataElementCategoryCombo : dataElementCategoryCombos.getDataElementCategoryCombos() )
- {
- populateDataElementCategoryCombo( dataElementCategoryCombo, false );
- }
- }
- }
-
- private void populateDataElementCategoryCombo( DataElementCategoryCombo dataElementCategoryCombo, boolean root )
- {
- dataElementCategoryCombo.setLink( getPathWithUid( dataElementCategoryCombo ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementCategoryCombo.getOptionCombos() );
- handleIdentifiableObjectCollection( dataElementCategoryCombo.getCategories() );
- }
- }
-
- private void populateDataElementCategoryOptions( DataElementCategoryOptions dataElementCategoryOptions, boolean root )
- {
- dataElementCategoryOptions.setLink( getBasePath( DataElementCategoryOptions.class ) );
-
- if ( root )
- {
- for ( DataElementCategoryOption dataElementCategoryOption : dataElementCategoryOptions.getDataElementCategoryOptions() )
- {
- populateDataElementCategoryOption( dataElementCategoryOption, false );
- }
- }
- }
-
- private void populateDataElementCategoryOption( DataElementCategoryOption dataElementCategoryOption, boolean root )
- {
- dataElementCategoryOption.setLink( getPathWithUid( dataElementCategoryOption ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementCategoryOption.getCategoryOptionCombos() );
- populateIdentifiableObject( dataElementCategoryOption.getCategory() );
- }
- }
-
- private void populateDataElementCategoryOptionCombos( DataElementCategoryOptionCombos dataElementCategoryOptionCombos, boolean root )
- {
- dataElementCategoryOptionCombos.setLink( getBasePath( DataElementCategoryOptionCombos.class ) );
-
- if ( root )
- {
- for ( DataElementCategoryOptionCombo dataElementCategoryOptionCombo : dataElementCategoryOptionCombos.getDataElementCategoryOptionCombos() )
- {
- populateDataElementCategoryOptionCombo( dataElementCategoryOptionCombo, false );
- }
- }
- }
-
- private void populateDataElementCategoryOptionCombo( DataElementCategoryOptionCombo dataElementCategoryOptionCombo, boolean root )
- {
- dataElementCategoryOptionCombo.setLink( getPathWithUid( dataElementCategoryOptionCombo ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementCategoryOptionCombo.getCategoryOptions() );
- populateIdentifiableObject( dataElementCategoryOptionCombo.getCategoryCombo() );
- }
- }
-
- private void populateDataElements( DataElements dataElements, boolean root )
- {
- dataElements.setLink( getBasePath( DataElements.class ) );
-
- if ( root )
- {
- for ( DataElement dataElement : dataElements.getDataElements() )
- {
- populateDataElement( dataElement, false );
- }
- }
- }
-
- private void populateDataElement( DataElement dataElement, boolean root )
- {
- dataElement.setLink( getPathWithUid( dataElement ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElement.getGroups() );
- handleIdentifiableObjectCollection( dataElement.getDataSets() );
- populateIdentifiableObject( dataElement.getCategoryCombo() );
- }
- }
-
- private void populateDataElementGroups( DataElementGroups dataElementGroups, boolean root )
- {
- dataElementGroups.setLink( getBasePath( DataElementGroups.class ) );
-
- if ( root )
- {
- for ( DataElementGroup dataElementGroup : dataElementGroups.getDataElementGroups() )
- {
- populateDataElementGroup( dataElementGroup, false );
- }
- }
- }
-
- private void populateDataElementGroup( DataElementGroup dataElementGroup, boolean root )
- {
- dataElementGroup.setLink( getPathWithUid( dataElementGroup ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementGroup.getMembers() );
- populateIdentifiableObject( dataElementGroup.getGroupSet() );
- }
- }
-
- private void populateDataElementGroupSets( DataElementGroupSets dataElementGroupSets, boolean root )
- {
- dataElementGroupSets.setLink( getBasePath( DataElementGroupSets.class ) );
-
- if ( root )
- {
- for ( DataElementGroupSet dataElementGroupSet : dataElementGroupSets.getDataElementGroupSets() )
- {
- populateDataElementGroupSet( dataElementGroupSet, false );
- }
- }
- }
-
- private void populateDataElementGroupSet( DataElementGroupSet dataElementGroupSet, boolean root )
- {
- dataElementGroupSet.setLink( getPathWithUid( dataElementGroupSet ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataElementGroupSet.getMembers() );
- }
- }
-
- private void populateIndicators( Indicators indicators, boolean root )
- {
- indicators.setLink( getBasePath( Indicators.class ) );
-
- for ( Indicator indicator : indicators.getIndicators() )
- {
- populateIndicator( indicator, false );
- }
- }
-
- private void populateIndicator( Indicator indicator, boolean root )
- {
- indicator.setLink( getPathWithUid( indicator ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( indicator.getGroups() );
- handleIdentifiableObjectCollection( indicator.getDataSets() );
- }
- }
-
- private void populateIndicatorGroups( IndicatorGroups indicatorGroups, boolean root )
- {
- indicatorGroups.setLink( getBasePath( IndicatorGroups.class ) );
-
- for ( IndicatorGroup indicatorGroup : indicatorGroups.getIndicatorGroups() )
- {
- populateIndicatorGroup( indicatorGroup, false );
- }
- }
-
- private void populateIndicatorGroup( IndicatorGroup indicatorGroup, boolean root )
- {
- indicatorGroup.setLink( getPathWithUid( indicatorGroup ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( indicatorGroup.getMembers() );
- populateIdentifiableObject( indicatorGroup.getGroupSet() );
- }
- }
-
- private void populateIndicatorGroupSets( IndicatorGroupSets indicatorGroupSets, boolean root )
- {
- indicatorGroupSets.setLink( getBasePath( IndicatorGroupSets.class ) );
-
- for ( IndicatorGroupSet indicatorGroupSet : indicatorGroupSets.getIndicatorGroupSets() )
- {
- populateIndicatorGroupSet( indicatorGroupSet, false );
- }
- }
-
- private void populateIndicatorGroupSet( IndicatorGroupSet indicatorGroupSet, boolean root )
- {
- indicatorGroupSet.setLink( getPathWithUid( indicatorGroupSet ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( indicatorGroupSet.getMembers() );
- }
- }
-
- private void populateOrganisationUnitGroups( OrganisationUnitGroups organisationUnitGroups, boolean root )
- {
- organisationUnitGroups.setLink( getBasePath( OrganisationUnitGroups.class ) );
-
- if ( root )
- {
- for ( OrganisationUnitGroup organisationUnitGroup : organisationUnitGroups.getOrganisationUnitGroups() )
- {
- populateOrganisationUnitGroup( organisationUnitGroup, false );
- }
- }
- }
-
- private void populateOrganisationUnitGroup( OrganisationUnitGroup organisationUnitGroup, boolean root )
- {
- organisationUnitGroup.setLink( getPathWithUid( organisationUnitGroup ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( organisationUnitGroup.getMembers() );
- populateIdentifiableObject( organisationUnitGroup.getGroupSet() );
- }
- }
-
- private void populateOrganisationUnitGroupSets( OrganisationUnitGroupSets organisationUnitGroupSets, boolean root )
- {
- organisationUnitGroupSets.setLink( getBasePath( OrganisationUnitGroupSets.class ) );
-
- if ( root )
- {
- for ( OrganisationUnitGroupSet organisationUnitGroupSet : organisationUnitGroupSets.getOrganisationUnitGroupSets() )
- {
- populateOrganisationUnitGroupSet( organisationUnitGroupSet, false );
- }
- }
- }
-
- private void populateOrganisationUnitGroupSet( OrganisationUnitGroupSet organisationUnitGroupSet, boolean root )
- {
- organisationUnitGroupSet.setLink( getPathWithUid( organisationUnitGroupSet ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( organisationUnitGroupSet.getOrganisationUnitGroups() );
- }
- }
-
- private void populateOrganisationUnits( OrganisationUnits organisationUnits, boolean root )
- {
- organisationUnits.setLink( getBasePath( OrganisationUnits.class ) );
-
- if ( root )
- {
- for ( OrganisationUnit organisationUnit : organisationUnits.getOrganisationUnits() )
- {
- populateOrganisationUnit( organisationUnit, false );
- }
- }
- }
-
- private void populateOrganisationUnit( OrganisationUnit organisationUnit, boolean root )
- {
- organisationUnit.setLink( getPathWithUid( organisationUnit ) );
-
- if ( root )
- {
- populateIdentifiableObject( organisationUnit.getParent() );
- handleIdentifiableObjectCollection( organisationUnit.getDataSets() );
- handleIdentifiableObjectCollection( organisationUnit.getGroups() );
- }
- }
-
- private void populateDataSets( DataSets dataSets, boolean root )
- {
- dataSets.setLink( getBasePath( DataSets.class ) );
-
- if ( root )
- {
- for ( DataSet dataSet : dataSets.getDataSets() )
- {
- populateDataSet( dataSet, false );
- }
- }
- }
-
- private void populateDataSet( DataSet dataSet, boolean root )
- {
- dataSet.setLink( getPathWithUid( dataSet ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( dataSet.getDataElements() );
- handleIdentifiableObjectCollection( dataSet.getIndicators() );
- handleIdentifiableObjectCollection( dataSet.getSources() );
- }
- }
-
- private void populateCharts( Charts charts, boolean root )
- {
- charts.setLink( getBasePath( Chart.class ) );
-
- if ( root )
- {
- for ( Chart chart : charts.getCharts() )
- {
- populateChart( chart, false );
- }
- }
- }
-
- private void populateChart( Chart chart, boolean root )
- {
- chart.setLink( getPathWithUid( chart ) );
-
- if ( root )
- {
- handleIdentifiableObjectCollection( chart.getIndicators() );
- handleIdentifiableObjectCollection( chart.getDataElements() );
- handleIdentifiableObjectCollection( chart.getOrganisationUnits() );
- handleIdentifiableObjectCollection( chart.getAllOrganisationUnits() );
- handleIdentifiableObjectCollection( chart.getDataSets() );
- handleIdentifiableObjectCollection( chart.getPeriods() );
- handleIdentifiableObjectCollection( chart.getAllPeriods() );
- }
- }
-
- public void handleIdentifiableObjectCollection( Collection<? extends BaseIdentifiableObject> identifiableObjects )
- {
- for ( BaseIdentifiableObject baseIdentifiableObject : identifiableObjects )
- {
- populateIdentifiableObject( baseIdentifiableObject );
- }
- }
-
- private void populateIdentifiableObject( BaseIdentifiableObject baseIdentifiableObject )
- {
- baseIdentifiableObject.setLink( getPathWithUid( baseIdentifiableObject ) );
+ if ( source instanceof BaseIdentifiableObject )
+ {
+ BaseIdentifiableObject entity = (BaseIdentifiableObject) source;
+ entity.setLink( getPathWithUid( entity ) );
+ }
+ else if ( source instanceof BaseLinkableObject )
+ {
+ BaseLinkableObject linkable = (BaseLinkableObject) source;
+ linkable.setLink( getBasePath( linkable.getClass() ) );
+ }
+
}
private String getPathWithUid( BaseIdentifiableObject baseIdentifiableObject )
@@ -613,7 +167,7 @@
return getBasePath( baseIdentifiableObject.getClass() ) + "/" + baseIdentifiableObject.getUid();
}
- private String getBasePath( Class clazz )
+ private String getBasePath( Class<?> clazz )
{
if ( rootPath == null )
{
@@ -635,7 +189,8 @@
String resourcePath = resourcePaths.get( clazz );
- // in some cases, the class is a dynamic subclass (usually subclassed with javaassist), so
+ // in some cases, the class is a dynamic subclass (usually subclassed
+ // with javaassist), so
// we need to fetch the superClass instead.
if ( resourcePath == null )
{
@@ -645,19 +200,4 @@
return rootPath + "/" + resourcePath;
}
-
-/*
- private String getCalculatedBasePath()
- {
- String path = request.getRequestURL().toString();
- path = StringUtils.stripFilenameExtension( path );
-
- while ( path.lastIndexOf( "/" ) == path.length() - 1 )
- {
- path = path.substring( 0, path.length() - 1 );
- }
-
- return path;
- }
-*/
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2Utils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2Utils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2Utils.java 2011-12-05 12:21:38 +0000
@@ -0,0 +1,27 @@
+package org.hisp.dhis.api.view;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
+
+import org.hisp.dhis.api.utils.WebLinkPopulatorListener;
+
+public class Jaxb2Utils
+{
+
+ public static Marshaller createMarshaller( Object domainModel, HttpServletRequest request )
+ throws JAXBException, PropertyException
+ {
+ JAXBContext context = JAXBContext.newInstance( domainModel.getClass() );
+
+ Marshaller marshaller = context.createMarshaller();
+ marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, false );
+ marshaller.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" );
+ WebLinkPopulatorListener listener = new WebLinkPopulatorListener( request );
+ marshaller.setListener( listener );
+ return marshaller;
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java 2011-12-03 14:35:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/Jaxb2View.java 2011-12-05 12:21:38 +0000
@@ -27,14 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.springframework.web.servlet.view.AbstractView;
+import java.io.OutputStream;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
-import java.io.OutputStream;
-import java.util.Map;
+
+import org.springframework.web.servlet.view.AbstractView;
/**
* @author mortenoh
@@ -62,10 +62,8 @@
}
OutputStream outputStream = response.getOutputStream();
- JAXBContext context = JAXBContext.newInstance( domainModel.getClass() );
- Marshaller marshaller = context.createMarshaller();
- marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, false );
- marshaller.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" );
+
+ Marshaller marshaller = Jaxb2Utils.createMarshaller( domainModel, request );
marshaller.marshal( domainModel, outputStream );
@@ -77,4 +75,5 @@
"\n<?xml-stylesheet type=\"text/xsl\" href=\"dhis-web-api/xslt/chart.xslt\"?>\n");
*/
}
+
}
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/MapGenerationView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/MapGenerationView.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/MapGenerationView.java 2011-12-05 12:21:38 +0000
@@ -0,0 +1,43 @@
+package org.hisp.dhis.api.view;
+
+import java.awt.image.BufferedImage;
+import java.util.Map;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.mapgeneration.MapGenerationService;
+import org.hisp.dhis.mapping.MapView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
+import org.springframework.web.servlet.view.AbstractView;
+
+public class MapGenerationView
+ extends AbstractView
+{
+
+ @Autowired
+ MapGenerationService mapGenerationService;
+
+ public MapGenerationView()
+ {
+ super();
+ setContentType( "image/png" );
+ }
+
+ @Override
+ protected void renderMergedOutputModel( Map<String, Object> model, HttpServletRequest request,
+ HttpServletResponse response )
+ throws Exception
+ {
+ MapView mapView = (MapView) model.get( "model" );
+ BufferedImage image = mapGenerationService.generateMapImage( new org.hisp.dhis.mapgeneration.Map( mapView ) );
+
+ response.setContentType( MediaType.IMAGE_PNG.toString() );
+ ImageIO.write( image, "PNG", response.getOutputStream() );
+
+
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java 2011-12-03 14:35:34 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java 2011-12-05 12:21:38 +0000
@@ -27,18 +27,18 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import org.springframework.web.servlet.view.AbstractUrlBasedView;
+import java.io.OutputStream;
+import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
import javax.xml.bind.util.JAXBSource;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
-import java.io.OutputStream;
-import java.util.Map;
+
+import org.springframework.web.servlet.view.AbstractUrlBasedView;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -66,13 +66,13 @@
// TODO throw exception
}
- JAXBContext context = JAXBContext.newInstance( domainModel.getClass() );
- Marshaller marshaller = context.createMarshaller();
- marshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, false );
- marshaller.setProperty( Marshaller.JAXB_ENCODING, "UTF-8" );
-
- Source xmlSource = new JAXBSource( context, domainModel );
-
+
+ Marshaller marshaller = Jaxb2Utils.createMarshaller( domainModel, request );
+
+ Source xmlSource = new JAXBSource( marshaller, domainModel );
+
+
+
Transformer transformer = TransformCacheImpl.instance().getHtmlTransformer();
OutputStream output = response.getOutputStream();
@@ -90,4 +90,5 @@
transformer.transform( xmlSource, new StreamResult( output ) );
}
+
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2011-11-28 18:15:52 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2011-12-05 12:21:38 +0000
@@ -20,6 +20,7 @@
<entry key="xml" value="application/xml" />
<entry key="pdf" value="application/pdf" />
<entry key="html" value="text/html" />
+ <entry key="png" value="image/png" />
</map>
</property>
@@ -33,6 +34,7 @@
<bean class="org.hisp.dhis.api.view.Jaxb2View" />
+ <bean name="mapGenerationView" class="org.hisp.dhis.api.view.MapGenerationView" />
</list>
</property>
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/list.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/list.xsl 2011-12-02 20:35:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/list.xsl 2011-12-05 12:21:38 +0000
@@ -4,7 +4,7 @@
<xsl:include href="identifiable-row.xsl"/>
<!-- match all plural elements -->
- <xsl:template match="charts|dataElements|indicators|organisationUnits|categories|categoryCombos|categoryOptions|dataElementGroups|dataElementGroupSets">
+ <xsl:template match="maps|charts|dataElements|indicators|organisationUnits|categories|categoryCombos|categoryOptions|dataElementGroups|dataElementGroupSets">
<xsl:variable name="elements" select="local-name()" />
<h3>
<xsl:value-of select="$elements"/>
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/map.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/map.xsl 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/map.xsl 2011-12-05 12:21:38 +0000
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+ <xsl:template match="map">
+ <div class="map">
+ <h2>Map <xsl:value-of select="@name"/></h2>
+ <table border="1">
+ <tr>
+ <td>Map rendering</td>
+ <td>
+ <a href="{@link}.png">PNG</a>
+ </td>
+ </tr>
+ <tr>
+ <td>ID</td>
+ <td>
+ <xsl:value-of select="@id"/>
+ </td>
+ </tr>
+ <tr>
+ <td>Last Updated</td>
+ <td>
+ <xsl:value-of select="@lastUpdated"/>
+ </td>
+ </tr>
+ </table>
+
+ </div>
+ </xsl:template>
+
+</xsl:stylesheet>
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/model2html.xsl'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/model2html.xsl 2011-12-02 20:35:16 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/templates/xslt/model2html.xsl 2011-12-05 12:21:38 +0000
@@ -11,6 +11,7 @@
<xsl:include href="list.xsl"/>
<!-- for rendering elements -->
+ <xsl:include href="map.xsl"/>
<xsl:include href="chart.xsl"/>
<xsl:include href="dataElement.xsl"/>
<xsl:include href="indicator.xsl"/>