------------------------------------------------------------ revno: 18533 committer: Morten Olav Hansen <morte...@gmail.com> branch nick: dhis2 timestamp: Mon 2015-03-09 13:41:37 +0530 message: implemented support for IN operator in filter (not optimized by criteria for yet) added: dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java modified: dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java 2015-02-20 08:38:07 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java 2015-03-09 08:11:37 +0000 @@ -34,6 +34,7 @@ import org.hisp.dhis.dxf2.objectfilter.ops.EqOp; import org.hisp.dhis.dxf2.objectfilter.ops.GtOp; import org.hisp.dhis.dxf2.objectfilter.ops.GteOp; +import org.hisp.dhis.dxf2.objectfilter.ops.InOp; import org.hisp.dhis.dxf2.objectfilter.ops.LikeOp; import org.hisp.dhis.dxf2.objectfilter.ops.LtOp; import org.hisp.dhis.dxf2.objectfilter.ops.LteOp; @@ -72,6 +73,7 @@ register( "null", NullOp.class ); register( "nnull", NnullOp.class ); register( "empty", EmptyCollectionOp.class ); + register( "in", InOp.class ); } public static void register( String type, Class<? extends Op> opClass ) === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/InOp.java 2015-03-09 08:11:37 +0000 @@ -0,0 +1,58 @@ +package org.hisp.dhis.dxf2.objectfilter.ops; + +/* + * Copyright (c) 2004-2015, 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 java.util.Collection; + +/** + * @author Morten Olav Hansen <morte...@gmail.com> + */ +public class InOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + Collection<String> items = getValue( Collection.class ); + + if ( items == null ) + { + return OpStatus.INCLUDE; + } + + for ( String item : items ) + { + if ( item.equals( object ) ) + { + return OpStatus.INCLUDE; + } + } + + return OpStatus.IGNORE; + } +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 2015-03-09 06:53:04 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 2015-03-09 08:11:37 +0000 @@ -28,8 +28,10 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +import com.google.common.collect.Lists; import org.hisp.dhis.system.util.DateUtils; +import java.util.Collection; import java.util.Date; /** @@ -106,6 +108,16 @@ { return (T) DateUtils.parseDate( value ); } + else if ( Collection.class.isAssignableFrom( klass ) ) + { + if ( value == null || !value.startsWith( "[" ) || !value.endsWith( "]" ) ) + { + return null; + } + + String[] split = value.substring( 1, value.length() - 1 ).split( "," ); + return (T) Lists.newArrayList( split ); + } return null; }
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : dhis2-devs@lists.launchpad.net Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp