=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java 2014-06-20 10:55:18 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java 1970-01-01 00:00:00 +0000 @@ -1,61 +0,0 @@ -package org.hisp.dhis.node; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.schema.Property; - -/** - * @author Morten Olav Hansen - */ -public abstract class AbstractNodePropertyConverter implements NodePropertyConverter -{ - @Override - public boolean canConvertTo( Property property, Object value ) - { - return false; - } - - @Override - public boolean canConvertFrom( Property property, Node value ) - { - return false; - } - - @Override - public Node convertTo( Property property, Object value ) - { - throw new IllegalAccessError( "Not implemented." ); - } - - @Override - public Object convertFrom( Property property, Node value ) - { - throw new IllegalAccessError( "Not implemented." ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2014-06-18 09:05:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 1970-01-01 00:00:00 +0000 @@ -1,158 +0,0 @@ -package org.hisp.dhis.node; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.config.Config; -import org.hisp.dhis.node.types.CollectionNode; -import org.hisp.dhis.node.types.ComplexNode; -import org.hisp.dhis.node.types.RootNode; -import org.hisp.dhis.node.types.SimpleNode; - -import java.io.OutputStream; - -/** - * @author Morten Olav Hansen - */ -public abstract class AbstractNodeSerializer implements NodeSerializer -{ - protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception - { - } - - protected void endSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception - { - } - - protected abstract void flushStream() throws Exception; - - protected Config config; - - @Override - public void serialize( RootNode rootNode, OutputStream outputStream ) throws Exception - { - this.config = rootNode.getConfig(); - startSerialize( rootNode, outputStream ); - writeRootNode( rootNode ); - endSerialize( rootNode, outputStream ); - this.config = null; - } - - protected abstract void startWriteRootNode( RootNode rootNode ) throws Exception; - - protected void writeRootNode( RootNode rootNode ) throws Exception - { - startWriteRootNode( rootNode ); - - for ( Node node : rootNode.getChildren() ) - { - dispatcher( node ); - flushStream(); - } - - endWriteRootNode( rootNode ); - flushStream(); - } - - protected abstract void endWriteRootNode( RootNode rootNode ) throws Exception; - - protected abstract void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception; - - protected void writeSimpleNode( SimpleNode simpleNode ) throws Exception - { - if ( !config.getInclusionStrategy().include( simpleNode.getValue() ) ) - { - return; - } - - startWriteSimpleNode( simpleNode ); - endWriteSimpleNode( simpleNode ); - } - - protected abstract void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception; - - protected abstract void startWriteComplexNode( ComplexNode complexNode ) throws Exception; - - protected void writeComplexNode( ComplexNode complexNode ) throws Exception - { - if ( !config.getInclusionStrategy().include( complexNode.getChildren() ) ) - { - return; - } - - startWriteComplexNode( complexNode ); - - for ( Node node : complexNode.getChildren() ) - { - dispatcher( node ); - flushStream(); - } - - endWriteComplexNode( complexNode ); - } - - protected abstract void endWriteComplexNode( ComplexNode complexNode ) throws Exception; - - protected abstract void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception; - - protected void writeCollectionNode( CollectionNode collectionNode ) throws Exception - { - if ( !config.getInclusionStrategy().include( collectionNode.getChildren() ) ) - { - return; - } - - startWriteCollectionNode( collectionNode ); - - for ( Node node : collectionNode.getChildren() ) - { - dispatcher( node ); - flushStream(); - } - - endWriteCollectionNode( collectionNode ); - } - - protected abstract void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception; - - private void dispatcher( Node node ) throws Exception - { - switch ( node.getType() ) - { - case SIMPLE: - writeSimpleNode( (SimpleNode) node ); - break; - case COMPLEX: - writeComplexNode( (ComplexNode) node ); - break; - case COLLECTION: - writeCollectionNode( (CollectionNode) node ); - break; - } - } -} === removed directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters' === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java 2014-06-20 10:55:18 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java 1970-01-01 00:00:00 +0000 @@ -1,72 +0,0 @@ -package org.hisp.dhis.node.converters; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; -import org.hisp.dhis.node.Node; -import org.hisp.dhis.node.types.SimpleNode; -import org.hisp.dhis.schema.Property; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - -import java.util.Collection; - -/** - * @author Morten Olav Hansen - */ -@Component -public class IsEmptyNodePropertyConverter extends AbstractNodePropertyConverter -{ - @Override - public String name() - { - return "isEmpty"; - } - - @Override - public boolean canConvertTo( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } - - @Override - public Node convertTo( Property property, Object value ) - { - if ( property.isCollection() ) - { - return new SimpleNode( property.getCollectionName(), ((Collection) value).isEmpty(), property.isAttribute() ); - } - else if ( String.class.isInstance( value ) ) - { - return new SimpleNode( property.getName(), StringUtils.isEmpty( value ), property.isAttribute() ); - } - - throw new IllegalStateException( "Should never get here, this property/value is not supported by this transformer." ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java 2014-06-20 10:55:18 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java 1970-01-01 00:00:00 +0000 @@ -1,72 +0,0 @@ -package org.hisp.dhis.node.converters; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; -import org.hisp.dhis.node.Node; -import org.hisp.dhis.node.types.SimpleNode; -import org.hisp.dhis.schema.Property; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - -import java.util.Collection; - -/** - * @author Morten Olav Hansen - */ -@Component -public class IsNotEmptyNodePropertyConverter extends AbstractNodePropertyConverter -{ - @Override - public String name() - { - return "isNotEmpty"; - } - - @Override - public boolean canConvertTo( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } - - @Override - public Node convertTo( Property property, Object value ) - { - if ( property.isCollection() ) - { - return new SimpleNode( property.getCollectionName(), !((Collection) value).isEmpty(), property.isAttribute() ); - } - else if ( String.class.isInstance( value ) ) - { - return new SimpleNode( property.getName(), !StringUtils.isEmpty( value ), property.isAttribute() ); - } - - throw new IllegalStateException( "Should never get here, this property/value is not supported by this transformer." ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java 2014-06-20 10:55:18 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java 1970-01-01 00:00:00 +0000 @@ -1,71 +0,0 @@ -package org.hisp.dhis.node.converters; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; -import org.hisp.dhis.node.Node; -import org.hisp.dhis.node.types.SimpleNode; -import org.hisp.dhis.schema.Property; -import org.springframework.stereotype.Component; - -import java.util.Collection; - -/** - * @author Morten Olav Hansen - */ -@Component -public class SizeNodePropertyConverter extends AbstractNodePropertyConverter -{ - @Override - public String name() - { - return "size"; - } - - @Override - public boolean canConvertTo( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } - - @Override - public Node convertTo( Property property, Object value ) - { - if ( property.isCollection() ) - { - return new SimpleNode( property.getCollectionName(), ((Collection) value).size(), property.isAttribute() ); - } - else if ( String.class.isInstance( value ) ) - { - return new SimpleNode( property.getName(), ((String) value).length(), property.isAttribute() ); - } - - throw new IllegalStateException( "Should never get here, this property/value is not supported by this transformer." ); - } -} === removed directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets' === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java 1970-01-01 00:00:00 +0000 @@ -1,54 +0,0 @@ -package org.hisp.dhis.node.presets; - -/* - * Copyright (c) 2004-2014, 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.google.common.collect.Lists; -import org.hisp.dhis.common.PresetProvider; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @author Morten Olav Hansen - */ -@Component -public class AllPresetProvider implements PresetProvider -{ - @Override - public String name() - { - return "all"; - } - - @Override - public List provide() - { - return Lists.newArrayList( "*" ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java 1970-01-01 00:00:00 +0000 @@ -1,54 +0,0 @@ -package org.hisp.dhis.node.presets; - -/* - * Copyright (c) 2004-2014, 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.google.common.collect.Lists; -import org.hisp.dhis.common.PresetProvider; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @author Morten Olav Hansen - */ -@Component -public class IdentifiablePresetProvider implements PresetProvider -{ - @Override - public String name() - { - return "identifiable"; - } - - @Override - public List provide() - { - return Lists.newArrayList( "id", "name", "code", "created", "lastUpdated", "href" ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java 1970-01-01 00:00:00 +0000 @@ -1,54 +0,0 @@ -package org.hisp.dhis.node.presets; - -/* - * Copyright (c) 2004-2014, 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.google.common.collect.Lists; -import org.hisp.dhis.common.PresetProvider; -import org.springframework.stereotype.Component; - -import java.util.List; - -/** - * @author Morten Olav Hansen - */ -@Component -public class NameablePresetProvider implements PresetProvider -{ - @Override - public String name() - { - return "nameable"; - } - - @Override - public List provide() - { - return Lists.newArrayList( "id", "name", "shortName", "description", "code", "created", "lastUpdated", "href" ); - } -} === removed directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers' === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java 2014-06-18 09:05:19 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java 1970-01-01 00:00:00 +0000 @@ -1,165 +0,0 @@ -package org.hisp.dhis.node.serializers; - -/* - * Copyright (c) 2004-2014, 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.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.google.common.collect.Lists; -import org.hisp.dhis.node.AbstractNodeSerializer; -import org.hisp.dhis.node.types.CollectionNode; -import org.hisp.dhis.node.types.ComplexNode; -import org.hisp.dhis.node.types.RootNode; -import org.hisp.dhis.node.types.SimpleNode; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; - -import java.io.OutputStream; -import java.util.List; - -/** - * @author Morten Olav Hansen - */ -@Component -@Scope( value = "prototype", proxyMode = ScopedProxyMode.INTERFACES ) -public class Jackson2JsonNodeSerializer extends AbstractNodeSerializer -{ - public static final String CONTENT_TYPE = "application/json"; - - public static final String JSONP_CALLBACK = "org.hisp.dhis.node.serializers.Jackson2JsonNodeSerializer.callback"; - - private final static ObjectMapper objectMapper = new ObjectMapper(); - - static - { - objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); - objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true ); - objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true ); - objectMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES ); - } - - private JsonGenerator generator = null; - - @Override - public List contentTypes() - { - return Lists.newArrayList( CONTENT_TYPE ); - } - - @Override - protected void flushStream() throws Exception - { - generator.flush(); - } - - @Override - protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception - { - generator = objectMapper.getFactory().createGenerator( outputStream ); - } - - @Override - protected void startWriteRootNode( RootNode rootNode ) throws Exception - { - if ( config.getProperties().containsKey( JSONP_CALLBACK ) ) - { - generator.writeRaw( config.getProperties().get( JSONP_CALLBACK ) + "(" ); - } - - generator.writeStartObject(); - } - - @Override - protected void endWriteRootNode( RootNode rootNode ) throws Exception - { - generator.writeEndObject(); - - if ( config.getProperties().containsKey( JSONP_CALLBACK ) ) - { - generator.writeRaw( ")" ); - } - } - - @Override - protected void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception - { - if ( simpleNode.getParent().isCollection() ) - { - generator.writeObject( simpleNode.getValue() ); - } - else - { - generator.writeObjectField( simpleNode.getName(), simpleNode.getValue() ); - } - } - - @Override - protected void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception - { - } - - @Override - protected void startWriteComplexNode( ComplexNode complexNode ) throws Exception - { - if ( complexNode.getParent().isCollection() ) - { - generator.writeStartObject(); - } - else - { - generator.writeObjectFieldStart( complexNode.getName() ); - } - } - - @Override - protected void endWriteComplexNode( ComplexNode complexNode ) throws Exception - { - generator.writeEndObject(); - } - - @Override - protected void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception - { - if ( collectionNode.getParent().isCollection() ) - { - generator.writeStartArray(); - } - else - { - generator.writeArrayFieldStart( collectionNode.getName() ); - } - } - - @Override - protected void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception - { - generator.writeEndArray(); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2014-06-17 14:06:57 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 1970-01-01 00:00:00 +0000 @@ -1,184 +0,0 @@ -package org.hisp.dhis.node.serializers; - -/* - * Copyright (c) 2004-2014, 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.google.common.collect.Lists; -import org.hisp.dhis.node.AbstractNodeSerializer; -import org.hisp.dhis.node.Node; -import org.hisp.dhis.node.types.CollectionNode; -import org.hisp.dhis.node.types.ComplexNode; -import org.hisp.dhis.node.types.RootNode; -import org.hisp.dhis.node.types.SimpleNode; -import org.springframework.context.annotation.Scope; -import org.springframework.context.annotation.ScopedProxyMode; -import org.springframework.stereotype.Component; -import org.springframework.util.StringUtils; - -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import java.io.OutputStream; -import java.util.List; - -/** - * @author Morten Olav Hansen - */ -@Component -@Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES) -public class StAXNodeSerializer extends AbstractNodeSerializer -{ - public static final String CONTENT_TYPE = "application/xml"; - - private static final XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); - - static - { - xmlFactory.setProperty( "javax.xml.stream.isRepairingNamespaces", true ); - } - - private XMLStreamWriter writer; - - @Override - public List contentTypes() - { - return Lists.newArrayList( CONTENT_TYPE ); - } - - @Override - protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception - { - writer = xmlFactory.createXMLStreamWriter( outputStream ); - writer.setDefaultNamespace( rootNode.getDefaultNamespace() ); - } - - @Override - protected void flushStream() throws Exception - { - writer.flush(); - } - - @Override - protected void startWriteRootNode( RootNode rootNode ) throws Exception - { - writer.writeStartDocument( "UTF-8", "1.0" ); - - if ( !StringUtils.isEmpty( rootNode.getComment() ) ) - { - writer.writeComment( rootNode.getComment() ); - } - - writeStartElement( rootNode ); - } - - @Override - protected void endWriteRootNode( RootNode rootNode ) throws Exception - { - writer.writeEndElement(); - writer.writeEndDocument(); - } - - @Override - protected void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception - { - String value = String.format( "%s", simpleNode.getValue() ); - - if ( simpleNode.isAttribute() ) - { - if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) ) - { - writer.writeAttribute( simpleNode.getNamespace(), simpleNode.getName(), value ); - } - else - { - writer.writeAttribute( simpleNode.getName(), value ); - } - } - else - { - writeStartElement( simpleNode ); - writer.writeCharacters( value ); - } - } - - @Override - protected void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception - { - if ( !simpleNode.isAttribute() ) - { - writer.writeEndElement(); - } - } - - @Override - protected void startWriteComplexNode( ComplexNode complexNode ) throws Exception - { - writeStartElement( complexNode ); - } - - @Override - protected void endWriteComplexNode( ComplexNode complexNode ) throws Exception - { - writer.writeEndElement(); - } - - @Override - protected void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception - { - if ( collectionNode.isWrapping() ) - { - writeStartElement( collectionNode ); - } - } - - @Override - protected void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception - { - if ( collectionNode.isWrapping() ) - { - writer.writeEndElement(); - } - } - - private void writeStartElement( Node node ) throws XMLStreamException - { - if ( !StringUtils.isEmpty( node.getComment() ) ) - { - writer.writeComment( node.getComment() ); - } - - if ( !StringUtils.isEmpty( node.getNamespace() ) ) - { - writer.writeStartElement( node.getNamespace(), node.getName() ); - } - else - { - writer.writeStartElement( node.getName() ); - } - } -} === removed directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers' === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java 2014-06-25 11:27:12 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java 1970-01-01 00:00:00 +0000 @@ -1,62 +0,0 @@ -package org.hisp.dhis.node.transformers; - -/* - * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNode; -import org.hisp.dhis.node.Node; -import org.hisp.dhis.node.NodeTransformer; -import org.springframework.stereotype.Component; - -import java.util.List; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * @author Morten Olav Hansen - */ -@Component -public class RenameNodeTransformer implements NodeTransformer -{ - @Override - public String name() - { - return "rename"; - } - - @Override - public Node transform( Node node, List args ) - { - checkNotNull( node ); - checkArgument( args.size() > 0, "rename requires a name parameter, .e.g: property|rename(newName)" ); - ((AbstractNode) node).setName( args.get( 0 ) ); - - return node; - } -} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,61 @@ +package org.hisp.dhis.node; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.schema.Property; + +/** + * @author Morten Olav Hansen + */ +public abstract class AbstractNodePropertyConverter implements NodePropertyConverter +{ + @Override + public boolean canConvertTo( Property property, Object value ) + { + return false; + } + + @Override + public boolean canConvertFrom( Property property, Node value ) + { + return false; + } + + @Override + public Node convertTo( Property property, Object value ) + { + throw new IllegalAccessError( "Not implemented." ); + } + + @Override + public Object convertFrom( Property property, Node value ) + { + throw new IllegalAccessError( "Not implemented." ); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,159 @@ +package org.hisp.dhis.node; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.config.Config; +import org.hisp.dhis.node.types.CollectionNode; +import org.hisp.dhis.node.types.ComplexNode; +import org.hisp.dhis.node.types.RootNode; +import org.hisp.dhis.node.types.SimpleNode; +import org.hisp.dhis.period.PeriodType; + +import java.io.OutputStream; + +/** + * @author Morten Olav Hansen + */ +public abstract class AbstractNodeSerializer implements NodeSerializer +{ + protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception + { + } + + protected void endSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception + { + } + + protected abstract void flushStream() throws Exception; + + protected Config config; + + @Override + public void serialize( RootNode rootNode, OutputStream outputStream ) throws Exception + { + this.config = rootNode.getConfig(); + startSerialize( rootNode, outputStream ); + writeRootNode( rootNode ); + endSerialize( rootNode, outputStream ); + this.config = null; + } + + protected abstract void startWriteRootNode( RootNode rootNode ) throws Exception; + + protected void writeRootNode( RootNode rootNode ) throws Exception + { + startWriteRootNode( rootNode ); + + for ( Node node : rootNode.getChildren() ) + { + dispatcher( node ); + flushStream(); + } + + endWriteRootNode( rootNode ); + flushStream(); + } + + protected abstract void endWriteRootNode( RootNode rootNode ) throws Exception; + + protected abstract void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception; + + protected void writeSimpleNode( SimpleNode simpleNode ) throws Exception + { + if ( !config.getInclusionStrategy().include( simpleNode.getValue() ) ) + { + return; + } + + startWriteSimpleNode( simpleNode ); + endWriteSimpleNode( simpleNode ); + } + + protected abstract void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception; + + protected abstract void startWriteComplexNode( ComplexNode complexNode ) throws Exception; + + protected void writeComplexNode( ComplexNode complexNode ) throws Exception + { + if ( !config.getInclusionStrategy().include( complexNode.getChildren() ) ) + { + return; + } + + startWriteComplexNode( complexNode ); + + for ( Node node : complexNode.getChildren() ) + { + dispatcher( node ); + flushStream(); + } + + endWriteComplexNode( complexNode ); + } + + protected abstract void endWriteComplexNode( ComplexNode complexNode ) throws Exception; + + protected abstract void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception; + + protected void writeCollectionNode( CollectionNode collectionNode ) throws Exception + { + if ( !config.getInclusionStrategy().include( collectionNode.getChildren() ) ) + { + return; + } + + startWriteCollectionNode( collectionNode ); + + for ( Node node : collectionNode.getChildren() ) + { + dispatcher( node ); + flushStream(); + } + + endWriteCollectionNode( collectionNode ); + } + + protected abstract void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception; + + private void dispatcher( Node node ) throws Exception + { + switch ( node.getType() ) + { + case SIMPLE: + writeSimpleNode( (SimpleNode) node ); + break; + case COMPLEX: + writeComplexNode( (ComplexNode) node ); + break; + case COLLECTION: + writeCollectionNode( (CollectionNode) node ); + break; + } + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,72 @@ +package org.hisp.dhis.node.converters; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; +import org.hisp.dhis.node.Node; +import org.hisp.dhis.node.types.SimpleNode; +import org.hisp.dhis.schema.Property; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import java.util.Collection; + +/** + * @author Morten Olav Hansen + */ +@Component +public class IsEmptyNodePropertyConverter extends AbstractNodePropertyConverter +{ + @Override + public String name() + { + return "isEmpty"; + } + + @Override + public boolean canConvertTo( Property property, Object value ) + { + return property.isCollection() || String.class.isInstance( value ); + } + + @Override + public Node convertTo( Property property, Object value ) + { + if ( property.isCollection() ) + { + return new SimpleNode( property.getCollectionName(), ((Collection) value).isEmpty(), property.isAttribute() ); + } + else if ( String.class.isInstance( value ) ) + { + return new SimpleNode( property.getName(), StringUtils.isEmpty( value ), property.isAttribute() ); + } + + throw new IllegalStateException( "Should never get here, this property/value is not supported by this field converter." ); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,72 @@ +package org.hisp.dhis.node.converters; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; +import org.hisp.dhis.node.Node; +import org.hisp.dhis.node.types.SimpleNode; +import org.hisp.dhis.schema.Property; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import java.util.Collection; + +/** + * @author Morten Olav Hansen + */ +@Component +public class IsNotEmptyNodePropertyConverter extends AbstractNodePropertyConverter +{ + @Override + public String name() + { + return "isNotEmpty"; + } + + @Override + public boolean canConvertTo( Property property, Object value ) + { + return property.isCollection() || String.class.isInstance( value ); + } + + @Override + public Node convertTo( Property property, Object value ) + { + if ( property.isCollection() ) + { + return new SimpleNode( property.getCollectionName(), !((Collection) value).isEmpty(), property.isAttribute() ); + } + else if ( String.class.isInstance( value ) ) + { + return new SimpleNode( property.getName(), !StringUtils.isEmpty( value ), property.isAttribute() ); + } + + throw new IllegalStateException( "Should never get here, this property/value is not supported by this field converter." ); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,71 @@ +package org.hisp.dhis.node.converters; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNodePropertyConverter; +import org.hisp.dhis.node.Node; +import org.hisp.dhis.node.types.SimpleNode; +import org.hisp.dhis.schema.Property; +import org.springframework.stereotype.Component; + +import java.util.Collection; + +/** + * @author Morten Olav Hansen + */ +@Component +public class SizeNodePropertyConverter extends AbstractNodePropertyConverter +{ + @Override + public String name() + { + return "size"; + } + + @Override + public boolean canConvertTo( Property property, Object value ) + { + return property.isCollection() || String.class.isInstance( value ); + } + + @Override + public Node convertTo( Property property, Object value ) + { + if ( property.isCollection() ) + { + return new SimpleNode( property.getCollectionName(), ((Collection) value).size(), property.isAttribute() ); + } + else if ( String.class.isInstance( value ) ) + { + return new SimpleNode( property.getName(), ((String) value).length(), property.isAttribute() ); + } + + throw new IllegalStateException( "Should never get here, this property/value is not supported by this field converter." ); + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/AllPresetProvider.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,54 @@ +package org.hisp.dhis.node.presets; + +/* + * Copyright (c) 2004-2014, 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.google.common.collect.Lists; +import org.hisp.dhis.common.PresetProvider; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@Component +public class AllPresetProvider implements PresetProvider +{ + @Override + public String name() + { + return "all"; + } + + @Override + public List provide() + { + return Lists.newArrayList( "*" ); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/IdentifiablePresetProvider.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,54 @@ +package org.hisp.dhis.node.presets; + +/* + * Copyright (c) 2004-2014, 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.google.common.collect.Lists; +import org.hisp.dhis.common.PresetProvider; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@Component +public class IdentifiablePresetProvider implements PresetProvider +{ + @Override + public String name() + { + return "identifiable"; + } + + @Override + public List provide() + { + return Lists.newArrayList( "id", "name", "code", "created", "lastUpdated", "href" ); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/presets/NameablePresetProvider.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,54 @@ +package org.hisp.dhis.node.presets; + +/* + * Copyright (c) 2004-2014, 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.google.common.collect.Lists; +import org.hisp.dhis.common.PresetProvider; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@Component +public class NameablePresetProvider implements PresetProvider +{ + @Override + public String name() + { + return "nameable"; + } + + @Override + public List provide() + { + return Lists.newArrayList( "id", "name", "shortName", "description", "code", "created", "lastUpdated", "href" ); + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/Jackson2JsonNodeSerializer.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,165 @@ +package org.hisp.dhis.node.serializers; + +/* + * Copyright (c) 2004-2014, 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.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.google.common.collect.Lists; +import org.hisp.dhis.node.AbstractNodeSerializer; +import org.hisp.dhis.node.types.CollectionNode; +import org.hisp.dhis.node.types.ComplexNode; +import org.hisp.dhis.node.types.RootNode; +import org.hisp.dhis.node.types.SimpleNode; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; + +import java.io.OutputStream; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@Component +@Scope( value = "prototype", proxyMode = ScopedProxyMode.INTERFACES ) +public class Jackson2JsonNodeSerializer extends AbstractNodeSerializer +{ + public static final String CONTENT_TYPE = "application/json"; + + public static final String JSONP_CALLBACK = "org.hisp.dhis.node.serializers.Jackson2JsonNodeSerializer.callback"; + + private final static ObjectMapper objectMapper = new ObjectMapper(); + + static + { + objectMapper.configure( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false ); + objectMapper.configure( SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, true ); + objectMapper.configure( SerializationFeature.WRAP_EXCEPTIONS, true ); + objectMapper.getFactory().enable( JsonGenerator.Feature.QUOTE_FIELD_NAMES ); + } + + private JsonGenerator generator = null; + + @Override + public List contentTypes() + { + return Lists.newArrayList( CONTENT_TYPE ); + } + + @Override + protected void flushStream() throws Exception + { + generator.flush(); + } + + @Override + protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception + { + generator = objectMapper.getFactory().createGenerator( outputStream ); + } + + @Override + protected void startWriteRootNode( RootNode rootNode ) throws Exception + { + if ( config.getProperties().containsKey( JSONP_CALLBACK ) ) + { + generator.writeRaw( config.getProperties().get( JSONP_CALLBACK ) + "(" ); + } + + generator.writeStartObject(); + } + + @Override + protected void endWriteRootNode( RootNode rootNode ) throws Exception + { + generator.writeEndObject(); + + if ( config.getProperties().containsKey( JSONP_CALLBACK ) ) + { + generator.writeRaw( ")" ); + } + } + + @Override + protected void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception + { + if ( simpleNode.getParent().isCollection() ) + { + generator.writeObject( simpleNode.getValue() ); + } + else + { + generator.writeObjectField( simpleNode.getName(), simpleNode.getValue() ); + } + } + + @Override + protected void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception + { + } + + @Override + protected void startWriteComplexNode( ComplexNode complexNode ) throws Exception + { + if ( complexNode.getParent().isCollection() ) + { + generator.writeStartObject(); + } + else + { + generator.writeObjectFieldStart( complexNode.getName() ); + } + } + + @Override + protected void endWriteComplexNode( ComplexNode complexNode ) throws Exception + { + generator.writeEndObject(); + } + + @Override + protected void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception + { + if ( collectionNode.getParent().isCollection() ) + { + generator.writeStartArray(); + } + else + { + generator.writeArrayFieldStart( collectionNode.getName() ); + } + } + + @Override + protected void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception + { + generator.writeEndArray(); + } +} === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/serializers/StAXNodeSerializer.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,184 @@ +package org.hisp.dhis.node.serializers; + +/* + * Copyright (c) 2004-2014, 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.google.common.collect.Lists; +import org.hisp.dhis.node.AbstractNodeSerializer; +import org.hisp.dhis.node.Node; +import org.hisp.dhis.node.types.CollectionNode; +import org.hisp.dhis.node.types.ComplexNode; +import org.hisp.dhis.node.types.RootNode; +import org.hisp.dhis.node.types.SimpleNode; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; +import java.io.OutputStream; +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +@Component +@Scope(value = "prototype", proxyMode = ScopedProxyMode.INTERFACES) +public class StAXNodeSerializer extends AbstractNodeSerializer +{ + public static final String CONTENT_TYPE = "application/xml"; + + private static final XMLOutputFactory xmlFactory = XMLOutputFactory.newInstance(); + + static + { + xmlFactory.setProperty( "javax.xml.stream.isRepairingNamespaces", true ); + } + + private XMLStreamWriter writer; + + @Override + public List contentTypes() + { + return Lists.newArrayList( CONTENT_TYPE ); + } + + @Override + protected void startSerialize( RootNode rootNode, OutputStream outputStream ) throws Exception + { + writer = xmlFactory.createXMLStreamWriter( outputStream ); + writer.setDefaultNamespace( rootNode.getDefaultNamespace() ); + } + + @Override + protected void flushStream() throws Exception + { + writer.flush(); + } + + @Override + protected void startWriteRootNode( RootNode rootNode ) throws Exception + { + writer.writeStartDocument( "UTF-8", "1.0" ); + + if ( !StringUtils.isEmpty( rootNode.getComment() ) ) + { + writer.writeComment( rootNode.getComment() ); + } + + writeStartElement( rootNode ); + } + + @Override + protected void endWriteRootNode( RootNode rootNode ) throws Exception + { + writer.writeEndElement(); + writer.writeEndDocument(); + } + + @Override + protected void startWriteSimpleNode( SimpleNode simpleNode ) throws Exception + { + String value = String.format( "%s", simpleNode.getValue() ); + + if ( simpleNode.isAttribute() ) + { + if ( !StringUtils.isEmpty( simpleNode.getNamespace() ) ) + { + writer.writeAttribute( simpleNode.getNamespace(), simpleNode.getName(), value ); + } + else + { + writer.writeAttribute( simpleNode.getName(), value ); + } + } + else + { + writeStartElement( simpleNode ); + writer.writeCharacters( value ); + } + } + + @Override + protected void endWriteSimpleNode( SimpleNode simpleNode ) throws Exception + { + if ( !simpleNode.isAttribute() ) + { + writer.writeEndElement(); + } + } + + @Override + protected void startWriteComplexNode( ComplexNode complexNode ) throws Exception + { + writeStartElement( complexNode ); + } + + @Override + protected void endWriteComplexNode( ComplexNode complexNode ) throws Exception + { + writer.writeEndElement(); + } + + @Override + protected void startWriteCollectionNode( CollectionNode collectionNode ) throws Exception + { + if ( collectionNode.isWrapping() ) + { + writeStartElement( collectionNode ); + } + } + + @Override + protected void endWriteCollectionNode( CollectionNode collectionNode ) throws Exception + { + if ( collectionNode.isWrapping() ) + { + writer.writeEndElement(); + } + } + + private void writeStartElement( Node node ) throws XMLStreamException + { + if ( !StringUtils.isEmpty( node.getComment() ) ) + { + writer.writeComment( node.getComment() ); + } + + if ( !StringUtils.isEmpty( node.getNamespace() ) ) + { + writer.writeStartElement( node.getNamespace(), node.getName() ); + } + else + { + writer.writeStartElement( node.getName() ); + } + } +} === added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/transformers' === added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java' --- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/node/transformers/RenameNodeTransformer.java 2014-07-18 13:32:19 +0000 @@ -0,0 +1,62 @@ +package org.hisp.dhis.node.transformers; + +/* + * Copyright (c) 2004-2014, 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 org.hisp.dhis.node.AbstractNode; +import org.hisp.dhis.node.Node; +import org.hisp.dhis.node.NodeTransformer; +import org.springframework.stereotype.Component; + +import java.util.List; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Morten Olav Hansen + */ +@Component +public class RenameNodeTransformer implements NodeTransformer +{ + @Override + public String name() + { + return "rename"; + } + + @Override + public Node transform( Node node, List args ) + { + checkNotNull( node ); + checkArgument( args.size() > 0, "rename requires a name parameter, .e.g: property|rename(newName)" ); + ((AbstractNode) node).setName( args.get( 0 ) ); + + return node; + } +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java 2014-07-18 09:17:18 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java 2014-07-18 13:32:19 +0000 @@ -28,14 +28,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE */ -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.annotation.PostConstruct; - +import com.google.common.base.Joiner; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.PresetProvider; import org.hisp.dhis.dxf2.parser.ParserService; @@ -46,16 +42,19 @@ import org.hisp.dhis.node.types.CollectionNode; import org.hisp.dhis.node.types.ComplexNode; import org.hisp.dhis.node.types.SimpleNode; +import org.hisp.dhis.period.PeriodType; import org.hisp.dhis.schema.Property; import org.hisp.dhis.schema.Schema; import org.hisp.dhis.schema.SchemaService; import org.hisp.dhis.system.util.ReflectionUtils; import org.springframework.beans.factory.annotation.Autowired; -import com.google.common.base.Joiner; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; +import javax.annotation.PostConstruct; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * @author Morten Olav Hansen