Skip to content

Commit a590c97

Browse files
committed
FIN-275 fix an issue in the transaction import not adding account synonyms
1 parent 8ff91b6 commit a590c97

File tree

6 files changed

+123
-103
lines changed

6 files changed

+123
-103
lines changed

bpmn-process/src/.camunda/element-templates/importer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,46 @@
296296
}
297297
}
298298
]
299+
},
300+
{
301+
"$schema": "https://unpkg.com/@camunda/element-templates-json-schema/resources/schema.json",
302+
"name": "Importer: Locate account in mapping",
303+
"description": "Locate the account id in the mapping configuration.",
304+
"id": "com.jongsoft.finance.bpmn.delegate.importer.LocateAccountInMapping",
305+
"version": 1,
306+
"appliesTo": [
307+
"bpmn:ServiceTask"
308+
],
309+
"properties": [
310+
{
311+
"label": "Implementation",
312+
"type": "String",
313+
"value": "${locateAccountInMapping}",
314+
"editable": false,
315+
"binding": {
316+
"type": "property",
317+
"name": "camunda:delegateExpression"
318+
}
319+
},
320+
{
321+
"label": "Account name",
322+
"type": "String",
323+
"binding": {
324+
"type": "camunda:inputParameter",
325+
"name": "name"
326+
},
327+
"constraint": {
328+
"notEmpty": true
329+
}
330+
},
331+
{
332+
"label": "Account id",
333+
"type": "String",
334+
"binding": {
335+
"type": "camunda:outputParameter",
336+
"source": "${accountId}"
337+
}
338+
}
339+
]
299340
}
300341
]

bpmn-process/src/main/java/com/jongsoft/finance/bpmn/delegate/account/LookupAccountMappingDelegate.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

bpmn-process/src/main/java/com/jongsoft/finance/bpmn/delegate/importer/LocateAccountInMapping.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
package com.jongsoft.finance.bpmn.delegate.importer;
22

3+
import com.jongsoft.finance.providers.AccountProvider;
4+
import jakarta.inject.Singleton;
35
import lombok.extern.slf4j.Slf4j;
46
import org.camunda.bpm.engine.delegate.DelegateExecution;
57
import org.camunda.bpm.engine.delegate.JavaDelegate;
68

79
import java.util.Collection;
810

