=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common' === removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops' === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EmptyCollectionOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EmptyCollectionOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EmptyCollectionOp.java 1970-01-01 00:00:00 +0000 @@ -1,69 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; - -/** - * @author Morten Olav Hansen - */ -public class EmptyCollectionOp extends Op -{ - @Override - public boolean wantValue() - { - return false; - } - - @Override - public OpStatus evaluate( Object object ) - { - if ( object == null ) - { - // TODO: ignore or include here? - return OpStatus.IGNORE; - } - - if ( Collection.class.isInstance( object ) ) - { - Collection c = (Collection) object; - - if ( c.isEmpty() ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EqOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EqOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/EqOp.java 1970-01-01 00:00:00 +0000 @@ -1,99 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public class EqOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( String.class.isInstance( object ) ) - { - String s1 = getValue( String.class ); - String s2 = (String) object; - - return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Boolean.class.isInstance( object ) ) - { - Boolean s1 = getValue( Boolean.class ); - Boolean s2 = (Boolean) object; - - return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Integer.class.isInstance( object ) ) - { - Integer s1 = getValue( Integer.class ); - Integer s2 = (Integer) object; - - return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Float.class.isInstance( object ) ) - { - Float s1 = getValue( Float.class ); - Float s2 = (Float) object; - - return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Collection.class.isInstance( object ) ) - { - Collection collection = (Collection) object; - Integer size = getValue( Integer.class ); - - if ( size != null && collection.size() == size ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - else if ( Date.class.isInstance( object ) ) - { - Date s1 = getValue( Date.class ); - Date s2 = (Date) object; - - return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/FilterOps.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/FilterOps.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/FilterOps.java 1970-01-01 00:00:00 +0000 @@ -1,73 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; - -import java.util.List; -import java.util.Map; - -/** -* @author Morten Olav Hansen -*/ -public class FilterOps -{ - private Map> filters = Maps.newHashMap(); - - FilterOps() - { - } - - public void addFilter( String opStr, Op op ) - { - if ( !filters.containsKey( opStr ) ) - { - filters.put( opStr, Lists.newArrayList() ); - } - - filters.get( opStr ).add( op ); - } - - public Map> getFilters() - { - return filters; - } - - public void setFilters( Map> filters ) - { - this.filters = filters; - } - - @Override - public String toString() - { - return filters.toString(); - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Filters.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Filters.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Filters.java 1970-01-01 00:00:00 +0000 @@ -1,154 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import com.google.common.collect.Maps; - -import java.util.Map; - -/** -* @author Morten Olav Hansen -*/ -public class Filters -{ - private Map filters = Maps.newHashMap(); - - public Filters() - { - } - - public void addFilter( String path, String operator, String value ) - { - FilterOps filterOps = createPath( path ); - - if ( filterOps == null ) - { - return; - } - - if ( OpFactory.canCreate( operator ) ) - { - Op op = OpFactory.create( operator ); - - if ( op.wantValue() ) - { - if ( value == null ) - { - return; - } - - op.setValue( value ); - } - - filterOps.addFilter( operator, op ); - } - } - - @SuppressWarnings( "unchecked" ) - private FilterOps createPath( String path ) - { - if ( !path.contains( "." ) ) - { - if ( !filters.containsKey( path ) ) - { - filters.put( path, new FilterOps() ); - } - - return (FilterOps) filters.get( path ); - } - - String[] split = path.split( "\\." ); - - Map c = filters; - - for ( int i = 0; i < split.length; i++ ) - { - boolean last = (i == (split.length - 1)); - - if ( c.containsKey( split[i] ) ) - { - if ( FilterOps.class.isInstance( c.get( split[i] ) ) ) - { - if ( last ) - { - return (FilterOps) c.get( split[i] ); - } - else - { - FilterOps self = (FilterOps) c.get( split[i] ); - Map map = Maps.newHashMap(); - map.put( "__self__", self ); - - c.put( split[i], map ); - c = map; - } - } - else - { - c = (Map) c.get( split[i] ); - } - } - else - { - if ( last ) - { - FilterOps filterOps = new FilterOps(); - c.put( split[i], filterOps ); - return filterOps; - } - else - { - Map map = Maps.newHashMap(); - c.put( split[i], map ); - c = map; - } - } - } - - return null; - } - - public Map getFilters() - { - return filters; - } - - public void setFilters( Map filters ) - { - this.filters = filters; - } - - @Override - public String toString() - { - return "Filters{" + - "filters=" + filters + - '}'; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GtOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GtOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GtOp.java 1970-01-01 00:00:00 +0000 @@ -1,85 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public class GtOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( Integer.class.isInstance( object ) ) - { - Integer s1 = getValue( Integer.class ); - Integer s2 = (Integer) object; - - return (s1 != null && s2 > s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Float.class.isInstance( object ) ) - { - Float s1 = getValue( Float.class ); - Float s2 = (Float) object; - - return (s1 != null && s2 > s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Collection.class.isInstance( object ) ) - { - Collection collection = (Collection) object; - Integer size = getValue( Integer.class ); - - if ( size != null && collection.size() > size ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - else if ( Date.class.isInstance( object ) ) - { - Date s1 = getValue( Date.class ); - Date s2 = (Date) object; - - return (s1 != null && s2.after( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GteOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GteOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/GteOp.java 1970-01-01 00:00:00 +0000 @@ -1,85 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public class GteOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( Integer.class.isInstance( object ) ) - { - Integer s1 = getValue( Integer.class ); - Integer s2 = (Integer) object; - - return (s1 != null && s2 >= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Float.class.isInstance( object ) ) - { - Float s1 = getValue( Float.class ); - Float s2 = (Float) object; - - return (s1 != null && s2 >= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Collection.class.isInstance( object ) ) - { - Collection collection = (Collection) object; - Integer size = getValue( Integer.class ); - - if ( size != null && collection.size() >= size ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - else if ( Date.class.isInstance( object ) ) - { - Date s1 = getValue( Date.class ); - Date s2 = (Date) object; - - return (s1 != null && (s2.after( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LikeOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LikeOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LikeOp.java 1970-01-01 00:00:00 +0000 @@ -1,54 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** -* @author Morten Olav Hansen -*/ -public class LikeOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( String.class.isInstance( object ) ) - { - String s1 = getValue( String.class ); - String s2 = (String) object; - - return (s1 != null && s2.toLowerCase().contains( s1.toLowerCase() )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LtOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LtOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LtOp.java 1970-01-01 00:00:00 +0000 @@ -1,85 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public class LtOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( Integer.class.isInstance( object ) ) - { - Integer s1 = getValue( Integer.class ); - Integer s2 = (Integer) object; - - return (s1 != null && s2 < s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Float.class.isInstance( object ) ) - { - Float s1 = getValue( Float.class ); - Float s2 = (Float) object; - - return (s1 != null && s2 < s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Collection.class.isInstance( object ) ) - { - Collection collection = (Collection) object; - Integer size = getValue( Integer.class ); - - if ( size != null && collection.size() < size ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - else if ( Date.class.isInstance( object ) ) - { - Date s1 = getValue( Date.class ); - Date s2 = (Date) object; - - return (s1 != null && (s2.before( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LteOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LteOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/LteOp.java 1970-01-01 00:00:00 +0000 @@ -1,85 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.util.Collection; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public class LteOp extends Op -{ - @Override - public OpStatus evaluate( Object object ) - { - if ( getValue() == null || object == null ) - { - return OpStatus.IGNORE; - } - - if ( Integer.class.isInstance( object ) ) - { - Integer s1 = getValue( Integer.class ); - Integer s2 = (Integer) object; - - return (s1 != null && s2 <= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Float.class.isInstance( object ) ) - { - Float s1 = getValue( Float.class ); - Float s2 = (Float) object; - - return (s1 != null && s2 <= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - else if ( Collection.class.isInstance( object ) ) - { - Collection collection = (Collection) object; - Integer size = getValue( Integer.class ); - - if ( size != null && collection.size() <= size ) - { - return OpStatus.INCLUDE; - } - else - { - return OpStatus.EXCLUDE; - } - } - else if ( Date.class.isInstance( object ) ) - { - Date s1 = getValue( Date.class ); - Date s2 = (Date) object; - - return (s1 != null && (s2.before( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NeqOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NeqOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NeqOp.java 1970-01-01 00:00:00 +0000 @@ -1,55 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** -* @author Morten Olav Hansen -*/ -public class NeqOp extends Op -{ - private Op op = OpFactory.create( "eq" ); - - @Override - public OpStatus evaluate( Object object ) - { - op.setValue( getValue() ); - OpStatus status = op.evaluate( object ); - - // switch status from EqOp - switch ( status ) - { - case INCLUDE: - return OpStatus.EXCLUDE; - case EXCLUDE: - return OpStatus.INCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NullOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NullOp.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/NullOp.java 1970-01-01 00:00:00 +0000 @@ -1,52 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** -* @author Morten Olav Hansen -*/ -public class NullOp extends Op -{ - @Override - public boolean wantValue() - { - return false; - } - - @Override - public OpStatus evaluate( Object object ) - { - if ( object == null ) - { - return OpStatus.INCLUDE; - } - - return OpStatus.IGNORE; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Op.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Op.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/Op.java 1970-01-01 00:00:00 +0000 @@ -1,123 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -/** - * @author Morten Olav Hansen - */ -public abstract class Op -{ - private String value; - - private static SimpleDateFormat[] simpleDateFormats = new SimpleDateFormat[]{ - new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ), - new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ), - new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm" ), - new SimpleDateFormat( "yyyy-MM-dd'T'HH" ), - new SimpleDateFormat( "yyyyMMdd" ), - new SimpleDateFormat( "yyyyMM" ), - new SimpleDateFormat( "yyyy" ) - }; - - public boolean wantValue() - { - return true; - } - - public void setValue( String value ) - { - this.value = value; - } - - public String getValue() - { - return value; - } - - @SuppressWarnings( "unchecked" ) - public T getValue( Class klass ) - { - if ( klass.isInstance( value ) ) - { - return (T) value; - } - - if ( Boolean.class.isAssignableFrom( klass ) ) - { - try - { - return (T) Boolean.valueOf( value ); - } - catch ( Exception ignored ) - { - } - } - else if ( Integer.class.isAssignableFrom( klass ) ) - { - try - { - return (T) Integer.valueOf( value ); - } - catch ( Exception ignored ) - { - } - } - else if ( Float.class.isAssignableFrom( klass ) ) - { - try - { - return (T) Float.valueOf( value ); - } - catch ( Exception ignored ) - { - } - } - else if ( Date.class.isAssignableFrom( klass ) ) - { - for ( SimpleDateFormat simpleDateFormat : simpleDateFormats ) - { - try - { - return (T) simpleDateFormat.parse( value ); - } - catch ( ParseException ignored ) - { - } - } - } - - return null; - } - - public abstract OpStatus evaluate( Object object ); -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpFactory.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpFactory.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpFactory.java 1970-01-01 00:00:00 +0000 @@ -1,82 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -import com.google.common.collect.Maps; - -import java.util.Map; - -/** - * @author Morten Olav Hansen - */ -public class OpFactory -{ - protected static Map> register = Maps.newHashMap(); - - static - { - register( "eq", EqOp.class ); - register( "neq", NeqOp.class ); - register( "like", LikeOp.class ); - register( "gt", GtOp.class ); - register( "gte", GteOp.class ); - register( "lt", LtOp.class ); - register( "lte", LteOp.class ); - register( "null", NullOp.class ); - register( "empty", EmptyCollectionOp.class ); - } - - public static void register( String type, Class opClass ) - { - register.put( type.toLowerCase(), opClass ); - } - - public static boolean canCreate( String type ) - { - return register.containsKey( type.toLowerCase() ); - } - - public static Op create( String type ) - { - Class opClass = register.get( type.toLowerCase() ); - - try - { - return opClass.newInstance(); - } - catch ( InstantiationException ignored ) - { - } - catch ( IllegalAccessException ignored ) - { - } - - return null; - } -} === removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpStatus.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpStatus.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/common/ops/OpStatus.java 1970-01-01 00:00:00 +0000 @@ -1,37 +0,0 @@ -package org.hisp.dhis.dxf2.common.ops; - -/* - * Copyright (c) 2004-2013, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -/** -* @author Morten Olav Hansen -*/ -public enum OpStatus -{ - INCLUDE, EXCLUDE, IGNORE -} === added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter' === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,358 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.hisp.dhis.common.IdentifiableObject; +import org.hisp.dhis.dxf2.filter.ops.Op; +import org.hisp.dhis.dxf2.schema.Property; +import org.hisp.dhis.dxf2.schema.Schema; +import org.hisp.dhis.dxf2.schema.SchemaService; +import org.hisp.dhis.system.util.ReflectionUtils; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public class DefaultFilterService implements FilterService +{ + @Autowired + private ParserService parserService; + + @Autowired + private SchemaService schemaService; + + @Override + public List filterObjects( List objects, List filters ) + { + if ( objects == null || objects.isEmpty() ) + { + return Lists.newArrayList(); + } + + Filters parsed = parserService.parserPropertyFilters( filters ); + + List list = Lists.newArrayList(); + + for ( T object : objects ) + { + if ( evaluateWithFilters( object, parsed ) ) + { + list.add( object ); + } + } + + return list; + } + + @Override + public List filterFields( List objects, String include, String exclude ) + { + List output = Lists.newArrayList(); + + if ( objects.isEmpty() ) + { + return output; + } + + Map fieldMap = Maps.newHashMap(); + + if ( include == null && exclude == null ) + { + Schema schema = schemaService.getSchema( objects.get( 0 ).getClass() ); + + for ( Property property : schema.getProperties() ) + { + fieldMap.put( property.getName(), Maps.newHashMap() ); + } + } + else if ( include == null ) + { + Schema schema = schemaService.getSchema( objects.get( 0 ).getClass() ); + + Map excludeMap = parserService.parseFieldExpression( exclude ); + + for ( Property property : schema.getProperties() ) + { + if ( !excludeMap.containsKey( property.getName() ) ) + { + fieldMap.put( property.getName(), Maps.newHashMap() ); + } + } + } + else + { + fieldMap = parserService.parseFieldExpression( include ); + } + + for ( Object object : objects ) + { + output.add( buildObjectOutput( object, fieldMap ) ); + } + + return output; + } + + @SuppressWarnings( "unchecked" ) + private Map buildObjectOutput( Object object, Map fieldMap ) + { + if ( object == null ) + { + return null; + } + + Map output = Maps.newHashMap(); + Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); + + for ( String key : fieldMap.keySet() ) + { + if ( !classMap.containsKey( key ) ) + { + continue; + } + + Map value = fieldMap.get( key ); + ReflectionUtils.PropertyDescriptor descriptor = classMap.get( key ); + Object returned = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); + + if ( returned == null ) + { + continue; + } + + if ( value.isEmpty() ) + { + if ( !descriptor.isIdentifiableObject() ) + { + output.put( key, returned ); + } + else if ( !descriptor.isCollection() ) + { + Map properties = getIdentifiableObjectProperties( returned ); + output.put( key, properties ); + } + else if ( descriptor.isCollection() ) + { + List> properties = getIdentifiableObjectCollectionProperties( returned ); + output.put( key, properties ); + } + } + else + { + if ( descriptor.isCollection() ) + { + Collection objects = (Collection) returned; + ArrayList arrayList = Lists.newArrayList(); + output.put( key, arrayList ); + + for ( Object obj : objects ) + { + Map properties = buildObjectOutput( obj, value ); + arrayList.add( properties ); + } + } + else + { + Map properties = buildObjectOutput( returned, value ); + output.put( key, properties ); + } + } + } + + return output; + } + + private List> getIdentifiableObjectCollectionProperties( Object object ) + { + List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); + return getIdentifiableObjectCollectionProperties( object, fields ); + } + + @SuppressWarnings( "unchecked" ) + private List> getIdentifiableObjectCollectionProperties( Object object, List fields ) + { + List> output = Lists.newArrayList(); + Collection identifiableObjects; + + try + { + identifiableObjects = (Collection) object; + } + catch ( ClassCastException ex ) + { + ex.printStackTrace(); + return output; + } + + for ( IdentifiableObject identifiableObject : identifiableObjects ) + { + Map properties = getIdentifiableObjectProperties( identifiableObject, fields ); + output.add( properties ); + } + + return output; + } + + private Map getIdentifiableObjectProperties( Object object ) + { + List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); + return getIdentifiableObjectProperties( object, fields ); + } + + private Map getIdentifiableObjectProperties( Object object, List fields ) + { + Map idProps = Maps.newLinkedHashMap(); + Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); + + for ( String field : fields ) + { + ReflectionUtils.PropertyDescriptor descriptor = classMap.get( field ); + + if ( descriptor == null ) + { + continue; + } + + Object o = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); + + if ( o != null ) + { + idProps.put( field, o ); + } + } + + return idProps; + } + + @SuppressWarnings( "unchecked" ) + private boolean evaluateWithFilters( T object, Filters filters ) + { + Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); + + for ( String field : filters.getFilters().keySet() ) + { + if ( !classMap.containsKey( field ) ) + { + System.err.println( "Skipping non-existent field: " + field ); + continue; + } + + ReflectionUtils.PropertyDescriptor descriptor = classMap.get( field ); + + Object value = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); + + Object filter = filters.getFilters().get( field ); + + if ( FilterOps.class.isInstance( filter ) ) + { + if ( evaluateFilterOps( value, (FilterOps) filter ) ) + { + return false; + } + } + else + { + Map map = (Map) filters.getFilters().get( field ); + Filters f = new Filters(); + f.setFilters( map ); + + if ( map.containsKey( "__self__" ) ) + { + if ( evaluateFilterOps( value, (FilterOps) map.get( "__self__" ) ) ) + { + return false; + } + + map.remove( "__self__" ); + } + + if ( descriptor.isIdentifiableObject() && !descriptor.isCollection() ) + { + if ( !evaluateWithFilters( (IdentifiableObject) value, f ) ) + { + return false; + } + } + else if ( descriptor.isIdentifiableObject() && descriptor.isCollection() ) + { + Collection idObjectCollection = (Collection) value; + + if ( idObjectCollection.isEmpty() ) + { + return false; + } + + for ( Object idObject : idObjectCollection ) + { + if ( !evaluateWithFilters( (IdentifiableObject) idObject, f ) ) + { + return false; + } + } + } + } + } + + return true; + } + + private boolean evaluateFilterOps( Object value, FilterOps filterOps ) + { + // filter through every operator treating multiple of same operator as OR + for ( String operator : filterOps.getFilters().keySet() ) + { + boolean include = false; + + List ops = filterOps.getFilters().get( operator ); + + for ( Op op : ops ) + { + switch ( op.evaluate( value ) ) + { + case INCLUDE: + { + include = true; + } + } + } + + if ( !include ) + { + return true; + } + } + return false; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,140 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.lang.StringUtils; + +import java.util.List; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public class DefaultParserService implements ParserService +{ + @Override + public Filters parserPropertyFilters( List filters ) + { + Filters parsed = new Filters(); + + for ( String filter : filters ) + { + String[] split = filter.split( ":" ); + + if ( !(split.length >= 2) ) + { + continue; + } + + if ( split.length >= 3 ) + { + parsed.addFilter( split[0], split[1], split[2] ); + } + else + { + parsed.addFilter( split[0], split[1], null ); + } + } + + return parsed; + } + + @Override + public Map parseFieldExpression( String fields ) + { + List prefixList = Lists.newArrayList(); + Map parsed = Maps.newHashMap(); + + StringBuilder builder = new StringBuilder(); + + for ( String c : fields.split( "" ) ) + { + if ( c.equals( "," ) ) + { + putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); + builder = new StringBuilder(); + continue; + } + + if ( c.equals( "[" ) ) + { + prefixList.add( builder.toString() ); + builder = new StringBuilder(); + continue; + } + + if ( c.equals( "]" ) ) + { + if ( !builder.toString().isEmpty() ) + { + putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); + } + + prefixList.remove( prefixList.size() - 1 ); + builder = new StringBuilder(); + continue; + } + + if ( StringUtils.isAlpha( c ) ) + { + builder.append( c ); + } + } + + if ( !builder.toString().isEmpty() ) + { + putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); + } + + return parsed; + } + + private String joinedWithPrefix( StringBuilder builder, List prefixList ) + { + String prefixes = StringUtils.join( prefixList, "." ); + prefixes = prefixes.isEmpty() ? builder.toString() : (prefixes + "." + builder.toString()); + return prefixes; + } + + @SuppressWarnings( "unchecked" ) + private void putInMap( Map map, String path ) + { + for ( String p : path.split( "\\." ) ) + { + if ( map.get( p ) == null ) + { + map.put( p, Maps.newHashMap() ); + } + + map = map.get( p ); + } + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterOps.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterOps.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterOps.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,74 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.hisp.dhis.dxf2.filter.ops.Op; + +import java.util.List; +import java.util.Map; + +/** +* @author Morten Olav Hansen +*/ +public class FilterOps +{ + private Map> filters = Maps.newHashMap(); + + FilterOps() + { + } + + public void addFilter( String opStr, Op op ) + { + if ( !filters.containsKey( opStr ) ) + { + filters.put( opStr, Lists.newArrayList() ); + } + + filters.get( opStr ).add( op ); + } + + public Map> getFilters() + { + return filters; + } + + public void setFilters( Map> filters ) + { + this.filters = filters; + } + + @Override + public String toString() + { + return filters.toString(); + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterService.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,43 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.common.IdentifiableObject; + +import java.util.List; + +/** + * @author Morten Olav Hansen + */ +public interface FilterService +{ + List filterObjects( List objects, List filters ); + + List filterFields( List objects, String include, String exclude ); +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/Filters.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/Filters.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/Filters.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,155 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Maps; +import org.hisp.dhis.dxf2.filter.ops.Op; + +import java.util.Map; + +/** +* @author Morten Olav Hansen +*/ +public class Filters +{ + private Map filters = Maps.newHashMap(); + + public Filters() + { + } + + public void addFilter( String path, String operator, String value ) + { + FilterOps filterOps = createPath( path ); + + if ( filterOps == null ) + { + return; + } + + if ( OpFactory.canCreate( operator ) ) + { + Op op = OpFactory.create( operator ); + + if ( op.wantValue() ) + { + if ( value == null ) + { + return; + } + + op.setValue( value ); + } + + filterOps.addFilter( operator, op ); + } + } + + @SuppressWarnings( "unchecked" ) + private FilterOps createPath( String path ) + { + if ( !path.contains( "." ) ) + { + if ( !filters.containsKey( path ) ) + { + filters.put( path, new FilterOps() ); + } + + return (FilterOps) filters.get( path ); + } + + String[] split = path.split( "\\." ); + + Map c = filters; + + for ( int i = 0; i < split.length; i++ ) + { + boolean last = (i == (split.length - 1)); + + if ( c.containsKey( split[i] ) ) + { + if ( FilterOps.class.isInstance( c.get( split[i] ) ) ) + { + if ( last ) + { + return (FilterOps) c.get( split[i] ); + } + else + { + FilterOps self = (FilterOps) c.get( split[i] ); + Map map = Maps.newHashMap(); + map.put( "__self__", self ); + + c.put( split[i], map ); + c = map; + } + } + else + { + c = (Map) c.get( split[i] ); + } + } + else + { + if ( last ) + { + FilterOps filterOps = new FilterOps(); + c.put( split[i], filterOps ); + return filterOps; + } + else + { + Map map = Maps.newHashMap(); + c.put( split[i], map ); + c = map; + } + } + } + + return null; + } + + public Map getFilters() + { + return filters; + } + + public void setFilters( Map filters ) + { + this.filters = filters; + } + + @Override + public String toString() + { + return "Filters{" + + "filters=" + filters + + '}'; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/OpFactory.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/OpFactory.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/OpFactory.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,92 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import com.google.common.collect.Maps; +import org.hisp.dhis.dxf2.filter.ops.EmptyCollectionOp; +import org.hisp.dhis.dxf2.filter.ops.EqOp; +import org.hisp.dhis.dxf2.filter.ops.GtOp; +import org.hisp.dhis.dxf2.filter.ops.GteOp; +import org.hisp.dhis.dxf2.filter.ops.LikeOp; +import org.hisp.dhis.dxf2.filter.ops.LtOp; +import org.hisp.dhis.dxf2.filter.ops.LteOp; +import org.hisp.dhis.dxf2.filter.ops.NeqOp; +import org.hisp.dhis.dxf2.filter.ops.NullOp; +import org.hisp.dhis.dxf2.filter.ops.Op; + +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public class OpFactory +{ + protected static Map> register = Maps.newHashMap(); + + static + { + register( "eq", EqOp.class ); + register( "neq", NeqOp.class ); + register( "like", LikeOp.class ); + register( "gt", GtOp.class ); + register( "gte", GteOp.class ); + register( "lt", LtOp.class ); + register( "lte", LteOp.class ); + register( "null", NullOp.class ); + register( "empty", EmptyCollectionOp.class ); + } + + public static void register( String type, Class opClass ) + { + register.put( type.toLowerCase(), opClass ); + } + + public static boolean canCreate( String type ) + { + return register.containsKey( type.toLowerCase() ); + } + + public static Op create( String type ) + { + Class opClass = register.get( type.toLowerCase() ); + + try + { + return opClass.newInstance(); + } + catch ( InstantiationException ignored ) + { + } + catch ( IllegalAccessException ignored ) + { + } + + return null; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,42 @@ +package org.hisp.dhis.dxf2.filter; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.List; +import java.util.Map; + +/** + * @author Morten Olav Hansen + */ +public interface ParserService +{ + Filters parserPropertyFilters( List filters ); + + Map parseFieldExpression( String filter ); +} === added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops' === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EmptyCollectionOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EmptyCollectionOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EmptyCollectionOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,69 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; + +/** + * @author Morten Olav Hansen + */ +public class EmptyCollectionOp extends Op +{ + @Override + public boolean wantValue() + { + return false; + } + + @Override + public OpStatus evaluate( Object object ) + { + if ( object == null ) + { + // TODO: ignore or include here? + return OpStatus.IGNORE; + } + + if ( Collection.class.isInstance( object ) ) + { + Collection c = (Collection) object; + + if ( c.isEmpty() ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EqOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EqOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EqOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,99 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class EqOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( String.class.isInstance( object ) ) + { + String s1 = getValue( String.class ); + String s2 = (String) object; + + return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Boolean.class.isInstance( object ) ) + { + Boolean s1 = getValue( Boolean.class ); + Boolean s2 = (Boolean) object; + + return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Integer.class.isInstance( object ) ) + { + Integer s1 = getValue( Integer.class ); + Integer s2 = (Integer) object; + + return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Float.class.isInstance( object ) ) + { + Float s1 = getValue( Float.class ); + Float s2 = (Float) object; + + return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + Integer size = getValue( Integer.class ); + + if ( size != null && collection.size() == size ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + else if ( Date.class.isInstance( object ) ) + { + Date s1 = getValue( Date.class ); + Date s2 = (Date) object; + + return (s1 != null && s2.equals( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GtOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GtOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GtOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,85 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class GtOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( Integer.class.isInstance( object ) ) + { + Integer s1 = getValue( Integer.class ); + Integer s2 = (Integer) object; + + return (s1 != null && s2 > s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Float.class.isInstance( object ) ) + { + Float s1 = getValue( Float.class ); + Float s2 = (Float) object; + + return (s1 != null && s2 > s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + Integer size = getValue( Integer.class ); + + if ( size != null && collection.size() > size ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + else if ( Date.class.isInstance( object ) ) + { + Date s1 = getValue( Date.class ); + Date s2 = (Date) object; + + return (s1 != null && s2.after( s1 )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GteOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GteOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GteOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,85 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class GteOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( Integer.class.isInstance( object ) ) + { + Integer s1 = getValue( Integer.class ); + Integer s2 = (Integer) object; + + return (s1 != null && s2 >= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Float.class.isInstance( object ) ) + { + Float s1 = getValue( Float.class ); + Float s2 = (Float) object; + + return (s1 != null && s2 >= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + Integer size = getValue( Integer.class ); + + if ( size != null && collection.size() >= size ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + else if ( Date.class.isInstance( object ) ) + { + Date s1 = getValue( Date.class ); + Date s2 = (Date) object; + + return (s1 != null && (s2.after( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LikeOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LikeOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LikeOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,54 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** +* @author Morten Olav Hansen +*/ +public class LikeOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( String.class.isInstance( object ) ) + { + String s1 = getValue( String.class ); + String s2 = (String) object; + + return (s1 != null && s2.toLowerCase().contains( s1.toLowerCase() )) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LtOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LtOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LtOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,85 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class LtOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( Integer.class.isInstance( object ) ) + { + Integer s1 = getValue( Integer.class ); + Integer s2 = (Integer) object; + + return (s1 != null && s2 < s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Float.class.isInstance( object ) ) + { + Float s1 = getValue( Float.class ); + Float s2 = (Float) object; + + return (s1 != null && s2 < s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + Integer size = getValue( Integer.class ); + + if ( size != null && collection.size() < size ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + else if ( Date.class.isInstance( object ) ) + { + Date s1 = getValue( Date.class ); + Date s2 = (Date) object; + + return (s1 != null && (s2.before( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LteOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LteOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LteOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,85 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.util.Collection; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public class LteOp extends Op +{ + @Override + public OpStatus evaluate( Object object ) + { + if ( getValue() == null || object == null ) + { + return OpStatus.IGNORE; + } + + if ( Integer.class.isInstance( object ) ) + { + Integer s1 = getValue( Integer.class ); + Integer s2 = (Integer) object; + + return (s1 != null && s2 <= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Float.class.isInstance( object ) ) + { + Float s1 = getValue( Float.class ); + Float s2 = (Float) object; + + return (s1 != null && s2 <= s1) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + else if ( Collection.class.isInstance( object ) ) + { + Collection collection = (Collection) object; + Integer size = getValue( Integer.class ); + + if ( size != null && collection.size() <= size ) + { + return OpStatus.INCLUDE; + } + else + { + return OpStatus.EXCLUDE; + } + } + else if ( Date.class.isInstance( object ) ) + { + Date s1 = getValue( Date.class ); + Date s2 = (Date) object; + + return (s1 != null && (s2.before( s1 ) || s2.equals( s1 ))) ? OpStatus.INCLUDE : OpStatus.EXCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NeqOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NeqOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NeqOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,57 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import org.hisp.dhis.dxf2.filter.OpFactory; + +/** +* @author Morten Olav Hansen +*/ +public class NeqOp extends Op +{ + private Op op = OpFactory.create( "eq" ); + + @Override + public OpStatus evaluate( Object object ) + { + op.setValue( getValue() ); + OpStatus status = op.evaluate( object ); + + // switch status from EqOp + switch ( status ) + { + case INCLUDE: + return OpStatus.EXCLUDE; + case EXCLUDE: + return OpStatus.INCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NullOp.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NullOp.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NullOp.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,52 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** +* @author Morten Olav Hansen +*/ +public class NullOp extends Op +{ + @Override + public boolean wantValue() + { + return false; + } + + @Override + public OpStatus evaluate( Object object ) + { + if ( object == null ) + { + return OpStatus.INCLUDE; + } + + return OpStatus.IGNORE; + } +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/Op.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/Op.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/Op.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,123 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +/** + * @author Morten Olav Hansen + */ +public abstract class Op +{ + private String value; + + private static SimpleDateFormat[] simpleDateFormats = new SimpleDateFormat[]{ + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ssZ" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm" ), + new SimpleDateFormat( "yyyy-MM-dd'T'HH" ), + new SimpleDateFormat( "yyyyMMdd" ), + new SimpleDateFormat( "yyyyMM" ), + new SimpleDateFormat( "yyyy" ) + }; + + public boolean wantValue() + { + return true; + } + + public void setValue( String value ) + { + this.value = value; + } + + public String getValue() + { + return value; + } + + @SuppressWarnings( "unchecked" ) + public T getValue( Class klass ) + { + if ( klass.isInstance( value ) ) + { + return (T) value; + } + + if ( Boolean.class.isAssignableFrom( klass ) ) + { + try + { + return (T) Boolean.valueOf( value ); + } + catch ( Exception ignored ) + { + } + } + else if ( Integer.class.isAssignableFrom( klass ) ) + { + try + { + return (T) Integer.valueOf( value ); + } + catch ( Exception ignored ) + { + } + } + else if ( Float.class.isAssignableFrom( klass ) ) + { + try + { + return (T) Float.valueOf( value ); + } + catch ( Exception ignored ) + { + } + } + else if ( Date.class.isAssignableFrom( klass ) ) + { + for ( SimpleDateFormat simpleDateFormat : simpleDateFormats ) + { + try + { + return (T) simpleDateFormat.parse( value ); + } + catch ( ParseException ignored ) + { + } + } + } + + return null; + } + + public abstract OpStatus evaluate( Object object ); +} === added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/OpStatus.java' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/OpStatus.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/OpStatus.java 2014-03-14 10:25:42 +0000 @@ -0,0 +1,37 @@ +package org.hisp.dhis.dxf2.filter.ops; + +/* + * Copyright (c) 2004-2013, University of Oslo + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * Neither the name of the HISP project nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** +* @author Morten Olav Hansen +*/ +public enum OpStatus +{ + INCLUDE, EXCLUDE, IGNORE +} === modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2014-03-13 15:56:48 +0000 +++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2014-03-14 10:25:42 +0000 @@ -6,6 +6,10 @@ + + + + === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-06 05:53:38 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2014-03-14 10:25:42 +0000 @@ -39,6 +39,7 @@ import org.hisp.dhis.common.Pager; import org.hisp.dhis.common.PagerUtils; import org.hisp.dhis.common.SharingUtils; +import org.hisp.dhis.dxf2.filter.FilterService; import org.hisp.dhis.dxf2.metadata.ExchangeClasses; import org.hisp.dhis.dxf2.utils.JacksonUtils; import org.hisp.dhis.system.util.ReflectionUtils; @@ -80,15 +81,18 @@ @Autowired protected CurrentUserService currentUserService; + @Autowired + protected FilterService filterService; + //-------------------------------------------------------------------------- // GET //-------------------------------------------------------------------------- @RequestMapping( value = "/filtered", method = RequestMethod.GET ) public void getJacksonClassMap( - @RequestParam( required = false ) String include, - @RequestParam( required = false ) String exclude, - @RequestParam( value = "filter", required = false ) List filters, + @RequestParam(required = false) String include, + @RequestParam(required = false) String exclude, + @RequestParam(value = "filter", required = false) List filters, @RequestParam Map parameters, HttpServletResponse response ) throws IOException { WebOptions options = new WebOptions( parameters ); @@ -116,7 +120,7 @@ if ( filters != null && !filters.isEmpty() ) { - entityList = WebUtils.filterObjects( entityList, filters ); + entityList = filterService.filterObjects( entityList, filters ); if ( hasPaging ) { @@ -126,7 +130,7 @@ } } - List objects = WebUtils.filterFields( entityList, include, exclude ); + List objects = filterService.filterFields( entityList, include, exclude ); Map output = Maps.newLinkedHashMap(); if ( hasPaging ) @@ -139,7 +143,7 @@ JacksonUtils.toJson( response.getOutputStream(), output ); } - @RequestMapping( method = RequestMethod.GET ) + @RequestMapping(method = RequestMethod.GET) public String getObjectList( @RequestParam Map parameters, Model model, HttpServletRequest request ) throws Exception { WebOptions options = new WebOptions( parameters ); @@ -166,7 +170,7 @@ return StringUtils.uncapitalize( getEntitySimpleName() ) + "List"; } - @RequestMapping( value = "/query/{query}", method = RequestMethod.GET ) + @RequestMapping(value = "/query/{query}", method = RequestMethod.GET) public String query( @PathVariable String query, @RequestParam Map parameters, Model model, HttpServletRequest request ) throws Exception { WebOptions options = new WebOptions( parameters ); @@ -195,8 +199,8 @@ return StringUtils.uncapitalize( getEntitySimpleName() ) + "List"; } - @RequestMapping( value = "/{uid}", method = RequestMethod.GET ) - public String getObject( @PathVariable( "uid" ) String uid, @RequestParam Map parameters, + @RequestMapping(value = "/{uid}", method = RequestMethod.GET) + public String getObject( @PathVariable("uid") String uid, @RequestParam Map parameters, Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { WebOptions options = new WebOptions( parameters ); @@ -226,7 +230,7 @@ return StringUtils.uncapitalize( getEntitySimpleName() ); } - @RequestMapping( value = "/search/{query}", method = RequestMethod.GET ) + @RequestMapping(value = "/search/{query}", method = RequestMethod.GET) public String search( @PathVariable String query, @RequestParam Map parameters, Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception { @@ -256,13 +260,13 @@ // POST //-------------------------------------------------------------------------- - @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) + @RequestMapping(method = RequestMethod.POST, consumes = { "application/xml", "text/xml" }) public void postXmlObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); } - @RequestMapping( method = RequestMethod.POST, consumes = "application/json" ) + @RequestMapping(method = RequestMethod.POST, consumes = "application/json") public void postJsonObject( HttpServletResponse response, HttpServletRequest request, InputStream input ) throws Exception { throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() ); @@ -272,16 +276,16 @@ // PUT //-------------------------------------------------------------------------- - @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" } ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" }) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream input ) throws Exception { throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); } - @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream input ) throws Exception + @RequestMapping(value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json") + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid, InputStream input ) throws Exception { throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() ); } @@ -290,9 +294,9 @@ // DELETE //-------------------------------------------------------------------------- - @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE ) - @ResponseStatus( value = HttpStatus.NO_CONTENT ) - public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws Exception + @RequestMapping(value = "/{uid}", method = RequestMethod.DELETE) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable("uid") String uid ) throws Exception { throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() ); } @@ -441,7 +445,7 @@ private String entitySimpleName; - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected Class getEntityClass() { if ( entityClass == null ) @@ -473,7 +477,7 @@ return entitySimpleName; } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") protected T getEntityInstance() { try === modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java' --- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2014-03-13 14:27:16 +0000 +++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebUtils.java 2014-03-14 10:25:42 +0000 @@ -34,9 +34,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hisp.dhis.api.controller.WebMetaData; -import org.hisp.dhis.dxf2.common.ops.FilterOps; -import org.hisp.dhis.dxf2.common.ops.Filters; -import org.hisp.dhis.dxf2.common.ops.Op; +import org.hisp.dhis.dxf2.filter.FilterOps; +import org.hisp.dhis.dxf2.filter.Filters; +import org.hisp.dhis.dxf2.filter.ops.Op; import org.hisp.dhis.common.DimensionalObject; import org.hisp.dhis.common.IdentifiableObject; import org.hisp.dhis.common.Pager; @@ -190,398 +190,4 @@ } } - @SuppressWarnings( "unchecked" ) - private static void putInMap( Map map, String path ) - { - for ( String p : path.split( "\\." ) ) - { - if ( map.get( p ) == null ) - { - map.put( p, Maps.newHashMap() ); - } - - map = map.get( p ); - } - } - - public static Map parseFieldExpression( String fields ) - { - List prefixList = Lists.newArrayList(); - Map parsed = Maps.newHashMap(); - - StringBuilder builder = new StringBuilder(); - - for ( String c : fields.split( "" ) ) - { - if ( c.equals( "," ) ) - { - putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); - builder = new StringBuilder(); - continue; - } - - if ( c.equals( "[" ) ) - { - prefixList.add( builder.toString() ); - builder = new StringBuilder(); - continue; - } - - if ( c.equals( "]" ) ) - { - if ( !builder.toString().isEmpty() ) - { - putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); - } - - prefixList.remove( prefixList.size() - 1 ); - builder = new StringBuilder(); - continue; - } - - if ( StringUtils.isAlpha( c ) ) - { - builder.append( c ); - } - } - - if ( !builder.toString().isEmpty() ) - { - putInMap( parsed, joinedWithPrefix( builder, prefixList ) ); - } - - return parsed; - } - - private static String joinedWithPrefix( StringBuilder builder, List prefixList ) - { - String prefixes = StringUtils.join( prefixList, "." ); - prefixes = prefixes.isEmpty() ? builder.toString() : (prefixes + "." + builder.toString()); - return prefixes; - } - - public static List filterFields( List objects, String include, String exclude ) - { - List output = Lists.newArrayList(); - - if ( objects.isEmpty() ) - { - return output; - } - - Map fieldMap = Maps.newHashMap(); - - if ( include == null && exclude == null ) - { - Map classMap = ReflectionUtils.getJacksonClassMap( objects.get( 0 ).getClass() ); - - for ( String key : classMap.keySet() ) - { - fieldMap.put( key, Maps.newHashMap() ); - } - } - else if ( include == null ) - { - Map classMap = ReflectionUtils.getJacksonClassMap( objects.get( 0 ).getClass() ); - Map excludeMap = parseFieldExpression( exclude ); - - for ( String key : classMap.keySet() ) - { - if ( !excludeMap.containsKey( key ) ) - { - fieldMap.put( key, Maps.newHashMap() ); - } - } - } - else - { - fieldMap = parseFieldExpression( include ); - } - - for ( Object object : objects ) - { - output.add( buildObjectOutput( object, fieldMap ) ); - } - - return output; - } - - @SuppressWarnings( "unchecked" ) - private static Map buildObjectOutput( Object object, Map fieldMap ) - { - if ( object == null ) - { - return null; - } - - Map output = Maps.newHashMap(); - Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); - - for ( String key : fieldMap.keySet() ) - { - if ( !classMap.containsKey( key ) ) - { - continue; - } - - Map value = fieldMap.get( key ); - ReflectionUtils.PropertyDescriptor descriptor = classMap.get( key ); - Object returned = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); - - if ( returned == null ) - { - continue; - } - - if ( value.isEmpty() ) - { - if ( !descriptor.isIdentifiableObject() ) - { - output.put( key, returned ); - } - else if ( !descriptor.isCollection() ) - { - Map properties = getIdentifiableObjectProperties( returned ); - output.put( key, properties ); - } - else if ( descriptor.isCollection() ) - { - List> properties = getIdentifiableObjectCollectionProperties( returned ); - output.put( key, properties ); - } - } - else - { - if ( descriptor.isCollection() ) - { - Collection objects = (Collection) returned; - ArrayList arrayList = Lists.newArrayList(); - output.put( key, arrayList ); - - for ( Object obj : objects ) - { - Map properties = buildObjectOutput( obj, value ); - arrayList.add( properties ); - } - } - else - { - Map properties = buildObjectOutput( returned, value ); - output.put( key, properties ); - } - } - } - - return output; - } - - private static List> getIdentifiableObjectCollectionProperties( Object object ) - { - List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); - return getIdentifiableObjectCollectionProperties( object, fields ); - } - - @SuppressWarnings( "unchecked" ) - private static List> getIdentifiableObjectCollectionProperties( Object object, List fields ) - { - List> output = Lists.newArrayList(); - Collection identifiableObjects; - - try - { - identifiableObjects = (Collection) object; - } - catch ( ClassCastException ex ) - { - ex.printStackTrace(); - return output; - } - - for ( IdentifiableObject identifiableObject : identifiableObjects ) - { - Map properties = getIdentifiableObjectProperties( identifiableObject, fields ); - output.add( properties ); - } - - return output; - } - - private static Map getIdentifiableObjectProperties( Object object ) - { - List fields = Lists.newArrayList( "id", "name", "code", "created", "lastUpdated" ); - return getIdentifiableObjectProperties( object, fields ); - } - - private static Map getIdentifiableObjectProperties( Object object, List fields ) - { - Map idProps = Maps.newLinkedHashMap(); - Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); - - for ( String field : fields ) - { - ReflectionUtils.PropertyDescriptor descriptor = classMap.get( field ); - - if ( descriptor == null ) - { - continue; - } - - Object o = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); - - if ( o != null ) - { - idProps.put( field, o ); - } - } - - return idProps; - } - - public static List filterObjects( List entityList, List filters ) - { - if ( entityList == null || entityList.isEmpty() ) - { - return Lists.newArrayList(); - } - - Filters parsed = parseFilters( filters ); - - List list = Lists.newArrayList(); - - for ( T object : entityList ) - { - if ( evaluateWithFilters( object, parsed ) ) - { - list.add( object ); - } - } - - return list; - } - - @SuppressWarnings( "unchecked" ) - private static boolean evaluateWithFilters( T object, Filters filters ) - { - Map classMap = ReflectionUtils.getJacksonClassMap( object.getClass() ); - - for ( String field : filters.getFilters().keySet() ) - { - if ( !classMap.containsKey( field ) ) - { - System.err.println( "Skipping non-existent field: " + field ); - continue; - } - - ReflectionUtils.PropertyDescriptor descriptor = classMap.get( field ); - - Object value = ReflectionUtils.invokeMethod( object, descriptor.getMethod() ); - - Object filter = filters.getFilters().get( field ); - - if ( FilterOps.class.isInstance( filter ) ) - { - if ( evaluateFilterOps( value, (FilterOps) filter ) ) - { - return false; - } - } - else - { - Map map = (Map) filters.getFilters().get( field ); - Filters f = new Filters(); - f.setFilters( map ); - - if ( map.containsKey( "__self__" ) ) - { - if ( evaluateFilterOps( value, (FilterOps) map.get( "__self__" ) ) ) - { - return false; - } - - map.remove( "__self__" ); - } - - if ( descriptor.isIdentifiableObject() && !descriptor.isCollection() ) - { - if ( !evaluateWithFilters( (IdentifiableObject) value, f ) ) - { - return false; - } - } - else if ( descriptor.isIdentifiableObject() && descriptor.isCollection() ) - { - Collection idObjectCollection = (Collection) value; - - if ( idObjectCollection.isEmpty() ) - { - return false; - } - - for ( Object idObject : idObjectCollection ) - { - if ( !evaluateWithFilters( (IdentifiableObject) idObject, f ) ) - { - return false; - } - } - } - } - } - - return true; - } - - private static boolean evaluateFilterOps( Object value, FilterOps filterOps ) - { - // filter through every operator treating multiple of same operator as OR - for ( String operator : filterOps.getFilters().keySet() ) - { - boolean include = false; - - List ops = filterOps.getFilters().get( operator ); - - for ( Op op : ops ) - { - switch ( op.evaluate( value ) ) - { - case INCLUDE: - { - include = true; - } - } - } - - if ( !include ) - { - return true; - } - } - return false; - } - - private static Filters parseFilters( List filters ) - { - Filters parsed = new Filters(); - - for ( String filter : filters ) - { - String[] split = filter.split( ":" ); - - if ( !(split.length >= 2) ) - { - continue; - } - - if ( split.length >= 3 ) - { - parsed.addFilter( split[0], split[1], split[2] ); - } - else - { - parsed.addFilter( split[0], split[1], null ); - } - } - - return parsed; - } }