=== added directory 'dhis-2/dhis-web/dhis-web-api' === added file 'dhis-2/dhis-web/dhis-web-api/pom.xml' --- dhis-2/dhis-web/dhis-web-api/pom.xml 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/pom.xml 2011-11-02 11:14:35 +0000 @@ -0,0 +1,42 @@ + + 4.0.0 + + + org.hisp.dhis + dhis-web + 2.6-SNAPSHOT + + + dhis-web-api + war + DHIS Web API + + + dhis-web-api + + + + + org.hisp.dhis + dhis-web-commons + + + org.hisp.dhis + dhis-web-commons-resources + war + + + org.hisp.dhis + dhis-service-core + + + org.springframework + spring-webmvc + + + + + ../../ + + === added directory 'dhis-2/dhis-web/dhis-web-api/src' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller' === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndexController.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,18 @@ +package org.hisp.dhis.api.controller; + +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.ResponseBody; + +@Controller +@RequestMapping( value = "/" ) +public class IndexController +{ + @RequestMapping( method = RequestMethod.GET ) + @ResponseBody + public String index() + { + return "Nothing to see here yet."; + } +} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 2011-09-16 10:22:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/HtmlPromotingUriConnegFilter.java 1970-01-01 00:00:00 +0000 @@ -1,95 +0,0 @@ -package org.hisp.dhis.web.api; - -import java.util.HashMap; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -import com.sun.jersey.api.container.filter.UriConnegFilter; -import com.sun.jersey.spi.container.ContainerRequest; - -public class HtmlPromotingUriConnegFilter - extends UriConnegFilter -{ - private static final String ACCEPT = "Accept"; - - private static Map mediaExtentions; - - static - { - mediaExtentions = new HashMap(); - mediaExtentions.put( "xml", MediaType.APPLICATION_XML_TYPE ); - mediaExtentions.put( "html", MediaType.TEXT_HTML_TYPE ); - mediaExtentions.put( "json", MediaType.APPLICATION_JSON_TYPE ); - mediaExtentions.put( "jsonp", new MediaType( "application", "javascript" ) ); - } - - public HtmlPromotingUriConnegFilter() - { - super( mediaExtentions ); - } - - @Override - public ContainerRequest filter( ContainerRequest request ) - { - String accept = request.getHeaderValue( ACCEPT ); - - if ( accept == null || accept.trim().isEmpty() ) - { - request.getRequestHeaders().putSingle( ACCEPT, MediaType.TEXT_HTML ); - } - else - { - accept = preferHtml( accept ); - request.getRequestHeaders().putSingle( ACCEPT, accept ); - } - - request = super.filter( request ); - - return request; - } - - public static String preferHtml( String accept ) - { - int i = accept.indexOf( "text/html" ); - - if ( i == -1 ) - { - if ( accept.trim().equals( "" ) ) - { - return "text/html"; - } - return "text/html," + accept; - } - - int start = accept.substring( 0, i ).lastIndexOf( ',' ); - - String result = ""; - - if ( start != -1 ) - { - result = accept.substring( 0, start ); - } - - int end = accept.indexOf( ',', i ); - - if ( end != -1 ) - { - if ( result.equals( "" ) ) - { - result = accept.substring( end + 1 ); - } - else - { - result = result + accept.substring( end ); - } - } - - if ( result.trim().equals( "" ) ) - { - return "text/html"; - } - - return "text/html," + result; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/ResponseUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/ResponseUtils.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/ResponseUtils.java 1970-01-01 00:00:00 +0000 @@ -1,31 +0,0 @@ -package org.hisp.dhis.web.api; - -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.ResponseBuilder; - -import org.hisp.dhis.system.util.DateUtils; - -public class ResponseUtils -{ - public static final String TEMPLATE_PATH = "dhis-web-api/"; - - public static ResponseBuilder response( boolean disallowCache, - String filename, boolean attachment ) - { - ResponseBuilder builder = Response.ok(); - - if ( disallowCache ) - { - builder.header( "Cache-Control", "no-cache" ); - builder.header( "Expires", DateUtils.getExpiredHttpDateString() ); - } - - if ( filename != null ) - { - String type = attachment ? "attachment" : "inline"; - builder.header( "Content-Disposition", type + "; filename=\"" + filename + "\"" ); - } - - return builder; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java 2011-09-12 08:29:53 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/UrlResourceListener.java 1970-01-01 00:00:00 +0000 @@ -1,83 +0,0 @@ -package org.hisp.dhis.web.api; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.Marshaller.Listener; - -import org.hisp.dhis.importexport.dxf2.model.DataSet; -import org.hisp.dhis.importexport.dxf2.model.DataSetLinks; -import org.hisp.dhis.importexport.dxf2.model.Link; -import org.hisp.dhis.importexport.dxf2.model.OrgUnit; -import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks; - -public class UrlResourceListener - extends Listener -{ - private UriInfo uriInfo; - - private Map, String> mapping; - - public UrlResourceListener( UriInfo uriInfo ) - { - super(); - this.uriInfo = uriInfo; - - mapping = new HashMap, String>(); - mapping.put( OrgUnit.class, "orgUnits/{id}" ); - mapping.put( DataSet.class, "dataSets/{id}" ); - } - - @Override - public void beforeMarshal( Object source ) - { - if ( source instanceof DataSet ) - { - addUrls( ((DataSet) source).getOrgUnitLinks(), OrgUnit.class ); - } - else if ( source instanceof DataSetLinks ) - { - addUrls( ((DataSetLinks) source).getDataSet(), DataSet.class ); - } - else if ( source instanceof OrgUnit ) - { - OrgUnit unit = (OrgUnit) source; - addUrls( unit.getChildren(), OrgUnit.class ); - addUrl( unit.getParent(), OrgUnit.class ); - addUrls( unit.getDataSets(), DataSet.class ); - } - else if ( source instanceof OrgUnitLinks ) - { - addUrls( ((OrgUnitLinks) source).getOrgUnit(), OrgUnit.class ); - } - } - - private void addUrls( List links, Class clazz ) - { - if ( links == null ) - { - return; - } - - for ( Link link : links ) - { - addUrl( link, clazz ); - } - } - - private void addUrl( Link link, Class clazz ) - { - if ( link == null ) - { - return; - } - - String id = link.getId(); - String path = mapping.get( clazz ); - String url = uriInfo.getBaseUriBuilder().path( path ).build( id ).toString(); - - link.setHref( url ); - } -} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java 2011-09-12 08:29:53 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/action/ImportDataValueAction.java 1970-01-01 00:00:00 +0000 @@ -1,222 +0,0 @@ -package org.hisp.dhis.web.api.action; - -/* - * Copyright (c) 2004-2010, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Date; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.struts2.ServletActionContext; -import org.apache.struts2.interceptor.ServletRequestAware; -import org.apache.struts2.interceptor.ServletResponseAware; -import org.hisp.dhis.dataelement.DataElement; -import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; -import org.hisp.dhis.dataelement.DataElementCategoryService; -import org.hisp.dhis.dataelement.DataElementService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.patientdatavalue.PatientDataValue; -import org.hisp.dhis.patientdatavalue.PatientDataValueService; -import org.hisp.dhis.program.ProgramStageInstance; -import org.hisp.dhis.program.ProgramStageInstanceService; - -import com.opensymphony.xwork2.Action; - -public class ImportDataValueAction - implements ServletRequestAware, ServletResponseAware, Action -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private ProgramStageInstanceService programStageInstanceService; - - private PatientDataValueService patientDataValueService; - - private DataElementService dataElementService; - - private HttpServletRequest request; - - private HttpServletResponse response; - - private OrganisationUnitService orgUnitService; - - private DataElementCategoryService dataElementCategoryService; - - // ------------------------------------------------------------------------- - // Set and get methods - // ------------------------------------------------------------------------- - - @Override - public void setServletResponse( HttpServletResponse response ) - { - this.response = response; - } - - @Override - public void setServletRequest( HttpServletRequest request ) - { - this.request = request; - } - - public HttpServletRequest getServletRequest() - { - return request; - } - - public HttpServletResponse getServletResponse() - { - return response; - } - - public ProgramStageInstanceService getProgramStageInstanceService() - { - return programStageInstanceService; - } - - public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService ) - { - this.programStageInstanceService = programStageInstanceService; - } - - public PatientDataValueService getPatientDataValueService() - { - return patientDataValueService; - } - - public void setPatientDataValueService( PatientDataValueService patientDataValueService ) - { - this.patientDataValueService = patientDataValueService; - } - - public DataElementService getDataElementService() - { - return dataElementService; - } - - public void setDataElementService( DataElementService dataElementService ) - { - this.dataElementService = dataElementService; - } - - public OrganisationUnitService getOrgUnitService() - { - return orgUnitService; - } - - public void setOrgUnitService( OrganisationUnitService orgUnitService ) - { - this.orgUnitService = orgUnitService; - } - - public DataElementCategoryService getDataElementCategoryService() - { - return dataElementCategoryService; - } - - public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) - { - this.dataElementCategoryService = dataElementCategoryService; - } - - // ------------------------------------------------------------------------- - // Output - // ------------------------------------------------------------------------- - - private InputStream inputStream; - - public InputStream getInputStream() - { - return inputStream; - } - - public void setInputStream( InputStream inputStream ) - { - this.inputStream = inputStream; - } - - // ------------------------------------------------------------------------- - // Action implementation - // ------------------------------------------------------------------------- - - @Override - public String execute() - throws Exception - { - String message = "Upload Successfully!"; - request = ServletActionContext.getRequest(); - response = ServletActionContext.getResponse(); - this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); - - InputStream clientInput = request.getInputStream(); - DataInputStream dis = new DataInputStream( clientInput ); - - if ( clientInput.available() > -1 ) - { - int numOfDataValue = dis.readInt(); - OrganisationUnit orgUnit = orgUnitService.getOrganisationUnit( dis.readInt() ); - this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); - try - { - for ( int i = 0; i < numOfDataValue; i++ ) - { - this.saveDataValue( dis, orgUnit ); - } - } - catch ( Exception ex ) - { - message = "Upload failed!"; - this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); - } - } - - return SUCCESS; - } - - private void saveDataValue( DataInputStream dis, OrganisationUnit orgUnit ) - throws IOException - { - DataElement dataElement = dataElementService.getDataElement( dis.readInt() ); - ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( dis.readInt() ); - DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( 1 ); - - PatientDataValue patientDataValue = new PatientDataValue(); - patientDataValue.setDataElement( dataElement ); - patientDataValue.setOptionCombo( optionCombo ); - patientDataValue.setOrganisationUnit( orgUnit ); - patientDataValue.setProgramStageInstance( programStageInstance ); - patientDataValue.setTimestamp( new Date() ); - patientDataValue.setProvidedByAnotherFacility( false ); - patientDataValue.setValue( dis.readUTF() ); - - patientDataValueService.savePatientDataValue( patientDataValue ); - } -} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/IllegalArgumentExceptionMapper.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/IllegalArgumentExceptionMapper.java 2011-09-12 08:29:53 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/IllegalArgumentExceptionMapper.java 1970-01-01 00:00:00 +0000 @@ -1,21 +0,0 @@ -package org.hisp.dhis.web.api.mapping; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import com.sun.jersey.spi.resource.Singleton; - -@Provider -@Singleton -public class IllegalArgumentExceptionMapper - implements ExceptionMapper -{ - @Override - public Response toResponse( IllegalArgumentException e ) - { - return Response.status( Status.CONFLICT ).entity( "Problem with input: " + e.getMessage() ).type( MediaType.TEXT_PLAIN ).build(); - } -} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ApiResource.java 1970-01-01 00:00:00 +0000 @@ -1,38 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import java.io.IOException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.apache.velocity.exception.MethodInvocationException; -import org.apache.velocity.exception.ParseErrorException; -import org.apache.velocity.exception.ResourceNotFoundException; -import org.hisp.dhis.system.velocity.VelocityManager; -import org.hisp.dhis.web.api.ResponseUtils; -import org.springframework.beans.factory.annotation.Required; - -import com.sun.jersey.api.view.ImplicitProduces; - -@Path( "/" ) -@ImplicitProduces( MediaType.TEXT_HTML ) -public class ApiResource -{ - private VelocityManager velocityManager; - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getDescription() - throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception - { - return velocityManager.render( null, ResponseUtils.TEMPLATE_PATH + "index" ); - } - - @Required - public void setVelocityManager( VelocityManager velocityManager ) - { - this.velocityManager = velocityManager; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 2011-10-23 12:24:24 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ChartResource.java 1970-01-01 00:00:00 +0000 @@ -1,140 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import java.io.IOException; -import java.io.OutputStream; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.StreamingOutput; - -import org.hisp.dhis.chart.Chart; -import org.hisp.dhis.chart.ChartService; -import org.hisp.dhis.i18n.I18nManager; -import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.indicator.IndicatorService; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.system.util.CodecUtils; -import org.hisp.dhis.util.ContextUtils; -import org.hisp.dhis.web.api.ResponseUtils; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; - -@Path( "/chart" ) -public class ChartResource -{ - private ChartService chartService; - - public void setChartService( ChartService chartService ) - { - this.chartService = chartService; - } - - private IndicatorService indicatorService; - - public void setIndicatorService( IndicatorService indicatorService ) - { - this.indicatorService = indicatorService; - } - - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - private I18nManager i18nManager; - - public void setI18nManager( I18nManager manager ) - { - i18nManager = manager; - } - - @GET - @Path( "/{id}/{width}/{height}" ) - @Produces( ContextUtils.CONTENT_TYPE_PNG ) - public Response getChart( @PathParam("id") Integer id, @PathParam("width") final Integer width, @PathParam("height") final Integer height ) - throws Exception - { - final JFreeChart jFreeChart = chartService.getJFreeChart( id, i18nManager.getI18nFormat() ); - - final Chart chart = chartService.getChart( id ); - - final String filename = CodecUtils.filenameEncode( chart.getTitle() + ".png" ); - - return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() - { - @Override - public void write( OutputStream out ) - throws IOException, WebApplicationException - { - ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); - } - } ).build(); - } - - @GET - @Path( "/period/{indicator}/{orgUnit}/{width}/{height}/{title}" ) - @Produces( ContextUtils.CONTENT_TYPE_PNG ) - public Response getPeriodChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid, - @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title ) - throws Exception - { - final Indicator indicator = indicatorService.getIndicator( indicatorUuid ); - - final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); - - if ( indicator == null || unit == null ) - { - return null; - } - - final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" ); - - final JFreeChart jFreeChart = chartService.getJFreePeriodChart( indicator, unit, title, i18nManager.getI18nFormat() ); - - return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() - { - public void write( OutputStream out ) - throws IOException, WebApplicationException - { - ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); - } - } ).build(); - } - - @GET - @Path( "/orgUnit/{indicator}/{orgUnit}/{width}/{height}/{title}" ) - @Produces( ContextUtils.CONTENT_TYPE_PNG ) - public Response getOrganisationUnitChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid, - @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title ) - throws Exception - { - final Indicator indicator = indicatorService.getIndicator( indicatorUuid ); - - final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); - - if ( indicator == null || unit == null ) - { - return null; - } - - final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" ); - - final JFreeChart jFreeChart = chartService.getJFreeOrganisationUnitChart( indicator, unit, title, i18nManager.getI18nFormat() ); - - return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() - { - public void write( OutputStream out ) - throws IOException, WebApplicationException - { - ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); - } - } ).build(); - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetResource.java 1970-01-01 00:00:00 +0000 @@ -1,99 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.dataset.DataSetService; -import org.hisp.dhis.importexport.dxf2.service.DataSetMapper; -import org.hisp.dhis.system.velocity.VelocityManager; -import org.hisp.dhis.web.api.ResponseUtils; -import org.hisp.dhis.web.api.UrlResourceListener; -import org.springframework.beans.factory.annotation.Required; - -import com.sun.jersey.api.json.JSONWithPadding; - -@Path( "dataSets/{uuid}" ) -public class DataSetResource -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataSetService dataSetService; - - @Required - public void setDataSetService( DataSetService dataSetService ) - { - this.dataSetService = dataSetService; - } - - @Required - public void setVelocityManager( VelocityManager velocityManager ) - { - this.velocityManager = velocityManager; - } - - private VelocityManager velocityManager; - - @Context - private UriInfo uriInfo; - - // ------------------------------------------------------------------------- - // Resource Impl - // ------------------------------------------------------------------------- - - @GET - @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) - public org.hisp.dhis.importexport.dxf2.model.DataSet getDataSetXml( @PathParam( "uuid" ) String uuid ) - { - DataSet dataSet = dataSetService.getDataSet( uuid ); - - if ( dataSet == null ) - { - throw new IllegalArgumentException( "No dataset with uuid " + uuid ); - } - - org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet ); - new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet ); - return dxfDataSet; - } - - @GET - @Produces( { "application/javascript" } ) - public JSONWithPadding getDataSet( @PathParam("uuid") String uuid, @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback ) - { - DataSet dataSet = dataSetService.getDataSet( uuid ); - - if ( dataSet == null ) - { - throw new IllegalArgumentException( "No dataset with uuid " + uuid ); - } - - org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet ); - new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet ); - - return new JSONWithPadding( dxfDataSet, callback ); - } - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getDataSet( @PathParam( "uuid" ) String uuid ) - { - DataSet dataSet = dataSetService.getDataSet( uuid ); - - if ( dataSet == null ) - { - throw new IllegalArgumentException( "No dataset with uuid " + uuid ); - } - - return velocityManager.render( dataSet, ResponseUtils.TEMPLATE_PATH + "dataSet" ); - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataSetsResource.java 1970-01-01 00:00:00 +0000 @@ -1,105 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import org.hisp.dhis.dataset.DataSet; -import org.hisp.dhis.dataset.DataSetService; -import org.hisp.dhis.importexport.dxf2.model.DataSetLinks; -import org.hisp.dhis.importexport.dxf2.service.LinkBuilder; -import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl; -import org.hisp.dhis.system.velocity.VelocityManager; -import org.hisp.dhis.util.ContextUtils; -import org.hisp.dhis.web.api.ResponseUtils; -import org.hisp.dhis.web.api.UrlResourceListener; -import org.springframework.beans.factory.annotation.Required; - -import com.sun.jersey.api.json.JSONWithPadding; - -@Path( "dataSets" ) -public class DataSetsResource -{ - // ------------------------------------------------------------------------- - // Dependencies - // ------------------------------------------------------------------------- - - private DataSetService dataSetService; - - @Required - public void setDataSetService( DataSetService dataSetService ) - { - this.dataSetService = dataSetService; - } - - private VelocityManager velocityManager; - - @Required - public void setVelocityManager( VelocityManager velocityManager ) - { - this.velocityManager = velocityManager; - } - - private LinkBuilder linkBuilder = new LinkBuilderImpl(); - - @Context - private UriInfo uriInfo; - - // ------------------------------------------------------------------------- - // Resource Impl - // ------------------------------------------------------------------------- - - @GET - @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) - public DataSetLinks getDataSetLinks() - { - DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) ); - new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks ); - return dataSetLinks; - } - - @GET - @Produces( ContextUtils.CONTENT_TYPE_JAVASCRIPT ) - public JSONWithPadding getDataSets( @QueryParam( "callback" ) @DefaultValue( "callback" ) - String callback ) - { - Collection dataSets = dataSetService.getAllDataSets(); - Map dataSetOutput = new HashMap(); - - List> dataSetsArray = new ArrayList>(); - - for ( DataSet dataSet : dataSets ) - { - Map dataSetMap = new HashMap(); - dataSetMap.put( "id", dataSet.getUuid() ); - dataSetMap.put( "href", uriInfo.getAbsolutePath().toASCIIString() + "/" + dataSet.getUuid() ); - dataSetMap.put( "name", dataSet.getName() ); - - dataSetsArray.add( dataSetMap ); - } - - dataSetOutput.put( "dataSets", dataSetsArray ); - - return new JSONWithPadding( dataSetOutput, callback ); - } - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getDataSetList() - { - DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) ); - new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks ); - return velocityManager.render( dataSetLinks.getDataSet(), ResponseUtils.TEMPLATE_PATH + "dataSets" ); - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DataValueSetsResource.java 1970-01-01 00:00:00 +0000 @@ -1,56 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import java.net.URI; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import org.hisp.dhis.importexport.dxf2.model.DataValueSet; -import org.hisp.dhis.importexport.dxf2.service.DataValueSetService; -import org.hisp.dhis.system.velocity.VelocityManager; -import org.hisp.dhis.web.api.ResponseUtils; -import org.springframework.beans.factory.annotation.Required; - -@Path( "dataValueSets" ) -public class DataValueSetsResource -{ - private DataValueSetService dataValueSetService; - - private VelocityManager velocityManager; - - @Context - private UriInfo uriInfo; - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getDescription() - { - URI uri = uriInfo.getBaseUriBuilder().path( DataSetsResource.class ).build( ); - return velocityManager.render( uri, ResponseUtils.TEMPLATE_PATH + "dataValueSets" ); - } - - @POST - @Consumes( MediaType.APPLICATION_XML ) - public void storeDataValueSet( DataValueSet dataValueSet ) - { - dataValueSetService.saveDataValueSet( dataValueSet ); - } - - @Required - public void setDataValueSetService( DataValueSetService dataValueSetService ) - { - this.dataValueSetService = dataValueSetService; - } - - @Required - public void setVelocityManager( VelocityManager velocityManager ) - { - this.velocityManager = velocityManager; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java 2011-09-12 08:29:53 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/DhisMediaType.java 1970-01-01 00:00:00 +0000 @@ -1,33 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -/* - * Copyright (c) 2004-2010, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -public class DhisMediaType -{ - public static final String DXF = "application/vnd.org.dhis2.dxf"; -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitResource.java 1970-01-01 00:00:00 +0000 @@ -1,78 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -/* - * Copyright (c) 2004-2010, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import org.hisp.dhis.importexport.dxf2.model.OrgUnit; -import org.hisp.dhis.importexport.dxf2.service.OrgUnitMapper; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.web.api.UrlResourceListener; - -@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) -@Consumes( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) -@Path( "/orgUnits/{id}" ) -public class OrgUnitResource -{ - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - @PathParam( "id" ) - private String id; - - @Context - private UriInfo uriInfo; - - @GET - @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) - public OrgUnit getOrgUnit() - { - OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id ); - - if ( unit == null ) - { - return null; - } - - OrgUnit orgUnit = new OrgUnitMapper().get( unit ); - new UrlResourceListener( uriInfo ).beforeMarshal( orgUnit ); - return orgUnit; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/OrgUnitsResource.java 1970-01-01 00:00:00 +0000 @@ -1,60 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.UriInfo; - -import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks; -import org.hisp.dhis.importexport.dxf2.service.LinkBuilder; -import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.system.velocity.VelocityManager; -import org.hisp.dhis.web.api.ResponseUtils; -import org.hisp.dhis.web.api.UrlResourceListener; -import org.springframework.beans.factory.annotation.Required; - -@Path( "orgUnits" ) -public class OrgUnitsResource -{ - private OrganisationUnitService organisationUnitService; - - private VelocityManager velocityManager; - - private LinkBuilder linkBuilder = new LinkBuilderImpl(); - - @Context - private UriInfo uriInfo; - - @GET - @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) - public OrgUnitLinks getOrgUnits() - { - OrgUnitLinks orgUnitLinks = new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) ); - new UrlResourceListener( uriInfo ).beforeMarshal( orgUnitLinks ); - return orgUnitLinks; - } - - @GET - @Produces( MediaType.TEXT_HTML ) - public String getOrgUnitsHtml() - { - OrgUnitLinks orgUnitLinks = new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) ); - new UrlResourceListener( uriInfo ).beforeMarshal( orgUnitLinks ); - return velocityManager.render( orgUnitLinks.getOrgUnit(), ResponseUtils.TEMPLATE_PATH + "orgUnits" ); - } - - @Required - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - @Required - public void setVelocityManager( VelocityManager velocityManager ) - { - this.velocityManager = velocityManager; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java 2011-10-23 13:02:22 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/resources/ReportResource.java 1970-01-01 00:00:00 +0000 @@ -1,82 +0,0 @@ -package org.hisp.dhis.web.api.resources; - -import static java.util.Calendar.MONTH; - -import java.io.IOException; -import java.io.OutputStream; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.StreamingOutput; - -import org.hisp.dhis.i18n.I18nFormat; -import org.hisp.dhis.i18n.I18nManager; -import org.hisp.dhis.organisationunit.OrganisationUnit; -import org.hisp.dhis.organisationunit.OrganisationUnitService; -import org.hisp.dhis.period.Cal; -import org.hisp.dhis.report.Report; -import org.hisp.dhis.report.ReportService; -import org.hisp.dhis.system.util.CodecUtils; -import org.hisp.dhis.util.ContextUtils; -import org.hisp.dhis.web.api.ResponseUtils; - -@Path( "/report/{report}/{orgUnit}" ) -public class ReportResource -{ - private ReportService reportService; - - public void setReportService( ReportService reportService ) - { - this.reportService = reportService; - } - - private OrganisationUnitService organisationUnitService; - - public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) - { - this.organisationUnitService = organisationUnitService; - } - - private I18nManager i18nManager; - - public void setI18nManager( I18nManager manager ) - { - i18nManager = manager; - } - - @GET - @Produces(ContextUtils.CONTENT_TYPE_PDF) - public Response renderReport( @PathParam("report") final Integer reportId, - @PathParam("orgUnit") final String orgUnitUuid ) - throws Exception - { - final Report report = reportService.getReport( reportId ); - - final OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); - - if ( report == null || organisationUnit == null ) - { - return null; - } - - final int organisationUnitId = organisationUnit.getId(); - - final I18nFormat format = i18nManager.getI18nFormat(); - - final String filename = CodecUtils.filenameEncode( report.getName() ) + "." + ReportService.REPORTTYPE_PDF; - - return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() - { - public void write( OutputStream out ) - throws IOException, WebApplicationException - { - reportService.renderReport( out, report, new Cal().now().subtract( MONTH, 1 ).time(), - organisationUnitId, ReportService.REPORTTYPE_PDF, format ); - } - } ).build(); - } -} === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/resources' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis' === added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-11-02 11:14:35 +0000 @@ -0,0 +1,7 @@ + + + + + + === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2011-11-02 11:14:35 +0000 @@ -0,0 +1,14 @@ + + + + + + + + + === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSet.vm' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSet.vm 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSet.vm 1970-01-01 00:00:00 +0000 @@ -1,34 +0,0 @@ - - - -

