------------------------------------------------------------ revno: 13912 committer: Morten Olav Hansen <[email protected]> branch nick: dhis2 timestamp: Mon 2014-02-03 11:00:26 +0700 message: expose symbol on orgUnitGroupSet.orgUnitGroups added: dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitGroupSymbolSerializer.java modified: dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitGroupSymbolSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitGroupSymbolSerializer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/JacksonOrganisationUnitGroupSymbolSerializer.java 2014-02-03 04:00:26 +0000 @@ -0,0 +1,103 @@ +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.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.OrganisationUnitGroup; + +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 <[email protected]> + */ +public class JacksonOrganisationUnitGroupSymbolSerializer extends JsonSerializer<OrganisationUnitGroup> +{ + private static DateFormat format = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ); + + @Override + public void serialize( OrganisationUnitGroup value, JsonGenerator jgen, SerializerProvider provider ) throws IOException + { + if ( ToXmlGenerator.class.isAssignableFrom( jgen.getClass() ) ) + { + ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen; + + try + { + XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter(); + + staxWriter.writeStartElement( DxfNamespaces.DXF_2_0, "organisationUnitGroup" ); + 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( "symbol", String.valueOf( value.getSymbol() ) ); + 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.writeStringField( "symbol", value.getSymbol() ); + + jgen.writeEndObject(); + } + } +} === modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java 2014-01-19 05:14:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitGroupSet.java 2014-02-03 04:00:26 +0000 @@ -40,6 +40,7 @@ import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.NameableObject; +import org.hisp.dhis.common.adapter.JacksonOrganisationUnitGroupSymbolSerializer; import org.hisp.dhis.common.annotation.Scanned; import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator; import org.hisp.dhis.common.view.DetailedView; @@ -57,7 +58,7 @@ /** * @author Kristian Nordal */ -@JacksonXmlRootElement(localName = "organisationUnitGroupSet", namespace = DxfNamespaces.DXF_2_0) +@JacksonXmlRootElement( localName = "organisationUnitGroupSet", namespace = DxfNamespaces.DXF_2_0 ) public class OrganisationUnitGroupSet extends BaseDimensionalObject { @@ -187,10 +188,10 @@ @Override @JsonProperty - @JsonSerialize(contentAs = BaseIdentifiableObject.class) - @JsonView({ DetailedView.class, DimensionalView.class }) - @JacksonXmlElementWrapper(localName = "items", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "item", namespace = DxfNamespaces.DXF_2_0) + @JsonSerialize( contentAs = BaseIdentifiableObject.class ) + @JsonView( { DetailedView.class, DimensionalView.class } ) + @JacksonXmlElementWrapper( localName = "items", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "item", namespace = DxfNamespaces.DXF_2_0 ) public List<NameableObject> getItems() { return new ArrayList<NameableObject>( organisationUnitGroups ); @@ -220,8 +221,8 @@ } @JsonProperty - @JsonView({ DetailedView.class, ExportView.class }) - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) public String getDescription() { return description; @@ -233,8 +234,8 @@ } @JsonProperty - @JsonView({ DetailedView.class, ExportView.class }) - @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 ) public boolean isCompulsory() { return compulsory; @@ -245,11 +246,12 @@ this.compulsory = compulsory; } - @JsonProperty(value = "organisationUnitGroups") - @JsonSerialize(contentAs = BaseIdentifiableObject.class) - @JsonView({ DetailedView.class, ExportView.class }) - @JacksonXmlElementWrapper(localName = "organisationUnitGroups", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty(localName = "organisationUnitGroup", namespace = DxfNamespaces.DXF_2_0) + @JsonProperty( value = "organisationUnitGroups" ) + // @JsonSerialize(contentAs = BaseIdentifiableObject.class) + @JsonSerialize( contentUsing = JacksonOrganisationUnitGroupSymbolSerializer.class ) + @JsonView( { DetailedView.class, ExportView.class } ) + @JacksonXmlElementWrapper( localName = "organisationUnitGroups", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "organisationUnitGroup", namespace = DxfNamespaces.DXF_2_0 ) public Set<OrganisationUnitGroup> getOrganisationUnitGroups() { return organisationUnitGroups; @@ -275,8 +277,8 @@ @JsonProperty( value = "attributes" ) @JsonView( { DetailedView.class, ExportView.class } ) - @JacksonXmlElementWrapper( localName = "attributes", namespace = DxfNamespaces.DXF_2_0) - @JacksonXmlProperty( localName = "attribute", namespace = DxfNamespaces.DXF_2_0) + @JacksonXmlElementWrapper( localName = "attributes", namespace = DxfNamespaces.DXF_2_0 ) + @JacksonXmlProperty( localName = "attribute", namespace = DxfNamespaces.DXF_2_0 ) public Set<AttributeValue> getAttributeValues() { return attributeValues;
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

