=== added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/mapping/IllegalArgumentExceptionMapper.java 2011-02-15 06:53:26 +0000 @@ -0,0 +1,23 @@ +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(); + } + +} === added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc' === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/web/api/rpc/RPCResource.java 2011-02-15 06:53:26 +0000 @@ -0,0 +1,189 @@ +package org.hisp.dhis.web.api.rpc; + +import java.net.URI; +import java.util.List; +import java.util.Set; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; +import javax.ws.rs.core.UriInfo; + +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo; +import org.hisp.dhis.dataset.DataSet; +import org.hisp.dhis.dataset.DataSetService; +import org.hisp.dhis.datavalue.DataValue; +import org.hisp.dhis.datavalue.DataValueService; +import org.hisp.dhis.importexport.datavalueset.DataValueSet; +import org.hisp.dhis.importexport.datavalueset.DataValueSetMapper; +import org.hisp.dhis.organisationunit.OrganisationUnit; +import org.springframework.beans.factory.annotation.Required; + +import com.ibatis.common.logging.Log; +import com.ibatis.common.logging.LogFactory; + +@Path( "/rpc" ) +public class RPCResource +{ + private static Log log = LogFactory.getLog( RPCResource.class ); + + private DataValueSetMapper dataValueSetMapper; + + private DataValueService dataValueService; + + private DataSetService dataSetService; + + @Context + UriInfo uriInfo; + + @POST + @Path( "dataValueSets" ) + @Consumes( MediaType.APPLICATION_XML ) + public void storeDataValueSet( DataValueSet dataValueSet ) + { + List dataValues = dataValueSetMapper.getDataValues( dataValueSet ); + + for ( DataValue dataValue : dataValues ) + { + dataValueService.addDataValue( dataValue ); + } + } + + @GET + @Produces( MediaType.TEXT_HTML ) + @Path( "dataSets" ) + public String getDataValueSets() + { + return getDataValueSet(); + } + + @GET + @Produces( MediaType.TEXT_HTML ) + public String getDataValueSet() + { + StringBuilder t = new StringBuilder(); + t.append( head( "Data sets available for reporting" ) ); + + t.append( "

Data sets available for reporting

\n