=== added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodePropertyConverter.java 2014-06-20 10:55:18 +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-api/src/main/java/org/hisp/dhis/node/NodePropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodePropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodePropertyConverter.java 2014-06-20 10:55:18 +0000 @@ -0,0 +1,36 @@ +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 + */ + +/** + * @author Morten Olav Hansen + */ +public interface NodePropertyConverter extends PropertyConverter +{ +} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeTransformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeTransformer.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/NodeTransformer.java 1970-01-01 00:00:00 +0000 @@ -1,36 +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 - */ - -/** - * @author Morten Olav Hansen - */ -public interface NodeTransformer extends Transformer -{ -} === added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/PropertyConverter.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/PropertyConverter.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/PropertyConverter.java 2014-06-20 10:55:18 +0000 @@ -0,0 +1,70 @@ +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 interface PropertyConverter +{ + /** + * @return Public/external name of this transformer. + */ + String name(); + + /** + * @param property Property instance belonging to value + * @param value Actual value to transform + * @return true of false depending on support + */ + boolean canConvertTo( Property property, S value ); + + /** + * @param property Property instance belonging to value + * @param value Actual value to transform + * @return true of false depending on support + */ + boolean canConvertFrom( Property property, D value ); + + /** + * @param property Property instance belonging to value + * @param value Actual value to transform + * @return Value transformed to a Node + */ + D convertTo( Property property, S value ); + + /** + * @param property Property instance belonging to value + * @param value Actual value to transform + * @return Value transformed to a Node + */ + S convertFrom( Property property, D value ); +} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Transformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Transformer.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/Transformer.java 1970-01-01 00:00:00 +0000 @@ -1,60 +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 interface Transformer -{ - /** - * @return Public/external name of this transformer. - */ - String name(); - - /** - * Transform value. Value can be null. - * - * @param property Property instance belonging to value - * @param value Actual value to transform - * @return Value transformed to a Node - */ - T transform( Property property, Object value ); - - /** - * Is this property/value supported by this transformer. Value can be null. - * - * @param property Property instance belonging to value - * @param value Actual value to transform - * @return true of false depending on support - */ - boolean canTransform( Property property, Object value ); -} === added directory 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters' === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsEmptyNodePropertyConverter.java 2014-06-20 10:55:18 +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 transformer." ); + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/IsNotEmptyNodePropertyConverter.java 2014-06-20 10:55:18 +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 transformer." ); + } +} === added 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 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/converters/SizeNodePropertyConverter.java 2014-06-20 10:55:18 +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 transformer." ); + } +} === 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/IsEmptyNodeTransformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/IsEmptyNodeTransformer.java 2014-06-19 14:44:28 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/IsEmptyNodeTransformer.java 1970-01-01 00:00:00 +0000 @@ -1,72 +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.Node; -import org.hisp.dhis.node.NodeTransformer; -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 IsEmptyNodeTransformer implements NodeTransformer -{ - @Override - public String name() - { - return "isEmpty"; - } - - @Override - public Node transform( 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." ); - } - - @Override - public boolean canTransform( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/IsNotEmptyNodeTransformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/IsNotEmptyNodeTransformer.java 2014-06-19 14:44:28 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/IsNotEmptyNodeTransformer.java 1970-01-01 00:00:00 +0000 @@ -1,72 +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.Node; -import org.hisp.dhis.node.NodeTransformer; -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 IsNotEmptyNodeTransformer implements NodeTransformer -{ - @Override - public String name() - { - return "isNotEmpty"; - } - - @Override - public Node transform( 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." ); - } - - @Override - public boolean canTransform( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } -} === removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/SizeNodeTransformer.java' --- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/SizeNodeTransformer.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/transformers/SizeNodeTransformer.java 1970-01-01 00:00:00 +0000 @@ -1,71 +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.Node; -import org.hisp.dhis.node.NodeTransformer; -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 SizeNodeTransformer implements NodeTransformer -{ - @Override - public String name() - { - return "size"; - } - - @Override - public Node transform( 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." ); - } - - @Override - public boolean canTransform( Property property, Object value ) - { - return property.isCollection() || String.class.isInstance( value ); - } -} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java 2014-06-20 09:10:42 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java 2014-06-20 10:55:18 +0000 @@ -34,7 +34,7 @@ import com.google.common.collect.Sets; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.PresetProvider; -import org.hisp.dhis.node.NodeTransformer; +import org.hisp.dhis.node.NodePropertyConverter; import org.hisp.dhis.node.types.CollectionNode; import org.hisp.dhis.node.types.ComplexNode; import org.hisp.dhis.node.types.SimpleNode; @@ -64,11 +64,11 @@ private Set presetProviders = Sets.newHashSet(); @Autowired(required = false) - private Set nodeTransformers = Sets.newHashSet(); + private Set nodePropertyConverters = Sets.newHashSet(); private ImmutableMap presets = ImmutableMap.of(); - private ImmutableMap transformers = ImmutableMap.of(); + private ImmutableMap converters = ImmutableMap.of(); @PostConstruct public void init() @@ -82,14 +82,14 @@ presets = presetBuilder.build(); - ImmutableMap.Builder transformerBuilder = ImmutableMap.builder(); + ImmutableMap.Builder converterBuilder = ImmutableMap.builder(); - for ( NodeTransformer transformer : nodeTransformers ) + for ( NodePropertyConverter converter : nodePropertyConverters ) { - transformerBuilder.put( transformer.name(), transformer ); + converterBuilder.put( converter.name(), converter ); } - transformers = transformerBuilder.build(); + converters = converterBuilder.build(); } @Override @@ -168,13 +168,13 @@ updateFields( fieldValue, property.getKlass() ); } - if ( fieldValue.haveNodeTransformer() ) + if ( fieldValue.haveNodePropertyConverter() ) { - NodeTransformer transformer = fieldValue.getNodeTransformer(); + NodePropertyConverter converter = fieldValue.getNodePropertyConverter(); - if ( transformer.canTransform( property, returnValue ) ) + if ( converter.canConvertTo( property, returnValue ) ) { - complexNode.addChild( transformer.transform( property, returnValue ) ); + complexNode.addChild( converter.convertTo( property, returnValue ) ); } } @@ -330,9 +330,9 @@ { FieldMap value = new FieldMap(); - if ( transformers.containsKey( split[1] ) ) + if ( converters.containsKey( split[1] ) ) { - value.setNodeTransformer( transformers.get( split[1] ) ); + value.setNodePropertyConverter( converters.get( split[1] ) ); fieldMap.put( split[0], value ); } } === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java 2014-06-19 12:20:10 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java 2014-06-20 10:55:18 +0000 @@ -31,7 +31,7 @@ import com.google.common.base.Objects; import com.google.common.collect.ForwardingMap; import com.google.common.collect.Maps; -import org.hisp.dhis.node.NodeTransformer; +import org.hisp.dhis.node.NodePropertyConverter; import java.util.Map; @@ -42,7 +42,7 @@ { private final Map delegate = Maps.newHashMap(); - private NodeTransformer nodeTransformer; + private NodePropertyConverter nodePropertyConverter; @Override protected Map delegate() @@ -50,19 +50,19 @@ return delegate; } - public NodeTransformer getNodeTransformer() - { - return nodeTransformer; - } - - public void setNodeTransformer( NodeTransformer nodeTransformer ) - { - this.nodeTransformer = nodeTransformer; - } - - public boolean haveNodeTransformer() - { - return nodeTransformer != null; + public NodePropertyConverter getNodePropertyConverter() + { + return nodePropertyConverter; + } + + public void setNodePropertyConverter( NodePropertyConverter nodePropertyConverter ) + { + this.nodePropertyConverter = nodePropertyConverter; + } + + public boolean haveNodePropertyConverter() + { + return nodePropertyConverter != null; } @Override @@ -70,7 +70,7 @@ { return Objects.toStringHelper( this ) .add( "map", standardToString() ) - .add( "nodeTransformer", nodeTransformer ) + .add( "nodePropertyConverter", nodePropertyConverter ) .toString(); } }