Data sets available for reporting

-

See the xml version

-

UUID: ${object.id}

-

Period type: ${object.periodType} - ${object.periodType.isoFormat}

- -

Org units reporting data set

- -
    -#foreach( $unit in $object.sources ) -
  • ${unit.name} - ${unit.uuid}
  • -#end -
- -

Data elements in data set

- -
    -#foreach( $dataElement in $object.dataElements ) -
  • ${dataElement.name} - ${dataElement.type} - ${dataElement.uuid} -#set( $optionCombos = $dataElement.categoryCombo.optionCombos ) -#if( $optionCombos && $optionCombos.size() > 0 ) -
      -#foreach( $optionCombo in $optionCombos ) -
    • ${optionCombo.name} - ${optionCombo.uuid}
    • -#end -
    -#end -
  • -#end -
- - \ No newline at end of file === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSets.vm' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSets.vm 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataSets.vm 1970-01-01 00:00:00 +0000 @@ -1,12 +0,0 @@ - - - -

Data sets available for reporting

-

See the xml version

- - - \ No newline at end of file === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataValueSets.vm' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataValueSets.vm 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/dataValueSets.vm 1970-01-01 00:00:00 +0000 @@ -1,14 +0,0 @@ - - - -

This resource is the place to post data value sets. Take a look at the - data sets to see what to post.

- -
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT"
-    dataSet="dataSet UUID"
-    period="periodInIsoFormat"
-    orgUnit="unit UUID">
-    <dataValue dataElement="data element UUID" categoryOptionCombo="UUID, only specify if used" storedBy="string" value="value" />
-    </dataValueSet>
- - \ No newline at end of file === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/index.vm' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/index.vm 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/index.vm 1970-01-01 00:00:00 +0000 @@ -1,26 +0,0 @@ - - - - DHIS2 Web API - - -

DHIS2 Web API

- -

Warning: This API is in no way ready for public consumption. Radical changes must be expected at any time!

- -

The api currently supports a specific pilot use case for posting of data value sets. - -

Posting data value sets

-

To find the needed information about the data sets you want to post data about, go to the data set list.

- -

If you don't want org units listed by data set, there is also the full list of org units

- -

Post according to the following template /api/dataValueSets/

-
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT"
-    dataSet="dataSet UUID"
-    period="periodInIsoFormat"
-    orgUnit="unit UUID">
-    <dataValue dataElement="data element UUID" categoryOptionCombo="UUID, only specify if used" storedBy="string" value="value" />
-    </dataValueSet>
- - \ No newline at end of file === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/orgUnits.vm' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/orgUnits.vm 2011-09-13 11:10:12 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/dhis-web-api/orgUnits.vm 1970-01-01 00:00:00 +0000 @@ -1,12 +0,0 @@ - - - -

