=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DashboardContentXmlAdapter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DashboardContentXmlAdapter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/DashboardContentXmlAdapter.java 2011-12-21 14:03:20 +0000 @@ -0,0 +1,62 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.dashboard.DashboardContent; + +import javax.xml.bind.annotation.adapters.XmlAdapter; +import java.util.UUID; + +/** + * @author Morten Olav Hansen + */ +public class DashboardContentXmlAdapter extends XmlAdapter +{ + private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter(); + + @Override + public DashboardContent unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception + { + DashboardContent dashboardContent = new DashboardContent(); + +/* + dashboardContent.setUid( identifiableObject.getUid() ); + dashboardContent.setLastUpdated( identifiableObject.getLastUpdated() ); + dashboardContent.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() ); +*/ + + return dashboardContent; + } + + @Override + public BaseIdentifiableObject marshal( DashboardContent dashboardContent ) throws Exception + { + return null; // baseIdentifiableObjectXmlAdapter.marshal( dashboardContent ); + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContent.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContent.java 2011-04-24 12:47:31 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContent.java 2011-12-21 14:03:20 +0000 @@ -27,71 +27,82 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.ArrayList; -import java.util.List; - +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.Dxf2Namespace; +import org.hisp.dhis.common.adapter.*; import org.hisp.dhis.document.Document; import org.hisp.dhis.mapping.MapView; import org.hisp.dhis.report.Report; import org.hisp.dhis.reporttable.ReportTable; import org.hisp.dhis.user.User; +import javax.xml.bind.annotation.*; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; +import java.util.ArrayList; +import java.util.List; + /** + * it would make sense to make this an idObject, so that we could have nameable (switchable?) + * dashboards, would be great for default content etc. + * * @author Lars Helge Overland - * @version $Id$ */ +@XmlRootElement( name = "dashboardContent", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class DashboardContent { private final static int MAX_DASHBOARD_ELEMENTS = 6; - + private int id; - + private User user; private List reports = new ArrayList(); - + private List documents = new ArrayList(); - + private List reportTables = new ArrayList(); private List mapViews = new ArrayList(); public DashboardContent() - { + { } - + public DashboardContent( User user ) { this.user = user; } - + public int hashCode() { return user.hashCode(); } - + public boolean equals( Object object ) - { + { if ( this == object ) { return true; } - + if ( object == null ) { return false; } - + if ( object.getClass() != getClass() ) { return false; } - + final DashboardContent other = (DashboardContent) object; - + return user.equals( other.user ); } - + // ------------------------------------------------------------------------- // Logic // ------------------------------------------------------------------------- @@ -101,57 +112,59 @@ if ( !reports.contains( report ) ) { reports.add( 0, report ); - + while ( reports.size() > MAX_DASHBOARD_ELEMENTS ) { reports.remove( MAX_DASHBOARD_ELEMENTS ); } } } - + public void addDocument( Document document ) { if ( !documents.contains( document ) ) { documents.add( 0, document ); - + while ( documents.size() > MAX_DASHBOARD_ELEMENTS ) { documents.remove( MAX_DASHBOARD_ELEMENTS ); } } } - + public void addReportTable( ReportTable reportTable ) { if ( !reportTables.contains( reportTable ) ) { reportTables.add( 0, reportTable ); - + while ( reportTables.size() > MAX_DASHBOARD_ELEMENTS ) { reportTables.remove( MAX_DASHBOARD_ELEMENTS ); } } } - + public void addMapView( MapView mapView ) { if ( !mapViews.contains( mapView ) ) { mapViews.add( 0, mapView ); - + while ( mapViews.size() > MAX_DASHBOARD_ELEMENTS ) { mapViews.remove( MAX_DASHBOARD_ELEMENTS ); } } } - + // ------------------------------------------------------------------------- // Getters & setters // ------------------------------------------------------------------------- + @XmlAttribute( name = "internalId" ) + @JsonProperty( value = "internalId" ) public int getId() { return id; @@ -162,6 +175,10 @@ this.id = id; } + @XmlElement( name = "user" ) + @XmlJavaTypeAdapter( UserXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public User getUser() { return user; @@ -172,6 +189,11 @@ this.user = user; } + @XmlElementWrapper( name = "reports" ) + @XmlElement( name = "report" ) + @XmlJavaTypeAdapter( ReportXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getReports() { return reports; @@ -182,6 +204,11 @@ this.reports = reports; } + @XmlElementWrapper( name = "documents" ) + @XmlElement( name = "document" ) + @XmlJavaTypeAdapter( DocumentXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getDocuments() { return documents; @@ -192,6 +219,11 @@ this.documents = documents; } + @XmlElementWrapper( name = "reportTables" ) + @XmlElement( name = "reportTable" ) + @XmlJavaTypeAdapter( ReportTableXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getReportTables() { return reportTables; @@ -202,6 +234,11 @@ this.reportTables = reportTables; } + @XmlElementWrapper( name = "mapViews" ) + @XmlElement( name = "mapView" ) + @XmlJavaTypeAdapter( MapViewXmlAdapter.class ) + @JsonProperty + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) public List getMapViews() { return mapViews; === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContents.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContents.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardContents.java 2011-12-21 14:03:20 +0000 @@ -0,0 +1,61 @@ +package org.hisp.dhis.dashboard; + +/* + * Copyright (c) 2004-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 org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonSerialize; +import org.hisp.dhis.common.BaseCollection; +import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.Dxf2Namespace; + +import javax.xml.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@XmlRootElement( name = "dashboardContents", namespace = Dxf2Namespace.NAMESPACE ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class DashboardContents extends BaseCollection +{ + private List dashboardContents = new ArrayList(); + + @XmlElementWrapper( name = "dashboardContents" ) + @XmlElement( name = "dashboardContent" ) + @JsonProperty( value = "dashboardContents" ) + public List getDashboardContents() + { + return dashboardContents; + } + + public void setDashboardContents( List dashboardContents ) + { + this.dashboardContents = dashboardContents; + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java 2010-04-12 21:23:33 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java 2011-12-21 14:03:20 +0000 @@ -27,10 +27,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.user.User; + import java.util.Collection; -import org.hisp.dhis.user.User; - /** * @author Lars Helge Overland * @version $Id$ @@ -38,10 +38,12 @@ public interface DashboardService { final String ID = DashboardService.class.getName(); - + void saveDashboardContent( DashboardContent dashboardContent ); - + + DashboardContent getDashboardContent( int id ); + DashboardContent getDashboardContent( User user ); - + Collection getAllDashboardContent(); } === modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java' --- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2011-12-09 20:04:48 +0000 +++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2011-12-21 14:03:20 +0000 @@ -27,14 +27,14 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; - import org.hisp.dhis.common.GenericStore; import org.hisp.dhis.dashboard.DashboardContent; import org.hisp.dhis.dashboard.DashboardService; import org.hisp.dhis.user.User; import org.springframework.transaction.annotation.Transactional; +import java.util.Collection; + /** * @author Lars Helge Overland * @version $Id$ @@ -57,19 +57,25 @@ // ------------------------------------------------------------------------- // DashboardService implementation // ------------------------------------------------------------------------- - + public void saveDashboardContent( DashboardContent dashboardContent ) { dashboardContentStore.save( dashboardContent ); } - + + @Override + public DashboardContent getDashboardContent( int id ) + { + return dashboardContentStore.get( id ); + } + public DashboardContent getDashboardContent( User user ) { DashboardContent content = dashboardContentStore.get( user.getId() ); - - return content != null ? content : new DashboardContent( user ); + + return content != null ? content : new DashboardContent( user ); } - + public Collection getAllDashboardContent() { return dashboardContentStore.getAll(); === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardContentController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardContentController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardContentController.java 2011-12-21 14:03:20 +0000 @@ -0,0 +1,148 @@ +package org.hisp.dhis.api.controller; + +/* + * Copyright (c) 2004-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 org.hisp.dhis.api.utils.IdentifiableObjectParams; +import org.hisp.dhis.dashboard.DashboardContent; +import org.hisp.dhis.dashboard.DashboardContents; +import org.hisp.dhis.dashboard.DashboardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.HttpRequestMethodNotSupportedException; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.InputStream; +import java.util.ArrayList; + +/** + * @author Morten Olav Hansen + */ +@Controller +@RequestMapping( value = DashboardContentController.RESOURCE_PATH ) +public class DashboardContentController +{ + public static final String RESOURCE_PATH = "/dashboardContents"; + + @Autowired + private DashboardService dashboardService; + + //------------------------------------------------------------------------------------------------------- + // GET + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.GET ) + public String getDashboardContents( IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + DashboardContents dashboardContents = new DashboardContents(); + dashboardContents.setDashboardContents( new ArrayList( dashboardService.getAllDashboardContent() ) ); + + /* + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( dashboardContents ); + } + */ + + model.addAttribute( "model", dashboardContents ); + + return "dashboardContents"; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public String getDashboardContent( @PathVariable( "uid" ) int id, IdentifiableObjectParams params, Model model, HttpServletRequest request ) + { + DashboardContent dashboardContent = dashboardService.getDashboardContent( id ); + + /* + if ( params.hasLinks() ) + { + WebLinkPopulator listener = new WebLinkPopulator( request ); + listener.addLinks( dashboardContent ); + } + */ + + model.addAttribute( "model", dashboardContent ); + + return "dashboardContent"; + } + + //------------------------------------------------------------------------------------------------------- + // POST + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postDashboardContentXML( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.CREATED ) + public void postDashboardContentJSON( HttpServletResponse response, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // PUT + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putDashboardContentXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void putDashboardContentJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); + } + + //------------------------------------------------------------------------------------------------------- + // DELETE + //------------------------------------------------------------------------------------------------------- + + @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) + @ResponseStatus( value = HttpStatus.NO_CONTENT ) + public void deleteDashboardContent( @PathVariable( "uid" ) String uid ) throws Exception + { + throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); + } +}