911
@Slf4j
12+
@Singleton
1013
public class LocateAccountInMapping implements JavaDelegate {
14+
15+
private final AccountProvider accountProvider;
16+
17+
public LocateAccountInMapping(AccountProvider accountProvider) {
18+
this.accountProvider = accountProvider;
19+
}
20+
1121
@Override
1222
public void execute(DelegateExecution delegateExecution) throws Exception {
1323
var accountName = (String) delegateExecution.getVariableLocal("name");
@@ -24,6 +34,23 @@ public void execute(DelegateExecution delegateExecution) throws Exception {
2434
.map(ExtractionMapping::getAccountId)
2535
.orElse(null);
2636

37+
determineSynonym(accountName, accountId);
38+
2739
delegateExecution.setVariableLocal("accountId", accountId);
2840
}
41+
42+
private void determineSynonym(String accountName, Long accountId) {
43+
if (accountId == null) {
44+
return;
45+
}
46+
47+
var account = accountProvider.lookup(accountId)
48+
.getOrThrow(() -> new IllegalStateException("Account not found: " + accountId));
49+
if (!account.getName().equals(accountName)) {
50+
log.info("Account name '{}' does not match the account name in the mapping '{}'.",
51+
account.getName(),
52+
accountName);
53+
account.registerSynonym(accountName);
54+
}
55+
}
2956
}

bpmn-process/src/main/resources/bpmn/transaction/import-job.bpmn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ When calling the flow the following variables must be set:
233233
</bpmn:userTask>
234234
<bpmn:sequenceFlow id="Flow_0upo10t" sourceRef="start_create_transaction" targetRef="read_transaction_storage" />
235235
<bpmn:sequenceFlow id="Flow_17ta9lo" sourceRef="read_transaction_storage" targetRef="locate_account_mapping" />
236-
<bpmn:serviceTask id="locate_account_mapping" name="Locate account in mapping" camunda:class="com.jongsoft.finance.bpmn.delegate.importer.LocateAccountInMapping">
236+
<bpmn:serviceTask id="locate_account_mapping" name="Locate account in mapping" camunda:modelerTemplate="com.jongsoft.finance.bpmn.delegate.importer.LocateAccountInMapping" camunda:modelerTemplateVersion="1" camunda:delegateExpression="${locateAccountInMapping}">
237237
<bpmn:extensionElements>
238238
<camunda:inputOutput>
239239
<camunda:inputParameter name="name">${transaction.opposingName}</camunda:inputParameter>

bpmn-process/src/main/resources/bpmn/transaction/transaction.rules.import.bpmn

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<bpmn:sequenceFlow id="SequenceFlow_1owrbto" sourceRef="determineAccountTask" targetRef="persistChangeTask" />
7373
<bpmn:endEvent id="processChangeEnd">
7474
<bpmn:incoming>SequenceFlow_19r3dzy</bpmn:incoming>
75+
<bpmn:incoming>entity_not_found</bpmn:incoming>
7576
</bpmn:endEvent>
7677
<bpmn:sequenceFlow id="SequenceFlow_19r3dzy" sourceRef="persistChangeTask" targetRef="processChangeEnd" />
7778
<bpmn:serviceTask id="determineAccountTask" name="Determine account" camunda:delegateExpression="${processAccountLookupDelegate}">
@@ -133,15 +134,13 @@
133134
<bpmn:incoming>sf_determineCategory</bpmn:incoming>
134135
<bpmn:outgoing>Flow_0va4wh6</bpmn:outgoing>
135136
</bpmn:serviceTask>
136-
<bpmn:sequenceFlow id="Flow_0va4wh6" sourceRef="determineCategoryTask" targetRef="compute_entity_id" />
137+
<bpmn:sequenceFlow id="Flow_0va4wh6" sourceRef="determineCategoryTask" targetRef="check_entity" />
137138
<bpmn:sequenceFlow id="Flow_0vivaah" sourceRef="compute_entity_id" targetRef="persistChangeTask" />
138139
<bpmn:serviceTask id="compute_entity_id" name="Grab Entity Id as String" camunda:expression="${entity.getId().toString()}" camunda:resultVariable="id">
139-
<bpmn:incoming>Flow_0va4wh6</bpmn:incoming>
140-
<bpmn:incoming>Flow_03rhrc4</bpmn:incoming>
141-
<bpmn:incoming>Flow_1rdo73q</bpmn:incoming>
140+
<bpmn:incoming>entity_exists</bpmn:incoming>
142141
<bpmn:outgoing>Flow_0vivaah</bpmn:outgoing>
143142
</bpmn:serviceTask>
144-
<bpmn:sequenceFlow id="Flow_03rhrc4" sourceRef="lookupRelevantBudget" targetRef="compute_entity_id" />
143+
<bpmn:sequenceFlow id="Flow_03rhrc4" sourceRef="lookupRelevantBudget" targetRef="check_entity" />
145144
<bpmn:serviceTask id="lookupRelevantBudget" name="Determine budget" camunda:modelerTemplate="com.jongsoft.finance.bpmn.budget.BudgetLookup" camunda:delegateExpression="${processBudgetLookupDelegate}">
146145
<bpmn:extensionElements>
147146
<camunda:inputOutput>
@@ -163,7 +162,18 @@
163162
<bpmn:incoming>sf_contract_lookup</bpmn:incoming>
164163
<bpmn:outgoing>Flow_1rdo73q</bpmn:outgoing>
165164
</bpmn:serviceTask>
166-
<bpmn:sequenceFlow id="Flow_1rdo73q" sourceRef="locateContract" targetRef="compute_entity_id" />
165+
<bpmn:sequenceFlow id="Flow_1rdo73q" sourceRef="locateContract" targetRef="check_entity" />
166+
<bpmn:exclusiveGateway id="check_entity" name="entity exists" default="entity_not_found">
167+
<bpmn:incoming>Flow_0va4wh6</bpmn:incoming>
168+
<bpmn:incoming>Flow_03rhrc4</bpmn:incoming>
169+
<bpmn:incoming>Flow_1rdo73q</bpmn:incoming>
170+
<bpmn:outgoing>entity_exists</bpmn:outgoing>
171+
<bpmn:outgoing>entity_not_found</bpmn:outgoing>
172+
</bpmn:exclusiveGateway>
173+
<bpmn:sequenceFlow id="entity_exists" name="yes" sourceRef="check_entity" targetRef="compute_entity_id">
174+
<bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${entity != null &amp;&amp; entity.getId() != null}</bpmn:conditionExpression>
175+
</bpmn:sequenceFlow>
176+
<bpmn:sequenceFlow id="entity_not_found" name="no" sourceRef="check_entity" targetRef="processChangeEnd" />
167177
</bpmn:subProcess>
168178
<bpmn:sequenceFlow id="SequenceFlow_1btdqvl" sourceRef="processRuleConfiguration" targetRef="hasGroup" />
169179
<bpmn:sequenceFlow id="SequenceFlow_03zw3cp" sourceRef="buildChangeSubProcess" targetRef="Task_1cw86mx" />
@@ -284,24 +294,30 @@
284294
<bpmndi:BPMNShape id="Activity_0kccv3o_di" bpmnElement="locateContract">
285295
<dc:Bounds x="1651" y="390" width="100" height="80" />
286296
</bpmndi:BPMNShape>
297+
<bpmndi:BPMNShape id="Gateway_00b68d3_di" bpmnElement="check_entity" isMarkerVisible="true">
298+
<dc:Bounds x="1895" y="605" width="50" height="50" />
299+
<bpmndi:BPMNLabel>
300+
<dc:Bounds x="1891" y="665" width="58" height="14" />
301+
</bpmndi:BPMNLabel>
302+
</bpmndi:BPMNShape>
287303
<bpmndi:BPMNEdge id="SequenceFlow_0tlb203_di" bpmnElement="SequenceFlow_0tlb203">
288304
<di:waypoint x="1429" y="430" />
289305
<di:waypoint x="1506" y="430" />
290306
</bpmndi:BPMNEdge>
291307
<bpmndi:BPMNEdge id="SequenceFlow_1tk5jhy_di" bpmnElement="sf_determineAccount">
292-
<di:waypoint x="1540" y="414" />
293-
<di:waypoint x="1540" y="330" />
308+
<di:waypoint x="1550" y="424" />
309+
<di:waypoint x="1550" y="330" />
294310
<di:waypoint x="1651" y="330" />
295311
<bpmndi:BPMNLabel>
296-
<dc:Bounds x="1519" y="366" width="21" height="14" />
312+
<dc:Bounds x="1529" y="371" width="21" height="14" />
297313
</bpmndi:BPMNLabel>
298314
</bpmndi:BPMNEdge>
299315
<bpmndi:BPMNEdge id="SequenceFlow_0co9o7z_di" bpmnElement="sf_determineBudget">
300-
<di:waypoint x="1541" y="445" />
301-
<di:waypoint x="1541" y="530" />
316+
<di:waypoint x="1550" y="436" />
317+
<di:waypoint x="1550" y="530" />
302318
<di:waypoint x="1651" y="530" />
303319
<bpmndi:BPMNLabel>
304-
<dc:Bounds x="1561" y="586" width="35" height="14" />
320+
<dc:Bounds x="1567" y="586" width="35" height="14" />
305321
</bpmndi:BPMNLabel>
306322
</bpmndi:BPMNEdge>
307323
<bpmndi:BPMNEdge id="SequenceFlow_04kbwr8_di" bpmnElement="sf_determineCategory">
@@ -344,8 +360,7 @@
344360
</bpmndi:BPMNEdge>
345361
<bpmndi:BPMNEdge id="Flow_0va4wh6_di" bpmnElement="Flow_0va4wh6">
346362
<di:waypoint x="1751" y="630" />
347-
<di:waypoint x="1920" y="630" />
348-
<di:waypoint x="1920" y="520" />
363+
<di:waypoint x="1895" y="630" />
349364
</bpmndi:BPMNEdge>
350365
<bpmndi:BPMNEdge id="Flow_0vivaah_di" bpmnElement="Flow_0vivaah">
351366
<di:waypoint x="1970" y="480" />
@@ -356,14 +371,29 @@
356371
<bpmndi:BPMNEdge id="Flow_03rhrc4_di" bpmnElement="Flow_03rhrc4">
357372
<di:waypoint x="1751" y="530" />
358373
<di:waypoint x="1811" y="530" />
359-
<di:waypoint x="1811" y="480" />
360-
<di:waypoint x="1870" y="480" />
374+
<di:waypoint x="1811" y="630" />
375+
<di:waypoint x="1895" y="630" />
361376
</bpmndi:BPMNEdge>
362377
<bpmndi:BPMNEdge id="Flow_1rdo73q_di" bpmnElement="Flow_1rdo73q">
363378
<di:waypoint x="1751" y="430" />
364379
<di:waypoint x="1811" y="430" />
365-
<di:waypoint x="1811" y="470" />
366-
<di:waypoint x="1870" y="470" />
380+
<di:waypoint x="1811" y="630" />
381+
<di:waypoint x="1895" y="630" />
382+
</bpmndi:BPMNEdge>
383+
<bpmndi:BPMNEdge id="Flow_045o8yc_di" bpmnElement="entity_exists">
384+
<di:waypoint x="1920" y="605" />
385+
<di:waypoint x="1920" y="520" />
386+
<bpmndi:BPMNLabel>
387+
<dc:Bounds x="1927" y="560" width="17" height="14" />
388+
</bpmndi:BPMNLabel>
389+
</bpmndi:BPMNEdge>
390+
<bpmndi:BPMNEdge id="Flow_1t6r9sc_di" bpmnElement="entity_not_found">
391+
<di:waypoint x="1945" y="630" />
392+
<di:waypoint x="2201" y="630" />
393+
<di:waypoint x="2201" y="418" />
394+
<bpmndi:BPMNLabel>
395+
<dc:Bounds x="2067" y="612" width="13" height="14" />
396+
</bpmndi:BPMNLabel>
367397
</bpmndi:BPMNEdge>
368398
<bpmndi:BPMNShape id="EndEvent_1djjkjl_di" bpmnElement="analyzeRuleEnd">
369399
<dc:Bounds x="2543" y="403" width="36" height="36" />

rule-engine/src/main/java/com/jongsoft/finance/rule/matcher/NumberMatcher.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.jongsoft.finance.rule.matcher;
22

3-
import java.util.function.Supplier;
4-
53
import com.jongsoft.finance.core.RuleOperation;
64

5+
import java.util.function.Supplier;
6+
77
public class NumberMatcher implements ConditionMatcher {
88

99
private Supplier<Boolean> innerMatcher;
@@ -12,6 +12,10 @@ public class NumberMatcher implements ConditionMatcher {
1212
public ConditionMatcher prepare(RuleOperation operation, String expectation, Object actual) {
1313
var checkAmount = Double.parseDouble(expectation);
1414
var castedActual = (Double) actual;
15+
if (castedActual == null) {
16+
innerMatcher = () -> false;
17+
return this;
18+
}
1519

1620
innerMatcher = switch (operation) {
1721
case LESS_THAN -> () -> castedActual < checkAmount;

0 commit comments

Comments
 (0)