Organisation units

-

See the xml version

- - - \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml 2011-11-02 11:14:35 +0000 @@ -0,0 +1,11 @@ + + + + + + + + + === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/webapp' === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF' === added file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2011-11-02 11:14:35 +0000 @@ -0,0 +1,106 @@ + + + + DHIS Web API + + + contextConfigLocation + classpath*:/META-INF/dhis/beans.xml + + + + automaticAccessType + ghostAdmin + + + + RedirectFilter + org.hisp.dhis.servlet.filter.HttpRedirectFilter + + redirectPath + api/ + + + + + OpenSessionInViewFilter + org.springframework.orm.hibernate3.support.OpenSessionInViewFilter + + + + springSecurityFilterChain + org.springframework.web.filter.DelegatingFilterProxy + + + + Struts + org.apache.struts2.dispatcher.FilterDispatcher + + + + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + + RedirectFilter + / + + + + OpenSessionInViewFilter + *.action + + + + springSecurityFilterChain + /* + + + + Struts + *.action + + + + encodingFilter + /* + + + + org.springframework.web.context.ContextLoaderListener + + + + org.hisp.dhis.system.startup.StartupListener + + + + + webapiServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath*:/META-INF/dhis/servlet.xml + + 1 + + + + webapiServlet + /api + + + webapiServlet + /api/* + + === renamed directory 'dhis-2/dhis-web/dhis-web-api' => 'dhis-2/dhis-web/dhis-web-api2' === modified file 'dhis-2/dhis-web/dhis-web-api2/pom.xml' --- dhis-2/dhis-web/dhis-web-api/pom.xml 2011-10-14 16:54:27 +0000 +++ dhis-2/dhis-web/dhis-web-api2/pom.xml 2011-11-02 11:14:35 +0000 @@ -8,12 +8,12 @@ 2.6-SNAPSHOT - dhis-web-api + dhis-web-api2 war - DHIS Web API + DHIS Web API2 - dhis-web-api + dhis-web-api2 @@ -84,3 +84,4 @@ ../../ + === added directory 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2' === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/HtmlPromotingUriConnegFilter.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/HtmlPromotingUriConnegFilter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/HtmlPromotingUriConnegFilter.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,95 @@ +package org.hisp.dhis.web.api2; + +import java.util.HashMap; +import java.util.Map; + +import javax.ws.rs.core.MediaType; + +import com.sun.jersey.api.container.filter.UriConnegFilter; +import com.sun.jersey.spi.container.ContainerRequest; + +public class HtmlPromotingUriConnegFilter + extends UriConnegFilter +{ + private static final String ACCEPT = "Accept"; + + private static Map mediaExtentions; + + static + { + mediaExtentions = new HashMap(); + mediaExtentions.put( "xml", MediaType.APPLICATION_XML_TYPE ); + mediaExtentions.put( "html", MediaType.TEXT_HTML_TYPE ); + mediaExtentions.put( "json", MediaType.APPLICATION_JSON_TYPE ); + mediaExtentions.put( "jsonp", new MediaType( "application", "javascript" ) ); + } + + public HtmlPromotingUriConnegFilter() + { + super( mediaExtentions ); + } + + @Override + public ContainerRequest filter( ContainerRequest request ) + { + String accept = request.getHeaderValue( ACCEPT ); + + if ( accept == null || accept.trim().isEmpty() ) + { + request.getRequestHeaders().putSingle( ACCEPT, MediaType.TEXT_HTML ); + } + else + { + accept = preferHtml( accept ); + request.getRequestHeaders().putSingle( ACCEPT, accept ); + } + + request = super.filter( request ); + + return request; + } + + public static String preferHtml( String accept ) + { + int i = accept.indexOf( "text/html" ); + + if ( i == -1 ) + { + if ( accept.trim().equals( "" ) ) + { + return "text/html"; + } + return "text/html," + accept; + } + + int start = accept.substring( 0, i ).lastIndexOf( ',' ); + + String result = ""; + + if ( start != -1 ) + { + result = accept.substring( 0, start ); + } + + int end = accept.indexOf( ',', i ); + + if ( end != -1 ) + { + if ( result.equals( "" ) ) + { + result = accept.substring( end + 1 ); + } + else + { + result = result + accept.substring( end ); + } + } + + if ( result.trim().equals( "" ) ) + { + return "text/html"; + } + + return "text/html," + result; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/ResponseUtils.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/ResponseUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/ResponseUtils.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,30 @@ +package org.hisp.dhis.web.api2; + +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; + +import org.hisp.dhis.system.util.DateUtils; + +public class ResponseUtils +{ + public static final String TEMPLATE_PATH = "dhis-web-api2/"; + + public static ResponseBuilder response( boolean disallowCache, String filename, boolean attachment ) + { + ResponseBuilder builder = Response.ok(); + + if ( disallowCache ) + { + builder.header( "Cache-Control", "no-cache" ); + builder.header( "Expires", DateUtils.getExpiredHttpDateString() ); + } + + if ( filename != null ) + { + String type = attachment ? "attachment" : "inline"; + builder.header( "Content-Disposition", type + "; filename=\"" + filename + "\"" ); + } + + return builder; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/UrlResourceListener.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/UrlResourceListener.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/UrlResourceListener.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,83 @@ +package org.hisp.dhis.web.api2; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.Marshaller.Listener; + +import org.hisp.dhis.importexport.dxf2.model.DataSet; +import org.hisp.dhis.importexport.dxf2.model.DataSetLinks; +import org.hisp.dhis.importexport.dxf2.model.Link; +import org.hisp.dhis.importexport.dxf2.model.OrgUnit; +import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks; + +public class UrlResourceListener + extends Listener +{ + private UriInfo uriInfo; + + private Map, String> mapping; + + public UrlResourceListener( UriInfo uriInfo ) + { + super(); + this.uriInfo = uriInfo; + + mapping = new HashMap, String>(); + mapping.put( OrgUnit.class, "orgUnits/{id}" ); + mapping.put( DataSet.class, "dataSets/{id}" ); + } + + @Override + public void beforeMarshal( Object source ) + { + if ( source instanceof DataSet ) + { + addUrls( ((DataSet) source).getOrgUnitLinks(), OrgUnit.class ); + } + else if ( source instanceof DataSetLinks ) + { + addUrls( ((DataSetLinks) source).getDataSet(), DataSet.class ); + } + else if ( source instanceof OrgUnit ) + { + OrgUnit unit = (OrgUnit) source; + addUrls( unit.getChildren(), OrgUnit.class ); + addUrl( unit.getParent(), OrgUnit.class ); + addUrls( unit.getDataSets(), DataSet.class ); + } + else if ( source instanceof OrgUnitLinks ) + { + addUrls( ((OrgUnitLinks) source).getOrgUnit(), OrgUnit.class ); + } + } + + private void addUrls( List links, Class clazz ) + { + if ( links == null ) + { + return; + } + + for ( Link link : links ) + { + addUrl( link, clazz ); + } + } + + private void addUrl( Link link, Class clazz ) + { + if ( link == null ) + { + return; + } + + String id = link.getId(); + String path = mapping.get( clazz ); + String url = uriInfo.getBaseUriBuilder().path( path ).build( id ).toString(); + + link.setHref( url ); + } +} === added directory 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/action' === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/action/ImportDataValueAction.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/action/ImportDataValueAction.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/action/ImportDataValueAction.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,222 @@ +package org.hisp.dhis.web.api2.action; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Date; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.interceptor.ServletRequestAware; +import org.apache.struts2.interceptor.ServletResponseAware; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataelement.DataElementCategoryService; +import org.hisp.dhis.dataelement.DataElementService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.patientdatavalue.PatientDataValue; +import org.hisp.dhis.patientdatavalue.PatientDataValueService; +import org.hisp.dhis.program.ProgramStageInstance; +import org.hisp.dhis.program.ProgramStageInstanceService; + +import com.opensymphony.xwork2.Action; + +public class ImportDataValueAction + implements ServletRequestAware, ServletResponseAware, Action +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private ProgramStageInstanceService programStageInstanceService; + + private PatientDataValueService patientDataValueService; + + private DataElementService dataElementService; + + private HttpServletRequest request; + + private HttpServletResponse response; + + private OrganisationUnitService orgUnitService; + + private DataElementCategoryService dataElementCategoryService; + + // ------------------------------------------------------------------------- + // Set and get methods + // ------------------------------------------------------------------------- + + @Override + public void setServletResponse( HttpServletResponse response ) + { + this.response = response; + } + + @Override + public void setServletRequest( HttpServletRequest request ) + { + this.request = request; + } + + public HttpServletRequest getServletRequest() + { + return request; + } + + public HttpServletResponse getServletResponse() + { + return response; + } + + public ProgramStageInstanceService getProgramStageInstanceService() + { + return programStageInstanceService; + } + + public void setProgramStageInstanceService( ProgramStageInstanceService programStageInstanceService ) + { + this.programStageInstanceService = programStageInstanceService; + } + + public PatientDataValueService getPatientDataValueService() + { + return patientDataValueService; + } + + public void setPatientDataValueService( PatientDataValueService patientDataValueService ) + { + this.patientDataValueService = patientDataValueService; + } + + public DataElementService getDataElementService() + { + return dataElementService; + } + + public void setDataElementService( DataElementService dataElementService ) + { + this.dataElementService = dataElementService; + } + + public OrganisationUnitService getOrgUnitService() + { + return orgUnitService; + } + + public void setOrgUnitService( OrganisationUnitService orgUnitService ) + { + this.orgUnitService = orgUnitService; + } + + public DataElementCategoryService getDataElementCategoryService() + { + return dataElementCategoryService; + } + + public void setDataElementCategoryService( DataElementCategoryService dataElementCategoryService ) + { + this.dataElementCategoryService = dataElementCategoryService; + } + + // ------------------------------------------------------------------------- + // Output + // ------------------------------------------------------------------------- + + private InputStream inputStream; + + public InputStream getInputStream() + { + return inputStream; + } + + public void setInputStream( InputStream inputStream ) + { + this.inputStream = inputStream; + } + + // ------------------------------------------------------------------------- + // Action implementation + // ------------------------------------------------------------------------- + + @Override + public String execute() + throws Exception + { + String message = "Upload Successfully!"; + request = ServletActionContext.getRequest(); + response = ServletActionContext.getResponse(); + this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); + + InputStream clientInput = request.getInputStream(); + DataInputStream dis = new DataInputStream( clientInput ); + + if ( clientInput.available() > -1 ) + { + int numOfDataValue = dis.readInt(); + OrganisationUnit orgUnit = orgUnitService.getOrganisationUnit( dis.readInt() ); + this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); + try + { + for ( int i = 0; i < numOfDataValue; i++ ) + { + this.saveDataValue( dis, orgUnit ); + } + } + catch ( Exception ex ) + { + message = "Upload failed!"; + this.setInputStream( new ByteArrayInputStream( message.getBytes() ) ); + } + } + + return SUCCESS; + } + + private void saveDataValue( DataInputStream dis, OrganisationUnit orgUnit ) + throws IOException + { + DataElement dataElement = dataElementService.getDataElement( dis.readInt() ); + ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( dis.readInt() ); + DataElementCategoryOptionCombo optionCombo = dataElementCategoryService.getDataElementCategoryOptionCombo( 1 ); + + PatientDataValue patientDataValue = new PatientDataValue(); + patientDataValue.setDataElement( dataElement ); + patientDataValue.setOptionCombo( optionCombo ); + patientDataValue.setOrganisationUnit( orgUnit ); + patientDataValue.setProgramStageInstance( programStageInstance ); + patientDataValue.setTimestamp( new Date() ); + patientDataValue.setProvidedByAnotherFacility( false ); + patientDataValue.setValue( dis.readUTF() ); + + patientDataValueService.savePatientDataValue( patientDataValue ); + } +} === added directory 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/mapping' === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/mapping/IllegalArgumentExceptionMapper.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/mapping/IllegalArgumentExceptionMapper.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/mapping/IllegalArgumentExceptionMapper.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,22 @@ +package org.hisp.dhis.web.api2.mapping; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import com.sun.jersey.spi.resource.Singleton; + +@Provider +@Singleton +public class IllegalArgumentExceptionMapper + implements ExceptionMapper +{ + @Override + public Response toResponse( IllegalArgumentException e ) + { + return Response.status( Status.CONFLICT ).entity( "Problem with input: " + e.getMessage() ) + .type( MediaType.TEXT_PLAIN ).build(); + } +} === added directory 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources' === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ApiResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ApiResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ApiResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,38 @@ +package org.hisp.dhis.web.api2.resources; + +import java.io.IOException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.velocity.exception.MethodInvocationException; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; +import org.hisp.dhis.system.velocity.VelocityManager; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.springframework.beans.factory.annotation.Required; + +import com.sun.jersey.api.view.ImplicitProduces; + +@Path( "/" ) +@ImplicitProduces( MediaType.TEXT_HTML ) +public class ApiResource +{ + private VelocityManager velocityManager; + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDescription() + throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, Exception + { + return velocityManager.render( null, ResponseUtils.TEMPLATE_PATH + "index" ); + } + + @Required + public void setVelocityManager( VelocityManager velocityManager ) + { + this.velocityManager = velocityManager; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ChartResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ChartResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ChartResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,140 @@ +package org.hisp.dhis.web.api2.resources; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; + +import org.hisp.dhis.chart.Chart; +import org.hisp.dhis.chart.ChartService; +import org.hisp.dhis.i18n.I18nManager; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorService; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.system.util.CodecUtils; +import org.hisp.dhis.util.ContextUtils; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.jfree.chart.ChartUtilities; +import org.jfree.chart.JFreeChart; + +@Path( "/chart" ) +public class ChartResource +{ + private ChartService chartService; + + public void setChartService( ChartService chartService ) + { + this.chartService = chartService; + } + + private IndicatorService indicatorService; + + public void setIndicatorService( IndicatorService indicatorService ) + { + this.indicatorService = indicatorService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + private I18nManager i18nManager; + + public void setI18nManager( I18nManager manager ) + { + i18nManager = manager; + } + + @GET + @Path( "/{id}/{width}/{height}" ) + @Produces( ContextUtils.CONTENT_TYPE_PNG ) + public Response getChart( @PathParam("id") Integer id, @PathParam("width") final Integer width, @PathParam("height") final Integer height ) + throws Exception + { + final JFreeChart jFreeChart = chartService.getJFreeChart( id, i18nManager.getI18nFormat() ); + + final Chart chart = chartService.getChart( id ); + + final String filename = CodecUtils.filenameEncode( chart.getTitle() + ".png" ); + + return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() + { + @Override + public void write( OutputStream out ) + throws IOException, WebApplicationException + { + ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); + } + } ).build(); + } + + @GET + @Path( "/period/{indicator}/{orgUnit}/{width}/{height}/{title}" ) + @Produces( ContextUtils.CONTENT_TYPE_PNG ) + public Response getPeriodChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid, + @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title ) + throws Exception + { + final Indicator indicator = indicatorService.getIndicator( indicatorUuid ); + + final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); + + if ( indicator == null || unit == null ) + { + return null; + } + + final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" ); + + final JFreeChart jFreeChart = chartService.getJFreePeriodChart( indicator, unit, title, i18nManager.getI18nFormat() ); + + return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() + { + public void write( OutputStream out ) + throws IOException, WebApplicationException + { + ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); + } + } ).build(); + } + + @GET + @Path( "/orgUnit/{indicator}/{orgUnit}/{width}/{height}/{title}" ) + @Produces( ContextUtils.CONTENT_TYPE_PNG ) + public Response getOrganisationUnitChart( @PathParam("indicator") String indicatorUuid, @PathParam("orgUnit") String orgUnitUuid, + @PathParam("width") final Integer width, @PathParam("height") final Integer height, @PathParam("title") Boolean title ) + throws Exception + { + final Indicator indicator = indicatorService.getIndicator( indicatorUuid ); + + final OrganisationUnit unit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); + + if ( indicator == null || unit == null ) + { + return null; + } + + final String filename = CodecUtils.filenameEncode( indicator.getName() + ".png" ); + + final JFreeChart jFreeChart = chartService.getJFreeOrganisationUnitChart( indicator, unit, title, i18nManager.getI18nFormat() ); + + return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() + { + public void write( OutputStream out ) + throws IOException, WebApplicationException + { + ChartUtilities.writeChartAsPNG( out, jFreeChart, width, height, true, 0 ); + } + } ).build(); + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,99 @@ +package org.hisp.dhis.web.api2.resources; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.importexport.dxf2.service.DataSetMapper; +import org.hisp.dhis.system.velocity.VelocityManager; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.hisp.dhis.web.api2.UrlResourceListener; +import org.springframework.beans.factory.annotation.Required; + +import com.sun.jersey.api.json.JSONWithPadding; + +@Path( "dataSets/{uuid}" ) +public class DataSetResource +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataSetService dataSetService; + + @Required + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + @Required + public void setVelocityManager( VelocityManager velocityManager ) + { + this.velocityManager = velocityManager; + } + + private VelocityManager velocityManager; + + @Context + private UriInfo uriInfo; + + // ------------------------------------------------------------------------- + // Resource Impl + // ------------------------------------------------------------------------- + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public org.hisp.dhis.importexport.dxf2.model.DataSet getDataSetXml( @PathParam( "uuid" ) String uuid ) + { + DataSet dataSet = dataSetService.getDataSet( uuid ); + + if ( dataSet == null ) + { + throw new IllegalArgumentException( "No dataset with uuid " + uuid ); + } + + org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet ); + new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet ); + return dxfDataSet; + } + + @GET + @Produces( { "application/javascript" } ) + public JSONWithPadding getDataSet( @PathParam("uuid") String uuid, @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback ) + { + DataSet dataSet = dataSetService.getDataSet( uuid ); + + if ( dataSet == null ) + { + throw new IllegalArgumentException( "No dataset with uuid " + uuid ); + } + + org.hisp.dhis.importexport.dxf2.model.DataSet dxfDataSet = new DataSetMapper().convert( dataSet ); + new UrlResourceListener( uriInfo ).beforeMarshal( dxfDataSet ); + + return new JSONWithPadding( dxfDataSet, callback ); + } + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDataSet( @PathParam( "uuid" ) String uuid ) + { + DataSet dataSet = dataSetService.getDataSet( uuid ); + + if ( dataSet == null ) + { + throw new IllegalArgumentException( "No dataset with uuid " + uuid ); + } + + return velocityManager.render( dataSet, ResponseUtils.TEMPLATE_PATH + "dataSet" ); + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetsResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetsResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataSetsResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,105 @@ +package org.hisp.dhis.web.api2.resources; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.importexport.dxf2.model.DataSetLinks; +import org.hisp.dhis.importexport.dxf2.service.LinkBuilder; +import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl; +import org.hisp.dhis.system.velocity.VelocityManager; +import org.hisp.dhis.util.ContextUtils; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.hisp.dhis.web.api2.UrlResourceListener; +import org.springframework.beans.factory.annotation.Required; + +import com.sun.jersey.api.json.JSONWithPadding; + +@Path( "dataSets" ) +public class DataSetsResource +{ + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + private DataSetService dataSetService; + + @Required + public void setDataSetService( DataSetService dataSetService ) + { + this.dataSetService = dataSetService; + } + + private VelocityManager velocityManager; + + @Required + public void setVelocityManager( VelocityManager velocityManager ) + { + this.velocityManager = velocityManager; + } + + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + @Context + private UriInfo uriInfo; + + // ------------------------------------------------------------------------- + // Resource Impl + // ------------------------------------------------------------------------- + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public DataSetLinks getDataSetLinks() + { + DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) ); + new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks ); + return dataSetLinks; + } + + @GET + @Produces( ContextUtils.CONTENT_TYPE_JAVASCRIPT ) + public JSONWithPadding getDataSets( @QueryParam( "callback" ) @DefaultValue( "callback" ) + String callback ) + { + Collection dataSets = dataSetService.getAllDataSets(); + Map dataSetOutput = new HashMap(); + + List> dataSetsArray = new ArrayList>(); + + for ( DataSet dataSet : dataSets ) + { + Map dataSetMap = new HashMap(); + dataSetMap.put( "id", dataSet.getUuid() ); + dataSetMap.put( "href", uriInfo.getAbsolutePath().toASCIIString() + "/" + dataSet.getUuid() ); + dataSetMap.put( "name", dataSet.getName() ); + + dataSetsArray.add( dataSetMap ); + } + + dataSetOutput.put( "dataSets", dataSetsArray ); + + return new JSONWithPadding( dataSetOutput, callback ); + } + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDataSetList() + { + DataSetLinks dataSetLinks = new DataSetLinks( linkBuilder.getLinks( dataSetService.getAllDataSets() ) ); + new UrlResourceListener( uriInfo ).beforeMarshal( dataSetLinks ); + return velocityManager.render( dataSetLinks.getDataSet(), ResponseUtils.TEMPLATE_PATH + "dataSets" ); + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataValueSetsResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataValueSetsResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DataValueSetsResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,56 @@ +package org.hisp.dhis.web.api2.resources; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.importexport.dxf2.model.DataValueSet; +import org.hisp.dhis.importexport.dxf2.service.DataValueSetService; +import org.hisp.dhis.system.velocity.VelocityManager; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.springframework.beans.factory.annotation.Required; + +@Path( "dataValueSets" ) +public class DataValueSetsResource +{ + private DataValueSetService dataValueSetService; + + private VelocityManager velocityManager; + + @Context + private UriInfo uriInfo; + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDescription() + { + URI uri = uriInfo.getBaseUriBuilder().path( DataSetsResource.class ).build( ); + return velocityManager.render( uri, ResponseUtils.TEMPLATE_PATH + "dataValueSets" ); + } + + @POST + @Consumes( MediaType.APPLICATION_XML ) + public void storeDataValueSet( DataValueSet dataValueSet ) + { + dataValueSetService.saveDataValueSet( dataValueSet ); + } + + @Required + public void setDataValueSetService( DataValueSetService dataValueSetService ) + { + this.dataValueSetService = dataValueSetService; + } + + @Required + public void setVelocityManager( VelocityManager velocityManager ) + { + this.velocityManager = velocityManager; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DhisMediaType.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DhisMediaType.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/DhisMediaType.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,33 @@ +package org.hisp.dhis.web.api2.resources; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +public class DhisMediaType +{ + public static final String DXF = "application/vnd.org.dhis2.dxf"; +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,78 @@ +package org.hisp.dhis.web.api2.resources; + +/* + * Copyright (c) 2004-2010, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.importexport.dxf2.model.OrgUnit; +import org.hisp.dhis.importexport.dxf2.service.OrgUnitMapper; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.web.api2.UrlResourceListener; + +@Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) +@Consumes( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) +@Path( "/orgUnits/{id}" ) +public class OrgUnitResource +{ + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + @PathParam( "id" ) + private String id; + + @Context + private UriInfo uriInfo; + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public OrgUnit getOrgUnit() + { + OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id ); + + if ( unit == null ) + { + return null; + } + + OrgUnit orgUnit = new OrgUnitMapper().get( unit ); + new UrlResourceListener( uriInfo ).beforeMarshal( orgUnit ); + return orgUnit; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitsResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitsResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/OrgUnitsResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,60 @@ +package org.hisp.dhis.web.api2.resources; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.importexport.dxf2.model.OrgUnitLinks; +import org.hisp.dhis.importexport.dxf2.service.LinkBuilder; +import org.hisp.dhis.importexport.dxf2.service.LinkBuilderImpl; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.system.velocity.VelocityManager; +import org.hisp.dhis.web.api2.ResponseUtils; +import org.hisp.dhis.web.api2.UrlResourceListener; +import org.springframework.beans.factory.annotation.Required; + +@Path( "orgUnits" ) +public class OrgUnitsResource +{ + private OrganisationUnitService organisationUnitService; + + private VelocityManager velocityManager; + + private LinkBuilder linkBuilder = new LinkBuilderImpl(); + + @Context + private UriInfo uriInfo; + + @GET + @Produces( { MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON } ) + public OrgUnitLinks getOrgUnits() + { + OrgUnitLinks orgUnitLinks = new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) ); + new UrlResourceListener( uriInfo ).beforeMarshal( orgUnitLinks ); + return orgUnitLinks; + } + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getOrgUnitsHtml() + { + OrgUnitLinks orgUnitLinks = new OrgUnitLinks( linkBuilder.getLinks( organisationUnitService.getAllOrganisationUnits() ) ); + new UrlResourceListener( uriInfo ).beforeMarshal( orgUnitLinks ); + return velocityManager.render( orgUnitLinks.getOrgUnit(), ResponseUtils.TEMPLATE_PATH + "orgUnits" ); + } + + @Required + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + @Required + public void setVelocityManager( VelocityManager velocityManager ) + { + this.velocityManager = velocityManager; + } +} === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ReportResource.java' --- dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ReportResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/java/org/hisp/dhis/web/api2/resources/ReportResource.java 2011-11-02 11:14:35 +0000 @@ -0,0 +1,82 @@ +package org.hisp.dhis.web.api2.resources; + +import static java.util.Calendar.MONTH; + +import java.io.IOException; +import java.io.OutputStream; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; + +import org.hisp.dhis.i18n.I18nFormat; +import org.hisp.dhis.i18n.I18nManager; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.hisp.dhis.organisationunit.OrganisationUnitService; +import org.hisp.dhis.period.Cal; +import org.hisp.dhis.report.Report; +import org.hisp.dhis.report.ReportService; +import org.hisp.dhis.system.util.CodecUtils; +import org.hisp.dhis.util.ContextUtils; +import org.hisp.dhis.web.api2.ResponseUtils; + +@Path( "/report/{report}/{orgUnit}" ) +public class ReportResource +{ + private ReportService reportService; + + public void setReportService( ReportService reportService ) + { + this.reportService = reportService; + } + + private OrganisationUnitService organisationUnitService; + + public void setOrganisationUnitService( OrganisationUnitService organisationUnitService ) + { + this.organisationUnitService = organisationUnitService; + } + + private I18nManager i18nManager; + + public void setI18nManager( I18nManager manager ) + { + i18nManager = manager; + } + + @GET + @Produces(ContextUtils.CONTENT_TYPE_PDF) + public Response renderReport( @PathParam("report") final Integer reportId, + @PathParam("orgUnit") final String orgUnitUuid ) + throws Exception + { + final Report report = reportService.getReport( reportId ); + + final OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit( orgUnitUuid ); + + if ( report == null || organisationUnit == null ) + { + return null; + } + + final int organisationUnitId = organisationUnit.getId(); + + final I18nFormat format = i18nManager.getI18nFormat(); + + final String filename = CodecUtils.filenameEncode( report.getName() ) + "." + ReportService.REPORTTYPE_PDF; + + return ResponseUtils.response( true, filename, false ).entity( new StreamingOutput() + { + public void write( OutputStream out ) + throws IOException, WebApplicationException + { + reportService.renderReport( out, report, new Cal().now().subtract( MONTH, 1 ).time(), + organisationUnitId, ReportService.REPORTTYPE_PDF, format ); + } + } ).build(); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/beans.xml 2011-10-07 10:08:02 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/META-INF/dhis/beans.xml 2011-11-02 11:14:35 +0000 @@ -5,39 +5,39 @@ - + - - - - - - - - - - - + + + + + + + + + + + - - - @@ -45,7 +45,7 @@ - @@ -58,7 +58,7 @@ - + === added directory 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2' === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSet.vm' --- dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSet.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSet.vm 2011-11-02 11:14:35 +0000 @@ -0,0 +1,34 @@ + + + +

Data sets available for reporting

+

See the xml version

+

UUID: ${object.id}

+

Period type: ${object.periodType} - ${object.periodType.isoFormat}

+ +

Org units reporting data set

+ +
    +#foreach( $unit in $object.sources ) +
  • ${unit.name} - ${unit.uuid}
  • +#end +
+ +

Data elements in data set

+ +
    +#foreach( $dataElement in $object.dataElements ) +
  • ${dataElement.name} - ${dataElement.type} - ${dataElement.uuid} +#set( $optionCombos = $dataElement.categoryCombo.optionCombos ) +#if( $optionCombos && $optionCombos.size() > 0 ) +
      +#foreach( $optionCombo in $optionCombos ) +
    • ${optionCombo.name} - ${optionCombo.uuid}
    • +#end +
    +#end +
  • +#end +
+ + \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSets.vm' --- dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSets.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataSets.vm 2011-11-02 11:14:35 +0000 @@ -0,0 +1,12 @@ + + + +

Data sets available for reporting

+

See the xml version

+ + + \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataValueSets.vm' --- dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataValueSets.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/dataValueSets.vm 2011-11-02 11:14:35 +0000 @@ -0,0 +1,14 @@ + + + +

This resource is the place to post data value sets. Take a look at the + data sets to see what to post.

+ +
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT"
+    dataSet="dataSet UUID"
+    period="periodInIsoFormat"
+    orgUnit="unit UUID">
+    <dataValue dataElement="data element UUID" categoryOptionCombo="UUID, only specify if used" storedBy="string" value="value" />
+    </dataValueSet>
+ + \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/index.vm' --- dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/index.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/index.vm 2011-11-02 11:14:35 +0000 @@ -0,0 +1,26 @@ + + + + DHIS2 Web API + + +

DHIS2 Web API

+ +

Warning: This API is in no way ready for public consumption. Radical changes must be expected at any time!

+ +

The api currently supports a specific pilot use case for posting of data value sets. + +

Posting data value sets

+

To find the needed information about the data sets you want to post data about, go to the data set list.

+ +

If you don't want org units listed by data set, there is also the full list of org units

+ +

Post according to the following template /api2/dataValueSets/

+
<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT"
+    dataSet="dataSet UUID"
+    period="periodInIsoFormat"
+    orgUnit="unit UUID">
+    <dataValue dataElement="data element UUID" categoryOptionCombo="UUID, only specify if used" storedBy="string" value="value" />
+    </dataValueSet>
+ + \ No newline at end of file === added file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/orgUnits.vm' --- dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/orgUnits.vm 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/dhis-web-api2/orgUnits.vm 2011-11-02 11:14:35 +0000 @@ -0,0 +1,12 @@ + + + +

Organisation units

+

See the xml version

+ + + \ No newline at end of file === modified file 'dhis-2/dhis-web/dhis-web-api2/src/main/resources/struts.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/resources/struts.xml 2011-06-23 14:44:17 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/resources/struts.xml 2011-11-02 11:14:35 +0000 @@ -5,7 +5,7 @@ - + === modified file 'dhis-2/dhis-web/dhis-web-api2/src/main/webapp/WEB-INF/web.xml' --- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/web.xml 2011-03-02 19:07:04 +0000 +++ dhis-2/dhis-web/dhis-web-api2/src/main/webapp/WEB-INF/web.xml 2011-11-02 11:14:35 +0000 @@ -2,7 +2,7 @@ - DHIS Case Entry + DHIS Web API2 contextConfigLocation @@ -19,24 +19,21 @@ org.hisp.dhis.servlet.filter.HttpRedirectFilter redirectPath - api/ + api2/ OpenSessionInViewFilter - - org.springframework.orm.hibernate3.support.OpenSessionInViewFilter + org.springframework.orm.hibernate3.support.OpenSessionInViewFilter springSecurityFilterChain - - org.springframework.web.filter.DelegatingFilterProxy + org.springframework.web.filter.DelegatingFilterProxy Struts - - org.apache.struts2.dispatcher.FilterDispatcher + org.apache.struts2.dispatcher.FilterDispatcher @@ -49,7 +46,7 @@ OpenSessionInViewFilter - /api/* + /api2/* springSecurityFilterChain @@ -61,12 +58,10 @@ - - org.springframework.web.context.ContextLoaderListener + org.springframework.web.context.ContextLoaderListener - - org.hisp.dhis.system.startup.StartupListener + org.hisp.dhis.system.startup.StartupListener @@ -78,8 +73,7 @@ com.sun.jersey.spi.container.ContainerRequestFilters - - com.sun.jersey.api.container.filter.LoggingFilter, org.hisp.dhis.web.api.HtmlPromotingUriConnegFilter + com.sun.jersey.api.container.filter.LoggingFilter, org.hisp.dhis.web.api.HtmlPromotingUriConnegFilter @@ -91,10 +85,10 @@ web-api - /api/* + /api2/* web-api - /api + /api2 === modified file 'dhis-2/dhis-web/dhis-web-portal/pom.xml' --- dhis-2/dhis-web/dhis-web-portal/pom.xml 2011-10-18 20:23:09 +0000 +++ dhis-2/dhis-web/dhis-web-portal/pom.xml 2011-11-02 11:14:35 +0000 @@ -146,6 +146,12 @@ org.hisp.dhis + dhis-web-api2 + ${project.version} + war + + + org.hisp.dhis dhis-web-light ${project.version} war === modified file 'dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml' --- dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-10-18 20:23:09 +0000 +++ dhis-2/dhis-web/dhis-web-portal/src/main/webapp/WEB-INF/web.xml 2011-11-02 11:14:35 +0000 @@ -38,18 +38,22 @@ RedirectFilter / + OpenSessionInViewFilter *.action + OpenSessionInViewFilter - /api/* + /api2/* + springSecurityFilterChain /* + Struts *.action @@ -63,9 +67,8 @@ - - web-api + jerseyServlet com.sun.jersey.spi.spring.container.servlet.SpringServlet com.sun.jersey.config.property.packages @@ -78,8 +81,23 @@ 1 - - web-api + + webapiServlet + org.springframework.web.servlet.DispatcherServlet + + contextConfigLocation + classpath*:/META-INF/dhis/servlet.xml + + 1 + + + + jerseyServlet + /api2/* + + + + webapiServlet /api/* === modified file 'dhis-2/dhis-web/pom.xml' --- dhis-2/dhis-web/pom.xml 2011-10-14 16:54:27 +0000 +++ dhis-2/dhis-web/pom.xml 2011-11-02 11:14:35 +0000 @@ -25,6 +25,7 @@ dhis-web-dashboard-integration dhis-web-caseentry dhis-web-api + dhis-web-api2 dhis-web-light dhis-web-portal === modified file 'dhis-2/pom.xml' --- dhis-2/pom.xml 2011-10-14 16:54:27 +0000 +++ dhis-2/pom.xml 2011-11-02 11:14:35 +0000 @@ -42,11 +42,11 @@ - + amplecode_maven2_repo AmpleCode Maven 2 repository http://www.amplecode.org/maven2 - + dhis.uio.no Dhis2 External Dependencies Repository @@ -247,8 +247,6 @@ org.hisp.dhis - - dhis-support-hibernate ${project.version} @@ -330,6 +328,11 @@ ${spring.version} + org.springframework + spring-webmvc + ${spring.version} + + org.aspectj aspectjrt 1.6.4