=== modified file 'dhis-2/dhis-dxf2/pom.xml' --- dhis-2/dhis-dxf2/pom.xml 2012-03-11 21:14:39 +0000 +++ dhis-2/dhis-dxf2/pom.xml 2012-03-22 15:11:32 +0000 @@ -1,7 +1,7 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 === added directory 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils' === added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java' --- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/JacksonUtils.java 2012-03-22 15:11:32 +0000 @@ -0,0 +1,157 @@ +package org.hisp.dhis.dxf2.utils; + +/* + * Copyright (c) 2004-2012, 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 com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; +import org.hisp.dhis.common.view.DetailedView; +import org.hisp.dhis.common.view.ExportView; +import org.hisp.dhis.common.view.IdentifiableObjectView; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public class JacksonUtils +{ + private static ObjectMapper jsonMapper = new ObjectMapper(); + + private static XmlMapper xmlMapper = new XmlMapper(); + + private static Map> viewClasses = new HashMap>(); + + static + { + jsonMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL ); + jsonMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); + jsonMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false ); + jsonMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); + jsonMapper.disable( MapperFeature.AUTO_DETECT_FIELDS ); + jsonMapper.disable( MapperFeature.AUTO_DETECT_CREATORS ); + jsonMapper.disable( MapperFeature.AUTO_DETECT_GETTERS ); + jsonMapper.disable( MapperFeature.AUTO_DETECT_SETTERS ); + jsonMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS ); + + jsonMapper.getJsonFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES ); + + xmlMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL ); + xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true ); + xmlMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); + xmlMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false ); + xmlMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); + xmlMapper.disable( MapperFeature.AUTO_DETECT_FIELDS ); + xmlMapper.disable( MapperFeature.AUTO_DETECT_CREATORS ); + xmlMapper.disable( MapperFeature.AUTO_DETECT_GETTERS ); + xmlMapper.disable( MapperFeature.AUTO_DETECT_SETTERS ); + xmlMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS ); + + // register view classes + viewClasses.put( "default", IdentifiableObjectView.class ); + viewClasses.put( "basic", IdentifiableObjectView.class ); + viewClasses.put( "detailed", DetailedView.class ); + viewClasses.put( "export", ExportView.class ); + } + + public static Class getViewClass( Object viewName ) + { + if ( viewName == null || !(viewName instanceof String && ((String) viewName).length() != 0) ) + { + return viewClasses.get( "default" ); + } + + return viewClasses.get( viewName ); + } + + //--------------------------------------------------------------------------------------------------- + // JSON + //--------------------------------------------------------------------------------------------------- + + public static void toJson( OutputStream output, Object value ) throws IOException + { + jsonMapper.writeValue( output, value ); + } + + public static String toJsonAsString( Object value ) throws IOException + { + return jsonMapper.writeValueAsString( value ); + } + + public static void toJsonWithView( OutputStream output, Object value, Class viewClass ) throws IOException + { + jsonMapper.writerWithView( viewClass ).writeValue( output, value ); + } + + public static String toJsonWithViewAsString( Object value, Class viewClass ) throws IOException + { + return jsonMapper.writerWithView( viewClass ).writeValueAsString( value ); + } + + public static T fromJson( InputStream input, Class clazz ) throws IOException + { + return (T) jsonMapper.readValue( input, clazz ); + } + + //--------------------------------------------------------------------------------------------------- + // XML + //--------------------------------------------------------------------------------------------------- + + public static void toXml( OutputStream output, Object value ) throws IOException + { + xmlMapper.writeValue( output, value ); + } + + public static String toXmlAsString( Object value ) throws IOException + { + return xmlMapper.writeValueAsString( value ); + } + + public static void toXmlWithView( OutputStream output, Object value, Class viewClass ) throws IOException + { + xmlMapper.writerWithView( viewClass ).writeValue( output, value ); + } + + public static String toXmlWithViewAsString( Object value, Class viewClass ) throws IOException + { + return xmlMapper.writerWithView( viewClass ).writeValueAsString( value ); + } + + public static T fromXml( InputStream input, Class clazz ) throws IOException + { + return (T) xmlMapper.readValue( input, clazz ); + } +} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AggregatedValueController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AggregatedValueController.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AggregatedValueController.java 2012-03-22 15:11:32 +0000 @@ -31,7 +31,7 @@ import org.hisp.dhis.aggregation.AggregatedDataValueService; import org.hisp.dhis.aggregation.AggregatedIndicatorValue; import org.hisp.dhis.api.utils.ContextUtils; -import org.hisp.dhis.api.view.JacksonUtils; +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.dataelement.DataElementService; import org.hisp.dhis.i18n.I18nManager; import org.hisp.dhis.i18n.I18nManagerException; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AttributeTypeController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AttributeTypeController.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AttributeTypeController.java 2012-03-22 15:11:32 +0000 @@ -29,7 +29,7 @@ import org.hisp.dhis.api.utils.IdentifiableObjectParams; import org.hisp.dhis.api.utils.WebLinkPopulator; -import org.hisp.dhis.api.view.JacksonUtils; +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.attribute.AttributeService; import org.hisp.dhis.attribute.Attributes; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java 2012-03-22 15:11:32 +0000 @@ -30,7 +30,7 @@ import org.hisp.dhis.api.utils.ContextUtils; import org.hisp.dhis.api.utils.IdentifiableObjectParams; import org.hisp.dhis.api.utils.WebLinkPopulator; -import org.hisp.dhis.api.view.JacksonUtils; +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.api.webdomain.Message; import org.hisp.dhis.common.Pager; import org.hisp.dhis.message.MessageConversation; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-03-20 14:48:09 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MetaDataController.java 2012-03-22 15:11:32 +0000 @@ -28,7 +28,7 @@ */ import org.hisp.dhis.api.utils.ContextUtils; -import org.hisp.dhis.api.view.JacksonUtils; +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.api.webdomain.DXF2; import org.hisp.dhis.attribute.Attribute; import org.hisp.dhis.attribute.AttributeService; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonJsonView.java 2012-03-22 15:11:32 +0000 @@ -28,6 +28,7 @@ */ import org.codehaus.jackson.map.util.JSONPObject; +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.springframework.web.servlet.view.AbstractView; import javax.servlet.http.HttpServletRequest; === removed file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonUtils.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonUtils.java 1970-01-01 00:00:00 +0000 @@ -1,157 +0,0 @@ -package org.hisp.dhis.api.view; - -/* - * Copyright (c) 2004-2012, 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 com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.dataformat.xml.XmlMapper; -import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; -import org.hisp.dhis.common.view.DetailedView; -import org.hisp.dhis.common.view.ExportView; -import org.hisp.dhis.common.view.IdentifiableObjectView; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.HashMap; -import java.util.Map; - -/** - * @author Morten Olav Hansen - */ -public class JacksonUtils -{ - private static ObjectMapper jsonMapper = new ObjectMapper(); - - private static XmlMapper xmlMapper = new XmlMapper(); - - private static Map> viewClasses = new HashMap>(); - - static - { - jsonMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL ); - jsonMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); - jsonMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false ); - jsonMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); - jsonMapper.disable( MapperFeature.AUTO_DETECT_FIELDS ); - jsonMapper.disable( MapperFeature.AUTO_DETECT_CREATORS ); - jsonMapper.disable( MapperFeature.AUTO_DETECT_GETTERS ); - jsonMapper.disable( MapperFeature.AUTO_DETECT_SETTERS ); - jsonMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS ); - - jsonMapper.getJsonFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES ); - - xmlMapper.setSerializationInclusion( JsonInclude.Include.NON_NULL ); - xmlMapper.configure( ToXmlGenerator.Feature.WRITE_XML_DECLARATION, true ); - xmlMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); - xmlMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, false ); - xmlMapper.configure( SerializationFeature.FAIL_ON_EMPTY_BEANS, false ); - xmlMapper.disable( MapperFeature.AUTO_DETECT_FIELDS ); - xmlMapper.disable( MapperFeature.AUTO_DETECT_CREATORS ); - xmlMapper.disable( MapperFeature.AUTO_DETECT_GETTERS ); - xmlMapper.disable( MapperFeature.AUTO_DETECT_SETTERS ); - xmlMapper.disable( MapperFeature.AUTO_DETECT_IS_GETTERS ); - - // register view classes - viewClasses.put( "default", IdentifiableObjectView.class ); - viewClasses.put( "basic", IdentifiableObjectView.class ); - viewClasses.put( "detailed", DetailedView.class ); - viewClasses.put( "export", ExportView.class ); - } - - public static Class getViewClass( Object viewName ) - { - if ( viewName == null || !(viewName instanceof String && ((String) viewName).length() != 0) ) - { - return viewClasses.get( "default" ); - } - - return viewClasses.get( viewName ); - } - - //--------------------------------------------------------------------------------------------------- - // JSON - //--------------------------------------------------------------------------------------------------- - - public static void toJson( OutputStream output, Object value ) throws IOException - { - jsonMapper.writeValue( output, value ); - } - - public static String toJsonAsString( Object value ) throws IOException - { - return jsonMapper.writeValueAsString( value ); - } - - public static void toJsonWithView( OutputStream output, Object value, Class viewClass ) throws IOException - { - jsonMapper.writerWithView( viewClass ).writeValue( output, value ); - } - - public static String toJsonWithViewAsString( Object value, Class viewClass ) throws IOException - { - return jsonMapper.writerWithView( viewClass ).writeValueAsString( value ); - } - - public static T fromJson( InputStream input, Class clazz ) throws IOException - { - return (T) jsonMapper.readValue( input, clazz ); - } - - //--------------------------------------------------------------------------------------------------- - // XML - //--------------------------------------------------------------------------------------------------- - - public static void toXml( OutputStream output, Object value ) throws IOException - { - xmlMapper.writeValue( output, value ); - } - - public static String toXmlAsString( Object value ) throws IOException - { - return xmlMapper.writeValueAsString( value ); - } - - public static void toXmlWithView( OutputStream output, Object value, Class viewClass ) throws IOException - { - xmlMapper.writerWithView( viewClass ).writeValue( output, value ); - } - - public static String toXmlWithViewAsString( Object value, Class viewClass ) throws IOException - { - return xmlMapper.writerWithView( viewClass ).writeValueAsString( value ); - } - - public static T fromXml( InputStream input, Class clazz ) throws IOException - { - return (T) xmlMapper.readValue( input, clazz ); - } -} === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/JacksonXmlView.java 2012-03-22 15:11:32 +0000 @@ -28,6 +28,7 @@ */ +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.springframework.web.servlet.view.AbstractView; import javax.servlet.http.HttpServletRequest; === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java 2012-03-22 15:04:58 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/view/XsltHtmlView.java 2012-03-22 15:11:32 +0000 @@ -27,6 +27,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.springframework.util.Assert; import org.springframework.web.servlet.view.AbstractUrlBasedView;