Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve importer setup #8

Merged
merged 8 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,3 @@ API documentation use the url:

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

## License
Copyright 2024 Jong Soft Development

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions bpmn-process/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ dependencies {
implementation(project(":core"))
implementation(project(":domain"))
implementation(project(":rule-engine"))
implementation(project(":transaction-importer:transaction-importer-api"))

// needed for the testing of the application
runtimeOnly(mn.h2)
runtimeOnly(mn.snakeyaml)
testRuntimeOnly(mn.logback.classic)
testImplementation(mn.micronaut.test.junit5)
testImplementation(libs.bundles.junit)
testRuntimeOnly(project(":transaction-importer:transaction-importer-csv"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
import java.io.Serializable;

@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, property = "_type")
public interface ProcessVariable extends Serializable {
public interface ProcessVariable {
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.jongsoft.finance.bpmn;

import com.jongsoft.finance.ProcessVariable;
import com.jongsoft.finance.bpmn.camunda.*;
import com.jongsoft.finance.core.DataSourceMigration;
import com.jongsoft.finance.serialized.ImportJobSettings;
import io.micronaut.context.ApplicationContext;
import io.micronaut.context.annotation.Context;
import io.micronaut.context.annotation.Factory;
import io.micronaut.context.annotation.Requires;
import io.micronaut.serde.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ProcessEngine;
Expand Down Expand Up @@ -54,6 +57,8 @@ public ProcessEngine processEngine() throws IOException {
configuration.setHistoryCleanupBatchWindowEndTime("03:00");
configuration.setHistoryTimeToLive("P1D");
configuration.setResolverFactories(List.of(new MicronautBeanResolver(applicationContext)));
configuration.setCustomPreVariableSerializers(List.of(
new JsonRecordSerializer<>(applicationContext.getBean(ObjectMapper.class), ProcessVariable.class)));

var processEngine = configuration.buildProcessEngine();
log.info("Created camunda process engine");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.jongsoft.finance.bpmn.camunda;

import io.micronaut.serde.ObjectMapper;
import org.camunda.bpm.engine.impl.variable.serializer.AbstractTypedValueSerializer;
import org.camunda.bpm.engine.impl.variable.serializer.ValueFields;
import org.camunda.bpm.engine.variable.Variables;
import org.camunda.bpm.engine.variable.impl.type.ObjectTypeImpl;
import org.camunda.bpm.engine.variable.impl.value.UntypedValueImpl;
import org.camunda.bpm.engine.variable.value.ObjectValue;
import org.camunda.bpm.engine.variable.value.TypedValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class JsonRecordSerializer<T> extends AbstractTypedValueSerializer<TypedValue> {
private static final Logger logger = LoggerFactory.getLogger(JsonRecordSerializer.class);

final ObjectMapper objectMapper;
final Class<T> supportedClass;

public JsonRecordSerializer(ObjectMapper objectMapper, Class<T> supportedClass) {
super(new ObjectTypeImpl());
this.objectMapper = objectMapper;
this.supportedClass = supportedClass;
}

@Override
public String getName() {
return "record-json";
}

@Override
public String getSerializationDataformat() {
return getName();
}

@Override
public TypedValue convertToTypedValue(UntypedValueImpl untypedValue) {
logger.debug("Converting untyped value to typed value: {}", untypedValue.getType());

var importJobSettings = (Record) untypedValue.getValue();
String jsonString;
try {
jsonString = objectMapper.writeValueAsString(importJobSettings);
} catch (IOException e) {
throw new RuntimeException("Could not serialize ImportJobSettings", e);
}
return Variables.serializedObjectValue(jsonString)
.serializationDataFormat(getName())
.create();
}

@Override
public void writeValue(TypedValue typedValue, ValueFields valueFields) {
ObjectValue objectValue = (ObjectValue) typedValue;
valueFields.setByteArrayValue(objectValue.getValueSerialized().getBytes());
}

@Override
public TypedValue readValue(ValueFields valueFields, boolean b, boolean b1) {
logger.debug("Reading value from value fields: {}", valueFields.getName());
try {
return Variables.objectValue(objectMapper.readValue(
new String(valueFields.getByteArrayValue()),
supportedClass))
.serializationDataFormat(getName())
.create();
} catch (IOException e) {
throw new RuntimeException("Could not deserialize ImportJobSettings", e);
}
}

@Override
protected boolean canWriteValue(TypedValue typedValue) {
logger.trace("Checking if value can be written: {}", typedValue.getValue().getClass().getSimpleName());
return supportedClass.isInstance(typedValue.getValue());
}
}

This file was deleted.

Loading
Loading