dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #30938
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15729: use inclusion stratey in node serializers, defaults to non null.
------------------------------------------------------------
revno: 15729
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-06-17 16:33:44 +0200
message:
use inclusion stratey in node serializers, defaults to non null.
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Inclusions.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Config.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2014-06-09 10:11:03 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/AbstractNodeSerializer.java 2014-06-17 14:33:44 +0000
@@ -28,6 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
+import org.hisp.dhis.node.config.Config;
import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.ComplexNode;
import org.hisp.dhis.node.types.RootNode;
@@ -50,12 +51,16 @@
protected abstract void flushStream() throws Exception;
+ private Config config;
+
@Override
public void serialize( RootNode rootNode, OutputStream outputStream ) throws Exception
{
+ this.config = rootNode.getConfig();
startSerialize( rootNode, outputStream );
writeRootNode( rootNode );
endSerialize( rootNode, outputStream );
+ this.config = null;
}
protected abstract void startWriteRootNode( RootNode rootNode ) throws Exception;
@@ -80,6 +85,11 @@
protected void writeSimpleNode( SimpleNode simpleNode ) throws Exception
{
+ if ( !config.getInclusionStrategy().include( simpleNode.getValue() ) )
+ {
+ return;
+ }
+
startWriteSimpleNode( simpleNode );
endWriteSimpleNode( simpleNode );
}
@@ -90,6 +100,11 @@
protected void writeComplexNode( ComplexNode complexNode ) throws Exception
{
+ if ( !config.getInclusionStrategy().include( complexNode.getChildren() ) )
+ {
+ return;
+ }
+
startWriteComplexNode( complexNode );
for ( Node node : complexNode.getChildren() )
@@ -107,6 +122,11 @@
protected void writeCollectionNode( CollectionNode collectionNode ) throws Exception
{
+ if ( !config.getInclusionStrategy().include( collectionNode.getChildren() ) )
+ {
+ return;
+ }
+
startWriteCollectionNode( collectionNode );
for ( Node node : collectionNode.getChildren() )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Config.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Config.java 2014-06-17 14:06:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Config.java 2014-06-17 14:33:44 +0000
@@ -36,9 +36,9 @@
/**
* Inclusion strategy to use. There are a few already defined inclusions in the Inclusions enum.
*
- * @see org.hisp.dhis.node.config.Inclusions
+ * @see org.hisp.dhis.node.config.InclusionStrategy.Include
*/
- private InclusionStrategy inclusionStrategy = Inclusions.ALWAYS;
+ private InclusionStrategy inclusionStrategy = InclusionStrategy.Include.NON_NULL;
public Config()
{
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java 2014-06-17 14:06:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/InclusionStrategy.java 2014-06-17 14:33:44 +0000
@@ -28,10 +28,67 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*/
+import org.springframework.util.StringUtils;
+
+import java.util.Collection;
+
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public interface InclusionStrategy
{
<T> boolean include( T object );
+
+ enum Include implements InclusionStrategy
+ {
+ /**
+ * Inclusion strategy that includes all objects.
+ */
+ ALWAYS,
+
+ /**
+ * Inclusion strategy that only includes non null objects.
+ */
+ NON_NULL
+ {
+ @Override
+ public <T> boolean include( T object )
+ {
+ return object != null;
+ }
+ },
+
+ /**
+ * Inclusion strategy that only includes non empty objects:
+ * -
+ */
+ NON_EMPTY
+ {
+ @Override
+ public <T> boolean include( T object )
+ {
+ if ( object == null )
+ {
+ return false;
+ }
+
+ if ( Collection.class.isAssignableFrom( object.getClass() ) )
+ {
+ return !((Collection<?>) object).isEmpty();
+ }
+ else if ( String.class.isAssignableFrom( object.getClass() ) )
+ {
+ return !StringUtils.isEmpty( object );
+ }
+
+ return true;
+ }
+ };
+
+ @Override
+ public <T> boolean include( T object )
+ {
+ return true;
+ }
+ }
}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Inclusions.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Inclusions.java 2014-06-17 14:06:57 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/config/Inclusions.java 1970-01-01 00:00:00 +0000
@@ -1,43 +0,0 @@
-package org.hisp.dhis.node.config;
-
-/*
- * 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 Inclusions implements InclusionStrategy
-{
- ALWAYS;
-
- @Override
- public <T> boolean include( T object )
- {
- return true;
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-17 14:06:57 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/filter/DefaultFilterService.java 2014-06-17 14:33:44 +0000
@@ -340,7 +340,7 @@
if ( object == null )
{
- return complexNode;
+ return null;
}
for ( String field : fields )