dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31158
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15848: use transformer pipeline for field renaming
------------------------------------------------------------
revno: 15848
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-06-25 20:32:36 +0700
message:
use transformer pipeline for field renaming
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/LinearNodePipeline.java
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/FieldMap.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/LinearNodePipeline.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/LinearNodePipeline.java 2014-06-25 11:27:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/node/LinearNodePipeline.java 2014-06-25 13:32:36 +0000
@@ -41,14 +41,26 @@
*/
public class LinearNodePipeline implements NodePipeline
{
- private List<NodeTransformer> nodeTransformers = Lists.newArrayList();
+ private class NodeTransformerWithArgs
+ {
+ NodeTransformer transformer;
+ List<String> args;
+
+ private NodeTransformerWithArgs( NodeTransformer transformer, List<String> args )
+ {
+ this.transformer = transformer;
+ this.args = args;
+ }
+ }
+
+ private List<NodeTransformerWithArgs> nodeTransformers = Lists.newArrayList();
@Override
public Node process( Node node )
{
- for ( NodeTransformer transformer : nodeTransformers )
+ for ( NodeTransformerWithArgs nodeTransformerWithArgs : nodeTransformers )
{
- node = transformer.transform( node, Lists.<String>newArrayList() );
+ node = nodeTransformerWithArgs.transformer.transform( node, nodeTransformerWithArgs.args );
}
return node;
@@ -56,6 +68,11 @@
public void addTransformer( NodeTransformer nodeTransformer )
{
- nodeTransformers.add( checkNotNull( nodeTransformer ) );
+ nodeTransformers.add( new NodeTransformerWithArgs( checkNotNull( nodeTransformer ), Lists.<String>newArrayList() ) );
+ }
+
+ public void addTransformer( NodeTransformer nodeTransformer, List<String> args )
+ {
+ nodeTransformers.add( new NodeTransformerWithArgs( checkNotNull( nodeTransformer ), args ) );
}
}
=== modified 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 2014-06-25 11:27:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/DefaultFieldFilterService.java 2014-06-25 13:32:36 +0000
@@ -39,6 +39,7 @@
import org.hisp.dhis.dxf2.parser.ParserService;
import org.hisp.dhis.node.AbstractNode;
import org.hisp.dhis.node.NodePropertyConverter;
+import org.hisp.dhis.node.NodeTransformer;
import org.hisp.dhis.node.types.CollectionNode;
import org.hisp.dhis.node.types.ComplexNode;
import org.hisp.dhis.node.types.SimpleNode;
@@ -68,16 +69,21 @@
@Autowired
private SchemaService schemaService;
- @Autowired(required = false)
+ @Autowired( required = false )
private Set<PresetProvider> presetProviders = Sets.newHashSet();
- @Autowired(required = false)
+ @Autowired( required = false )
private Set<NodePropertyConverter> nodePropertyConverters = Sets.newHashSet();
+ @Autowired( required = false )
+ private Set<NodeTransformer> nodeTransformers = Sets.newHashSet();
+
private ImmutableMap<String, PresetProvider> presets = ImmutableMap.of();
private ImmutableMap<String, NodePropertyConverter> converters = ImmutableMap.of();
+ private ImmutableMap<String, NodeTransformer> transformers = ImmutableMap.of();
+
@PostConstruct
public void init()
{
@@ -98,6 +104,15 @@
}
converters = converterBuilder.build();
+
+ ImmutableMap.Builder<String, NodeTransformer> transformerBuilder = ImmutableMap.builder();
+
+ for ( NodeTransformer transformer : nodeTransformers )
+ {
+ transformerBuilder.put( transformer.name(), transformer );
+ }
+
+ transformers = transformerBuilder.build();
}
@Override
@@ -138,7 +153,7 @@
return collectionNode;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings( "unchecked" )
private ComplexNode buildComplexNode( FieldMap fieldMap, Class<?> klass, Object object )
{
Schema schema = schemaService.getDynamicSchema( klass );
@@ -272,12 +287,7 @@
if ( child != null )
{
- if ( fieldValue.getAlias() != null )
- {
- child.setName( fieldValue.getAlias() );
- }
-
- complexNode.addChild( child );
+ complexNode.addChild( fieldValue.getPipeline().process( child ) );
}
}
@@ -356,7 +366,12 @@
}
}
- value.setAlias( matcher.group( 3 ) );
+ if ( matcher.group( 3 ) != null )
+ {
+ NodeTransformer transformer = transformers.get( "rename" );
+ value.getPipeline().addTransformer( transformer, Lists.newArrayList( matcher.group( 3 ) ) );
+ }
+
fieldMap.put( matcher.group( 1 ), value );
cleanupFields.add( fieldKey );
=== modified 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 2014-06-25 11:27:12 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/fieldfilter/FieldMap.java 2014-06-25 13:32:36 +0000
@@ -31,6 +31,7 @@
import com.google.common.base.Objects;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.Maps;
+import org.hisp.dhis.node.LinearNodePipeline;
import org.hisp.dhis.node.NodePropertyConverter;
import java.util.Map;
@@ -44,7 +45,7 @@
private NodePropertyConverter nodePropertyConverter;
- private String alias;
+ private final LinearNodePipeline pipeline = new LinearNodePipeline();
@Override
protected Map<String, FieldMap> delegate()
@@ -67,14 +68,9 @@
return nodePropertyConverter != null;
}
- public String getAlias()
- {
- return alias;
- }
-
- public void setAlias( String alias )
- {
- this.alias = alias;
+ public LinearNodePipeline getPipeline()
+ {
+ return pipeline;
}
@Override
@@ -82,7 +78,6 @@
{
return Objects.toStringHelper( this )
.add( "map", standardToString() )
- .add( "alias", alias )
.add( "nodePropertyConverter", nodePropertyConverter )
.toString();
}