Skip to content

Commit 38950f5

Browse files
authored
Improve importer setup (#8)
* Extract dedicated modules for importers. Allowing multiple importer types in the future. * Remove licence from the readme * Update the importer process to use the new setup with the importer-api * Enforce that the ImportConfig contains the type of import that should be run. * Add early exception when the import job yields no transactions. * Add some documentation to the importer delegates for BPMN processes.
1 parent 8efda17 commit 38950f5

File tree

59 files changed

+947
-510
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+947
-510
lines changed

README.md

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,3 @@ API documentation use the url:
4848

4949
http://localhost:8080/spec/index.html
5050

51-
## License
52-
Copyright 2024 Jong Soft Development
53-
54-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
55-
associated documentation files (the "Software"), to deal in the Software without restriction, including
56-
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
57-
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
58-
the following conditions:
59-
60-
The above copyright notice and this permission notice shall be included in all copies or substantial
61-
portions of the Software.
62-
63-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
64-
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
66-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
67-
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

bpmn-process/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ dependencies {
2323
implementation(project(":core"))
2424
implementation(project(":domain"))
2525
implementation(project(":rule-engine"))
26+
implementation(project(":transaction-importer:transaction-importer-api"))
2627

2728
// needed for the testing of the application
2829
runtimeOnly(mn.h2)
2930
runtimeOnly(mn.snakeyaml)
3031
testRuntimeOnly(mn.logback.classic)
3132
testImplementation(mn.micronaut.test.junit5)
3233
testImplementation(libs.bundles.junit)
34+
testRuntimeOnly(project(":transaction-importer:transaction-importer-csv"))
3335
}

bpmn-process/src/main/java/com/jongsoft/finance/ProcessVariable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
import java.io.Serializable;
66

77
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "_type")
8-
public interface ProcessVariable extends Serializable {
8+
public interface ProcessVariable {
99
}

bpmn-process/src/main/java/com/jongsoft/finance/bpmn/ProcessEngineConfiguration.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.jongsoft.finance.bpmn;
22

3+
import com.jongsoft.finance.ProcessVariable;
34
import com.jongsoft.finance.bpmn.camunda.*;
45
import com.jongsoft.finance.core.DataSourceMigration;
6+
import com.jongsoft.finance.serialized.ImportJobSettings;
57
import io.micronaut.context.ApplicationContext;
68
import io.micronaut.context.annotation.Context;
79
import io.micronaut.context.annotation.Factory;
810
import io.micronaut.context.annotation.Requires;
11+
import io.micronaut.serde.ObjectMapper;
912
import lombok.extern.slf4j.Slf4j;
1013
import org.camunda.bpm.engine.HistoryService;
1114
import org.camunda.bpm.engine.ProcessEngine;
@@ -54,6 +57,8 @@ public ProcessEngine processEngine() throws IOException {
5457
configuration.setHistoryCleanupBatchWindowEndTime("03:00");
5558
configuration.setHistoryTimeToLive("P1D");
5659
configuration.setResolverFactories(List.of(new MicronautBeanResolver(applicationContext)));
60+
configuration.setCustomPreVariableSerializers(List.of(
61+
new JsonRecordSerializer<>(applicationContext.getBean(ObjectMapper.class), ProcessVariable.class)));
5762

5863
var processEngine = configuration.buildProcessEngine();
5964
log.info("Created camunda process engine");
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.jongsoft.finance.bpmn.camunda;
2+
3+
import io.micronaut.serde.ObjectMapper;
4+
import org.camunda.bpm.engine.impl.variable.serializer.AbstractTypedValueSerializer;
5+
import org.camunda.bpm.engine.impl.variable.serializer.ValueFields;
6+
import org.camunda.bpm.engine.variable.Variables;
7+
import org.camunda.bpm.engine.variable.impl.type.ObjectTypeImpl;
8+
import org.camunda.bpm.engine.variable.impl.value.UntypedValueImpl;
9+
import org.camunda.bpm.engine.variable.value.ObjectValue;
10+
import org.camunda.bpm.engine.variable.value.TypedValue;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
14+
import java.io.IOException;
15+
16+
public class JsonRecordSerializer<T> extends AbstractTypedValueSerializer<TypedValue> {
17+
private static final Logger logger = LoggerFactory.getLogger(JsonRecordSerializer.class);
18+
19+
final ObjectMapper objectMapper;
20+
final Class<T> supportedClass;
21+
22+
public JsonRecordSerializer(ObjectMapper objectMapper, Class<T> supportedClass) {
23+
super(new ObjectTypeImpl());
24+
this.objectMapper = objectMapper;
25+
this.supportedClass = supportedClass;
26+
}
27+
28+
@Override
29+
public String getName() {
30+
return "record-json";
31+
}
32+
33+
@Override
34+
public String getSerializationDataformat() {
35+
return getName();
36+
}
37+
38+
@Override
39+
public TypedValue convertToTypedValue(UntypedValueImpl untypedValue) {
40+
logger.debug("Converting untyped value to typed value: {}", untypedValue.getType());
41+
42+
var importJobSettings = (Record) untypedValue.getValue();
43+
String jsonString;
44+
try {
45+
jsonString = objectMapper.writeValueAsString(importJobSettings);
46+
} catch (IOException e) {
47+
throw new RuntimeException("Could not serialize ImportJobSettings", e);
48+
}
49+
return Variables.serializedObjectValue(jsonString)
50+
.serializationDataFormat(getName())
51+
.create();
52+
}
53+
54+
@Override
55+
public void writeValue(TypedValue typedValue, ValueFields valueFields) {
56+
ObjectValue objectValue = (ObjectValue) typedValue;
57+
valueFields.setByteArrayValue(objectValue.getValueSerialized().getBytes());
58+
}
59+
60+
@Override
61+
public TypedValue readValue(ValueFields valueFields, boolean b, boolean b1) {
62+
logger.debug("Reading value from value fields: {}", valueFields.getName());
63+
try {
64+
return Variables.objectValue(objectMapper.readValue(
65+
new String(valueFields.getByteArrayValue()),
66+
supportedClass))
67+
.serializationDataFormat(getName())
68+
.create();
69+
} catch (IOException e) {
70+
throw new RuntimeException("Could not deserialize ImportJobSettings", e);
71+
}
72+
}
73+
74+
@Override
75+
protected boolean canWriteValue(TypedValue typedValue) {
76+
logger.trace("Checking if value can be written: {}", typedValue.getValue().getClass().getSimpleName());
77+
return supportedClass.isInstance(typedValue.getValue());
78+
}
79+
}

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

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

0 commit comments

Comments
 (0)