Skip to content

Commit

Permalink
INTEROP-64: migrate routes to YAML DSL (#199)
Browse files Browse the repository at this point in the history
* INTEROP-64: migrate routes to YAML DSL

* fix: force header value to be integer

* docs: correct typo

Co-authored-by: Johan Hole <johan.hole@dhis2.org>

* refactor: move global exception handler to its own config file

---------

Co-authored-by: cjmamo <823038+claudemamo@users.noreply.github.com>
Co-authored-by: Johan Hole <johan.hole@dhis2.org>
  • Loading branch information
3 people authored Jan 7, 2025
1 parent 665260f commit f8f30a8
Show file tree
Hide file tree
Showing 35 changed files with 997 additions and 1,081 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,19 +527,18 @@ Besides being highly configurable, just about any piece of DHIS-to-RapidPro's fu
Integration flows in DHIS-to-RapidPro, known as [routes](https://camel.apache.org/manual/routes.html) in Apache Camel, are named according to their purpose. You can override any route if you know its name. The following is a list of the important routes that you may want to override:
| Route name | Description |
|------------------------|----------------------------------------------------------------------------------------|
| RapidPro Webhook | Accepts and queues RapidPro webhook messages |
| Consume Report | De-queues the report for delivery to DHIS2 |
| Transform Report | Maps and enriches the report as received by RapidPro prior to transmitting it to DHIS2 |
| Transmit Report | Transmits the report to DHIS2 |
| Retry Reports | Re-queues reports marked for replay |
| Scan RapidPro Flows | Polls RapidPro for flow runs and queues them |
| Broadcast Reminders | Queries DHIS2 for overdue reports and sends any reminders to RapidPro |
| Set up RapidPro | Configures RapidPro for integration with DHIS2 |
| Create RapidPro Fields | Creates contact fields on RapidPro |
| Create RapidPro Group | Creates contact group on RapidPro |
| Sync RapidPro Contacts | Synchronises RapidPro contacts with DHIS2 users |
| Route ID | Description |
|----------------------|----------------------------------------------------------------------------------------|
| rapidproWebhook | Accepts and queues RapidPro webhook messages |
| consumeReport | De-queues the report for delivery to DHIS2 |
| transformReport | Maps and enriches the report as received by RapidPro prior to transmitting it to DHIS2 |
| transmitReport | Transmits the report to DHIS2 |
| scanRapidproFlows | Polls RapidPro for flow runs and queues them |
| broadcastReminders | Queries DHIS2 for overdue reports and sends any reminders to RapidPro |
| setUpRapidpro | Configures RapidPro for integration with DHIS2 |
| createRapidproFields | Creates contact fields on RapidPro |
| createRapidproGroup | Creates contact group on RapidPro |
| syncRapidproContacts | Synchronises RapidPro contacts with DHIS2 users |
You should place the file or files containing the custom routes in a directory named `routes` within DHIS-to-RapidPro's current directory. The custom route will override the inbuilt route if the routes match by name. DHIS-to-RapidPro can reload the routes while its running therefore you have the option to extend the application at runtime.

Expand All @@ -549,7 +548,7 @@ What follows is an example of a custom YAML route that overrides the inbuilt `Tr

```yaml
- route:
id: "Transmit Report"
id: "transmitReport"
from:
uri: "direct:transmitReport"
steps:
Expand Down
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<camel.version>4.7.0</camel.version>
<camel.version>4.8.2</camel.version>
<surefire.plugin.version>3.1.2</surefire.plugin.version>
<spring.boot-version>3.3.3</spring.boot-version>
<spring.boot-version>3.4.1</spring.boot-version>
<hawtio.version>2.17.7</hawtio.version>
<dhis.image.name>2.38.3.1</dhis.image.name>
<spring.sql.init.platform>h2</spring.sql.init.platform>
Expand Down Expand Up @@ -87,7 +87,6 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot-version}</version>
<configuration>
<executable>true</executable>
<layout>ZIP</layout>
</configuration>
<executions>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.hisp.dhis.integration.rapidpro.aggregationStrategy;

import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;

import java.util.List;

import static org.apache.camel.builder.Builder.jsonpath;

public class DataElementCodeAggrStrategy implements AggregationStrategy
{
@Override
public Exchange aggregate( Exchange oldExchange, Exchange newExchange )
{
oldExchange.getMessage().setHeader( "dataElementCodes", jsonpath( "$.dataElements..code" ).evaluate( newExchange, List.class ) );
return oldExchange;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.hisp.dhis.integration.rapidpro.aggregationStrategy;

import org.apache.camel.AggregationStrategy;
import org.apache.camel.Exchange;

public class PeriodAggrStrategy implements AggregationStrategy
{
@Override
public Exchange aggregate( Exchange oldExchange, Exchange newExchange )
{
oldExchange.getMessage().setHeader( "period", newExchange.getMessage().getBody() );
return oldExchange;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public class ProgramStageEventsAggrStrategy extends AbstractAggregationStrategy

@Override
public Exchange doAggregate( Exchange oldExchange, Exchange newExchange )
throws
Exception
{
if ( oldExchange == null )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.hisp.dhis.integration.rapidpro.expression;

import org.apache.camel.Exchange;
import org.apache.camel.Expression;
import org.hisp.dhis.integration.rapidpro.ProgramStageToFlowMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class FlowUuidsExpr implements Expression
{
@Autowired
private ProgramStageToFlowMap programStageToFlowMap;

@Value( "${rapidpro.flow.uuids:}" )
private String aggregateReportFlowUuids;

@Override
public <T> T evaluate( Exchange exchange, Class<T> type )
{
String programStageFlowUuids = programStageToFlowMap.getFlowUuids();
String flowUuids = (programStageFlowUuids.isEmpty() && aggregateReportFlowUuids.isEmpty()) ?
"" :
String.join( ",", programStageFlowUuids, aggregateReportFlowUuids );
return (T) flowUuids;
}

public ProgramStageToFlowMap getProgramStageToFlowMap()
{
return programStageToFlowMap;
}

public void setProgramStageToFlowMap( ProgramStageToFlowMap programStageToFlowMap )
{
this.programStageToFlowMap = programStageToFlowMap;
}

public String getAggregateReportFlowUuids()
{
return aggregateReportFlowUuids;
}

public void setAggregateReportFlowUuids( String aggregateReportFlowUuids )
{
this.aggregateReportFlowUuids = aggregateReportFlowUuids;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.util.Map;

@Component
public class LastRunAtColumnReader implements Expression
public class LastRunAtColumnReaderExpr implements Expression
{
@Override
public <T> T evaluate( Exchange exchange, Class<T> type )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@

import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
import java.util.Map;

@Component
public class LastRunCalculator implements Expression
public class LastRunCalculatorExpr implements Expression
{
@Override
public <T> T evaluate( Exchange exchange, Class<T> type )
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit f8f30a8

Please sign in to comment.