=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitChildrenSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitChildrenSerializer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitChildrenSerializer.java 2013-11-28 13:52:05 +0000 @@ -0,0 +1,104 @@ +package org.hisp.dhis.common.adapter; + +/* + * Copyright (c) 2004-2013, 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.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator; +import org.hisp.dhis.common.DxfNamespaces; +import org.hisp.dhis.organisationunit.OrganisationUnit; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; + +/** + * @author Morten Olav Hansen + */ +public class JacksonOrganisationUnitChildrenSerializer extends JsonSerializer +{ + private static DateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ); + + @Override + public void serialize( OrganisationUnit value, JsonGenerator jgen, SerializerProvider provider ) throws IOException, JsonProcessingException + { + if ( ToXmlGenerator.class.isAssignableFrom( jgen.getClass() ) ) + { + ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen; + + try + { + XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter(); + + staxWriter.writeStartElement( DxfNamespaces.DXF_2_0, "child" ); + staxWriter.writeAttribute( "id", value.getUid() ); + staxWriter.writeAttribute( "name", value.getName() ); + staxWriter.writeAttribute( "created", format.format( value.getCreated() ) ); + staxWriter.writeAttribute( "lastUpdated", format.format( value.getLastUpdated() ) ); + + if ( value.getHref() != null ) + { + staxWriter.writeAttribute( "href", value.getHref() ); + } + + staxWriter.writeAttribute( "haveChildren", String.valueOf( value.hasChild() ) ); + staxWriter.writeEndElement(); + } + catch ( XMLStreamException e ) + { + e.printStackTrace(); + } + } + else + { + jgen.writeStartObject(); + + jgen.writeStringField( "id", value.getUid() ); + jgen.writeStringField( "name", value.getName() ); + jgen.writeFieldName( "created" ); + provider.defaultSerializeDateValue( value.getCreated(), jgen ); + + jgen.writeFieldName( "lastUpdated" ); + provider.defaultSerializeDateValue( value.getLastUpdated(), jgen ); + + if ( value.getHref() != null ) + { + jgen.writeStringField( "href", value.getHref() ); + } + + jgen.writeBooleanField( "haveChildren", value.hasChild() ); + + jgen.writeEndObject(); + } + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2013-10-16 13:35:17 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnit.java 2013-11-28 13:52:05 +0000 @@ -41,6 +41,7 @@ import org.hisp.dhis.common.BaseNameableObject; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.common.adapter.JacksonOrganisationUnitChildrenSerializer; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.common.view.DetailedView; import org.hisp.dhis.common.view.ExportView; @@ -699,7 +700,8 @@ } @JsonProperty - @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + //@JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonSerialize( contentUsing = JacksonOrganisationUnitChildrenSerializer.class) @JsonView( { DetailedView.class } ) @JacksonXmlElementWrapper( localName = "children", namespace = DxfNamespaces.DXF_2_0 ) @JacksonXmlProperty( localName = "child", namespace = DxfNamespaces.DXF_2_0 ) === modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitGroup.vm' --- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitGroup.vm 2013-10-10 15:32:40 +0000 +++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnitGroup.vm 2013-11-28 13:52:05 +0000 @@ -23,41 +23,41 @@ - - - - - - + + + + + + #foreach( $organisationUnitGroup in $organisationUnitGroups ) @@ -69,24 +69,24 @@ #parse( "/dhis-web-commons/paging/paging.vm" ) +
$i18n.getString( "name" )$i18n.getString( "operations" )
$i18n.getString( "name" )$i18n.getString( "operations" )
$encoder.htmlEncode( $organisationUnitGroup.displayName ) - #if ( $security.canManage( $organisationUnitGroup ) ) - $i18n.getString( 'sharing_settings' ) - #else - - #end - - #if( $security.canUpdate( $organisationUnitGroup ) ) - $i18n.getString( 'edit' ) - #else - - #end - - #if( $security.canUpdate( $organisationUnitGroup ) ) - $i18n.getString( 'translation_translate' ) - #else - - #end - - #if( $security.canDelete( $organisationUnitGroup ) ) - $i18n.getString( 'remove' ) - #else - - #end + #if ( $security.canManage( $organisationUnitGroup ) ) + $i18n.getString( 'sharing_settings' ) + #else + + #end + + #if( $security.canUpdate( $organisationUnitGroup ) ) + $i18n.getString( 'edit' ) + #else + + #end + + #if( $security.canUpdate( $organisationUnitGroup ) ) + $i18n.getString( 'translation_translate' ) + #else + + #end + + #if( $security.canDelete( $organisationUnitGroup ) ) + $i18n.getString( 'remove' ) + #else + + #end $i18n.getString( 'show_details' ) - -
-
- $i18n.getString( 'hide_details' ) -
+
+
+ $i18n.getString( 'hide_details' ) +





-
-
- $i18n.getString( 'hide_warning' ) -
-

-
+
+
+ $i18n.getString( 'hide_warning' ) +
+

+