dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31038
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15783: moved object filter, field filter, and parser into their own packages
------------------------------------------------------------
revno: 15783
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-06-20 13:14:18 +0200
message:
moved object filter, field filter, and parser into their own packages
removed:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultObjectFilterService.java
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/FieldFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterOps.java
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/ObjectFilterService.java
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/ParserService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/
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/EqOp.java
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/GteOp.java
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/LtOp.java
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/NeqOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NnullOp.java
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/Op.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/OpStatus.java
added:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldMap.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/DefaultObjectFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/FilterOps.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/Filters.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ObjectFilterService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EmptyCollectionOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EqOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GtOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GteOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LikeOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LtOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LteOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NeqOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NnullOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NullOp.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/OpStatus.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/DefaultParserService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/ParserService.java
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter'
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,414 @@
+package org.hisp.dhis.dxf2.fieldfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.PresetProvider;
+import org.hisp.dhis.dxf2.parser.ParserService;
+import org.hisp.dhis.node.NodePropertyConverter;
+import org.hisp.dhis.node.types.CollectionNode;
+import org.hisp.dhis.node.types.ComplexNode;
+import org.hisp.dhis.node.types.SimpleNode;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.system.util.ReflectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.annotation.PostConstruct;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultFieldFilterService implements FieldFilterService
+{
+ private static final Log log = LogFactory.getLog( DefaultFieldFilterService.class );
+
+ @Autowired
+ private ParserService parserService;
+
+ @Autowired
+ private SchemaService schemaService;
+
+ @Autowired(required = false)
+ private Set<PresetProvider> presetProviders = Sets.newHashSet();
+
+ @Autowired( required = false )
+ private Set<NodePropertyConverter> nodePropertyConverters = Sets.newHashSet();
+
+ private ImmutableMap<String, PresetProvider> presets = ImmutableMap.of();
+
+ private ImmutableMap<String, NodePropertyConverter> converters = ImmutableMap.of();
+
+ @PostConstruct
+ public void init()
+ {
+ ImmutableMap.Builder<String, PresetProvider> presetBuilder = ImmutableMap.builder();
+
+ for ( PresetProvider presetProvider : presetProviders )
+ {
+ presetBuilder.put( presetProvider.name(), presetProvider );
+ }
+
+ presets = presetBuilder.build();
+
+ ImmutableMap.Builder<String, NodePropertyConverter> converterBuilder = ImmutableMap.builder();
+
+ for ( NodePropertyConverter converter : nodePropertyConverters )
+ {
+ converterBuilder.put( converter.name(), converter );
+ }
+
+ converters = converterBuilder.build();
+ }
+
+ @Override
+ public <T extends IdentifiableObject> CollectionNode filter( Class<?> klass, List<T> objects, List<String> fieldList )
+ {
+ String fields = fieldList == null ? "" : Joiner.on( "," ).join( fieldList );
+
+ Schema rootSchema = schemaService.getDynamicSchema( klass );
+
+ CollectionNode collectionNode = new CollectionNode( rootSchema.getCollectionName() );
+ collectionNode.setNamespace( rootSchema.getNamespace() );
+
+ if ( objects == null || objects.isEmpty() )
+ {
+ return collectionNode;
+ }
+
+ FieldMap fieldMap = new FieldMap();
+ Schema schema = schemaService.getDynamicSchema( objects.get( 0 ).getClass() );
+
+ if ( fields == null )
+ {
+ for ( Property property : schema.getProperties() )
+ {
+ fieldMap.put( property.getName(), new FieldMap() );
+ }
+ }
+ else
+ {
+ fieldMap = parserService.parseFieldFilter( fields );
+ }
+
+ for ( Object object : objects )
+ {
+ collectionNode.addChild( buildComplexNode( fieldMap, klass, object ) );
+ }
+
+ return collectionNode;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private ComplexNode buildComplexNode( FieldMap fieldMap, Class<?> klass, Object object )
+ {
+ Schema schema = schemaService.getDynamicSchema( klass );
+
+ ComplexNode complexNode = new ComplexNode( schema.getName() );
+ complexNode.setNamespace( schema.getNamespace() );
+
+ if ( object == null )
+ {
+ return complexNode;
+ }
+
+ updateFields( fieldMap, schema.getKlass() );
+
+ for ( String fieldKey : fieldMap.keySet() )
+ {
+ if ( !schema.getPropertyMap().containsKey( fieldKey ) )
+ {
+ continue;
+ }
+
+ Property property = schema.getPropertyMap().get( fieldKey );
+
+ Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
+ Schema propertySchema = schemaService.getDynamicSchema( property.getKlass() );
+
+ FieldMap fieldValue = fieldMap.get( fieldKey );
+
+ if ( property.isCollection() )
+ {
+ updateFields( fieldValue, property.getItemKlass() );
+ }
+ else
+ {
+ updateFields( fieldValue, property.getKlass() );
+ }
+
+ if ( fieldValue.haveNodePropertyConverter() )
+ {
+ NodePropertyConverter converter = fieldValue.getNodePropertyConverter();
+
+ if ( converter.canConvertTo( property, returnValue ) )
+ {
+ complexNode.addChild( converter.convertTo( property, returnValue ) );
+ }
+
+ }
+ else if ( fieldValue.isEmpty() )
+ {
+ List<String> fields = presets.get( "identifiable" ).provide();
+
+ if ( property.isCollection() )
+ {
+ Collection<?> collection = (Collection<?>) returnValue;
+
+ CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
+ collectionNode.setNamespace( property.getNamespace() );
+
+ if ( property.isIdentifiableObject() )
+ {
+ for ( Object collectionObject : collection )
+ {
+ collectionNode.addChild( getProperties( property, collectionObject, fields ) );
+ }
+ }
+ else if ( !property.isSimple() )
+ {
+ FieldMap map = getFullFieldMap( schemaService.getDynamicSchema( property.getItemKlass() ) );
+
+ for ( Object collectionObject : collection )
+ {
+ ComplexNode node = buildComplexNode( map, property.getItemKlass(), collectionObject );
+
+ if ( !node.getChildren().isEmpty() )
+ {
+ collectionNode.addChild( node );
+ }
+ }
+ }
+ else
+ {
+ for ( Object collectionObject : collection )
+ {
+ collectionNode.addChild( new SimpleNode( property.getName(), collectionObject ) );
+ }
+ }
+ }
+ else if ( property.isIdentifiableObject() )
+ {
+ complexNode.addChild( getProperties( property, returnValue, fields ) );
+ }
+ else
+ {
+ if ( propertySchema.getProperties().isEmpty() )
+ {
+ SimpleNode simpleNode = new SimpleNode( fieldKey, returnValue );
+ simpleNode.setAttribute( property.isAttribute() );
+ simpleNode.setNamespace( property.getNamespace() );
+
+ complexNode.addChild( simpleNode );
+ }
+ else
+ {
+ complexNode.addChild( buildComplexNode( getFullFieldMap( propertySchema ), property.getKlass(),
+ returnValue ) );
+ }
+ }
+ }
+ else
+ {
+ if ( property.isCollection() )
+ {
+ CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
+ collectionNode.setNamespace( property.getNamespace() );
+
+ for ( Object collectionObject : (Collection<?>) returnValue )
+ {
+ ComplexNode node = buildComplexNode( fieldValue, property.getItemKlass(), collectionObject );
+
+ if ( !node.getChildren().isEmpty() )
+ {
+ collectionNode.addChild( node );
+ }
+ }
+ }
+ else
+ {
+ ComplexNode node = buildComplexNode( fieldValue, property.getKlass(), returnValue );
+
+ if ( !node.getChildren().isEmpty() )
+ {
+ complexNode.addChild( node );
+ }
+ }
+ }
+ }
+
+ return complexNode;
+ }
+
+ private void updateFields( FieldMap fieldMap, Class<?> klass )
+ {
+ // we need two run this (at least) two times, since some of the presets might contain other presets
+ _updateFields( fieldMap, klass, true );
+ _updateFields( fieldMap, klass, false );
+ }
+
+ private void _updateFields( FieldMap fieldMap, Class<?> klass, boolean expandOnly )
+ {
+ Schema schema = schemaService.getDynamicSchema( klass );
+ List<String> cleanupFields = Lists.newArrayList();
+
+ for ( String fieldKey : Sets.newHashSet( fieldMap.keySet() ) )
+ {
+ if ( "*".equals( fieldKey ) )
+ {
+ for ( String mapKey : schema.getPropertyMap().keySet() )
+ {
+ if ( !fieldMap.containsKey( mapKey ) )
+ {
+ fieldMap.put( mapKey, new FieldMap() );
+ }
+ }
+
+ cleanupFields.add( fieldKey );
+ }
+ else if ( fieldKey.startsWith( ":" ) )
+ {
+ PresetProvider presetProvider = presets.get( fieldKey.substring( 1 ) );
+
+ if ( presetProvider == null )
+ {
+ continue;
+ }
+
+ List<String> fields = presetProvider.provide();
+
+ for ( String field : fields )
+ {
+ if ( !fieldMap.containsKey( field ) )
+ {
+ fieldMap.put( field, new FieldMap() );
+ }
+ }
+
+ cleanupFields.add( fieldKey );
+ }
+ else if ( fieldKey.startsWith( "!" ) && !expandOnly )
+ {
+ cleanupFields.add( fieldKey );
+ }
+ else if ( fieldKey.contains( "::" ) )
+ {
+ String[] split = fieldKey.split( "::" );
+
+ if ( split.length == 2 )
+ {
+ FieldMap value = new FieldMap();
+
+ if ( converters.containsKey( split[1] ) )
+ {
+ value.setNodePropertyConverter( converters.get( split[1] ) );
+ fieldMap.put( split[0], value );
+ }
+ }
+
+ cleanupFields.add( fieldKey );
+ }
+ }
+
+ for ( String field : cleanupFields )
+ {
+ fieldMap.remove( field );
+
+ if ( !expandOnly )
+ {
+ fieldMap.remove( field.substring( 1 ) );
+ }
+ }
+ }
+
+ private FieldMap getFullFieldMap( Schema schema )
+ {
+ FieldMap fieldMap = new FieldMap();
+
+ for ( String mapKey : schema.getPropertyMap().keySet() )
+ {
+ fieldMap.put( mapKey, new FieldMap() );
+ }
+
+ return fieldMap;
+ }
+
+ private ComplexNode getProperties( Property currentProperty, Object object, List<String> fields )
+ {
+ if ( object == null )
+ {
+ return null;
+ }
+
+ ComplexNode complexNode = new ComplexNode( currentProperty.getName() );
+ complexNode.setNamespace( currentProperty.getNamespace() );
+
+ Schema schema;
+
+ if ( currentProperty.isCollection() )
+ {
+ schema = schemaService.getDynamicSchema( currentProperty.getItemKlass() );
+
+ }
+ else
+ {
+ schema = schemaService.getDynamicSchema( currentProperty.getKlass() );
+ }
+
+ for ( String field : fields )
+ {
+ Property property = schema.getPropertyMap().get( field );
+
+ if ( property == null )
+ {
+ continue;
+ }
+
+ Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
+
+ SimpleNode simpleNode = new SimpleNode( field, returnValue );
+ simpleNode.setAttribute( property.isAttribute() );
+ simpleNode.setNamespace( property.getNamespace() );
+
+ complexNode.addChild( simpleNode );
+ }
+
+ return complexNode;
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldFilterService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldFilterService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.dxf2.fieldfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.node.types.CollectionNode;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface FieldFilterService
+{
+ /**
+ * Perform inclusion/exclusion on a list of objects.
+ *
+ * @param objects List to filter
+ * @param fieldList Field filter
+ * @return List of objects with only wanted properties
+ */
+ <T extends IdentifiableObject> CollectionNode filter( Class<?> klass, List<T> objects, List<String> fieldList );
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldMap.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldMap.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldMap.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,76 @@
+package org.hisp.dhis.dxf2.fieldfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
+ */
+
+import com.google.common.base.Objects;
+import com.google.common.collect.ForwardingMap;
+import com.google.common.collect.Maps;
+import org.hisp.dhis.node.NodePropertyConverter;
+
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class FieldMap extends ForwardingMap<String, FieldMap>
+{
+ private final Map<String, FieldMap> delegate = Maps.newHashMap();
+
+ private NodePropertyConverter nodePropertyConverter;
+
+ @Override
+ protected Map<String, FieldMap> delegate()
+ {
+ return delegate;
+ }
+
+ public NodePropertyConverter getNodePropertyConverter()
+ {
+ return nodePropertyConverter;
+ }
+
+ public void setNodePropertyConverter( NodePropertyConverter nodePropertyConverter )
+ {
+ this.nodePropertyConverter = nodePropertyConverter;
+ }
+
+ public boolean haveNodePropertyConverter()
+ {
+ return nodePropertyConverter != null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return Objects.toStringHelper( this )
+ .add( "map", standardToString() )
+ .add( "nodePropertyConverter", nodePropertyConverter )
+ .toString();
+ }
+}
=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter'
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java 2014-06-20 10:55:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFieldFilterService.java 1970-01-01 00:00:00 +0000
@@ -1,409 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.PresetProvider;
-import org.hisp.dhis.node.NodePropertyConverter;
-import org.hisp.dhis.node.types.CollectionNode;
-import org.hisp.dhis.node.types.ComplexNode;
-import org.hisp.dhis.node.types.SimpleNode;
-import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.Schema;
-import org.hisp.dhis.schema.SchemaService;
-import org.hisp.dhis.system.util.ReflectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.annotation.PostConstruct;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class DefaultFieldFilterService implements FieldFilterService
-{
- @Autowired
- private ParserService parserService;
-
- @Autowired
- private SchemaService schemaService;
-
- @Autowired(required = false)
- private Set<PresetProvider> presetProviders = Sets.newHashSet();
-
- @Autowired(required = false)
- private Set<NodePropertyConverter> nodePropertyConverters = Sets.newHashSet();
-
- private ImmutableMap<String, PresetProvider> presets = ImmutableMap.of();
-
- private ImmutableMap<String, NodePropertyConverter> converters = ImmutableMap.of();
-
- @PostConstruct
- public void init()
- {
- ImmutableMap.Builder<String, PresetProvider> presetBuilder = ImmutableMap.builder();
-
- for ( PresetProvider presetProvider : presetProviders )
- {
- presetBuilder.put( presetProvider.name(), presetProvider );
- }
-
- presets = presetBuilder.build();
-
- ImmutableMap.Builder<String, NodePropertyConverter> converterBuilder = ImmutableMap.builder();
-
- for ( NodePropertyConverter converter : nodePropertyConverters )
- {
- converterBuilder.put( converter.name(), converter );
- }
-
- converters = converterBuilder.build();
- }
-
- @Override
- public <T extends IdentifiableObject> CollectionNode filter( Class<?> klass, List<T> objects, List<String> fieldList )
- {
- String fields = fieldList == null ? "" : Joiner.on( "," ).join( fieldList );
-
- Schema rootSchema = schemaService.getDynamicSchema( klass );
-
- CollectionNode collectionNode = new CollectionNode( rootSchema.getCollectionName() );
- collectionNode.setNamespace( rootSchema.getNamespace() );
-
- if ( objects == null || objects.isEmpty() )
- {
- return collectionNode;
- }
-
- FieldMap fieldMap = new FieldMap();
- Schema schema = schemaService.getDynamicSchema( objects.get( 0 ).getClass() );
-
- if ( fields == null )
- {
- for ( Property property : schema.getProperties() )
- {
- fieldMap.put( property.getName(), new FieldMap() );
- }
- }
- else
- {
- fieldMap = parserService.parseFieldFilter( fields );
- }
-
- for ( Object object : objects )
- {
- collectionNode.addChild( buildComplexNode( fieldMap, klass, object ) );
- }
-
- return collectionNode;
- }
-
- @SuppressWarnings("unchecked")
- private ComplexNode buildComplexNode( FieldMap fieldMap, Class<?> klass, Object object )
- {
- Schema schema = schemaService.getDynamicSchema( klass );
-
- ComplexNode complexNode = new ComplexNode( schema.getName() );
- complexNode.setNamespace( schema.getNamespace() );
-
- if ( object == null )
- {
- return complexNode;
- }
-
- updateFields( fieldMap, schema.getKlass() );
-
- for ( String fieldKey : fieldMap.keySet() )
- {
- if ( !schema.getPropertyMap().containsKey( fieldKey ) )
- {
- continue;
- }
-
- Property property = schema.getPropertyMap().get( fieldKey );
-
- Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
- Schema propertySchema = schemaService.getDynamicSchema( property.getKlass() );
-
- FieldMap fieldValue = fieldMap.get( fieldKey );
-
- if ( property.isCollection() )
- {
- updateFields( fieldValue, property.getItemKlass() );
- }
- else
- {
- updateFields( fieldValue, property.getKlass() );
- }
-
- if ( fieldValue.haveNodePropertyConverter() )
- {
- NodePropertyConverter converter = fieldValue.getNodePropertyConverter();
-
- if ( converter.canConvertTo( property, returnValue ) )
- {
- complexNode.addChild( converter.convertTo( property, returnValue ) );
- }
-
- }
- else if ( fieldValue.isEmpty() )
- {
- List<String> fields = presets.get( "identifiable" ).provide();
-
- if ( property.isCollection() )
- {
- Collection<?> collection = (Collection<?>) returnValue;
-
- CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
- collectionNode.setNamespace( property.getNamespace() );
-
- if ( property.isIdentifiableObject() )
- {
- for ( Object collectionObject : collection )
- {
- collectionNode.addChild( getProperties( property, collectionObject, fields ) );
- }
- }
- else if ( !property.isSimple() )
- {
- FieldMap map = getFullFieldMap( schemaService.getDynamicSchema( property.getItemKlass() ) );
-
- for ( Object collectionObject : collection )
- {
- ComplexNode node = buildComplexNode( map, property.getItemKlass(), collectionObject );
-
- if ( !node.getChildren().isEmpty() )
- {
- collectionNode.addChild( node );
- }
- }
- }
- else
- {
- for ( Object collectionObject : collection )
- {
- collectionNode.addChild( new SimpleNode( property.getName(), collectionObject ) );
- }
- }
- }
- else if ( property.isIdentifiableObject() )
- {
- complexNode.addChild( getProperties( property, returnValue, fields ) );
- }
- else
- {
- if ( propertySchema.getProperties().isEmpty() )
- {
- SimpleNode simpleNode = new SimpleNode( fieldKey, returnValue );
- simpleNode.setAttribute( property.isAttribute() );
- simpleNode.setNamespace( property.getNamespace() );
-
- complexNode.addChild( simpleNode );
- }
- else
- {
- complexNode.addChild( buildComplexNode( getFullFieldMap( propertySchema ), property.getKlass(),
- returnValue ) );
- }
- }
- }
- else
- {
- if ( property.isCollection() )
- {
- CollectionNode collectionNode = complexNode.addChild( new CollectionNode( property.getCollectionName() ) );
- collectionNode.setNamespace( property.getNamespace() );
-
- for ( Object collectionObject : (Collection<?>) returnValue )
- {
- ComplexNode node = buildComplexNode( fieldValue, property.getItemKlass(), collectionObject );
-
- if ( !node.getChildren().isEmpty() )
- {
- collectionNode.addChild( node );
- }
- }
- }
- else
- {
- ComplexNode node = buildComplexNode( fieldValue, property.getKlass(), returnValue );
-
- if ( !node.getChildren().isEmpty() )
- {
- complexNode.addChild( node );
- }
- }
- }
- }
-
- return complexNode;
- }
-
- private void updateFields( FieldMap fieldMap, Class<?> klass )
- {
- // we need two run this (at least) two times, since some of the presets might contain other presets
- _updateFields( fieldMap, klass, true );
- _updateFields( fieldMap, klass, false );
- }
-
- private void _updateFields( FieldMap fieldMap, Class<?> klass, boolean expandOnly )
- {
- Schema schema = schemaService.getDynamicSchema( klass );
- List<String> cleanupFields = Lists.newArrayList();
-
- for ( String fieldKey : Sets.newHashSet( fieldMap.keySet() ) )
- {
- if ( "*".equals( fieldKey ) )
- {
- for ( String mapKey : schema.getPropertyMap().keySet() )
- {
- if ( !fieldMap.containsKey( mapKey ) )
- {
- fieldMap.put( mapKey, new FieldMap() );
- }
- }
-
- cleanupFields.add( fieldKey );
- }
- else if ( fieldKey.startsWith( ":" ) )
- {
- PresetProvider presetProvider = presets.get( fieldKey.substring( 1 ) );
-
- if ( presetProvider == null )
- {
- continue;
- }
-
- List<String> fields = presetProvider.provide();
-
- for ( String field : fields )
- {
- if ( !fieldMap.containsKey( field ) )
- {
- fieldMap.put( field, new FieldMap() );
- }
- }
-
- cleanupFields.add( fieldKey );
- }
- else if ( fieldKey.startsWith( "!" ) && !expandOnly )
- {
- cleanupFields.add( fieldKey );
- }
- else if ( fieldKey.contains( "::" ) )
- {
- String[] split = fieldKey.split( "::" );
-
- if ( split.length == 2 )
- {
- FieldMap value = new FieldMap();
-
- if ( converters.containsKey( split[1] ) )
- {
- value.setNodePropertyConverter( converters.get( split[1] ) );
- fieldMap.put( split[0], value );
- }
- }
-
- cleanupFields.add( fieldKey );
- }
- }
-
- for ( String field : cleanupFields )
- {
- fieldMap.remove( field );
-
- if ( !expandOnly )
- {
- fieldMap.remove( field.substring( 1 ) );
- }
- }
- }
-
- private FieldMap getFullFieldMap( Schema schema )
- {
- FieldMap fieldMap = new FieldMap();
-
- for ( String mapKey : schema.getPropertyMap().keySet() )
- {
- fieldMap.put( mapKey, new FieldMap() );
- }
-
- return fieldMap;
- }
-
- private ComplexNode getProperties( Property currentProperty, Object object, List<String> fields )
- {
- if ( object == null )
- {
- return null;
- }
-
- ComplexNode complexNode = new ComplexNode( currentProperty.getName() );
- complexNode.setNamespace( currentProperty.getNamespace() );
-
- Schema schema;
-
- if ( currentProperty.isCollection() )
- {
- schema = schemaService.getDynamicSchema( currentProperty.getItemKlass() );
-
- }
- else
- {
- schema = schemaService.getDynamicSchema( currentProperty.getKlass() );
- }
-
- for ( String field : fields )
- {
- Property property = schema.getPropertyMap().get( field );
-
- if ( property == null )
- {
- continue;
- }
-
- Object returnValue = ReflectionUtils.invokeMethod( object, property.getGetterMethod() );
-
- SimpleNode simpleNode = new SimpleNode( field, returnValue );
- simpleNode.setAttribute( property.isAttribute() );
- simpleNode.setNamespace( property.getNamespace() );
-
- complexNode.addChild( simpleNode );
- }
-
- return complexNode;
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultObjectFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultObjectFilterService.java 2014-06-17 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultObjectFilterService.java 1970-01-01 00:00:00 +0000
@@ -1,189 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Lists;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.dxf2.filter.ops.Op;
-import org.hisp.dhis.schema.Property;
-import org.hisp.dhis.schema.Schema;
-import org.hisp.dhis.schema.SchemaService;
-import org.hisp.dhis.system.util.ReflectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class DefaultObjectFilterService implements ObjectFilterService
-{
- @Autowired
- private ParserService parserService;
-
- @Autowired
- private SchemaService schemaService;
-
- @Override
- public <T extends IdentifiableObject> List<T> filter( List<T> objects, List<String> filters )
- {
- if ( objects == null || objects.isEmpty() )
- {
- return Lists.newArrayList();
- }
-
- Filters parsed = parserService.parseObjectFilter( filters );
-
- List<T> list = Lists.newArrayList();
-
- for ( T object : objects )
- {
- if ( evaluateWithFilters( object, parsed ) )
- {
- list.add( object );
- }
- }
-
- return list;
- }
-
- @SuppressWarnings( "unchecked" )
- private <T> boolean evaluateWithFilters( T object, Filters filters )
- {
- Schema schema = schemaService.getDynamicSchema( object.getClass() );
-
- for ( String field : filters.getFilters().keySet() )
- {
- if ( !schema.getPropertyMap().containsKey( field ) )
- {
- continue;
- }
-
- Property descriptor = schema.getPropertyMap().get( field );
-
- if ( descriptor == null )
- {
- continue;
- }
-
- Object value = ReflectionUtils.invokeMethod( object, descriptor.getGetterMethod() );
-
- Object filter = filters.getFilters().get( field );
-
- if ( FilterOps.class.isInstance( filter ) )
- {
- if ( evaluateFilterOps( value, (FilterOps) filter ) )
- {
- return false;
- }
- }
- else
- {
- Map<String, Object> map = (Map<String, Object>) 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.isCollection() )
- {
- if ( !evaluateWithFilters( value, f ) )
- {
- return false;
- }
- }
- else
- {
- Collection<?> objectCollection = (Collection<?>) value;
-
- if ( objectCollection.isEmpty() )
- {
- return false;
- }
-
- boolean include = false;
-
- for ( Object idObject : objectCollection )
- {
- if ( evaluateWithFilters( idObject, f ) )
- {
- include = true;
- }
- }
-
- if ( !include )
- {
- 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<Op> ops = filterOps.getFilters().get( operator );
-
- for ( Op op : ops )
- {
- switch ( op.evaluate( value ) )
- {
- case INCLUDE:
- {
- include = true;
- }
- }
- }
-
- if ( !include )
- {
- return true;
- }
- }
-
- return false;
- }
-}
=== removed 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 2014-06-19 10:51:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultParserService.java 1970-01-01 00:00:00 +0000
@@ -1,143 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.StringUtils;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class DefaultParserService implements ParserService
-{
- @Override
- public Filters parseObjectFilter( List<String> 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 FieldMap parseFieldFilter( String fields )
- {
- List<String> prefixList = Lists.newArrayList();
- FieldMap fieldMap = new FieldMap();
-
- StringBuilder builder = new StringBuilder();
-
- for ( String c : fields.split( "" ) )
- {
- if ( c.equals( "," ) )
- {
- putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
- builder = new StringBuilder();
- continue;
- }
-
- if ( c.equals( "[" ) || c.equals( "(" ) || c.equals( "{" ) )
- {
- prefixList.add( builder.toString() );
- builder = new StringBuilder();
- continue;
- }
-
- if ( c.equals( "]" ) || c.equals( ")" ) || c.equals( "}" ) )
- {
- if ( !builder.toString().isEmpty() )
- {
- putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
- }
-
- prefixList.remove( prefixList.size() - 1 );
- builder = new StringBuilder();
- continue;
- }
-
- if ( StringUtils.isAlpha( c ) || c.equals( "*" ) || c.equals( ":" ) || c.equals( "!" ) )
- {
- builder.append( c );
- }
- }
-
- if ( !builder.toString().isEmpty() )
- {
- putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
- }
-
- return fieldMap;
- }
-
- private String joinedWithPrefix( StringBuilder builder, List<String> prefixList )
- {
- String prefixes = StringUtils.join( prefixList, "." );
- prefixes = prefixes.isEmpty() ? builder.toString() : (prefixes + "." + builder.toString());
- return prefixes;
- }
-
- @SuppressWarnings( "unchecked" )
- private void putInMap( FieldMap fieldMap, String path )
- {
- if ( StringUtils.isEmpty( path ) )
- {
- return;
- }
-
- for ( String p : path.split( "\\." ) )
- {
- if ( fieldMap.get( p ) == null )
- {
- fieldMap.put( p, new FieldMap() );
- }
-
- fieldMap = fieldMap.get( p );
- }
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldFilterService.java 2014-06-17 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldFilterService.java 1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.node.types.CollectionNode;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface FieldFilterService
-{
- /**
- * Perform inclusion/exclusion on a list of objects.
- *
- * @param objects List to filter
- * @param fieldList Field filter
- * @return List of objects with only wanted properties
- */
- <T extends IdentifiableObject> CollectionNode filter( Class<?> klass, List<T> objects, List<String> fieldList );
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java 2014-06-20 10:55:18 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FieldMap.java 1970-01-01 00:00:00 +0000
@@ -1,76 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
- */
-
-import com.google.common.base.Objects;
-import com.google.common.collect.ForwardingMap;
-import com.google.common.collect.Maps;
-import org.hisp.dhis.node.NodePropertyConverter;
-
-import java.util.Map;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class FieldMap extends ForwardingMap<String, FieldMap>
-{
- private final Map<String, FieldMap> delegate = Maps.newHashMap();
-
- private NodePropertyConverter nodePropertyConverter;
-
- @Override
- protected Map<String, FieldMap> delegate()
- {
- return delegate;
- }
-
- public NodePropertyConverter getNodePropertyConverter()
- {
- return nodePropertyConverter;
- }
-
- public void setNodePropertyConverter( NodePropertyConverter nodePropertyConverter )
- {
- this.nodePropertyConverter = nodePropertyConverter;
- }
-
- public boolean haveNodePropertyConverter()
- {
- return nodePropertyConverter != null;
- }
-
- @Override
- public String toString()
- {
- return Objects.toStringHelper( this )
- .add( "map", standardToString() )
- .add( "nodePropertyConverter", nodePropertyConverter )
- .toString();
- }
-}
=== removed 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 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/FilterOps.java 1970-01-01 00:00:00 +0000
@@ -1,74 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Lists;
-import 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 <mortenoh@xxxxxxxxx>
-*/
-public class FilterOps
-{
- private Map<String, List<Op>> filters = Maps.newHashMap();
-
- FilterOps()
- {
- }
-
- public void addFilter( String opStr, Op op )
- {
- if ( !filters.containsKey( opStr ) )
- {
- filters.put( opStr, Lists.<Op>newArrayList() );
- }
-
- filters.get( opStr ).add( op );
- }
-
- public Map<String, List<Op>> getFilters()
- {
- return filters;
- }
-
- public void setFilters( Map<String, List<Op>> 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/filter/Filters.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/Filters.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/Filters.java 1970-01-01 00:00:00 +0000
@@ -1,155 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.Maps;
-import org.hisp.dhis.dxf2.filter.ops.Op;
-
-import java.util.Map;
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-public class Filters
-{
- private Map<String, Object> 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<String, Object> 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<String, Object> map = Maps.newHashMap();
- map.put( "__self__", self );
-
- c.put( split[i], map );
- c = map;
- }
- }
- else
- {
- c = (Map<String, Object>) c.get( split[i] );
- }
- }
- else
- {
- if ( last )
- {
- FilterOps filterOps = new FilterOps();
- c.put( split[i], filterOps );
- return filterOps;
- }
- else
- {
- Map<String, Object> map = Maps.newHashMap();
- c.put( split[i], map );
- c = map;
- }
- }
- }
-
- return null;
- }
-
- public Map<String, Object> getFilters()
- {
- return filters;
- }
-
- public void setFilters( Map<String, Object> 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/filter/ObjectFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ObjectFilterService.java 2014-06-17 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ObjectFilterService.java 1970-01-01 00:00:00 +0000
@@ -1,49 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.common.IdentifiableObject;
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface ObjectFilterService
-{
- /**
- * Filter a list of objects based on un-parsed filter string.
- * In-memory filter
- *
- * @param objects List to filter
- * @param filters Filter string
- * @return Filtered object list
- */
- <T extends IdentifiableObject> List<T> filter( List<T> objects, List<String> filters );
-}
=== removed 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 2014-05-06 03:02:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/OpFactory.java 1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import com.google.common.collect.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.NnullOp;
-import org.hisp.dhis.dxf2.filter.ops.NullOp;
-import org.hisp.dhis.dxf2.filter.ops.Op;
-
-import java.util.Map;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class OpFactory
-{
- protected static Map<String, Class<? extends Op>> 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( "nnull", NnullOp.class );
- register( "empty", EmptyCollectionOp.class );
- }
-
- public static void register( String type, Class<? extends Op> opClass )
- {
- register.put( type.toLowerCase(), opClass );
- }
-
- public static boolean canCreate( String type )
- {
- return register.containsKey( type.toLowerCase() );
- }
-
- public static Op create( String type )
- {
- Class<? extends Op> 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/filter/ParserService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java 2014-06-19 10:51:49 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ParserService.java 1970-01-01 00:00:00 +0000
@@ -1,54 +0,0 @@
-package org.hisp.dhis.dxf2.filter;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public interface ParserService
-{
- /**
- * Parses and generates Ops based on filter string, used for object filtering.
- *
- * @param filters One or more filter strings to parse
- * @return Filters object
- */
- Filters parseObjectFilter( List<String> filters );
-
- /**
- * Parses and writes out fieldMap with included/excluded properties.
- *
- * @param filter String to parse, can be used for both inclusion/exclusion
- * @return FieldMap with property name as key, and another FieldMap as value (recursive)
- * @see org.hisp.dhis.dxf2.filter.FieldMap
- */
- FieldMap parseFieldFilter( String filter );
-}
=== removed directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops'
=== removed 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 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,69 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/EqOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/EqOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,99 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/GtOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GtOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,85 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/GteOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/GteOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,85 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/LikeOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LikeOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,54 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-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/filter/ops/LtOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LtOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,85 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/LteOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/LteOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,85 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.Collection;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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/filter/ops/NeqOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NeqOp.java 2014-05-05 18:01:22 +0000
+++ 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
@@ -1,56 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import org.hisp.dhis.dxf2.filter.OpFactory;
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-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 )
- {
- case INCLUDE:
- return OpStatus.EXCLUDE;
- case EXCLUDE:
- return OpStatus.INCLUDE;
- default:
- return OpStatus.IGNORE;
- }
- }
-}
=== removed file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NnullOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NnullOp.java 2014-05-06 03:02:33 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NnullOp.java 1970-01-01 00:00:00 +0000
@@ -1,52 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-public class NnullOp 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/filter/ops/NullOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/NullOp.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,52 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-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/filter/ops/Op.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/Op.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,123 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-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> 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/filter/ops/OpStatus.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/ops/OpStatus.java 2014-03-18 08:10:10 +0000
+++ 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
@@ -1,37 +0,0 @@
-package org.hisp.dhis.dxf2.filter.ops;
-
-/*
- * Copyright (c) 2004-2014, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- *
- * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/**
-* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
-*/
-public enum OpStatus
-{
- INCLUDE, EXCLUDE, IGNORE
-}
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter'
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/DefaultObjectFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/DefaultObjectFilterService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/DefaultObjectFilterService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,190 @@
+package org.hisp.dhis.dxf2.objectfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.dxf2.objectfilter.ops.Op;
+import org.hisp.dhis.dxf2.parser.ParserService;
+import org.hisp.dhis.schema.Property;
+import org.hisp.dhis.schema.Schema;
+import org.hisp.dhis.schema.SchemaService;
+import org.hisp.dhis.system.util.ReflectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultObjectFilterService implements ObjectFilterService
+{
+ @Autowired
+ private ParserService parserService;
+
+ @Autowired
+ private SchemaService schemaService;
+
+ @Override
+ public <T extends IdentifiableObject> List<T> filter( List<T> objects, List<String> filters )
+ {
+ if ( objects == null || objects.isEmpty() )
+ {
+ return Lists.newArrayList();
+ }
+
+ Filters parsed = parserService.parseObjectFilter( filters );
+
+ List<T> list = Lists.newArrayList();
+
+ for ( T object : objects )
+ {
+ if ( evaluateWithFilters( object, parsed ) )
+ {
+ list.add( object );
+ }
+ }
+
+ return list;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private <T> boolean evaluateWithFilters( T object, Filters filters )
+ {
+ Schema schema = schemaService.getDynamicSchema( object.getClass() );
+
+ for ( String field : filters.getFilters().keySet() )
+ {
+ if ( !schema.getPropertyMap().containsKey( field ) )
+ {
+ continue;
+ }
+
+ Property descriptor = schema.getPropertyMap().get( field );
+
+ if ( descriptor == null )
+ {
+ continue;
+ }
+
+ Object value = ReflectionUtils.invokeMethod( object, descriptor.getGetterMethod() );
+
+ Object filter = filters.getFilters().get( field );
+
+ if ( FilterOps.class.isInstance( filter ) )
+ {
+ if ( evaluateFilterOps( value, (FilterOps) filter ) )
+ {
+ return false;
+ }
+ }
+ else
+ {
+ Map<String, Object> map = (Map<String, Object>) 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.isCollection() )
+ {
+ if ( !evaluateWithFilters( value, f ) )
+ {
+ return false;
+ }
+ }
+ else
+ {
+ Collection<?> objectCollection = (Collection<?>) value;
+
+ if ( objectCollection.isEmpty() )
+ {
+ return false;
+ }
+
+ boolean include = false;
+
+ for ( Object idObject : objectCollection )
+ {
+ if ( evaluateWithFilters( idObject, f ) )
+ {
+ include = true;
+ }
+ }
+
+ if ( !include )
+ {
+ 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<Op> 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/objectfilter/FilterOps.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/FilterOps.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/FilterOps.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,74 @@
+package org.hisp.dhis.dxf2.objectfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.hisp.dhis.dxf2.objectfilter.ops.Op;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+public class FilterOps
+{
+ private Map<String, List<Op>> filters = Maps.newHashMap();
+
+ FilterOps()
+ {
+ }
+
+ public void addFilter( String opStr, Op op )
+ {
+ if ( !filters.containsKey( opStr ) )
+ {
+ filters.put( opStr, Lists.<Op>newArrayList() );
+ }
+
+ filters.get( opStr ).add( op );
+ }
+
+ public Map<String, List<Op>> getFilters()
+ {
+ return filters;
+ }
+
+ public void setFilters( Map<String, List<Op>> 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/objectfilter/Filters.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/Filters.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/Filters.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,155 @@
+package org.hisp.dhis.dxf2.objectfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Maps;
+import org.hisp.dhis.dxf2.objectfilter.ops.Op;
+
+import java.util.Map;
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+public class Filters
+{
+ private Map<String, Object> 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<String, Object> 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<String, Object> map = Maps.newHashMap();
+ map.put( "__self__", self );
+
+ c.put( split[i], map );
+ c = map;
+ }
+ }
+ else
+ {
+ c = (Map<String, Object>) c.get( split[i] );
+ }
+ }
+ else
+ {
+ if ( last )
+ {
+ FilterOps filterOps = new FilterOps();
+ c.put( split[i], filterOps );
+ return filterOps;
+ }
+ else
+ {
+ Map<String, Object> map = Maps.newHashMap();
+ c.put( split[i], map );
+ c = map;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public Map<String, Object> getFilters()
+ {
+ return filters;
+ }
+
+ public void setFilters( Map<String, Object> 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/objectfilter/ObjectFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ObjectFilterService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ObjectFilterService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,49 @@
+package org.hisp.dhis.dxf2.objectfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.IdentifiableObject;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface ObjectFilterService
+{
+ /**
+ * Filter a list of objects based on un-parsed filter string.
+ * In-memory filter
+ *
+ * @param objects List to filter
+ * @param filters Filter string
+ * @return Filtered object list
+ */
+ <T extends IdentifiableObject> List<T> filter( List<T> objects, List<String> filters );
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/OpFactory.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,94 @@
+package org.hisp.dhis.dxf2.objectfilter;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Maps;
+import org.hisp.dhis.dxf2.objectfilter.ops.EmptyCollectionOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.EqOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.GtOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.GteOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.LikeOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.LtOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.LteOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.NeqOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.NnullOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.NullOp;
+import org.hisp.dhis.dxf2.objectfilter.ops.Op;
+
+import java.util.Map;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class OpFactory
+{
+ protected static Map<String, Class<? extends Op>> 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( "nnull", NnullOp.class );
+ register( "empty", EmptyCollectionOp.class );
+ }
+
+ public static void register( String type, Class<? extends Op> opClass )
+ {
+ register.put( type.toLowerCase(), opClass );
+ }
+
+ public static boolean canCreate( String type )
+ {
+ return register.containsKey( type.toLowerCase() );
+ }
+
+ public static Op create( String type )
+ {
+ Class<? extends Op> opClass = register.get( type.toLowerCase() );
+
+ try
+ {
+ return opClass.newInstance();
+ }
+ catch ( InstantiationException ignored )
+ {
+ }
+ catch ( IllegalAccessException ignored )
+ {
+ }
+
+ return null;
+ }
+}
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops'
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EmptyCollectionOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EmptyCollectionOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EmptyCollectionOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,69 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/EqOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EqOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/EqOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,99 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/GtOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GtOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GtOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/GteOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GteOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/GteOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/LikeOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LikeOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LikeOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,54 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+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/objectfilter/ops/LtOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LtOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LtOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/LteOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LteOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/LteOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,85 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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/objectfilter/ops/NeqOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NeqOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NeqOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,56 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.dxf2.objectfilter.OpFactory;
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+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 )
+ {
+ case INCLUDE:
+ return OpStatus.EXCLUDE;
+ case EXCLUDE:
+ return OpStatus.INCLUDE;
+ default:
+ return OpStatus.IGNORE;
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NnullOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NnullOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NnullOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+public class NnullOp 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/objectfilter/ops/NullOp.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NullOp.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/NullOp.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,52 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+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/objectfilter/ops/Op.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/Op.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,123 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+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> 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/objectfilter/ops/OpStatus.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/OpStatus.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/objectfilter/ops/OpStatus.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,37 @@
+package org.hisp.dhis.dxf2.objectfilter.ops;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+*/
+public enum OpStatus
+{
+ INCLUDE, EXCLUDE, IGNORE
+}
=== added directory 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser'
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/DefaultParserService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/DefaultParserService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/DefaultParserService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,145 @@
+package org.hisp.dhis.dxf2.parser;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.google.common.collect.Lists;
+import org.apache.commons.lang.StringUtils;
+import org.hisp.dhis.dxf2.fieldfilter.FieldMap;
+import org.hisp.dhis.dxf2.objectfilter.Filters;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class DefaultParserService implements ParserService
+{
+ @Override
+ public Filters parseObjectFilter( List<String> 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 FieldMap parseFieldFilter( String fields )
+ {
+ List<String> prefixList = Lists.newArrayList();
+ FieldMap fieldMap = new FieldMap();
+
+ StringBuilder builder = new StringBuilder();
+
+ for ( String c : fields.split( "" ) )
+ {
+ if ( c.equals( "," ) )
+ {
+ putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
+ builder = new StringBuilder();
+ continue;
+ }
+
+ if ( c.equals( "[" ) || c.equals( "(" ) || c.equals( "{" ) )
+ {
+ prefixList.add( builder.toString() );
+ builder = new StringBuilder();
+ continue;
+ }
+
+ if ( c.equals( "]" ) || c.equals( ")" ) || c.equals( "}" ) )
+ {
+ if ( !builder.toString().isEmpty() )
+ {
+ putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
+ }
+
+ prefixList.remove( prefixList.size() - 1 );
+ builder = new StringBuilder();
+ continue;
+ }
+
+ if ( StringUtils.isAlpha( c ) || c.equals( "*" ) || c.equals( ":" ) || c.equals( "!" ) )
+ {
+ builder.append( c );
+ }
+ }
+
+ if ( !builder.toString().isEmpty() )
+ {
+ putInMap( fieldMap, joinedWithPrefix( builder, prefixList ) );
+ }
+
+ return fieldMap;
+ }
+
+ private String joinedWithPrefix( StringBuilder builder, List<String> prefixList )
+ {
+ String prefixes = StringUtils.join( prefixList, "." );
+ prefixes = prefixes.isEmpty() ? builder.toString() : (prefixes + "." + builder.toString());
+ return prefixes;
+ }
+
+ @SuppressWarnings( "unchecked" )
+ private void putInMap( FieldMap fieldMap, String path )
+ {
+ if ( StringUtils.isEmpty( path ) )
+ {
+ return;
+ }
+
+ for ( String p : path.split( "\\." ) )
+ {
+ if ( fieldMap.get( p ) == null )
+ {
+ fieldMap.put( p, new FieldMap() );
+ }
+
+ fieldMap = fieldMap.get( p );
+ }
+ }
+}
=== added file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/ParserService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/ParserService.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/parser/ParserService.java 2014-06-20 11:14:18 +0000
@@ -0,0 +1,57 @@
+package org.hisp.dhis.dxf2.parser;
+
+/*
+ * Copyright (c) 2004-2014, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.dxf2.fieldfilter.FieldMap;
+import org.hisp.dhis.dxf2.objectfilter.Filters;
+
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public interface ParserService
+{
+ /**
+ * Parses and generates Ops based on filter string, used for object filtering.
+ *
+ * @param filters One or more filter strings to parse
+ * @return Filters object
+ */
+ Filters parseObjectFilter( List<String> filters );
+
+ /**
+ * Parses and writes out fieldMap with included/excluded properties.
+ *
+ * @param filter String to parse, can be used for both inclusion/exclusion
+ * @return FieldMap with property name as key, and another FieldMap as value (recursive)
+ * @see org.hisp.dhis.dxf2.fieldfilter.FieldMap
+ */
+ FieldMap parseFieldFilter( String filter );
+}
=== 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-06-17 15:28:24 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/resources/META-INF/dhis/beans.xml 2014-06-20 11:14:18 +0000
@@ -5,11 +5,11 @@
<bean id="org.hisp.dhis.dxf2.render.RenderService" class="org.hisp.dhis.dxf2.render.DefaultRenderService" />
- <bean id="org.hisp.dhis.dxf2.filter.ObjectFilterService" class="org.hisp.dhis.dxf2.filter.DefaultObjectFilterService" />
-
- <bean id="org.hisp.dhis.dxf2.filter.FieldFilterService" class="org.hisp.dhis.dxf2.filter.DefaultFieldFilterService" />
-
- <bean id="org.hisp.dhis.dxf2.filter.ParserService" class="org.hisp.dhis.dxf2.filter.DefaultParserService" />
+ <bean id="org.hisp.dhis.dxf2.objectfilter.ObjectFilterService" class="org.hisp.dhis.dxf2.objectfilter.DefaultObjectFilterService" />
+
+ <bean id="org.hisp.dhis.dxf2.fieldfilter.FieldFilterService" class="org.hisp.dhis.dxf2.fieldfilter.DefaultFieldFilterService" />
+
+ <bean id="org.hisp.dhis.dxf2.parser.ParserService" class="org.hisp.dhis.dxf2.parser.DefaultParserService" />
<bean id="org.hisp.dhis.dxf2.metadata.ExportService" class="org.hisp.dhis.dxf2.metadata.DefaultExportService" scope="prototype" />
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-18 07:15:48 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java 2014-06-20 11:14:18 +0000
@@ -39,8 +39,8 @@
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.Pager;
import org.hisp.dhis.common.PagerUtils;
-import org.hisp.dhis.dxf2.filter.FieldFilterService;
-import org.hisp.dhis.dxf2.filter.ObjectFilterService;
+import org.hisp.dhis.dxf2.fieldfilter.FieldFilterService;
+import org.hisp.dhis.dxf2.objectfilter.ObjectFilterService;
import org.hisp.dhis.dxf2.metadata.ImportService;
import org.hisp.dhis.dxf2.metadata.ImportTypeSummary;
import org.hisp.dhis.dxf2.render.RenderService;