=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/codelist/CodeList.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/codelist/CodeList.java 2011-11-15 12:09:13 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/codelist/CodeList.java 2011-11-15 19:27:13 +0000 @@ -2,10 +2,7 @@ import org.hisp.dhis.common.AbstractIdentifiableObject; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.*; import java.util.ArrayList; import java.util.List; @@ -13,10 +10,9 @@ * @author Morten Olav Hansen */ @XmlRootElement( name = "codeList" ) -@XmlAccessorType( value = XmlAccessType.FIELD ) +@XmlAccessorType( value = XmlAccessType.NONE ) public class CodeList { - @XmlElement( name = "code" ) private List list = new ArrayList(); public CodeList() @@ -29,6 +25,7 @@ this.list = list; } + @XmlElement( name = "code" ) public List getList() { return list; === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-11-04 09:34:37 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/AbstractIdentifiableObject.java 2011-11-15 19:27:13 +0000 @@ -27,17 +27,20 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.*; + /** * @author Bob Jolliffe */ +@XmlRootElement( name = "identifiableObject" ) +@XmlAccessorType( value = XmlAccessType.NONE ) public abstract class AbstractIdentifiableObject implements IdentifiableObject { @@ -89,6 +92,7 @@ this.name = name; } + @XmlAttribute @Override public int getId() { @@ -111,6 +115,7 @@ this.uuid = uuid; } + @XmlAttribute @Override public String getUid() { @@ -122,6 +127,7 @@ this.uid = uid; } + @XmlAttribute @Override public String getCode() { @@ -133,6 +139,7 @@ this.code = code; } + @XmlAttribute @Override public String getName() { @@ -144,6 +151,7 @@ this.name = name; } + @XmlAttribute public Date getLastUpdated() { return lastUpdated; @@ -156,7 +164,6 @@ /** * Set autogenerated fields on save or update - * */ public void setAutoFields() { @@ -175,7 +182,7 @@ /** * Get a map of uuids to internal identifiers - * + * * @param objects the IdentifiableObjects to put in the map * @return the map */ @@ -195,7 +202,7 @@ /** * Get a map of uids to internal identifiers - * + * * @param objects the IdentifiableObjects to put in the map * @return the map */ @@ -215,7 +222,7 @@ /** * Get a map of codes to internal identifiers - * + * * @param objects the NameableObjects to put in the map * @return the map */ @@ -236,8 +243,7 @@ { log.warn( object.getClass() + ": Duplicate code " + code ); map.remove( code ); - } - else + } else { map.put( code, internalId ); } === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-11-04 09:34:37 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElement.java 2011-11-15 19:27:13 +0000 @@ -27,11 +27,6 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.apache.commons.lang.StringEscapeUtils; import org.hisp.dhis.attribute.AttributeValue; import org.hisp.dhis.common.AbstractNameableObject; @@ -39,6 +34,14 @@ import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.period.YearlyPeriodType; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * A DataElement is a definition (meta-information about) of the entities that * are captured in the system. An example from public health care is a @@ -48,15 +51,16 @@ * children. The sum of the children represent the same entity as the parent. * Hiearchies of DataElements are used to give more fine- or course-grained * representations of the entities. - * + *

* DataElement acts as a DimensionSet in the dynamic dimensional model, and as a * DimensionOption in the static DataElement dimension. - * + * * @author Kristian Nordal * @version $Id: DataElement.java 5540 2008-08-19 10:47:07Z larshelg $ */ -public class DataElement - extends AbstractNameableObject +@XmlRootElement( name = "dataElement" ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class DataElement extends AbstractNameableObject { /** * Determines if a de-serialized file is compatible with this class. @@ -91,7 +95,7 @@ * The name to appear in forms. */ private String formName; - + /** * If this DataElement is active or not (enabled or disabled). */ @@ -197,7 +201,7 @@ return false; } - if ( !(o instanceof DataElement) ) + if ( !( o instanceof DataElement ) ) { return false; } @@ -252,7 +256,7 @@ */ public String getDetailedNumberType() { - return (type != null && type.equals( VALUE_TYPE_INT ) && numberType != null) ? numberType : type; + return ( type != null && type.equals( VALUE_TYPE_INT ) && numberType != null ) ? numberType : type; } /** @@ -368,7 +372,7 @@ result.append( "}" ); return result.toString(); } - + // ------------------------------------------------------------------------- // Getters and setters // ------------------------------------------------------------------------- === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-09-24 11:35:11 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/indicator/Indicator.java 2011-11-15 19:27:13 +0000 @@ -35,12 +35,17 @@ import org.hisp.dhis.common.AbstractNameableObject; import org.hisp.dhis.dataset.DataSet; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + /** * @author Lars Helge Overland * @version $Id: Indicator.java 5540 2008-08-19 10:47:07Z larshelg $ */ -public class Indicator - extends AbstractNameableObject +@XmlRootElement( name = "indicator" ) +@XmlAccessorType( value = XmlAccessType.NONE ) +public class Indicator extends AbstractNameableObject { /** * Determines if a de-serialized file is compatible with this class. === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ChartController.java 1970-01-01 00:00:00 +0000 @@ -1,68 +0,0 @@ -package org.hisp.dhis.api.controller; - -import org.hisp.dhis.api.listener.IdentifiableObjectListener; -import org.hisp.dhis.api.resources.XChart; -import org.hisp.dhis.api.resources.XCharts; -import org.hisp.dhis.chart.Chart; -import org.hisp.dhis.chart.ChartService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletRequest; -import java.util.Collection; - -@Controller -@RequestMapping( value = "/charts" ) -public class ChartController -{ - @Autowired - private ChartService chartService; - - @RequestMapping( method = RequestMethod.GET ) - public XCharts getCharts( HttpServletRequest request ) - { - XCharts charts = new XCharts(); - - Collection allCharts = chartService.getAllCharts(); - - for ( Chart chart : allCharts ) - { - charts.getCharts().add( new XChart( chart ) ); - } - - new IdentifiableObjectListener( request ).beforeMarshal( charts ); - - return charts; - } - - @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) - public XChart getChart( @PathVariable( "uid" ) Integer uid, HttpServletRequest request ) - { - XChart chart = new XChart( chartService.getChart( uid ) ); - - new IdentifiableObjectListener( request ).beforeMarshal( chart ); - - return chart; - } - - @RequestMapping( method = RequestMethod.POST ) - @ResponseBody - public void postChart( XChart chart ) - { - - } - - /* - @RequestMapping( method = RequestMethod.POST ) - public void postChart( InputStream inputStream ) throws IOException - { - StringWriter writer = new StringWriter(); - IOUtils.copy( inputStream, writer, "UTF-8" ); - System.err.println( writer.toString() ); - } - */ -} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataElementController.java 2011-11-15 19:27:13 +0000 @@ -0,0 +1,39 @@ +package org.hisp.dhis.api.controller; + +import org.hisp.dhis.codelist.CodeList; +import org.hisp.dhis.dataelement.DataElement; +import org.hisp.dhis.dataelement.DataElementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping( value = "/dataElements" ) +public class DataElementController +{ + @Autowired + private DataElementService dataElementService; + + @RequestMapping( method = RequestMethod.GET ) + public CodeList getDataElements() + { + List dataElements = new ArrayList( dataElementService.getAllActiveDataElements() ); + CodeList codeList = new CodeList( dataElements ); + + return codeList; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public DataElement getDataElement( @PathVariable( "uid" ) Integer uid, HttpServletRequest request ) + { + DataElement dataElement = dataElementService.getDataElement( uid ); + + return dataElement; + } +} === added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndicatorController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndicatorController.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/IndicatorController.java 2011-11-15 19:27:13 +0000 @@ -0,0 +1,39 @@ +package org.hisp.dhis.api.controller; + +import org.hisp.dhis.codelist.CodeList; +import org.hisp.dhis.indicator.Indicator; +import org.hisp.dhis.indicator.IndicatorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping( value = "/indicators" ) +public class IndicatorController +{ + @Autowired + private IndicatorService indicatorService; + + @RequestMapping( method = RequestMethod.GET ) + public CodeList getIndicators() + { + List indicators = new ArrayList( indicatorService.getAllIndicators() ); + CodeList codeList = new CodeList( indicators ); + + return codeList; + } + + @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) + public Indicator getIndicator( @PathVariable( "uid" ) Integer uid, HttpServletRequest request ) + { + Indicator indicator = indicatorService.getIndicator( uid ); + + return indicator; + } +} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/converter/Jaxb2HttpMessageConverter.java 1970-01-01 00:00:00 +0000 @@ -1,49 +0,0 @@ -package org.hisp.dhis.api.converter; - -import org.hisp.dhis.api.resources.XIdentifiableObject; -import org.springframework.http.HttpInputMessage; -import org.springframework.http.HttpOutputMessage; -import org.springframework.http.MediaType; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.http.converter.HttpMessageNotWritableException; - -import java.io.IOException; -import java.util.List; - -public class Jaxb2HttpMessageConverter implements HttpMessageConverter -{ - @Override - public boolean canRead( Class clazz, MediaType mediaType ) - { - System.err.println("canread"); - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public boolean canWrite( Class clazz, MediaType mediaType ) - { - System.err.println("canwriter"); - return false; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public List getSupportedMediaTypes() - { - System.err.println("getsupportedmediatypes"); - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public XIdentifiableObject read( Class clazz, HttpInputMessage inputMessage ) throws IOException, HttpMessageNotReadableException - { - System.err.println("read"); - return null; //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void write( XIdentifiableObject identifiableObject, MediaType contentType, HttpOutputMessage outputMessage ) throws IOException, HttpMessageNotWritableException - { - System.err.println("write"); - } -} === removed directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources' === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XChart.java 1970-01-01 00:00:00 +0000 @@ -1,23 +0,0 @@ -package org.hisp.dhis.api.resources; - -import javax.xml.bind.annotation.XmlRootElement; - -import org.hisp.dhis.chart.Chart; - -@XmlRootElement( name = "chart" ) -public class XChart - extends XIdentifiableObject -{ - private Chart chart; - - public XChart() - { - - } - - public XChart( Chart chart ) - { - super( chart ); - this.chart = chart; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XCharts.java 1970-01-01 00:00:00 +0000 @@ -1,24 +0,0 @@ -package org.hisp.dhis.api.resources; - -import java.util.ArrayList; -import java.util.List; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -@XmlRootElement( name = "charts" ) -public class XCharts -{ - private List charts = new ArrayList(); - - public XCharts() - { - - } - - @XmlElement( name = "chart" ) - public List getCharts() - { - return charts; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XIdentifiableObject.java 1970-01-01 00:00:00 +0000 @@ -1,73 +0,0 @@ -package org.hisp.dhis.api.resources; - -import org.hisp.dhis.common.IdentifiableObject; - -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import java.util.Date; - -@XmlRootElement -public class XIdentifiableObject -{ - private IdentifiableObject identifiableObject; - - private String href; - - public XIdentifiableObject() - { - - } - - public XIdentifiableObject( IdentifiableObject identifiableObject ) - { - this.identifiableObject = identifiableObject; - } - - @XmlAttribute - public int getId() - { - return identifiableObject.getId(); - } - - @XmlAttribute - public String getUuid() - { - return identifiableObject.getUuid(); - } - - @XmlAttribute - public String getUid() - { - return identifiableObject.getUid(); - } - - @XmlAttribute - public String getName() - { - return identifiableObject.getName(); - } - - @XmlAttribute - public String getCode() - { - return identifiableObject.getCode(); - } - - @XmlAttribute - public Date getLastUpdated() - { - return identifiableObject.getLastUpdated(); - } - - @XmlAttribute - public String getHref() - { - return href; - } - - public void setHref( String href ) - { - this.href = href; - } -} === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/XNameableObject.java 1970-01-01 00:00:00 +0000 @@ -1,43 +0,0 @@ -package org.hisp.dhis.api.resources; - -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -import org.hisp.dhis.common.NameableObject; - -@XmlRootElement -public class XNameableObject - extends XIdentifiableObject -{ - private NameableObject nameableObject; - - public XNameableObject() - { - - } - - public XNameableObject( NameableObject nameableObject ) - { - super( nameableObject ); - this.nameableObject = nameableObject; - } - - @XmlElement - public String getAlternativeName() - { - return nameableObject.getAlternativeName(); - } - - @XmlElement - public String getShortName() - { - return nameableObject.getShortName(); - } - - @XmlElement - public String getDescription() - { - return nameableObject.getDescription(); - } - -} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java 2011-11-12 15:46:34 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/ExtendedMappingJacksonView.java 2011-11-15 19:27:13 +0000 @@ -3,8 +3,10 @@ import org.codehaus.jackson.JsonEncoding; import org.codehaus.jackson.JsonFactory; import org.codehaus.jackson.JsonGenerator; +import org.codehaus.jackson.map.AnnotationIntrospector; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.util.JSONPObject; +import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; import org.springframework.web.servlet.view.json.MappingJacksonJsonView; import javax.servlet.http.HttpServletRequest; @@ -16,7 +18,6 @@ */ public class ExtendedMappingJacksonView extends MappingJacksonJsonView { - private boolean includeRootElement = false; private boolean withPadding = false; @@ -65,12 +66,17 @@ { Object value = filterModel( model ); ObjectMapper objectMapper = new ObjectMapper(); + + AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); + objectMapper.getDeserializationConfig().setAnnotationIntrospector( introspector ); + objectMapper.getSerializationConfig().setAnnotationIntrospector( introspector ); + JsonFactory jf = objectMapper.getJsonFactory(); JsonGenerator jg = jf.createJsonGenerator( response.getOutputStream(), JsonEncoding.UTF8 ); if ( !includeRootElement && value instanceof Map ) { - Map map = ( Map ) value; + Map map = (Map) value; if ( map.size() == 1 ) { @@ -89,7 +95,8 @@ JSONPObject valueWithPadding = new JSONPObject( callback, value ); jg.writeObject( valueWithPadding ); - } else + } + else { jg.writeObject( value ); }