From 3941d68b50b13f3393b3ecbe390372e45abccb57 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 16 Sep 2020 18:02:19 +0200
Subject: [PATCH 001/155] Initial, non functional, draft version of Kafka
consumer integration
Signed-off-by: Jeroen Gommans
---
client/cards/build.gradle | 20 ++
client/cards/src/main/avro/I8n.avsc | 22 ++
client/cards/src/main/avro/card.avsc | 200 ++++++++++++++++++
client/cards/src/main/avro/cardCommand.avsc | 29 +++
client/cards/src/main/avro/detail.avsc | 43 ++++
client/cards/src/main/avro/recipient.avsc | 34 +++
client/cards/src/main/avro/timespan.avsc | 21 ++
config/dev/cards-publication-dev.yml | 14 ++
services/core/cards-publication/build.gradle | 3 +
.../kafka/command/BaseCommandHandler.java | 72 +++++++
.../kafka/command/CommandHandler.java | 11 +
.../command/CreateCardCommandHandler.java | 35 +++
.../command/DeleteCardCommandHandler.java | 24 +++
.../command/UpdateCardCommandHandler.java | 24 +++
.../CardCommandConsumerConfiguration.java | 54 +++++
.../CardCommandConsumerDeserializer.java | 32 +++
.../consumer/CardCommandConsumerListener.java | 42 ++++
17 files changed, 680 insertions(+)
create mode 100644 client/cards/src/main/avro/I8n.avsc
create mode 100644 client/cards/src/main/avro/card.avsc
create mode 100644 client/cards/src/main/avro/cardCommand.avsc
create mode 100644 client/cards/src/main/avro/detail.avsc
create mode 100644 client/cards/src/main/avro/recipient.avsc
create mode 100644 client/cards/src/main/avro/timespan.avsc
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
diff --git a/client/cards/build.gradle b/client/cards/build.gradle
index b20cc85029..ed5098054b 100755
--- a/client/cards/build.gradle
+++ b/client/cards/build.gradle
@@ -1,3 +1,18 @@
+buildscript {
+ repositories {
+ jcenter()
+ }
+ dependencies {
+ classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:0.20.0"
+ }
+}
+
+apply plugin: "com.commercehub.gradle.plugin.avro"
+
+dependencies {
+ compile "org.apache.avro:avro:1.10.0"
+}
+
jar {
manifest {
attributes( "Created-By" : "Gradle ${gradle.gradleVersion}",
@@ -26,4 +41,9 @@ swaggerSources {
}
}
+avro {
+ createSetters = true
+ fieldVisibility = "PRIVATE"
+ stringType = "String"
+}
diff --git a/client/cards/src/main/avro/I8n.avsc b/client/cards/src/main/avro/I8n.avsc
new file mode 100644
index 0000000000..8bd09ccf99
--- /dev/null
+++ b/client/cards/src/main/avro/I8n.avsc
@@ -0,0 +1,22 @@
+{
+ "type": "record",
+ "name": "I18n",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "key",
+ "type":"string"
+ },
+ {
+ "name" : "parameters",
+ "type" : [
+ "null",
+ {
+ "type": "map",
+ "values": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
new file mode 100644
index 0000000000..9865685ee2
--- /dev/null
+++ b/client/cards/src/main/avro/card.avsc
@@ -0,0 +1,200 @@
+{
+ "type": "record",
+ "name": "Card",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ // id is mapped to taskId in cardCommand
+//// {
+//// "name": "id",
+//// "type": "string"
+//// },
+ {
+ "name": "parentCardId",
+ "type": ["null", "string"],
+ "default": null
+ },
+ {
+ "name": "publisher",
+ "type": "string"
+ },
+ {
+ "name": "publisherVersion",
+ "type": "string"
+ },
+ {
+ "name": "process",
+ "type": ["null","string"],
+ "default": null
+ },
+ // processId is mapped to processId in cardCommand
+// {
+// "name": "processId",
+// "type": "string"
+// },
+ {
+ "name": "state",
+ "type": ["null","string"],
+ "default": null
+ },
+ {
+ "name": "publishDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "deletionDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "lttd",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "startDate",
+ "type": "long",
+ "logicalType": "date"
+ },
+ {
+ "name": "endDate",
+ "type": ["null","long"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "severity",
+ "type": {
+ "name": "SeverityType",
+ "type": "enum",
+ "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
+ }
+ },
+ {
+ "name": "tags",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "timespans",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "timespan",
+ "type": "Timespan"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "details",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "detail",
+ "type": "Detail"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "summary",
+ "type": "I18n"
+ },
+ {
+ "name": "recipient",
+ "type": ["null","Recipient"],
+ "default": null
+ },
+ {
+ "name": "userRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "groupRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "externalRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entitiesAllowedToRespond",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entityRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "hasBeenAcknowledged",
+ "type": [
+ "null",
+ "boolean"
+ ],
+ "default": null
+ },
+ {
+ "name": "data",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/cardCommand.avsc b/client/cards/src/main/avro/cardCommand.avsc
new file mode 100644
index 0000000000..0c050a5dd8
--- /dev/null
+++ b/client/cards/src/main/avro/cardCommand.avsc
@@ -0,0 +1,29 @@
+{
+ "type": "record",
+ "name": "CardCommand",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ { "name": "command",
+ "type":
+ {
+ "name": "CommandType",
+ "type": "enum",
+ "symbols" : ["UNKNOWN","CREATE_CARD", "UPDATE_CARD", "DELETE_CARD"],
+ "default": "UNKNOWN"
+ }
+ },
+ {
+ "name": "taskId",
+ "type": "string"
+ },
+ {
+ "name": "processId",
+ "type": "string"
+ },
+ {
+ "name": "card",
+ "type": ["null","Card"],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/detail.avsc b/client/cards/src/main/avro/detail.avsc
new file mode 100644
index 0000000000..1592374f52
--- /dev/null
+++ b/client/cards/src/main/avro/detail.avsc
@@ -0,0 +1,43 @@
+{
+ "type": "record",
+ "name": "Detail",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "title",
+ "type":"I18n"
+ },
+ {
+ "name": "titleStyle",
+ "type": ["null", "string" ],
+ "default": null
+ },
+ {
+ "name": "titlePosition",
+ "type": [
+ "null",
+ {
+ "name": "TitlePositionType",
+ "type": "enum",
+ "symbols" : ["UP", "DOWN", "NONE"]
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "templateName",
+ "type": "string"
+ },
+ {
+ "name": "styles",
+ "type" : [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/recipient.avsc b/client/cards/src/main/avro/recipient.avsc
new file mode 100644
index 0000000000..1945341ebe
--- /dev/null
+++ b/client/cards/src/main/avro/recipient.avsc
@@ -0,0 +1,34 @@
+{
+ "type": "record",
+ "name": "Recipient",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "type",
+ "type": {
+ "name": "RecipientType",
+ "type": "enum",
+ "symbols" : ["DEADEND", "GROUP", "UNION","USER"]
+ }
+ },
+ {
+ "name": "recipients",
+ "type" : [
+ "null",
+ {
+ "type": "array",
+ "items": "Recipient"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "identity",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/timespan.avsc b/client/cards/src/main/avro/timespan.avsc
new file mode 100644
index 0000000000..2692bceeb7
--- /dev/null
+++ b/client/cards/src/main/avro/timespan.avsc
@@ -0,0 +1,21 @@
+{
+ "type": "record",
+ "name": "Timespan",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "start",
+ "type": "int",
+ "logicalType": "date"
+ },
+ {
+ "name" : "end",
+ "type": [
+ "null",
+ "int"
+ ],
+ "logicalType": "date",
+ "default" : null
+ }
+ ]
+}
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index d4a46c6352..04b231944a 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -3,6 +3,20 @@ server:
spring:
application:
name: cards-publication
+ kafka:
+ bootstrap-servers: localhost:9092
+ consumer:
+ group-id: smt01
+ topics:
+ name: camundaKafka
+
+logging:
+ org:
+ lfenergy:
+ operatorfabric:
+ cards:
+ publication: DEBUG
+
#here we put urls for all feign clients
users:
diff --git a/services/core/cards-publication/build.gradle b/services/core/cards-publication/build.gradle
index 37a5f31f0c..459c9f90a9 100755
--- a/services/core/cards-publication/build.gradle
+++ b/services/core/cards-publication/build.gradle
@@ -8,6 +8,9 @@ dependencies {
compileOnly boot.annotationConfiguration
annotationProcessor boot.annotationConfiguration
+ implementation 'org.springframework.kafka:spring-kafka'
+ implementation 'com.google.code.gson:gson:2.8.6'
+
compile boot.starterWebflux
compile project(':client:cards-client-data')
compile project(':tools:spring:spring-mongo-utilities')
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
new file mode 100644
index 0000000000..b32840052e
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -0,0 +1,72 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import com.google.gson.*;
+import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.model.*;
+
+import java.lang.reflect.Type;
+import java.time.Instant;
+
+
+@Slf4j
+public class BaseCommandHandler {
+ // TODO: Move Type Converters to own class
+ private static class InstantTypeConverter
+ implements JsonSerializer, JsonDeserializer {
+ @Override
+ public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
+ return new JsonPrimitive(src.toEpochMilli());
+ }
+
+ @Override
+ public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return Instant.ofEpochMilli(json.getAsLong());
+ }
+ }
+
+ private static class I18nTypeConverter
+ implements JsonSerializer, JsonDeserializer {
+ @Override
+ public JsonElement serialize(I18nPublicationData src, Type srcType, JsonSerializationContext context) {
+ return context.serialize(src);
+ }
+
+ @Override
+ public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, I18nPublicationData.class);
+ }
+ }
+
+ private static class RecipientTypeConverter
+ implements JsonSerializer, JsonDeserializer {
+ @Override
+ public JsonElement serialize(RecipientPublicationData src, Type srcType, JsonSerializationContext context) {
+ return context.serialize(src);
+ }
+
+ @Override
+ public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, RecipientPublicationData.class);
+ }
+ }
+
+ protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
+ Card kafkaCard = cardCommand.getCard();
+
+ // TODO: Replace Gson with Jackson
+ Gson gson = new GsonBuilder()
+ .registerTypeAdapter(Instant.class, new InstantTypeConverter())
+ .registerTypeAdapter(I18n.class, new I18nTypeConverter())
+ .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
+ .create();
+ CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
+ card.setId(cardCommand.getTaskId());
+ card.setProcess(cardCommand.getProcessId());
+ return card;
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
new file mode 100644
index 0000000000..eadced66d1
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
@@ -0,0 +1,11 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+
+public interface CommandHandler {
+
+ CommandType getCommandType();
+
+ void executeCommand(CardCommand cardCommand);
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
new file mode 100644
index 0000000000..a5de034ddf
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -0,0 +1,35 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
+import org.springframework.stereotype.Component;
+import reactor.core.publisher.Flux;
+
+@Component
+@Slf4j
+public class CreateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+
+ private final CardProcessingService cardProcessingService;
+
+ public CreateCardCommandHandler(CardProcessingService cardProcessingService) {
+ super();
+ this.cardProcessingService = cardProcessingService;
+ }
+
+ @Override
+ public CommandType getCommandType() {
+ return CommandType.CREATE_CARD;
+ }
+
+ @Override
+ public void executeCommand(CardCommand cardCommand) {
+ log.debug("Received Kafka CREATE CARD with processId {}, taskId {} and variables: {}",
+ cardCommand.getProcessId(), cardCommand.getTaskId(), cardCommand.getCard().getData());
+
+ CardPublicationData card = buildCardPublicationData(cardCommand);
+ cardProcessingService.processCards(Flux.just(card));
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
new file mode 100644
index 0000000000..7594410272
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -0,0 +1,24 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class DeleteCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+
+ public DeleteCardCommandHandler() {
+ super();
+ }
+
+ @Override
+ public CommandType getCommandType() {
+ return CommandType.DELETE_CARD;
+ }
+
+ @Override
+ public void executeCommand(CardCommand cardCommand) {
+
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
new file mode 100644
index 0000000000..e5de7550bc
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -0,0 +1,24 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class UpdateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+
+ public UpdateCardCommandHandler() {
+ super();
+ }
+
+ @Override
+ public CommandType getCommandType() {
+ return CommandType.UPDATE_CARD;
+ }
+
+ @Override
+ public void executeCommand(CardCommand cardCommand) {
+
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
new file mode 100644
index 0000000000..6c505aa0fa
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
@@ -0,0 +1,54 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
+import org.springframework.kafka.config.KafkaListenerContainerFactory;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+
+import java.util.HashMap;
+import java.util.Map;
+
+@Configuration
+public class CardCommandConsumerConfiguration {
+ @Value("${spring.kafka.bootstrap-servers}")
+ private String bootstrapServers;
+
+ @Value("${spring.kafka.consumer.group-id}")
+ private String groupId;
+
+ private Map consumerConfig() {
+ Map props = new HashMap<>();
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+ props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
+ props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+// props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
+// props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, 0);
+ return props;
+ }
+
+ private ConsumerFactory consumerFactory() {
+ return new DefaultKafkaConsumerFactory<>(
+ consumerConfig(),
+ new StringDeserializer(),
+ new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
+ );
+ }
+
+ @Bean
+ public KafkaListenerContainerFactory> kafkaListenerContainerFactory() {
+ ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
+ factory.setConsumerFactory(consumerFactory());
+ factory.setConcurrency(1);
+ factory.getContainerProperties().setPollTimeout(1000);
+// factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
+ return factory;
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
new file mode 100644
index 0000000000..311ad8f050
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
@@ -0,0 +1,32 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.specific.SpecificRecord;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.serialization.Deserializer;
+
+import java.io.IOException;
+
+public class CardCommandConsumerDeserializer implements Deserializer {
+
+ private final DecoderFactory decoderFactory = DecoderFactory.get();
+ private final DatumReader datumReader;
+
+ public CardCommandConsumerDeserializer(DatumReader datumReader) {
+ this.datumReader = datumReader;
+ }
+
+ @Override
+ public T deserialize(String s, byte[] payload) {
+ if (payload == null) {
+ return null;
+ } else {
+ try {
+ return datumReader.read(null, this.decoderFactory.binaryDecoder(payload, null));
+ } catch (IOException ex) {
+ throw new SerializationException("Error deserializing Avro message", ex);
+ }
+ }
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
new file mode 100644
index 0000000000..c478d6d8fd
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -0,0 +1,42 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.consumer.ConsumerRecord;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
+import org.springframework.kafka.annotation.KafkaListener;
+import org.springframework.messaging.handler.annotation.Payload;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+@Slf4j
+@Component
+public class CardCommandConsumerListener {
+
+ private final Map commandHandlerMap;
+
+ public CardCommandConsumerListener(List commandHandlerList) {
+ commandHandlerMap = commandHandlerList.stream()
+ .collect(Collectors.toMap(CommandHandler::getCommandType, it -> it));
+ }
+
+ @KafkaListener(topics = "${spring.kafka.topics.name}", containerFactory = "kafkaListenerContainerFactory")
+ public void receivedCommand(@Payload ConsumerRecord record) {
+ log.info("Key: {}, Value: {}, Partition: {}, Offset: {}",
+ record.key(), record.value(), record.partition(), record.offset());
+ CardCommand cardCommand = record.value();
+ log.debug("Received {}", cardCommand);
+
+ CommandHandler commandHandler = commandHandlerMap.get(cardCommand.getCommand());
+ if (commandHandler != null) {
+ commandHandler.executeCommand(cardCommand);
+ }
+ else {
+ throw new IllegalStateException("No command handler available for " + cardCommand.getCommand());
+ }
+ }
+}
From a63f86b8ccca2461b97e4c5d0a5338c1eb65d73c Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 17 Sep 2020 09:21:19 +0200
Subject: [PATCH 002/155] Removed unneeded serializers
Signed-off-by: Jeroen Gommans
---
.../kafka/command/BaseCommandHandler.java | 16 ++--------------
1 file changed, 2 insertions(+), 14 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index b32840052e..5e0b8b9b97 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -27,13 +27,7 @@ public Instant deserialize(JsonElement json, Type type, JsonDeserializationConte
}
}
- private static class I18nTypeConverter
- implements JsonSerializer, JsonDeserializer {
- @Override
- public JsonElement serialize(I18nPublicationData src, Type srcType, JsonSerializationContext context) {
- return context.serialize(src);
- }
-
+ private static class I18nTypeConverter implements JsonDeserializer {
@Override
public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
throws JsonParseException {
@@ -41,13 +35,7 @@ public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext
}
}
- private static class RecipientTypeConverter
- implements JsonSerializer, JsonDeserializer {
- @Override
- public JsonElement serialize(RecipientPublicationData src, Type srcType, JsonSerializationContext context) {
- return context.serialize(src);
- }
-
+ private static class RecipientTypeConverter implements JsonDeserializer {
@Override
public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
throws JsonParseException {
From 7bb0fdbba00d64a851dca3b946a689586a3a0849 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 17 Sep 2020 14:02:31 +0200
Subject: [PATCH 003/155] Added versions to configuration file
Signed-off-by: Jeroen Gommans
---
client/cards/build.gradle | 4 ++--
services/core/cards-publication/build.gradle | 2 +-
versions.properties | 3 +++
3 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/client/cards/build.gradle b/client/cards/build.gradle
index ed5098054b..5ab63b08c8 100755
--- a/client/cards/build.gradle
+++ b/client/cards/build.gradle
@@ -3,14 +3,14 @@ buildscript {
jcenter()
}
dependencies {
- classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:0.20.0"
+ classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:${versions['gradle.avro.plugin']}"
}
}
apply plugin: "com.commercehub.gradle.plugin.avro"
dependencies {
- compile "org.apache.avro:avro:1.10.0"
+ compile "org.apache.avro:avro:${versions['avro']}"
}
jar {
diff --git a/services/core/cards-publication/build.gradle b/services/core/cards-publication/build.gradle
index 459c9f90a9..5cff149472 100755
--- a/services/core/cards-publication/build.gradle
+++ b/services/core/cards-publication/build.gradle
@@ -9,7 +9,7 @@ dependencies {
annotationProcessor boot.annotationConfiguration
implementation 'org.springframework.kafka:spring-kafka'
- implementation 'com.google.code.gson:gson:2.8.6'
+ implementation "com.google.code.gson:gson:${versions['com.google.code.gson']}"
compile boot.starterWebflux
compile project(':client:cards-client-data')
diff --git a/versions.properties b/versions.properties
index 2db11e2f45..bfbfc61e9a 100755
--- a/versions.properties
+++ b/versions.properties
@@ -13,6 +13,7 @@ gradle.docker=0.19.2
feign=11.0
jacksonAnnotations=2.11.1
apache.commons.collections4=4.4
+com.google.code.gson=2.8.6
# testing libs
assertj=3.15.0
@@ -25,3 +26,5 @@ swagger=2.3.1
swaggerUI=3.10.0
swagger.generator.plugin=2.12.0
springfox=2.9.2
+avro=1.10.0
+gradle.avro.plugin=0.20.0
From d47bb9c75cd4e3a1f8cca8878ff5e7bf44c58038 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 17 Sep 2020 14:12:28 +0200
Subject: [PATCH 004/155] Refactoreed gson config
Signed-off-by: Jeroen Gommans
---
.../configuration/json/GsonConfig.java | 54 +++++++++++++++++++
.../kafka/command/BaseCommandHandler.java | 40 ++------------
2 files changed, 57 insertions(+), 37 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
new file mode 100644
index 0000000000..1d302c5440
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
@@ -0,0 +1,54 @@
+package org.lfenergy.operatorfabric.cards.publication.configuration.json;
+
+import com.google.gson.*;
+import org.lfenergy.operatorfabric.cards.publication.model.I18n;
+import org.lfenergy.operatorfabric.cards.publication.model.I18nPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.model.Recipient;
+import org.lfenergy.operatorfabric.cards.publication.model.RecipientPublicationData;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.lang.reflect.Type;
+import java.time.Instant;
+
+@Configuration
+public class GsonConfig {
+ private static class InstantTypeConverter
+ implements JsonSerializer, JsonDeserializer {
+ @Override
+ public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
+ return new JsonPrimitive(src.toEpochMilli());
+ }
+
+ @Override
+ public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return Instant.ofEpochMilli(json.getAsLong());
+ }
+ }
+
+ private static class I18nTypeConverter implements JsonDeserializer {
+ @Override
+ public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, I18nPublicationData.class);
+ }
+ }
+
+ private static class RecipientTypeConverter implements JsonDeserializer {
+ @Override
+ public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, RecipientPublicationData.class);
+ }
+ }
+
+ @Bean
+ public Gson gson() {
+ return new GsonBuilder()
+ .registerTypeAdapter(Instant.class, new InstantTypeConverter())
+ .registerTypeAdapter(I18n.class, new I18nTypeConverter())
+ .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
+ .create();
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 5e0b8b9b97..cbc1780769 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -5,53 +5,19 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.model.*;
-
-import java.lang.reflect.Type;
-import java.time.Instant;
+import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class BaseCommandHandler {
- // TODO: Move Type Converters to own class
- private static class InstantTypeConverter
- implements JsonSerializer, JsonDeserializer {
- @Override
- public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
- return new JsonPrimitive(src.toEpochMilli());
- }
-
- @Override
- public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return Instant.ofEpochMilli(json.getAsLong());
- }
- }
- private static class I18nTypeConverter implements JsonDeserializer {
- @Override
- public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, I18nPublicationData.class);
- }
- }
-
- private static class RecipientTypeConverter implements JsonDeserializer {
- @Override
- public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, RecipientPublicationData.class);
- }
- }
+ @Autowired
+ private Gson gson;
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
// TODO: Replace Gson with Jackson
- Gson gson = new GsonBuilder()
- .registerTypeAdapter(Instant.class, new InstantTypeConverter())
- .registerTypeAdapter(I18n.class, new I18nTypeConverter())
- .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
- .create();
CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
card.setId(cardCommand.getTaskId());
card.setProcess(cardCommand.getProcessId());
From f399ed838845ac4fa7715785f7195700b571a1f8 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 17 Sep 2020 14:13:24 +0200
Subject: [PATCH 005/155] Refactored gson config
Signed-off-by: Jeroen Gommans
---
.../configuration/json/GsonConfig.java | 54 +++++++++++++++++++
.../kafka/command/BaseCommandHandler.java | 41 ++------------
2 files changed, 57 insertions(+), 38 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
new file mode 100644
index 0000000000..1d302c5440
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
@@ -0,0 +1,54 @@
+package org.lfenergy.operatorfabric.cards.publication.configuration.json;
+
+import com.google.gson.*;
+import org.lfenergy.operatorfabric.cards.publication.model.I18n;
+import org.lfenergy.operatorfabric.cards.publication.model.I18nPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.model.Recipient;
+import org.lfenergy.operatorfabric.cards.publication.model.RecipientPublicationData;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import java.lang.reflect.Type;
+import java.time.Instant;
+
+@Configuration
+public class GsonConfig {
+ private static class InstantTypeConverter
+ implements JsonSerializer, JsonDeserializer {
+ @Override
+ public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
+ return new JsonPrimitive(src.toEpochMilli());
+ }
+
+ @Override
+ public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return Instant.ofEpochMilli(json.getAsLong());
+ }
+ }
+
+ private static class I18nTypeConverter implements JsonDeserializer {
+ @Override
+ public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, I18nPublicationData.class);
+ }
+ }
+
+ private static class RecipientTypeConverter implements JsonDeserializer {
+ @Override
+ public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
+ throws JsonParseException {
+ return context.deserialize(json, RecipientPublicationData.class);
+ }
+ }
+
+ @Bean
+ public Gson gson() {
+ return new GsonBuilder()
+ .registerTypeAdapter(Instant.class, new InstantTypeConverter())
+ .registerTypeAdapter(I18n.class, new I18nTypeConverter())
+ .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
+ .create();
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 5e0b8b9b97..3c7ca15203 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -5,53 +5,18 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.model.*;
-
-import java.lang.reflect.Type;
-import java.time.Instant;
+import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class BaseCommandHandler {
- // TODO: Move Type Converters to own class
- private static class InstantTypeConverter
- implements JsonSerializer, JsonDeserializer {
- @Override
- public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
- return new JsonPrimitive(src.toEpochMilli());
- }
-
- @Override
- public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return Instant.ofEpochMilli(json.getAsLong());
- }
- }
- private static class I18nTypeConverter implements JsonDeserializer {
- @Override
- public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, I18nPublicationData.class);
- }
- }
-
- private static class RecipientTypeConverter implements JsonDeserializer {
- @Override
- public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, RecipientPublicationData.class);
- }
- }
+ @Autowired
+ private Gson gson;
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
- // TODO: Replace Gson with Jackson
- Gson gson = new GsonBuilder()
- .registerTypeAdapter(Instant.class, new InstantTypeConverter())
- .registerTypeAdapter(I18n.class, new I18nTypeConverter())
- .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
- .create();
CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
card.setId(cardCommand.getTaskId());
card.setProcess(cardCommand.getProcessId());
From ac01d1454b081979da094fe64875c8ddb2166f6e Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 17 Sep 2020 17:06:21 +0200
Subject: [PATCH 006/155] Fixed config error
Signed-off-by: Jeroen Gommans
---
config/dev/cards-publication-dev.yml | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index 04b231944a..cd89b47a89 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -11,11 +11,12 @@ spring:
name: camundaKafka
logging:
- org:
- lfenergy:
- operatorfabric:
- cards:
- publication: DEBUG
+ level:
+ org:
+ lfenergy:
+ operatorfabric:
+ cards:
+ publication: DEBUG
#here we put urls for all feign clients
From c59a0426dff2f2da8201c352f6ead33b5cfd675d Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Mon, 21 Sep 2020 15:54:16 +0200
Subject: [PATCH 007/155] Fixed Flux. Renamed some AVRO fields
Signed-off-by: Jeroen Gommans
---
client/cards/src/main/avro/card.avsc | 12 ++++++------
client/cards/src/main/avro/cardCommand.avsc | 4 ++--
.../kafka/command/BaseCommandHandler.java | 4 ++--
.../kafka/command/CreateCardCommandHandler.java | 6 +++---
4 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
index 9865685ee2..21c649cafc 100644
--- a/client/cards/src/main/avro/card.avsc
+++ b/client/cards/src/main/avro/card.avsc
@@ -18,14 +18,14 @@
"type": "string"
},
{
- "name": "publisherVersion",
+ "name": "processVersion",
"type": "string"
},
- {
- "name": "process",
- "type": ["null","string"],
- "default": null
- },
+ // process is mapped to process in cardCommand
+// {
+// "name": "process",
+// "type": "string"
+// },
// processId is mapped to processId in cardCommand
// {
// "name": "processId",
diff --git a/client/cards/src/main/avro/cardCommand.avsc b/client/cards/src/main/avro/cardCommand.avsc
index 0c050a5dd8..9d9be39ab9 100644
--- a/client/cards/src/main/avro/cardCommand.avsc
+++ b/client/cards/src/main/avro/cardCommand.avsc
@@ -13,11 +13,11 @@
}
},
{
- "name": "taskId",
+ "name": "process",
"type": "string"
},
{
- "name": "processId",
+ "name": "processInstanceId",
"type": "string"
},
{
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 3c7ca15203..661b929537 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -18,8 +18,8 @@ protected CardPublicationData buildCardPublicationData(CardCommand cardCommand)
Card kafkaCard = cardCommand.getCard();
CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
- card.setId(cardCommand.getTaskId());
- card.setProcess(cardCommand.getProcessId());
+ card.setProcess(cardCommand.getProcess());
+ card.setProcessInstanceId(cardCommand.getProcessInstanceId());
return card;
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index a5de034ddf..1f93a0b3be 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -26,10 +26,10 @@ public CommandType getCommandType() {
@Override
public void executeCommand(CardCommand cardCommand) {
- log.debug("Received Kafka CREATE CARD with processId {}, taskId {} and variables: {}",
- cardCommand.getProcessId(), cardCommand.getTaskId(), cardCommand.getCard().getData());
+ log.debug("Received Kafka CREATE CARD with processInstanceId {}, taskId {} and variables: {}",
+ cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
CardPublicationData card = buildCardPublicationData(cardCommand);
- cardProcessingService.processCards(Flux.just(card));
+ cardProcessingService.processCards(Flux.just(card)).subscribe();
}
}
From 93c8b68796407bf089e4d1e514464de03a13aaff Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Mon, 21 Sep 2020 16:40:09 +0200
Subject: [PATCH 008/155] Added conditional Kafka based on kafka topic present
in config file
Signed-off-by: Jeroen Gommans
---
.../kafka/consumer/CardCommandConsumerConfiguration.java | 3 +++
.../kafka/consumer/CardCommandConsumerListener.java | 2 ++
2 files changed, 5 insertions(+)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
index 6c505aa0fa..43d6d76d00 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
@@ -5,6 +5,8 @@
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
@@ -17,6 +19,7 @@
import java.util.Map;
@Configuration
+@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
public class CardCommandConsumerConfiguration {
@Value("${spring.kafka.bootstrap-servers}")
private String bootstrapServers;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
index c478d6d8fd..1b473a378d 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -5,6 +5,7 @@
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
@@ -15,6 +16,7 @@
@Slf4j
@Component
+@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
public class CardCommandConsumerListener {
private final Map commandHandlerMap;
From c940fff2954ccff5fc820ba272d9da327a9c6248 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 22 Sep 2020 11:46:05 +0200
Subject: [PATCH 009/155] Added test for gson config
Signed-off-by: Jeroen Gommans
---
.../configuration/GsonConfigShould.java | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
new file mode 100644
index 0000000000..6b411ed95d
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
@@ -0,0 +1,73 @@
+package org.lfenergy.operatorfabric.cards.publication.configuration;
+
+import com.google.gson.Gson;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.cards.model.RecipientEnum;
+import org.lfenergy.operatorfabric.cards.model.SeverityEnum;
+import org.lfenergy.operatorfabric.cards.publication.application.UnitTestApplication;
+import org.lfenergy.operatorfabric.cards.publication.configuration.json.GsonConfig;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.model.I18nPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.model.Recipient;
+import org.lfenergy.operatorfabric.cards.publication.model.RecipientPublicationData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.validation.Valid;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.List;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.lfenergy.operatorfabric.cards.model.RecipientEnum.DEADEND;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(classes={UnitTestApplication.class, GsonConfig.class})
+@ActiveProfiles(profiles = {"native"})
+@Slf4j
+class GsonConfigShould {
+ @Autowired
+ private Gson gson;
+
+ @Test
+ public void readCard() {
+ String stringCard = "{" +
+ "\"publishDate\": 123,"+
+ "\"summary\": {\"key\": \"Default summary\", \"parameters\": null},"+
+ "\"recipient\": {\"type\": \"USER\", \"recipients\": null, \"identity\": \"tso1-operator\"}," +
+ "\"data\": {"+
+ "\"double\": 123.4,"+
+ "\"string\": \"test\","+
+ "\"object\": {"+
+ "\"double\": 456,"+
+ "\"string\": \"test2\""+
+ "}"+
+ "}"+
+ "}";
+ CardPublicationData card = gson.fromJson(stringCard, CardPublicationData.class);
+ assertThat(card.getData()).isNotNull();
+ assertThat(((Map) card.getData()).get("double")).isEqualTo(123.4);
+ assertThat(((Map) card.getData()).get("string")).isEqualTo("test");
+ assertThat((Map) ((Map) card.getData()).get("object")).isNotNull();
+ assertThat(((Map) ((Map) card.getData()).get("object")).get("double")).isEqualTo(456.0);
+ assertThat(((Map) ((Map) card.getData()).get("object")).get("string")).isEqualTo("test2");
+ assertThat(card.getRecipient().getIdentity()).isEqualTo("tso1-operator");
+ assertThat(card.getRecipient().getType()).isEqualTo(RecipientEnum.USER);
+ assertThat(card.getSummary().getKey()).isEqualTo("Default summary");
+ assertThat(card.getPublishDate().toEpochMilli()).isEqualTo(123);
+ }
+
+ @Test
+ public void testInstantConversion() {
+ Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
+ String nowString = gson.toJson(now);
+ Instant nowSerialized = gson.fromJson(nowString, Instant.class);
+ assertThat(now).isEqualTo(nowSerialized);
+ }
+}
From fcd390881e5c688b40f6a13ff8b8299b56f47d9b Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 22 Sep 2020 14:23:55 +0200
Subject: [PATCH 010/155] Added unit tests for CardCommand handlers
Signed-off-by: Jeroen Gommans
---
.../kafka/command/BaseCommandHandler.java | 10 +++-
.../command/CreateCardCommandHandler.java | 8 ---
.../command/DeleteCardCommandHandler.java | 12 ++--
.../command/UpdateCardCommandHandler.java | 13 ++--
.../CreateCardCommandHandlerShould.java | 59 +++++++++++++++++++
.../DeleteCardCommandHandlerShould.java | 52 ++++++++++++++++
.../command/UpdateCardCommandHandlerTest.java | 51 ++++++++++++++++
.../org.mockito.plugins.MockMaker | 1 +
8 files changed, 186 insertions(+), 20 deletions(-)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
create mode 100644 services/core/cards-publication/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 661b929537..48094c1505 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -1,18 +1,24 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.google.gson.*;
+import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.model.*;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
-public class BaseCommandHandler {
+@NoArgsConstructor
+public abstract class BaseCommandHandler {
@Autowired
- private Gson gson;
+ protected CardProcessingService cardProcessingService;
+
+ @Autowired
+ private Gson gson;
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index 1f93a0b3be..ec3e293691 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -4,7 +4,6 @@
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
-import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
@@ -12,13 +11,6 @@
@Slf4j
public class CreateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
- private final CardProcessingService cardProcessingService;
-
- public CreateCardCommandHandler(CardProcessingService cardProcessingService) {
- super();
- this.cardProcessingService = cardProcessingService;
- }
-
@Override
public CommandType getCommandType() {
return CommandType.CREATE_CARD;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
index 7594410272..4f0414e33a 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -1,16 +1,15 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.springframework.stereotype.Component;
@Component
+@Slf4j
public class DeleteCardCommandHandler extends BaseCommandHandler implements CommandHandler {
- public DeleteCardCommandHandler() {
- super();
- }
-
@Override
public CommandType getCommandType() {
return CommandType.DELETE_CARD;
@@ -18,7 +17,10 @@ public CommandType getCommandType() {
@Override
public void executeCommand(CardCommand cardCommand) {
+ log.debug("Received Kafka DELETE CARD with processInstanceId {}, taskId {} and variables: {}",
+ cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
+ CardPublicationData card = buildCardPublicationData(cardCommand);
+ cardProcessingService.deleteCard(card.getProcessInstanceId());
}
-
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
index e5de7550bc..df04355b41 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -1,16 +1,16 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.springframework.stereotype.Component;
+import reactor.core.publisher.Flux;
@Component
+@Slf4j
public class UpdateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
- public UpdateCardCommandHandler() {
- super();
- }
-
@Override
public CommandType getCommandType() {
return CommandType.UPDATE_CARD;
@@ -18,7 +18,10 @@ public CommandType getCommandType() {
@Override
public void executeCommand(CardCommand cardCommand) {
+ log.debug("Received Kafka UPDATE CARD with processInstanceId {}, taskId {} and variables: {}",
+ cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
+ CardPublicationData card = buildCardPublicationData(cardCommand);
+ cardProcessingService.processCards(Flux.just(card)).subscribe();
}
-
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
new file mode 100644
index 0000000000..d9a8f7cbde
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -0,0 +1,59 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.CardPublicationApplication;
+import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+import reactor.core.publisher.Mono;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.setMaxElementsForPrinting;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class CreateCardCommandHandlerShould {
+
+ @Mock
+ Gson gson;
+
+ @Mock
+ CardProcessingService cardProcessingService;
+
+ @InjectMocks
+ CreateCardCommandHandler createCardCommandHandler;
+
+ @Test
+ void getCommandType() {
+ assertThat(createCardCommandHandler.getCommandType().equals(CommandType.CREATE_CARD));
+ }
+
+ @Test
+ void executeCommand() {
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
+ createCardCommandHandler.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService).processCards(any());
+ }
+}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
new file mode 100644
index 0000000000..43586d5393
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -0,0 +1,52 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import com.google.gson.Gson;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+import reactor.core.publisher.Mono;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class DeleteCardCommandHandlerShould {
+
+ @Mock
+ Gson gson;
+
+ @Mock
+ CardProcessingService cardProcessingService;
+
+ @InjectMocks
+ DeleteCardCommandHandler deleteCardCommandHandler;
+
+ @Test
+ void getCommandType() {
+ assertThat(deleteCardCommandHandler.getCommandType().equals(CommandType.DELETE_CARD));
+ }
+
+ @Test
+ void executeCommand() {
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ deleteCardCommandHandler.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService).deleteCard(any());
+ }
+}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
new file mode 100644
index 0000000000..52332bf838
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
@@ -0,0 +1,51 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import com.google.gson.Gson;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+import reactor.core.publisher.Mono;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class UpdateCardCommandHandlerTest {
+ @Mock
+ Gson gson;
+
+ @Mock
+ CardProcessingService cardProcessingService;
+
+ @InjectMocks
+ UpdateCardCommandHandler updateCardCommandHandler;
+
+ @Test
+ void getCommandType() {
+ assertThat(updateCardCommandHandler.getCommandType().equals(CommandType.UPDATE_CARD));
+ }
+
+ @Test
+ void executeCommand() {
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
+ updateCardCommandHandler.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService).processCards(any());
+ }
+}
diff --git a/services/core/cards-publication/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/services/core/cards-publication/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644
index 0000000000..1f0955d450
--- /dev/null
+++ b/services/core/cards-publication/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
@@ -0,0 +1 @@
+mock-maker-inline
From a79945f7e634bb8b1b52bdd21847e1ede37c263c Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 22 Sep 2020 16:08:14 +0200
Subject: [PATCH 011/155] Removed unneeded import
Signed-off-by: Jeroen Gommans
---
.../kafka/consumer/CardCommandConsumerConfiguration.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
index 43d6d76d00..7de46d1216 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
@@ -1,12 +1,11 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-import org.lfenergy.operatorfabric.avro.CardCommand;
import org.apache.avro.specific.SpecificDatumReader;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
+import org.lfenergy.operatorfabric.avro.CardCommand;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
From 323f4484dee915bc831d9963c259862f70173912 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 23 Sep 2020 12:16:51 +0200
Subject: [PATCH 012/155] Added unit test for Kafka listener
Signed-off-by: Jeroen Gommans
---
.../CardCommandConsumerConfiguration.java | 3 --
.../CardCommandConsumerListenerShould.java | 52 +++++++++++++++++++
2 files changed, 52 insertions(+), 3 deletions(-)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
index 7de46d1216..8706cafc2e 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
@@ -31,8 +31,6 @@ private Map consumerConfig() {
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
-// props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
-// props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, 0);
return props;
}
@@ -50,7 +48,6 @@ public KafkaListenerContainerFactory commandHandlerList = Arrays.asList(createMock, deleteMock);
+ CardCommand cardCommandMock = mock(CardCommand.class);
+
+ when(createMock.getCommandType()).thenReturn(CommandType.CREATE_CARD);
+ when(deleteMock.getCommandType()).thenReturn(CommandType.DELETE_CARD);
+ when (cardCommandMock.getCommand()).thenReturn(CommandType.CREATE_CARD);
+
+ CardCommandConsumerListener cardCommandConsumerListener = new CardCommandConsumerListener(commandHandlerList);
+ ConsumerRecord recordMock = mock(ConsumerRecord.class);
+ when(recordMock.value()).thenReturn(cardCommandMock);
+ cardCommandConsumerListener.receivedCommand(recordMock);
+
+ verify(createMock).executeCommand(any());
+ verify(deleteMock, times(0)).executeCommand(any());
+ }
+
+ @Test
+ void noHandler() {
+ CardCommandConsumerListener cardCommandConsumerListener = new CardCommandConsumerListener(Collections.emptyList());
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ ConsumerRecord recordMock = mock(ConsumerRecord.class);
+ when(recordMock.value()).thenReturn(cardCommandMock);
+ Assertions.assertThrows(IllegalStateException.class, ()-> cardCommandConsumerListener.receivedCommand(recordMock));
+ }
+}
From 37374be2bac0010fc61e34a7f739c36dda320810 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 23 Sep 2020 12:33:30 +0200
Subject: [PATCH 013/155] More code coverage
Signed-off-by: Jeroen Gommans
---
.../CreateCardCommandHandlerShould.java | 8 -----
.../DeleteCardCommandHandlerShould.java | 3 --
...ardCommandConsumerConfigurationShould.java | 31 +++++++++++++++++++
3 files changed, 31 insertions(+), 11 deletions(-)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index d9a8f7cbde..9e6c33247e 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -1,29 +1,21 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.google.gson.Gson;
-import com.google.gson.JsonElement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
-import org.lfenergy.operatorfabric.cards.publication.CardPublicationApplication;
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
-import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
import reactor.core.publisher.Mono;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.setMaxElementsForPrinting;
-import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
index 43586d5393..9b78d3b3e6 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -6,17 +6,14 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
-import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
-import reactor.core.publisher.Mono;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
new file mode 100644
index 0000000000..9d52e0396f
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
@@ -0,0 +1,31 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.mockito.InjectMocks;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.kafka.config.KafkaListenerContainerFactory;
+import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+@ExtendWith(MockitoExtension.class)
+class CardCommandConsumerConfigurationShould {
+
+ @InjectMocks
+ private CardCommandConsumerConfiguration consumerConfig;
+
+ @Test
+ void kafkaListenerContainerFactory() {
+ String groupId = "myGroupId";
+ ReflectionTestUtils.setField(consumerConfig, "groupId", groupId);
+
+ KafkaListenerContainerFactory> container =
+ consumerConfig.kafkaListenerContainerFactory();
+
+ assertThat(groupId, is(container.createContainer("MyContainer").getGroupId()));
+ }
+}
From aa1ec2f8cd6041ffe1362eb9fcf97b3aef342aa6 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 23 Sep 2020 12:38:04 +0200
Subject: [PATCH 014/155] Added profiles
Signed-off-by: Jeroen Gommans
---
.../cards/publication/configuration/GsonConfigShould.java | 2 +-
.../kafka/consumer/CardCommandConsumerConfigurationShould.java | 2 ++
.../kafka/consumer/CardCommandConsumerListenerShould.java | 2 ++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
index 6b411ed95d..6f99d431e6 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
@@ -29,7 +29,7 @@
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes={UnitTestApplication.class, GsonConfig.class})
-@ActiveProfiles(profiles = {"native"})
+@ActiveProfiles(profiles = {"native", "test"})
@Slf4j
class GsonConfigShould {
@Autowired
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
index 9d52e0396f..e3f4445599 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
@@ -7,12 +7,14 @@
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.util.ReflectionTestUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
class CardCommandConsumerConfigurationShould {
@InjectMocks
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
index 8fee06799f..fe4a5aeac4 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
@@ -12,6 +12,7 @@
import org.lfenergy.operatorfabric.cards.publication.kafka.command.UpdateCardCommandHandler;
import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
import java.util.*;
@@ -19,6 +20,7 @@
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
class CardCommandConsumerListenerShould {
@Test
From bd2f345e52f7b4c629414684c2e6b918a8ce9add Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 24 Sep 2020 16:10:42 +0200
Subject: [PATCH 015/155] Removed comments from AVRO file
Signed-off-by: Jeroen Gommans
---
client/cards/src/main/avro/card.avsc | 15 ---------------
1 file changed, 15 deletions(-)
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
index 21c649cafc..6c19677868 100644
--- a/client/cards/src/main/avro/card.avsc
+++ b/client/cards/src/main/avro/card.avsc
@@ -3,11 +3,6 @@
"name": "Card",
"namespace": "org.lfenergy.operatorfabric.avro",
"fields": [
- // id is mapped to taskId in cardCommand
-//// {
-//// "name": "id",
-//// "type": "string"
-//// },
{
"name": "parentCardId",
"type": ["null", "string"],
@@ -21,16 +16,6 @@
"name": "processVersion",
"type": "string"
},
- // process is mapped to process in cardCommand
-// {
-// "name": "process",
-// "type": "string"
-// },
- // processId is mapped to processId in cardCommand
-// {
-// "name": "processId",
-// "type": "string"
-// },
{
"name": "state",
"type": ["null","string"],
From 93b99b5a6d4d00e5f7efb8c7e99dc917cb9eb336 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Fri, 25 Sep 2020 10:44:04 +0200
Subject: [PATCH 016/155] [OC-1073-smt-414] added opfab kafka autoconfiguration
Signed-off-by: Sjoerd Adema
---
config/dev/cards-publication-dev.yml | 6 --
.../ConsumerFactoryAutoConfiguration.java | 34 +++++++++++
...ListenerContainerFactoryConfiguration.java | 60 +++++++++++++++++++
.../CardCommandConsumerConfiguration.java | 54 -----------------
.../consumer/CardCommandConsumerListener.java | 4 +-
.../main/resources/META-INF/spring.factories | 2 +
6 files changed, 97 insertions(+), 63 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
delete mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
create mode 100644 services/core/cards-publication/src/main/resources/META-INF/spring.factories
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index 04b231944a..e48d69deeb 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -3,12 +3,6 @@ server:
spring:
application:
name: cards-publication
- kafka:
- bootstrap-servers: localhost:9092
- consumer:
- group-id: smt01
- topics:
- name: camundaKafka
logging:
org:
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
new file mode 100644
index 0000000000..807d3acbfb
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
@@ -0,0 +1,34 @@
+package org.lfenergy.operatorfabric.cards.autoconfiguration;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+
+import java.util.Map;
+
+@Slf4j
+@RequiredArgsConstructor
+@ConditionalOnProperty("spring.kafka.consumer.group-id")
+@Import(KafkaListenerContainerFactoryConfiguration.class)
+@Configuration
+public class ConsumerFactoryAutoConfiguration {
+
+ private final KafkaProperties kafkaProperties;
+
+ private Map consumerConfig() {
+ log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
+ return kafkaProperties.buildConsumerProperties();
+ }
+
+ @Bean
+ ConsumerFactory consumerFactory() {
+ return new DefaultKafkaConsumerFactory<>(consumerConfig());
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
new file mode 100644
index 0000000000..0ca114d063
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
@@ -0,0 +1,60 @@
+package org.lfenergy.operatorfabric.cards.autoconfiguration;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
+import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerListener;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
+import org.springframework.kafka.config.KafkaListenerContainerFactory;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+
+import java.time.Duration;
+import java.util.List;
+
+@Slf4j
+@RequiredArgsConstructor
+@Configuration
+public class KafkaListenerContainerFactoryConfiguration {
+
+ private final KafkaProperties kafkaProperties;
+
+ @Bean
+ public KafkaListenerContainerFactory> kafkaListenerContainerFactory(ConsumerFactory consumerFactory) {
+ KafkaProperties.Listener listener = kafkaProperties.getListener();
+ Integer concurrency = getConcurrency(listener);
+ Long pollTimeOut = getPollTimeout(listener);
+ log.debug("Concurrency: " + concurrency);
+ log.debug("PollTimeout: " + pollTimeOut);
+ ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
+ factory.setConsumerFactory(consumerFactory);
+ factory.setConcurrency(concurrency);
+ factory.getContainerProperties().setPollTimeout(pollTimeOut);
+ return factory;
+ }
+
+ private Integer getConcurrency(KafkaProperties.Listener listener) {
+ Integer concurrency = listener.getConcurrency();
+ if (concurrency != null) {
+ return concurrency;
+ }
+ return 1;
+ }
+
+ private Long getPollTimeout(KafkaProperties.Listener listener) {
+ Duration duration = listener.getPollTimeout();
+ if (duration != null) {
+ return duration.toMillis();
+ }
+ return 1000l;
+ }
+
+ @Bean
+ CardCommandConsumerListener createConsumerListener(List commandHandlerList) {
+ return new CardCommandConsumerListener(commandHandlerList);
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
deleted file mode 100644
index 6c505aa0fa..0000000000
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.kafka.clients.consumer.ConsumerConfig;
-import org.apache.kafka.common.serialization.StringDeserializer;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
-import org.springframework.kafka.config.KafkaListenerContainerFactory;
-import org.springframework.kafka.core.ConsumerFactory;
-import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
-import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-
-import java.util.HashMap;
-import java.util.Map;
-
-@Configuration
-public class CardCommandConsumerConfiguration {
- @Value("${spring.kafka.bootstrap-servers}")
- private String bootstrapServers;
-
- @Value("${spring.kafka.consumer.group-id}")
- private String groupId;
-
- private Map consumerConfig() {
- Map props = new HashMap<>();
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
- props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
- props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
-// props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
-// props.put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, 0);
- return props;
- }
-
- private ConsumerFactory consumerFactory() {
- return new DefaultKafkaConsumerFactory<>(
- consumerConfig(),
- new StringDeserializer(),
- new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
- );
- }
-
- @Bean
- public KafkaListenerContainerFactory> kafkaListenerContainerFactory() {
- ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
- factory.setConsumerFactory(consumerFactory());
- factory.setConcurrency(1);
- factory.getContainerProperties().setPollTimeout(1000);
-// factory.getContainerProperties().setAckMode(ContainerProperties.AckMode.MANUAL_IMMEDIATE);
- return factory;
- }
-}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
index c478d6d8fd..74efd29393 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -7,14 +7,12 @@
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.Payload;
-import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
-@Component
public class CardCommandConsumerListener {
private final Map commandHandlerMap;
@@ -24,7 +22,7 @@ public CardCommandConsumerListener(List commandHandlerList) {
.collect(Collectors.toMap(CommandHandler::getCommandType, it -> it));
}
- @KafkaListener(topics = "${spring.kafka.topics.name}", containerFactory = "kafkaListenerContainerFactory")
+ @KafkaListener(topics = "${spring.kafka.topics.name:opfab}", containerFactory = "kafkaListenerContainerFactory")
public void receivedCommand(@Payload ConsumerRecord record) {
log.info("Key: {}, Value: {}, Partition: {}, Offset: {}",
record.key(), record.value(), record.partition(), record.offset());
diff --git a/services/core/cards-publication/src/main/resources/META-INF/spring.factories b/services/core/cards-publication/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..1c81cc867d
--- /dev/null
+++ b/services/core/cards-publication/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ org.lfenergy.operatorfabric.cards.autoconfiguration.ConsumerFactoryAutoConfiguration
From 337d986543530a41a91e99e10bd58287335f4785 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Fri, 25 Sep 2020 13:12:43 +0200
Subject: [PATCH 017/155] [OC-1073-smt-414] added kafka configuration for
docker-compose
Signed-off-by: Sjoerd Adema
---
config/docker/docker-compose.yml | 2 ++
config/docker/kafka-env.properties | 1 +
2 files changed, 3 insertions(+)
create mode 100644 config/docker/kafka-env.properties
diff --git a/config/docker/docker-compose.yml b/config/docker/docker-compose.yml
index 71deb62787..6869714464 100755
--- a/config/docker/docker-compose.yml
+++ b/config/docker/docker-compose.yml
@@ -62,6 +62,8 @@ services:
- "../certificates:/certificates_to_add"
- "./common-docker.yml:/config/common-docker.yml"
- "./cards-publication-docker.yml:/config/application-docker.yml"
+ env_file:
+ - kafka-env.properties
cards-consultation:
container_name: cards-consultation
image: "lfeoperatorfabric/of-cards-consultation-business-service:SNAPSHOT"
diff --git a/config/docker/kafka-env.properties b/config/docker/kafka-env.properties
new file mode 100644
index 0000000000..a7d2f047dc
--- /dev/null
+++ b/config/docker/kafka-env.properties
@@ -0,0 +1 @@
+#SPRING_KAFKA_CONSUMER_GROUP_ID=opfab
From 1f343e8ea37d33ab7afcb7c327b0664e296083f6 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 28 Sep 2020 13:57:01 +0200
Subject: [PATCH 018/155] [OC-1073-smt-414] removed test
Signed-off-by: Sjoerd Adema
---
...ardCommandConsumerConfigurationShould.java | 33 -------------------
1 file changed, 33 deletions(-)
delete mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
deleted file mode 100644
index e3f4445599..0000000000
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.mockito.InjectMocks;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.kafka.config.KafkaListenerContainerFactory;
-import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-@ExtendWith(MockitoExtension.class)
-@ActiveProfiles(profiles = {"native", "test"})
-class CardCommandConsumerConfigurationShould {
-
- @InjectMocks
- private CardCommandConsumerConfiguration consumerConfig;
-
- @Test
- void kafkaListenerContainerFactory() {
- String groupId = "myGroupId";
- ReflectionTestUtils.setField(consumerConfig, "groupId", groupId);
-
- KafkaListenerContainerFactory> container =
- consumerConfig.kafkaListenerContainerFactory();
-
- assertThat(groupId, is(container.createContainer("MyContainer").getGroupId()));
- }
-}
From 3f7f89eecbd731a7c5e4df31ae3d0dd4f0517d75 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 30 Sep 2020 12:03:23 +0200
Subject: [PATCH 019/155] Fix for deserializing CardPublicationData.data
---
.../kafka/command/BaseCommandHandler.java | 23 +++++++++
.../CreateCardCommandHandlerShould.java | 47 ++++++++++++++++++-
.../DeleteCardCommandHandlerShould.java | 1 -
.../command/UpdateCardCommandHandlerTest.java | 1 -
.../CardCommandConsumerListenerShould.java | 3 --
5 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 48094c1505..1279133376 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -1,5 +1,8 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.*;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -9,6 +12,9 @@
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.Collections;
+import java.util.Map;
+
@Slf4j
@NoArgsConstructor
@@ -20,12 +26,29 @@ public abstract class BaseCommandHandler {
@Autowired
private Gson gson;
+ @Autowired
+ private ObjectMapper mapper;
+
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
+ // Need to use gson here for now due to Kafka/Avro
CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
card.setProcess(cardCommand.getProcess());
card.setProcessInstanceId(cardCommand.getProcessInstanceId());
+
+ Map cardData = Collections.emptyMap();
+ String cardDataString = kafkaCard.getData();
+ if (cardDataString != null) {
+ try {
+ cardData = mapper.readValue(cardDataString, new TypeReference>() {
+ });
+ } catch (JsonProcessingException e) {
+ log.error("Failure reading card data {}", e.getMessage());
+ }
+ }
+ card.setData(cardData);
+
return card;
}
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index 9e6c33247e..8912389a40 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -1,5 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -13,9 +14,14 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.util.ReflectionTestUtils;
import reactor.core.publisher.Mono;
-import static org.assertj.core.api.Assertions.assertThat;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
@@ -33,7 +39,7 @@ class CreateCardCommandHandlerShould {
@Test
void getCommandType() {
- assertThat(createCardCommandHandler.getCommandType().equals(CommandType.CREATE_CARD));
+ assertThat(createCardCommandHandler.getCommandType(), is(CommandType.CREATE_CARD));
}
@Test
@@ -48,4 +54,41 @@ void executeCommand() {
verify(cardProcessingService).processCards(any());
}
+
+
+ @Test
+ void deserializeOK() {
+ ReflectionTestUtils.setField(createCardCommandHandler, "mapper", new ObjectMapper());
+ String key1="key1";
+ Integer value1 = 123;
+ String key2 = "another key";
+ String value2 ="another value";
+
+ Map dataMap = deserializeCardDataTest("{\""+key1+"\":"+value1+",\""+key2+"\":\""+value2+"\"}");
+ assertNotNull(dataMap);
+ assertThat(dataMap.get(key1), is(value1));
+ assertThat(dataMap.get(key2), is(value2));
+ }
+
+ @Test
+ void deserializeWithError() {
+ Map dataMap = deserializeCardDataTest("{-}");
+ assertNotNull(dataMap);
+ assertThat(dataMap.isEmpty(),is(true));
+ }
+
+ private Map deserializeCardDataTest(String cardData) {
+ ReflectionTestUtils.setField(createCardCommandHandler, "mapper", new ObjectMapper());
+
+ CardCommand cardCommandMock = mock(CardCommand.class);
+
+ Card card = new Card();
+ card.setData(cardData);
+
+ when(cardCommandMock.getCard()).thenReturn(card);
+ when(gson.fromJson((String) any(), any())).thenReturn(new CardPublicationData());
+
+ CardPublicationData cardPublicationData = createCardCommandHandler.buildCardPublicationData(cardCommandMock);
+ return ( Map) cardPublicationData.getData();
+ }
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
index 9b78d3b3e6..c107693f16 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -14,7 +14,6 @@
import org.springframework.test.context.ActiveProfiles;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
index 52332bf838..3b37f4e804 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
@@ -16,7 +16,6 @@
import reactor.core.publisher.Mono;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
index fe4a5aeac4..f86e8390fc 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListenerShould.java
@@ -9,14 +9,11 @@
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CreateCardCommandHandler;
import org.lfenergy.operatorfabric.cards.publication.kafka.command.DeleteCardCommandHandler;
-import org.lfenergy.operatorfabric.cards.publication.kafka.command.UpdateCardCommandHandler;
-import org.mockito.InjectMocks;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
import java.util.*;
-import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
From 7f7b5f6af30ab8c075d608fe9ddde3272a05539c Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Thu, 1 Oct 2020 15:29:20 +0200
Subject: [PATCH 020/155] [OC-1073] fixed kafka configuration
Signed-off-by: Sjoerd Adema
---
config/dev/kafka-dev.yml | 8 ++++++++
.../ConsumerFactoryAutoConfiguration.java | 3 ++-
...afkaListenerContainerFactoryConfiguration.java | 5 +++--
.../consumer/CardCommandConsumerDeserializer.java | 15 +++++++--------
.../publication/model/CardPublicationData.java | 8 ++++++--
5 files changed, 26 insertions(+), 13 deletions(-)
create mode 100644 config/dev/kafka-dev.yml
diff --git a/config/dev/kafka-dev.yml b/config/dev/kafka-dev.yml
new file mode 100644
index 0000000000..2ac87bf4fd
--- /dev/null
+++ b/config/dev/kafka-dev.yml
@@ -0,0 +1,8 @@
+spring:
+ kafka:
+ consumer:
+ group-id: opfab-command
+ value-deserializer: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
+ auto-offset-reset: earliest
+
+
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
index 807d3acbfb..49d83a39f6 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
@@ -2,6 +2,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.avro.CardCommand;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
@@ -27,7 +28,7 @@ private Map consumerConfig() {
}
@Bean
- ConsumerFactory consumerFactory() {
+ ConsumerFactory consumerFactory() {
return new DefaultKafkaConsumerFactory<>(consumerConfig());
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
index 0ca114d063..57e3ff8380 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
@@ -2,6 +2,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerListener;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
@@ -23,13 +24,13 @@ public class KafkaListenerContainerFactoryConfiguration {
private final KafkaProperties kafkaProperties;
@Bean
- public KafkaListenerContainerFactory> kafkaListenerContainerFactory(ConsumerFactory consumerFactory) {
+ public KafkaListenerContainerFactory> kafkaListenerContainerFactory(ConsumerFactory consumerFactory) {
KafkaProperties.Listener listener = kafkaProperties.getListener();
Integer concurrency = getConcurrency(listener);
Long pollTimeOut = getPollTimeout(listener);
log.debug("Concurrency: " + concurrency);
log.debug("PollTimeout: " + pollTimeOut);
- ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
+ ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory);
factory.setConcurrency(concurrency);
factory.getContainerProperties().setPollTimeout(pollTimeOut);
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
index 311ad8f050..40dafdd5f2 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
@@ -1,24 +1,23 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+import lombok.NoArgsConstructor;
import org.apache.avro.io.DatumReader;
import org.apache.avro.io.DecoderFactory;
-import org.apache.avro.specific.SpecificRecord;
+import org.apache.avro.specific.SpecificDatumReader;
import org.apache.kafka.common.errors.SerializationException;
import org.apache.kafka.common.serialization.Deserializer;
+import org.lfenergy.operatorfabric.avro.CardCommand;
import java.io.IOException;
-public class CardCommandConsumerDeserializer implements Deserializer {
+@NoArgsConstructor
+public class CardCommandConsumerDeserializer implements Deserializer {
private final DecoderFactory decoderFactory = DecoderFactory.get();
- private final DatumReader datumReader;
-
- public CardCommandConsumerDeserializer(DatumReader datumReader) {
- this.datumReader = datumReader;
- }
+ private final DatumReader datumReader = new SpecificDatumReader<>();
@Override
- public T deserialize(String s, byte[] payload) {
+ public CardCommand deserialize(String s, byte[] payload) {
if (payload == null) {
return null;
} else {
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
index bb66de4723..bb7366016a 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
@@ -13,7 +13,11 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
-import lombok.*;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.Singular;
import org.lfenergy.operatorfabric.cards.model.SeverityEnum;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
@@ -22,7 +26,6 @@
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
-import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.util.HashSet;
import java.util.List;
@@ -119,6 +122,7 @@ public class CardPublicationData implements Card {
private Boolean hasBeenRead;
@Indexed
private String processStateKey;
+ @Builder.Default
private PublisherTypeEnum publisherType = PublisherTypeEnum.EXTERNAL;
public void prepare(Instant publishDate) {
From e8492aa531c8b969673679a1614a6f2533a57709 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Fri, 2 Oct 2020 12:52:27 +0200
Subject: [PATCH 021/155] Removed GSON and replaced it by Jackson
---
client/cards/src/main/avro/card.avsc | 2 +-
services/core/cards-publication/build.gradle | 1 -
.../configuration/json/GsonConfig.java | 54 --------------
.../kafka/command/BaseCommandHandler.java | 36 +++++----
.../command/CreateCardCommandHandler.java | 10 +++
.../command/DeleteCardCommandHandler.java | 10 +++
.../command/UpdateCardCommandHandler.java | 10 +++
.../configuration/GsonConfigShould.java | 73 -------------------
.../CreateCardCommandHandlerShould.java | 27 ++++---
.../DeleteCardCommandHandlerShould.java | 27 ++++---
.../command/UpdateCardCommandHandlerTest.java | 27 ++++---
versions.properties | 1 -
12 files changed, 102 insertions(+), 176 deletions(-)
delete mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
delete mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
index 6c19677868..0e64bdcc41 100644
--- a/client/cards/src/main/avro/card.avsc
+++ b/client/cards/src/main/avro/card.avsc
@@ -4,7 +4,7 @@
"namespace": "org.lfenergy.operatorfabric.avro",
"fields": [
{
- "name": "parentCardId",
+ "name": "parentCardUid",
"type": ["null", "string"],
"default": null
},
diff --git a/services/core/cards-publication/build.gradle b/services/core/cards-publication/build.gradle
index 5cff149472..f03118ea3b 100755
--- a/services/core/cards-publication/build.gradle
+++ b/services/core/cards-publication/build.gradle
@@ -9,7 +9,6 @@ dependencies {
annotationProcessor boot.annotationConfiguration
implementation 'org.springframework.kafka:spring-kafka'
- implementation "com.google.code.gson:gson:${versions['com.google.code.gson']}"
compile boot.starterWebflux
compile project(':client:cards-client-data')
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
deleted file mode 100644
index 1d302c5440..0000000000
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/json/GsonConfig.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.configuration.json;
-
-import com.google.gson.*;
-import org.lfenergy.operatorfabric.cards.publication.model.I18n;
-import org.lfenergy.operatorfabric.cards.publication.model.I18nPublicationData;
-import org.lfenergy.operatorfabric.cards.publication.model.Recipient;
-import org.lfenergy.operatorfabric.cards.publication.model.RecipientPublicationData;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-import java.lang.reflect.Type;
-import java.time.Instant;
-
-@Configuration
-public class GsonConfig {
- private static class InstantTypeConverter
- implements JsonSerializer, JsonDeserializer {
- @Override
- public JsonElement serialize(Instant src, Type srcType, JsonSerializationContext context) {
- return new JsonPrimitive(src.toEpochMilli());
- }
-
- @Override
- public Instant deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return Instant.ofEpochMilli(json.getAsLong());
- }
- }
-
- private static class I18nTypeConverter implements JsonDeserializer {
- @Override
- public I18n deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, I18nPublicationData.class);
- }
- }
-
- private static class RecipientTypeConverter implements JsonDeserializer {
- @Override
- public Recipient deserialize(JsonElement json, Type type, JsonDeserializationContext context)
- throws JsonParseException {
- return context.deserialize(json, RecipientPublicationData.class);
- }
- }
-
- @Bean
- public Gson gson() {
- return new GsonBuilder()
- .registerTypeAdapter(Instant.class, new InstantTypeConverter())
- .registerTypeAdapter(I18n.class, new I18nTypeConverter())
- .registerTypeAdapter(Recipient.class, new RecipientTypeConverter())
- .create();
- }
-}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 48094c1505..3b86e79bda 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -1,31 +1,41 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.google.gson.*;
-import lombok.NoArgsConstructor;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.lfenergy.operatorfabric.cards.publication.model.*;
-import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+@Component
@Slf4j
-@NoArgsConstructor
public abstract class BaseCommandHandler {
+ private final ObjectMapper objectMapper;
- @Autowired
- protected CardProcessingService cardProcessingService;
-
- @Autowired
- private Gson gson;
+ public BaseCommandHandler(ObjectMapper objectMapper) {
+ this.objectMapper = objectMapper;
+ // REQUIRE_SETTERS_FOR_GETTERS is needed to prevent the AVRO getSchema() call from being serialized
+ this.objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
+ }
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
- CardPublicationData card = gson.fromJson(gson.toJson(kafkaCard), CardPublicationData.class);
- card.setProcess(cardCommand.getProcess());
- card.setProcessInstanceId(cardCommand.getProcessInstanceId());
+
+ CardPublicationData card = null;
+ try {
+ card = objectMapper.readValue(objectMapper.writeValueAsString(kafkaCard), CardPublicationData.class);
+ card.setProcess(cardCommand.getProcess());
+ card.setProcessInstanceId(cardCommand.getProcessInstanceId());
+
+ } catch (JsonProcessingException e) {
+ log.error("Unable to serialize card {} into CardPublicationData. Message: {}", kafkaCard, e.getMessage());
+ e.printStackTrace();
+ }
return card;
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index ec3e293691..fb352c8262 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -1,9 +1,12 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
@@ -11,6 +14,13 @@
@Slf4j
public class CreateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+ private final CardProcessingService cardProcessingService;
+
+ public CreateCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
+ super(objectMapper);
+ this.cardProcessingService = cardProcessingService;
+ }
+
@Override
public CommandType getCommandType() {
return CommandType.CREATE_CARD;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
index 4f0414e33a..4422557f9a 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -1,15 +1,25 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DeleteCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+ private final CardProcessingService cardProcessingService;
+
+ public DeleteCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
+ super(objectMapper);
+ this.cardProcessingService = cardProcessingService;
+ }
+
@Override
public CommandType getCommandType() {
return CommandType.DELETE_CARD;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
index df04355b41..59ac873621 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -1,9 +1,12 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
@@ -11,6 +14,13 @@
@Slf4j
public class UpdateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
+ private final CardProcessingService cardProcessingService;
+
+ public UpdateCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
+ super(objectMapper);
+ this.cardProcessingService = cardProcessingService;
+ }
+
@Override
public CommandType getCommandType() {
return CommandType.UPDATE_CARD;
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
deleted file mode 100644
index 6f99d431e6..0000000000
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/configuration/GsonConfigShould.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.configuration;
-
-import com.google.gson.Gson;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.lfenergy.operatorfabric.cards.model.RecipientEnum;
-import org.lfenergy.operatorfabric.cards.model.SeverityEnum;
-import org.lfenergy.operatorfabric.cards.publication.application.UnitTestApplication;
-import org.lfenergy.operatorfabric.cards.publication.configuration.json.GsonConfig;
-import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
-import org.lfenergy.operatorfabric.cards.publication.model.I18nPublicationData;
-import org.lfenergy.operatorfabric.cards.publication.model.Recipient;
-import org.lfenergy.operatorfabric.cards.publication.model.RecipientPublicationData;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit.jupiter.SpringExtension;
-
-import javax.validation.Valid;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
-import java.util.List;
-import java.util.Map;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.core.Is.is;
-import static org.lfenergy.operatorfabric.cards.model.RecipientEnum.DEADEND;
-
-@ExtendWith(SpringExtension.class)
-@SpringBootTest(classes={UnitTestApplication.class, GsonConfig.class})
-@ActiveProfiles(profiles = {"native", "test"})
-@Slf4j
-class GsonConfigShould {
- @Autowired
- private Gson gson;
-
- @Test
- public void readCard() {
- String stringCard = "{" +
- "\"publishDate\": 123,"+
- "\"summary\": {\"key\": \"Default summary\", \"parameters\": null},"+
- "\"recipient\": {\"type\": \"USER\", \"recipients\": null, \"identity\": \"tso1-operator\"}," +
- "\"data\": {"+
- "\"double\": 123.4,"+
- "\"string\": \"test\","+
- "\"object\": {"+
- "\"double\": 456,"+
- "\"string\": \"test2\""+
- "}"+
- "}"+
- "}";
- CardPublicationData card = gson.fromJson(stringCard, CardPublicationData.class);
- assertThat(card.getData()).isNotNull();
- assertThat(((Map) card.getData()).get("double")).isEqualTo(123.4);
- assertThat(((Map) card.getData()).get("string")).isEqualTo("test");
- assertThat((Map) ((Map) card.getData()).get("object")).isNotNull();
- assertThat(((Map) ((Map) card.getData()).get("object")).get("double")).isEqualTo(456.0);
- assertThat(((Map) ((Map) card.getData()).get("object")).get("string")).isEqualTo("test2");
- assertThat(card.getRecipient().getIdentity()).isEqualTo("tso1-operator");
- assertThat(card.getRecipient().getType()).isEqualTo(RecipientEnum.USER);
- assertThat(card.getSummary().getKey()).isEqualTo("Default summary");
- assertThat(card.getPublishDate().toEpochMilli()).isEqualTo(123);
- }
-
- @Test
- public void testInstantConversion() {
- Instant now = Instant.now().truncatedTo(ChronoUnit.MILLIS);
- String nowString = gson.toJson(now);
- Instant nowSerialized = gson.fromJson(nowString, Instant.class);
- assertThat(now).isEqualTo(nowSerialized);
- }
-}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index 9e6c33247e..fa3de9d2da 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -1,7 +1,10 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.google.gson.Gson;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
@@ -9,8 +12,6 @@
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
import reactor.core.publisher.Mono;
@@ -20,29 +21,33 @@
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class CreateCardCommandHandlerShould {
- @Mock
- Gson gson;
-
- @Mock
CardProcessingService cardProcessingService;
-
- @InjectMocks
+ ObjectMapper objectMapper;
CreateCardCommandHandler createCardCommandHandler;
+ @BeforeAll
+ public void setUp() {
+ cardProcessingService = mock(CardProcessingService.class);
+ objectMapper = mock(ObjectMapper.class);
+ createCardCommandHandler = new CreateCardCommandHandler(cardProcessingService, objectMapper);
+ }
+
@Test
void getCommandType() {
assertThat(createCardCommandHandler.getCommandType().equals(CommandType.CREATE_CARD));
}
@Test
- void executeCommand() {
+ void executeCommand() throws JsonProcessingException {
CardCommand cardCommandMock = mock(CardCommand.class);
CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
Card cardMock = mock(Card.class);
when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
createCardCommandHandler.executeCommand(cardCommandMock);
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
index 9b78d3b3e6..feb32171d7 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -1,15 +1,16 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.google.gson.Gson;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
@@ -19,29 +20,33 @@
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DeleteCardCommandHandlerShould {
- @Mock
- Gson gson;
-
- @Mock
CardProcessingService cardProcessingService;
-
- @InjectMocks
+ ObjectMapper objectMapper;
DeleteCardCommandHandler deleteCardCommandHandler;
+ @BeforeAll
+ public void setUp() {
+ cardProcessingService = mock(CardProcessingService.class);
+ objectMapper = mock(ObjectMapper.class);
+ deleteCardCommandHandler = new DeleteCardCommandHandler(cardProcessingService, objectMapper);
+ }
+
@Test
void getCommandType() {
assertThat(deleteCardCommandHandler.getCommandType().equals(CommandType.DELETE_CARD));
}
@Test
- void executeCommand() {
+ void executeCommand() throws JsonProcessingException {
CardCommand cardCommandMock = mock(CardCommand.class);
CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
Card cardMock = mock(Card.class);
when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
deleteCardCommandHandler.executeCommand(cardCommandMock);
verify(cardProcessingService).deleteCard(any());
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
index 52332bf838..2ef0c8d6e0 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
@@ -1,7 +1,10 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.google.gson.Gson;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
@@ -9,8 +12,6 @@
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
import reactor.core.publisher.Mono;
@@ -21,28 +22,32 @@
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class UpdateCardCommandHandlerTest {
- @Mock
- Gson gson;
-
- @Mock
CardProcessingService cardProcessingService;
-
- @InjectMocks
+ ObjectMapper objectMapper;
UpdateCardCommandHandler updateCardCommandHandler;
+ @BeforeAll
+ public void setUp() {
+ cardProcessingService = mock(CardProcessingService.class);
+ objectMapper = mock(ObjectMapper.class);
+ updateCardCommandHandler = new UpdateCardCommandHandler(cardProcessingService, objectMapper);
+ }
+
@Test
void getCommandType() {
assertThat(updateCardCommandHandler.getCommandType().equals(CommandType.UPDATE_CARD));
}
@Test
- void executeCommand() {
+ void executeCommand() throws JsonProcessingException {
CardCommand cardCommandMock = mock(CardCommand.class);
CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
Card cardMock = mock(Card.class);
when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(gson.fromJson((String) any(), any())).thenReturn(cardPublicationDataMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
updateCardCommandHandler.executeCommand(cardCommandMock);
diff --git a/versions.properties b/versions.properties
index bfbfc61e9a..fa2224c954 100755
--- a/versions.properties
+++ b/versions.properties
@@ -13,7 +13,6 @@ gradle.docker=0.19.2
feign=11.0
jacksonAnnotations=2.11.1
apache.commons.collections4=4.4
-com.google.code.gson=2.8.6
# testing libs
assertj=3.15.0
From 94edc166d521dcc2059eb712338e9a27cf869def Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Fri, 2 Oct 2020 13:37:07 +0200
Subject: [PATCH 022/155] Refactored code. Updated test cases
---
.../kafka/command/BaseCommandHandler.java | 1 -
.../kafka/command/CommandHandler.java | 1 +
.../kafka/command/CreateCardCommandHandler.java | 7 +++++--
.../kafka/command/DeleteCardCommandHandler.java | 4 +++-
.../kafka/command/UpdateCardCommandHandler.java | 4 +++-
.../command/CreateCardCommandHandlerShould.java | 16 ++++++++++++++++
.../command/DeleteCardCommandHandlerShould.java | 17 +++++++++++++++++
.../command/UpdateCardCommandHandlerTest.java | 15 +++++++++++++++
8 files changed, 60 insertions(+), 5 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 3b86e79bda..faca14b3e1 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -34,7 +34,6 @@ protected CardPublicationData buildCardPublicationData(CardCommand cardCommand)
} catch (JsonProcessingException e) {
log.error("Unable to serialize card {} into CardPublicationData. Message: {}", kafkaCard, e.getMessage());
- e.printStackTrace();
}
return card;
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
index eadced66d1..083008c086 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
@@ -1,5 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.core.JsonProcessingException;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index fb352c8262..745159b9e8 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -1,5 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -27,11 +28,13 @@ public CommandType getCommandType() {
}
@Override
- public void executeCommand(CardCommand cardCommand) {
+ public void executeCommand(CardCommand cardCommand) {
log.debug("Received Kafka CREATE CARD with processInstanceId {}, taskId {} and variables: {}",
cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
CardPublicationData card = buildCardPublicationData(cardCommand);
- cardProcessingService.processCards(Flux.just(card)).subscribe();
+ if (card != null) {
+ cardProcessingService.processCards(Flux.just(card)).subscribe();
+ }
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
index 4422557f9a..2371d4c138 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -31,6 +31,8 @@ public void executeCommand(CardCommand cardCommand) {
cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
CardPublicationData card = buildCardPublicationData(cardCommand);
- cardProcessingService.deleteCard(card.getProcessInstanceId());
+ if (card != null) {
+ cardProcessingService.deleteCard(card.getProcessInstanceId());
+ }
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
index 59ac873621..87615c244b 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -32,6 +32,8 @@ public void executeCommand(CardCommand cardCommand) {
cardCommand.getProcessInstanceId(), cardCommand.getProcess(), cardCommand.getCard().getData());
CardPublicationData card = buildCardPublicationData(cardCommand);
- cardProcessingService.processCards(Flux.just(card)).subscribe();
+ if (card != null) {
+ cardProcessingService.processCards(Flux.just(card)).subscribe();
+ }
}
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index fa3de9d2da..7df287f6c4 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -53,4 +53,20 @@ void executeCommand() throws JsonProcessingException {
verify(cardProcessingService).processCards(any());
}
+
+ @Test
+ void executeCommandNoCard() throws JsonProcessingException {
+ CreateCardCommandHandler createCardCommandHandlerRealMapper = new CreateCardCommandHandler(cardProcessingService, new ObjectMapper());
+
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
+ when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
+ createCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService, times(0)).processCards(any());
+ }
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
index feb32171d7..336ca9f7bf 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -9,10 +9,12 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
+import reactor.core.publisher.Mono;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -51,4 +53,19 @@ void executeCommand() throws JsonProcessingException {
verify(cardProcessingService).deleteCard(any());
}
+
+ @Test
+ void executeCommandNoCard() throws JsonProcessingException {
+ DeleteCardCommandHandler deleteCardCommandHandlerRealMapper = new DeleteCardCommandHandler(cardProcessingService, new ObjectMapper());
+
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
+ when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
+ deleteCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
+ verify(cardProcessingService, times(0)).processCards(any());
+ }
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
index 2ef0c8d6e0..2f3f43b2e2 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
@@ -53,4 +53,19 @@ void executeCommand() throws JsonProcessingException {
verify(cardProcessingService).processCards(any());
}
+
+ @Test
+ void executeCommandNoCard() throws JsonProcessingException {
+ UpdateCardCommandHandler updateCardCommandHandlerRealMapper = new UpdateCardCommandHandler(cardProcessingService, new ObjectMapper());
+
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
+ Card cardMock = mock(Card.class);
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
+ when(objectMapper.writeValueAsString(any())).thenReturn("");
+ when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
+ when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
+ updateCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
+ verify(cardProcessingService, times(0)).processCards(any());
+ }
}
From 854c2907cbdbd82efed88dcad35ed21103eb8495 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 09:48:15 +0200
Subject: [PATCH 023/155] [OC-1073] all avro types in one file
Signed-off-by: Sjoerd Adema
---
client/cards/src/main/avro/I8n.avsc | 22 --
client/cards/src/main/avro/card.avsc | 185 ---------
client/cards/src/main/avro/cardCommand.avsc | 365 ++++++++++++++++--
client/cards/src/main/avro/detail.avsc | 43 ---
client/cards/src/main/avro/recipient.avsc | 34 --
client/cards/src/main/avro/timespan.avsc | 21 -
.../ConsumerFactoryAutoConfiguration.java | 3 +-
7 files changed, 344 insertions(+), 329 deletions(-)
delete mode 100644 client/cards/src/main/avro/I8n.avsc
delete mode 100644 client/cards/src/main/avro/card.avsc
delete mode 100644 client/cards/src/main/avro/detail.avsc
delete mode 100644 client/cards/src/main/avro/recipient.avsc
delete mode 100644 client/cards/src/main/avro/timespan.avsc
diff --git a/client/cards/src/main/avro/I8n.avsc b/client/cards/src/main/avro/I8n.avsc
deleted file mode 100644
index 8bd09ccf99..0000000000
--- a/client/cards/src/main/avro/I8n.avsc
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "type": "record",
- "name": "I18n",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "key",
- "type":"string"
- },
- {
- "name" : "parameters",
- "type" : [
- "null",
- {
- "type": "map",
- "values": "string"
- }
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
deleted file mode 100644
index 6c19677868..0000000000
--- a/client/cards/src/main/avro/card.avsc
+++ /dev/null
@@ -1,185 +0,0 @@
-{
- "type": "record",
- "name": "Card",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "parentCardId",
- "type": ["null", "string"],
- "default": null
- },
- {
- "name": "publisher",
- "type": "string"
- },
- {
- "name": "processVersion",
- "type": "string"
- },
- {
- "name": "state",
- "type": ["null","string"],
- "default": null
- },
- {
- "name": "publishDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "deletionDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "lttd",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "startDate",
- "type": "long",
- "logicalType": "date"
- },
- {
- "name": "endDate",
- "type": ["null","long"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "severity",
- "type": {
- "name": "SeverityType",
- "type": "enum",
- "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
- }
- },
- {
- "name": "tags",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "timespans",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "timespan",
- "type": "Timespan"
- }
- }
- ],
- "default": null
- },
- {
- "name": "details",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "detail",
- "type": "Detail"
- }
- }
- ],
- "default": null
- },
- {
- "name": "title",
- "type": "I18n"
- },
- {
- "name": "summary",
- "type": "I18n"
- },
- {
- "name": "recipient",
- "type": ["null","Recipient"],
- "default": null
- },
- {
- "name": "userRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "groupRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "externalRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entitiesAllowedToRespond",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entityRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "hasBeenAcknowledged",
- "type": [
- "null",
- "boolean"
- ],
- "default": null
- },
- {
- "name": "data",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/cardCommand.avsc b/client/cards/src/main/avro/cardCommand.avsc
index 9d9be39ab9..e5cf21c56d 100644
--- a/client/cards/src/main/avro/cardCommand.avsc
+++ b/client/cards/src/main/avro/cardCommand.avsc
@@ -1,29 +1,348 @@
-{
- "type": "record",
- "name": "CardCommand",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- { "name": "command",
- "type":
+[
+ {
+ "type": "record",
+ "name": "Timespan",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "start",
+ "type": "int",
+ "logicalType": "date"
+ },
+ {
+ "name" : "end",
+ "type": [
+ "null",
+ "int"
+ ],
+ "logicalType": "date",
+ "default" : null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "I18n",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "key",
+ "type": "string"
+ },
+ {
+ "name": "parameters",
+ "type": [
+ "null",
+ {
+ "type": "map",
+ "values": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Detail",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "titleStyle",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ },
+ {
+ "name": "titlePosition",
+ "type": [
+ "null",
+ {
+ "name": "TitlePositionType",
+ "type": "enum",
+ "symbols": [
+ "UP",
+ "DOWN",
+ "NONE"
+ ]
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "templateName",
+ "type": "string"
+ },
+ {
+ "name": "styles",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Recipient",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "type",
+ "type": {
+ "name": "RecipientType",
+ "type": "enum",
+ "symbols": [
+ "DEADEND",
+ "GROUP",
+ "UNION",
+ "USER"
+ ]
+ }
+ },
+ {
+ "name": "recipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "Recipient"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "identity",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Card",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "parentCardId",
+ "type": ["null", "string"],
+ "default": null
+ },
+ {
+ "name": "publisher",
+ "type": "string"
+ },
+ {
+ "name": "processVersion",
+ "type": "string"
+ },
+ {
+ "name": "state",
+ "type": ["null","string"],
+ "default": null
+ },
+ {
+ "name": "publishDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "deletionDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "lttd",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "startDate",
+ "type": "long",
+ "logicalType": "date"
+ },
+ {
+ "name": "endDate",
+ "type": ["null","long"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "severity",
+ "type": {
+ "name": "SeverityType",
+ "type": "enum",
+ "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
+ }
+ },
+ {
+ "name": "tags",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "timespans",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "timespan",
+ "type": "Timespan"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "details",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "detail",
+ "type": "Detail"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "summary",
+ "type": "I18n"
+ },
+ {
+ "name": "recipient",
+ "type": ["null","Recipient"],
+ "default": null
+ },
+ {
+ "name": "userRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "groupRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "externalRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entitiesAllowedToRespond",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entityRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "hasBeenAcknowledged",
+ "type": [
+ "null",
+ "boolean"
+ ],
+ "default": null
+ },
+ {
+ "name": "data",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "CardCommand",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ { "name": "command",
+ "type":
{
"name": "CommandType",
"type": "enum",
"symbols" : ["UNKNOWN","CREATE_CARD", "UPDATE_CARD", "DELETE_CARD"],
"default": "UNKNOWN"
}
- },
- {
- "name": "process",
- "type": "string"
- },
- {
- "name": "processInstanceId",
- "type": "string"
- },
- {
- "name": "card",
- "type": ["null","Card"],
- "default": null
- }
- ]
-}
+ },
+ {
+ "name": "process",
+ "type": "string"
+ },
+ {
+ "name": "processInstanceId",
+ "type": "string"
+ },
+ {
+ "name": "card",
+ "type": ["null","Card"],
+ "default": null
+ }
+ ]
+ }
+]
diff --git a/client/cards/src/main/avro/detail.avsc b/client/cards/src/main/avro/detail.avsc
deleted file mode 100644
index 1592374f52..0000000000
--- a/client/cards/src/main/avro/detail.avsc
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "type": "record",
- "name": "Detail",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "title",
- "type":"I18n"
- },
- {
- "name": "titleStyle",
- "type": ["null", "string" ],
- "default": null
- },
- {
- "name": "titlePosition",
- "type": [
- "null",
- {
- "name": "TitlePositionType",
- "type": "enum",
- "symbols" : ["UP", "DOWN", "NONE"]
- }
- ],
- "default": null
- },
- {
- "name": "templateName",
- "type": "string"
- },
- {
- "name": "styles",
- "type" : [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/recipient.avsc b/client/cards/src/main/avro/recipient.avsc
deleted file mode 100644
index 1945341ebe..0000000000
--- a/client/cards/src/main/avro/recipient.avsc
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "type": "record",
- "name": "Recipient",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "type",
- "type": {
- "name": "RecipientType",
- "type": "enum",
- "symbols" : ["DEADEND", "GROUP", "UNION","USER"]
- }
- },
- {
- "name": "recipients",
- "type" : [
- "null",
- {
- "type": "array",
- "items": "Recipient"
- }
- ],
- "default": null
- },
- {
- "name": "identity",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/timespan.avsc b/client/cards/src/main/avro/timespan.avsc
deleted file mode 100644
index 2692bceeb7..0000000000
--- a/client/cards/src/main/avro/timespan.avsc
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "type": "record",
- "name": "Timespan",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "start",
- "type": "int",
- "logicalType": "date"
- },
- {
- "name" : "end",
- "type": [
- "null",
- "int"
- ],
- "logicalType": "date",
- "default" : null
- }
- ]
-}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
index 49d83a39f6..b6836a85a9 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
@@ -24,7 +24,8 @@ public class ConsumerFactoryAutoConfiguration {
private Map consumerConfig() {
log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
- return kafkaProperties.buildConsumerProperties();
+ Map props = kafkaProperties.buildConsumerProperties();
+ return props;
}
@Bean
From 67df46dd11627d65b7dc75e5121ea1a2c8a33512 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 11:07:56 +0200
Subject: [PATCH 024/155] [OC-1073-serialization] added autoconfiguration
Signed-off-by: Sjoerd Adema
---
client/cards/src/main/avro/I8n.avsc | 22 --
client/cards/src/main/avro/card.avsc | 185 ---------
client/cards/src/main/avro/cardCommand.avsc | 365 ++++++++++++++++--
client/cards/src/main/avro/detail.avsc | 43 ---
client/cards/src/main/avro/recipient.avsc | 34 --
client/cards/src/main/avro/timespan.avsc | 21 -
config/dev/cards-publication-dev.yml | 4 +-
.../ConsumerFactoryAutoConfiguration.java | 54 +++
.../CardCommandConsumerConfiguration.java | 57 ++-
.../consumer/CardCommandConsumerListener.java | 5 +-
.../main/resources/META-INF/spring.factories | 2 +
11 files changed, 428 insertions(+), 364 deletions(-)
delete mode 100644 client/cards/src/main/avro/I8n.avsc
delete mode 100644 client/cards/src/main/avro/card.avsc
delete mode 100644 client/cards/src/main/avro/detail.avsc
delete mode 100644 client/cards/src/main/avro/recipient.avsc
delete mode 100644 client/cards/src/main/avro/timespan.avsc
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
create mode 100644 services/core/cards-publication/src/main/resources/META-INF/spring.factories
diff --git a/client/cards/src/main/avro/I8n.avsc b/client/cards/src/main/avro/I8n.avsc
deleted file mode 100644
index 8bd09ccf99..0000000000
--- a/client/cards/src/main/avro/I8n.avsc
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "type": "record",
- "name": "I18n",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "key",
- "type":"string"
- },
- {
- "name" : "parameters",
- "type" : [
- "null",
- {
- "type": "map",
- "values": "string"
- }
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
deleted file mode 100644
index 6c19677868..0000000000
--- a/client/cards/src/main/avro/card.avsc
+++ /dev/null
@@ -1,185 +0,0 @@
-{
- "type": "record",
- "name": "Card",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "parentCardId",
- "type": ["null", "string"],
- "default": null
- },
- {
- "name": "publisher",
- "type": "string"
- },
- {
- "name": "processVersion",
- "type": "string"
- },
- {
- "name": "state",
- "type": ["null","string"],
- "default": null
- },
- {
- "name": "publishDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "deletionDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "lttd",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "startDate",
- "type": "long",
- "logicalType": "date"
- },
- {
- "name": "endDate",
- "type": ["null","long"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "severity",
- "type": {
- "name": "SeverityType",
- "type": "enum",
- "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
- }
- },
- {
- "name": "tags",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "timespans",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "timespan",
- "type": "Timespan"
- }
- }
- ],
- "default": null
- },
- {
- "name": "details",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "detail",
- "type": "Detail"
- }
- }
- ],
- "default": null
- },
- {
- "name": "title",
- "type": "I18n"
- },
- {
- "name": "summary",
- "type": "I18n"
- },
- {
- "name": "recipient",
- "type": ["null","Recipient"],
- "default": null
- },
- {
- "name": "userRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "groupRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "externalRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entitiesAllowedToRespond",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entityRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "hasBeenAcknowledged",
- "type": [
- "null",
- "boolean"
- ],
- "default": null
- },
- {
- "name": "data",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/cardCommand.avsc b/client/cards/src/main/avro/cardCommand.avsc
index 9d9be39ab9..e5cf21c56d 100644
--- a/client/cards/src/main/avro/cardCommand.avsc
+++ b/client/cards/src/main/avro/cardCommand.avsc
@@ -1,29 +1,348 @@
-{
- "type": "record",
- "name": "CardCommand",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- { "name": "command",
- "type":
+[
+ {
+ "type": "record",
+ "name": "Timespan",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "start",
+ "type": "int",
+ "logicalType": "date"
+ },
+ {
+ "name" : "end",
+ "type": [
+ "null",
+ "int"
+ ],
+ "logicalType": "date",
+ "default" : null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "I18n",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "key",
+ "type": "string"
+ },
+ {
+ "name": "parameters",
+ "type": [
+ "null",
+ {
+ "type": "map",
+ "values": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Detail",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "titleStyle",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ },
+ {
+ "name": "titlePosition",
+ "type": [
+ "null",
+ {
+ "name": "TitlePositionType",
+ "type": "enum",
+ "symbols": [
+ "UP",
+ "DOWN",
+ "NONE"
+ ]
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "templateName",
+ "type": "string"
+ },
+ {
+ "name": "styles",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Recipient",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "type",
+ "type": {
+ "name": "RecipientType",
+ "type": "enum",
+ "symbols": [
+ "DEADEND",
+ "GROUP",
+ "UNION",
+ "USER"
+ ]
+ }
+ },
+ {
+ "name": "recipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "Recipient"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "identity",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "Card",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "parentCardId",
+ "type": ["null", "string"],
+ "default": null
+ },
+ {
+ "name": "publisher",
+ "type": "string"
+ },
+ {
+ "name": "processVersion",
+ "type": "string"
+ },
+ {
+ "name": "state",
+ "type": ["null","string"],
+ "default": null
+ },
+ {
+ "name": "publishDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "deletionDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "lttd",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "startDate",
+ "type": "long",
+ "logicalType": "date"
+ },
+ {
+ "name": "endDate",
+ "type": ["null","long"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "severity",
+ "type": {
+ "name": "SeverityType",
+ "type": "enum",
+ "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
+ }
+ },
+ {
+ "name": "tags",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "timespans",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "timespan",
+ "type": "Timespan"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "details",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "detail",
+ "type": "Detail"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "summary",
+ "type": "I18n"
+ },
+ {
+ "name": "recipient",
+ "type": ["null","Recipient"],
+ "default": null
+ },
+ {
+ "name": "userRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "groupRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "externalRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entitiesAllowedToRespond",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entityRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "hasBeenAcknowledged",
+ "type": [
+ "null",
+ "boolean"
+ ],
+ "default": null
+ },
+ {
+ "name": "data",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+ },
+ {
+ "type": "record",
+ "name": "CardCommand",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ { "name": "command",
+ "type":
{
"name": "CommandType",
"type": "enum",
"symbols" : ["UNKNOWN","CREATE_CARD", "UPDATE_CARD", "DELETE_CARD"],
"default": "UNKNOWN"
}
- },
- {
- "name": "process",
- "type": "string"
- },
- {
- "name": "processInstanceId",
- "type": "string"
- },
- {
- "name": "card",
- "type": ["null","Card"],
- "default": null
- }
- ]
-}
+ },
+ {
+ "name": "process",
+ "type": "string"
+ },
+ {
+ "name": "processInstanceId",
+ "type": "string"
+ },
+ {
+ "name": "card",
+ "type": ["null","Card"],
+ "default": null
+ }
+ ]
+ }
+]
diff --git a/client/cards/src/main/avro/detail.avsc b/client/cards/src/main/avro/detail.avsc
deleted file mode 100644
index 1592374f52..0000000000
--- a/client/cards/src/main/avro/detail.avsc
+++ /dev/null
@@ -1,43 +0,0 @@
-{
- "type": "record",
- "name": "Detail",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "title",
- "type":"I18n"
- },
- {
- "name": "titleStyle",
- "type": ["null", "string" ],
- "default": null
- },
- {
- "name": "titlePosition",
- "type": [
- "null",
- {
- "name": "TitlePositionType",
- "type": "enum",
- "symbols" : ["UP", "DOWN", "NONE"]
- }
- ],
- "default": null
- },
- {
- "name": "templateName",
- "type": "string"
- },
- {
- "name": "styles",
- "type" : [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/recipient.avsc b/client/cards/src/main/avro/recipient.avsc
deleted file mode 100644
index 1945341ebe..0000000000
--- a/client/cards/src/main/avro/recipient.avsc
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "type": "record",
- "name": "Recipient",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "type",
- "type": {
- "name": "RecipientType",
- "type": "enum",
- "symbols" : ["DEADEND", "GROUP", "UNION","USER"]
- }
- },
- {
- "name": "recipients",
- "type" : [
- "null",
- {
- "type": "array",
- "items": "Recipient"
- }
- ],
- "default": null
- },
- {
- "name": "identity",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
-}
diff --git a/client/cards/src/main/avro/timespan.avsc b/client/cards/src/main/avro/timespan.avsc
deleted file mode 100644
index 2692bceeb7..0000000000
--- a/client/cards/src/main/avro/timespan.avsc
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "type": "record",
- "name": "Timespan",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "start",
- "type": "int",
- "logicalType": "date"
- },
- {
- "name" : "end",
- "type": [
- "null",
- "int"
- ],
- "logicalType": "date",
- "default" : null
- }
- ]
-}
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index cd89b47a89..bed0c7944e 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -7,8 +7,8 @@ spring:
bootstrap-servers: localhost:9092
consumer:
group-id: smt01
- topics:
- name: camundaKafka
+# topics:
+# name: opfab
logging:
level:
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
new file mode 100644
index 0000000000..385244213d
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
@@ -0,0 +1,54 @@
+package org.lfenergy.operatorfabric.autoconfigure.kafka;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
+import org.apache.kafka.common.serialization.StringDeserializer;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+
+import java.util.Map;
+
+@Slf4j
+@RequiredArgsConstructor
+@ConditionalOnProperty("spring.kafka.consumer.group-id")
+//@Import(KafkaListenerContainerFactoryConfiguration.class)
+@Configuration
+public class ConsumerFactoryAutoConfiguration {
+
+ private final KafkaProperties kafkaProperties;
+
+ @Value("${spring.kafka.bootstrap-servers}")
+ private String bootstrapServers;
+
+ @Value("${spring.kafka.consumer.group-id}")
+ private String groupId;
+
+ private Map consumerConfig() {
+ Map props = kafkaProperties.buildConsumerProperties();
+ log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
+ props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+ props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
+ props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+ return props;
+ }
+
+ @Bean
+ ConsumerFactory consumerFactory() {
+// return new DefaultKafkaConsumerFactory<>(consumerConfig());
+ return new DefaultKafkaConsumerFactory<>(
+ consumerConfig(),
+ new StringDeserializer(),
+ new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
+ );
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
index 8706cafc2e..0cf77f8237 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
@@ -1,51 +1,46 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.kafka.clients.consumer.ConsumerConfig;
-import org.apache.kafka.common.serialization.StringDeserializer;
+import lombok.RequiredArgsConstructor;
import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.core.ConsumerFactory;
-import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-import java.util.HashMap;
-import java.util.Map;
-
+@RequiredArgsConstructor
@Configuration
-@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
+//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
public class CardCommandConsumerConfiguration {
- @Value("${spring.kafka.bootstrap-servers}")
- private String bootstrapServers;
-
- @Value("${spring.kafka.consumer.group-id}")
- private String groupId;
+// @Value("${spring.kafka.bootstrap-servers}")
+// private String bootstrapServers;
+//
+// @Value("${spring.kafka.consumer.group-id}")
+// private String groupId;
+//
+// private Map consumerConfig() {
+// Map props = new HashMap<>();
+// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
+// props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
+// props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
+// return props;
+// }
+//
+// private ConsumerFactory consumerFactory() {
+// return new DefaultKafkaConsumerFactory<>(
+// consumerConfig(),
+// new StringDeserializer(),
+// new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
+// );
+// }
- private Map consumerConfig() {
- Map props = new HashMap<>();
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
- props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
- props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
- return props;
- }
-
- private ConsumerFactory consumerFactory() {
- return new DefaultKafkaConsumerFactory<>(
- consumerConfig(),
- new StringDeserializer(),
- new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
- );
- }
+ private final ConsumerFactory consumerFactory;
@Bean
public KafkaListenerContainerFactory> kafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
- factory.setConsumerFactory(consumerFactory());
+ factory.setConsumerFactory(consumerFactory);
factory.setConcurrency(1);
factory.getContainerProperties().setPollTimeout(1000);
return factory;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
index 1b473a378d..059e9a9335 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -5,7 +5,6 @@
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;
@@ -16,7 +15,7 @@
@Slf4j
@Component
-@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
+//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
public class CardCommandConsumerListener {
private final Map commandHandlerMap;
@@ -26,7 +25,7 @@ public CardCommandConsumerListener(List commandHandlerList) {
.collect(Collectors.toMap(CommandHandler::getCommandType, it -> it));
}
- @KafkaListener(topics = "${spring.kafka.topics.name}", containerFactory = "kafkaListenerContainerFactory")
+ @KafkaListener(topics = "${spoc.kafka.topics.topicname:opfab}", containerFactory = "kafkaListenerContainerFactory")
public void receivedCommand(@Payload ConsumerRecord record) {
log.info("Key: {}, Value: {}, Partition: {}, Offset: {}",
record.key(), record.value(), record.partition(), record.offset());
diff --git a/services/core/cards-publication/src/main/resources/META-INF/spring.factories b/services/core/cards-publication/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000000..7abd496c8b
--- /dev/null
+++ b/services/core/cards-publication/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,2 @@
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+ org.lfenergy.operatorfabric.autoconfigure.kafka.ConsumerFactoryAutoConfiguration
From 8239a7713b9a9fad7acb21d97ce1354ea43bcc19 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 11:15:23 +0200
Subject: [PATCH 025/155] [OC-1073-serialization] removed redundant
configuration code
Signed-off-by: Sjoerd Adema
---
config/dev/cards-publication-dev.yml | 1 -
config/dev/kafka.yml | 10 ++++++++++
.../kafka/ConsumerFactoryAutoConfiguration.java | 11 -----------
3 files changed, 10 insertions(+), 12 deletions(-)
create mode 100644 config/dev/kafka.yml
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index bed0c7944e..902925e03e 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -4,7 +4,6 @@ spring:
application:
name: cards-publication
kafka:
- bootstrap-servers: localhost:9092
consumer:
group-id: smt01
# topics:
diff --git a/config/dev/kafka.yml b/config/dev/kafka.yml
new file mode 100644
index 0000000000..e728af1c41
--- /dev/null
+++ b/config/dev/kafka.yml
@@ -0,0 +1,10 @@
+#spring:
+# kafka:
+# consumer:
+# group-id: smt01
+# value-deserializer: nl.prototype.kafka.basic.consumer.CardCommandConsumerDeserializer
+# auto-offset-reset: earliest
+# enable-auto-commit: false
+# listener:
+# concurrency: 1
+# poll-timeout: 2000
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
index 385244213d..6c6ede4d88 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
@@ -3,11 +3,9 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
@@ -26,18 +24,9 @@ public class ConsumerFactoryAutoConfiguration {
private final KafkaProperties kafkaProperties;
- @Value("${spring.kafka.bootstrap-servers}")
- private String bootstrapServers;
-
- @Value("${spring.kafka.consumer.group-id}")
- private String groupId;
-
private Map consumerConfig() {
Map props = kafkaProperties.buildConsumerProperties();
log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
- props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
- props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
- props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
return props;
}
From fec14e0ce878b0c4f4f0583eea7bfec42a3fa3d6 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 11:18:56 +0200
Subject: [PATCH 026/155] [OC-1073-serialization] moved configuration
properties to kafka yaml file
Signed-off-by: Sjoerd Adema
---
config/dev/cards-publication-dev.yml | 5 -----
config/dev/kafka.yml | 8 ++++----
2 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index 902925e03e..99f4cb00c8 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -3,11 +3,6 @@ server:
spring:
application:
name: cards-publication
- kafka:
- consumer:
- group-id: smt01
-# topics:
-# name: opfab
logging:
level:
diff --git a/config/dev/kafka.yml b/config/dev/kafka.yml
index e728af1c41..46dc2fc393 100644
--- a/config/dev/kafka.yml
+++ b/config/dev/kafka.yml
@@ -1,7 +1,7 @@
-#spring:
-# kafka:
-# consumer:
-# group-id: smt01
+spring:
+ kafka:
+ consumer:
+ group-id: smt01
# value-deserializer: nl.prototype.kafka.basic.consumer.CardCommandConsumerDeserializer
# auto-offset-reset: earliest
# enable-auto-commit: false
From e411f14c829137ab3076015d93a2f9f3fa2a137a Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 11:29:57 +0200
Subject: [PATCH 027/155] [OC-1073-serialization] removed serialization
arguments from DefaultKafkaConsumerFactory constructor
Signed-off-by: Sjoerd Adema
---
config/dev/kafka.yml | 5 ++-
.../ConsumerFactoryAutoConfiguration.java | 10 +-----
.../kafka/consumer/BaseAvroDeserializer.java | 32 +++++++++++++++++++
.../CardCommandConsumerDeserializer.java | 30 +++--------------
4 files changed, 40 insertions(+), 37 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializer.java
diff --git a/config/dev/kafka.yml b/config/dev/kafka.yml
index 46dc2fc393..d6f5ac6f96 100644
--- a/config/dev/kafka.yml
+++ b/config/dev/kafka.yml
@@ -2,9 +2,8 @@ spring:
kafka:
consumer:
group-id: smt01
-# value-deserializer: nl.prototype.kafka.basic.consumer.CardCommandConsumerDeserializer
-# auto-offset-reset: earliest
-# enable-auto-commit: false
+ value-deserializer: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
+ auto-offset-reset: earliest
# listener:
# concurrency: 1
# poll-timeout: 2000
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
index 6c6ede4d88..c730ac2026 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
@@ -2,10 +2,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.apache.avro.specific.SpecificDatumReader;
-import org.apache.kafka.common.serialization.StringDeserializer;
import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
@@ -32,12 +29,7 @@ private Map consumerConfig() {
@Bean
ConsumerFactory consumerFactory() {
-// return new DefaultKafkaConsumerFactory<>(consumerConfig());
- return new DefaultKafkaConsumerFactory<>(
- consumerConfig(),
- new StringDeserializer(),
- new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
- );
+ return new DefaultKafkaConsumerFactory<>(consumerConfig());
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializer.java
new file mode 100644
index 0000000000..1084f05d85
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializer.java
@@ -0,0 +1,32 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.apache.avro.io.DatumReader;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.specific.SpecificRecord;
+import org.apache.kafka.common.errors.SerializationException;
+import org.apache.kafka.common.serialization.Deserializer;
+
+import java.io.IOException;
+
+public class BaseAvroDeserializer implements Deserializer {
+
+ private final DecoderFactory decoderFactory = DecoderFactory.get();
+ private final DatumReader datumReader;
+
+ protected BaseAvroDeserializer(DatumReader datumReader) {
+ this.datumReader = datumReader;
+ }
+
+ @Override
+ public T deserialize(String s, byte[] payload) {
+ if (payload == null) {
+ return null;
+ } else {
+ try {
+ return datumReader.read(null, this.decoderFactory.binaryDecoder(payload, null));
+ } catch (IOException ex) {
+ throw new SerializationException("Error deserializing Avro message", ex);
+ }
+ }
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
index 311ad8f050..17a75c1ab9 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
@@ -1,32 +1,12 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-import org.apache.avro.io.DatumReader;
-import org.apache.avro.io.DecoderFactory;
-import org.apache.avro.specific.SpecificRecord;
-import org.apache.kafka.common.errors.SerializationException;
-import org.apache.kafka.common.serialization.Deserializer;
+import org.apache.avro.specific.SpecificDatumReader;
+import org.lfenergy.operatorfabric.avro.CardCommand;
-import java.io.IOException;
+public class CardCommandConsumerDeserializer extends BaseAvroDeserializer {
-public class CardCommandConsumerDeserializer implements Deserializer {
-
- private final DecoderFactory decoderFactory = DecoderFactory.get();
- private final DatumReader datumReader;
-
- public CardCommandConsumerDeserializer(DatumReader datumReader) {
- this.datumReader = datumReader;
+ public CardCommandConsumerDeserializer() {
+ super(new SpecificDatumReader<>(CardCommand.class));
}
- @Override
- public T deserialize(String s, byte[] payload) {
- if (payload == null) {
- return null;
- } else {
- try {
- return datumReader.read(null, this.decoderFactory.binaryDecoder(payload, null));
- } catch (IOException ex) {
- throw new SerializationException("Error deserializing Avro message", ex);
- }
- }
- }
}
From 3cb536e210bd36100ee8f8c0635c466c971be8d5 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 12:27:44 +0200
Subject: [PATCH 028/155] [OC-1073-serialization] added
KafkaListenerContainerFactoryConfiguration
Signed-off-by: Sjoerd Adema
---
.../ConsumerFactoryAutoConfiguration.java | 3 +-
...ListenerContainerFactoryConfiguration.java | 63 +++++++++++++++++++
.../CardCommandConsumerConfiguration.java | 48 --------------
.../consumer/CardCommandConsumerListener.java | 3 -
...ardCommandConsumerConfigurationShould.java | 33 ----------
5 files changed, 65 insertions(+), 85 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfiguration.java
delete mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
delete mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
index c730ac2026..279819a511 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
@@ -7,6 +7,7 @@
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Import;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
@@ -15,7 +16,7 @@
@Slf4j
@RequiredArgsConstructor
@ConditionalOnProperty("spring.kafka.consumer.group-id")
-//@Import(KafkaListenerContainerFactoryConfiguration.class)
+@Import(KafkaListenerContainerFactoryConfiguration.class)
@Configuration
public class ConsumerFactoryAutoConfiguration {
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfiguration.java
new file mode 100644
index 0000000000..c0e8548c37
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfiguration.java
@@ -0,0 +1,63 @@
+package org.lfenergy.operatorfabric.autoconfigure.kafka;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
+import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerListener;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
+import org.springframework.kafka.config.KafkaListenerContainerFactory;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+
+import java.time.Duration;
+import java.util.List;
+
+@Slf4j
+@RequiredArgsConstructor
+@Configuration
+public class KafkaListenerContainerFactoryConfiguration {
+
+ private final KafkaProperties kafkaProperties;
+
+ private final ConsumerFactory consumerFactory;
+
+ private Integer getConcurrency(KafkaProperties.Listener listener) {
+ Integer concurrency = listener.getConcurrency();
+ if (concurrency != null) {
+ return concurrency;
+ }
+ return 1;
+ }
+
+ private Long getPollTimeout(KafkaProperties.Listener listener) {
+ Duration duration = listener.getPollTimeout();
+ if (duration != null) {
+ return duration.toMillis();
+ }
+ return 1000l;
+ }
+
+ @Bean
+ public KafkaListenerContainerFactory> kafkaListenerContainerFactory() {
+ KafkaProperties.Listener listener = kafkaProperties.getListener();
+ Integer concurrency = getConcurrency(listener);
+ Long pollTimeOut = getPollTimeout(listener);
+ log.info("Concurrency: " + concurrency);
+ log.info("PollTimeout: " + pollTimeOut);
+ ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
+ factory.setConsumerFactory(consumerFactory);
+ factory.setConcurrency(concurrency);
+ factory.getContainerProperties().setPollTimeout(pollTimeOut);
+ return factory;
+ }
+
+ @Bean
+ CardCommandConsumerListener createCardCommandConsumerListener(List commandHandlerList) {
+ return new CardCommandConsumerListener(commandHandlerList);
+ }
+
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
deleted file mode 100644
index 0cf77f8237..0000000000
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfiguration.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-
-import lombok.RequiredArgsConstructor;
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
-import org.springframework.kafka.config.KafkaListenerContainerFactory;
-import org.springframework.kafka.core.ConsumerFactory;
-import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-
-@RequiredArgsConstructor
-@Configuration
-//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
-public class CardCommandConsumerConfiguration {
-// @Value("${spring.kafka.bootstrap-servers}")
-// private String bootstrapServers;
-//
-// @Value("${spring.kafka.consumer.group-id}")
-// private String groupId;
-//
-// private Map consumerConfig() {
-// Map props = new HashMap<>();
-// props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
-// props.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
-// props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
-// return props;
-// }
-//
-// private ConsumerFactory consumerFactory() {
-// return new DefaultKafkaConsumerFactory<>(
-// consumerConfig(),
-// new StringDeserializer(),
-// new CardCommandConsumerDeserializer<>(new SpecificDatumReader<>(CardCommand.class))
-// );
-// }
-
- private final ConsumerFactory consumerFactory;
-
- @Bean
- public KafkaListenerContainerFactory> kafkaListenerContainerFactory() {
- ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
- factory.setConsumerFactory(consumerFactory);
- factory.setConcurrency(1);
- factory.getContainerProperties().setPollTimeout(1000);
- return factory;
- }
-}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
index 059e9a9335..1526a1b993 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -7,15 +7,12 @@
import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.messaging.handler.annotation.Payload;
-import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
-@Component
-//@ConditionalOnExpression("!T(org.springframework.util.StringUtils).isEmpty('${spring.kafka.topics.name:}')")
public class CardCommandConsumerListener {
private final Map commandHandlerMap;
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
deleted file mode 100644
index e3f4445599..0000000000
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerConfigurationShould.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
-
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.ExtendWith;
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.mockito.InjectMocks;
-import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.kafka.config.KafkaListenerContainerFactory;
-import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.util.ReflectionTestUtils;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.Is.is;
-
-@ExtendWith(MockitoExtension.class)
-@ActiveProfiles(profiles = {"native", "test"})
-class CardCommandConsumerConfigurationShould {
-
- @InjectMocks
- private CardCommandConsumerConfiguration consumerConfig;
-
- @Test
- void kafkaListenerContainerFactory() {
- String groupId = "myGroupId";
- ReflectionTestUtils.setField(consumerConfig, "groupId", groupId);
-
- KafkaListenerContainerFactory> container =
- consumerConfig.kafkaListenerContainerFactory();
-
- assertThat(groupId, is(container.createContainer("MyContainer").getGroupId()));
- }
-}
From a59b983cee2113c0c18afff137a89d753f2025fc Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 5 Oct 2020 12:48:32 +0200
Subject: [PATCH 029/155] [OC-1073-serialization] align configuration for
docker environment and removed redundant config file
Signed-off-by: Sjoerd Adema
---
config/dev/kafka-dev.yml | 4 +++-
config/dev/kafka.yml | 9 ---------
config/docker/kafka-env.properties | 3 +++
3 files changed, 6 insertions(+), 10 deletions(-)
delete mode 100644 config/dev/kafka.yml
diff --git a/config/dev/kafka-dev.yml b/config/dev/kafka-dev.yml
index 2ac87bf4fd..ae9b8dd34a 100644
--- a/config/dev/kafka-dev.yml
+++ b/config/dev/kafka-dev.yml
@@ -1,8 +1,10 @@
spring:
kafka:
consumer:
- group-id: opfab-command
+ group-id: smt01
value-deserializer: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
auto-offset-reset: earliest
+ listener:
+ poll-timeout: 2000
diff --git a/config/dev/kafka.yml b/config/dev/kafka.yml
deleted file mode 100644
index d6f5ac6f96..0000000000
--- a/config/dev/kafka.yml
+++ /dev/null
@@ -1,9 +0,0 @@
-spring:
- kafka:
- consumer:
- group-id: smt01
- value-deserializer: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
- auto-offset-reset: earliest
-# listener:
-# concurrency: 1
-# poll-timeout: 2000
diff --git a/config/docker/kafka-env.properties b/config/docker/kafka-env.properties
index a7d2f047dc..b5d9d31fd5 100644
--- a/config/docker/kafka-env.properties
+++ b/config/docker/kafka-env.properties
@@ -1 +1,4 @@
#SPRING_KAFKA_CONSUMER_GROUP_ID=opfab
+SPRING_KAFKA_CONSUMER_VALUE_DESERIALIZER=org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
+SPRING_KAFKA_CONSUMER_AUTO_OFFSET_RESET=earliest
+
From 2eb243767d21eee8f60955af130d794ad8d913a3 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Mon, 5 Oct 2020 17:18:52 +0200
Subject: [PATCH 030/155] More code coverage. Fixed mapper merge conflict
Signed-off-by: Jeroen Gommans
---
.../kafka/command/BaseCommandHandler.java | 5 +--
.../CreateCardCommandHandlerShould.java | 35 +++++++++++++++++--
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index ae0bef7773..671db9fd4e 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -26,9 +26,6 @@ public BaseCommandHandler(ObjectMapper objectMapper) {
this.objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
}
- @Autowired
- private ObjectMapper mapper;
-
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
@@ -41,7 +38,7 @@ protected CardPublicationData buildCardPublicationData(CardCommand cardCommand)
String cardDataString = kafkaCard.getData();
if (cardDataString != null) {
- cardData = mapper.readValue(cardDataString, new TypeReference>() {
+ cardData = objectMapper.readValue(cardDataString, new TypeReference>() {
});
}
card.setData(cardData);
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index 9abd199b45..d8b0c00b40 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -1,6 +1,7 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -9,13 +10,20 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.configuration.json.JacksonConfig;
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.data.mongodb.core.aggregation.VariableOperators;
import org.springframework.test.context.ActiveProfiles;
import reactor.core.publisher.Mono;
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.*;
@@ -43,6 +51,7 @@ void getCommandType() {
@Test
void executeCommand() throws JsonProcessingException {
+ reset (cardProcessingService);
CardCommand cardCommandMock = mock(CardCommand.class);
CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
Card cardMock = mock(Card.class);
@@ -54,19 +63,39 @@ void executeCommand() throws JsonProcessingException {
verify(cardProcessingService).processCards(any());
}
+
@Test
void executeCommandNoCard() throws JsonProcessingException {
+ reset (cardProcessingService);
CreateCardCommandHandler createCardCommandHandlerRealMapper = new CreateCardCommandHandler(cardProcessingService, new ObjectMapper());
CardCommand cardCommandMock = mock(CardCommand.class);
- CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
Card cardMock = mock(Card.class);
when(cardCommandMock.getCard()).thenReturn(cardMock);
+ createCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService, times(0)).processCards(any());
+ }
+
+ @Test
+ void executeCommandCardData() throws JsonProcessingException {
+ reset (cardProcessingService);
+ CardCommand cardCommandMock = mock(CardCommand.class);
+ CardPublicationData cardPublicationDataMock = new CardPublicationData (); // CardPublicationData.class);
+ Map map = new HashMap<>();
+ map.put("Key", new BigDecimal(12));
+ Card cardMock = mock(Card.class);
+
+ when(cardMock.getData()).thenReturn("");
+ when(cardCommandMock.getCard()).thenReturn(cardMock);
when(objectMapper.writeValueAsString(any())).thenReturn("");
when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
+ when(objectMapper.readValue(anyString(), (TypeReference) any())).thenReturn(map);
when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
- createCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
- verify(cardProcessingService, times(0)).processCards(any());
+ createCardCommandHandler.executeCommand(cardCommandMock);
+
+ verify(cardProcessingService).processCards(any());
+ assertThat(cardPublicationDataMock.getData(), is(map));
}
}
From e7a59dbb690882f89a441ce2a77e10f7b34e7bce Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Tue, 6 Oct 2020 10:57:39 +0200
Subject: [PATCH 031/155] [OC-1073] removed redundant files
Signed-off-by: Sjoerd Adema
---
.../ConsumerFactoryAutoConfiguration.java | 35 -----------
...ListenerContainerFactoryConfiguration.java | 61 -------------------
2 files changed, 96 deletions(-)
delete mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
delete mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
deleted file mode 100644
index 49d83a39f6..0000000000
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package org.lfenergy.operatorfabric.cards.autoconfiguration;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.kafka.core.ConsumerFactory;
-import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
-
-import java.util.Map;
-
-@Slf4j
-@RequiredArgsConstructor
-@ConditionalOnProperty("spring.kafka.consumer.group-id")
-@Import(KafkaListenerContainerFactoryConfiguration.class)
-@Configuration
-public class ConsumerFactoryAutoConfiguration {
-
- private final KafkaProperties kafkaProperties;
-
- private Map consumerConfig() {
- log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
- return kafkaProperties.buildConsumerProperties();
- }
-
- @Bean
- ConsumerFactory consumerFactory() {
- return new DefaultKafkaConsumerFactory<>(consumerConfig());
- }
-
-}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
deleted file mode 100644
index 57e3ff8380..0000000000
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/KafkaListenerContainerFactoryConfiguration.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package org.lfenergy.operatorfabric.cards.autoconfiguration;
-
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.lfenergy.operatorfabric.avro.CardCommand;
-import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
-import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerListener;
-import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
-import org.springframework.kafka.config.KafkaListenerContainerFactory;
-import org.springframework.kafka.core.ConsumerFactory;
-import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
-
-import java.time.Duration;
-import java.util.List;
-
-@Slf4j
-@RequiredArgsConstructor
-@Configuration
-public class KafkaListenerContainerFactoryConfiguration {
-
- private final KafkaProperties kafkaProperties;
-
- @Bean
- public KafkaListenerContainerFactory> kafkaListenerContainerFactory(ConsumerFactory consumerFactory) {
- KafkaProperties.Listener listener = kafkaProperties.getListener();
- Integer concurrency = getConcurrency(listener);
- Long pollTimeOut = getPollTimeout(listener);
- log.debug("Concurrency: " + concurrency);
- log.debug("PollTimeout: " + pollTimeOut);
- ConcurrentKafkaListenerContainerFactory factory = new ConcurrentKafkaListenerContainerFactory<>();
- factory.setConsumerFactory(consumerFactory);
- factory.setConcurrency(concurrency);
- factory.getContainerProperties().setPollTimeout(pollTimeOut);
- return factory;
- }
-
- private Integer getConcurrency(KafkaProperties.Listener listener) {
- Integer concurrency = listener.getConcurrency();
- if (concurrency != null) {
- return concurrency;
- }
- return 1;
- }
-
- private Long getPollTimeout(KafkaProperties.Listener listener) {
- Duration duration = listener.getPollTimeout();
- if (duration != null) {
- return duration.toMillis();
- }
- return 1000l;
- }
-
- @Bean
- CardCommandConsumerListener createConsumerListener(List commandHandlerList) {
- return new CardCommandConsumerListener(commandHandlerList);
- }
-
-}
From d3c2bb89654e269ac76fd99869d8c041f0326a0d Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Thu, 8 Oct 2020 15:57:46 +0200
Subject: [PATCH 032/155] [OC-1073-smt-481] added Spring
ErrorHandlingDeserializer
Signed-off-by: Sjoerd Adema
---
config/dev/kafka-dev.yml | 10 +++++++---
config/docker/kafka-env.properties | 2 ++
.../ConsumerFactoryAutoConfiguration.java | 13 +++++++++++++
.../consumer/CardCommandConsumerDeserializer.java | 2 +-
4 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/config/dev/kafka-dev.yml b/config/dev/kafka-dev.yml
index 2ac87bf4fd..ddc4896e3a 100644
--- a/config/dev/kafka-dev.yml
+++ b/config/dev/kafka-dev.yml
@@ -2,7 +2,11 @@ spring:
kafka:
consumer:
group-id: opfab-command
- value-deserializer: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
auto-offset-reset: earliest
-
-
+ deserializer:
+ key:
+ delegate:
+ class: org.apache.kafka.common.serialization.StringDeserializer
+ value:
+ delegate:
+ class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
diff --git a/config/docker/kafka-env.properties b/config/docker/kafka-env.properties
index a7d2f047dc..dc70368ee4 100644
--- a/config/docker/kafka-env.properties
+++ b/config/docker/kafka-env.properties
@@ -1 +1,3 @@
#SPRING_KAFKA_CONSUMER_GROUP_ID=opfab
+SPRING_DESERIALIZER_KEY_DELEGATE_CLASS=org.apache.kafka.common.serialization.StringDeserializer
+SPRING_DESERIALIZER_VALUE_DELEGATE_CLASS=org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
index b6836a85a9..39b57e17b8 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/autoconfiguration/ConsumerFactoryAutoConfiguration.java
@@ -2,7 +2,9 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.context.annotation.Bean;
@@ -10,6 +12,7 @@
import org.springframework.context.annotation.Import;
import org.springframework.kafka.core.ConsumerFactory;
import org.springframework.kafka.core.DefaultKafkaConsumerFactory;
+import org.springframework.kafka.support.serializer.ErrorHandlingDeserializer;
import java.util.Map;
@@ -22,9 +25,19 @@ public class ConsumerFactoryAutoConfiguration {
private final KafkaProperties kafkaProperties;
+ @Value("${spring.deserializer.value.delegate.class}")
+ private String deserializerValueClass;
+
+ @Value("${spring.deserializer.key.delegate.class}")
+ private String deserializerKeyClass;
+
private Map consumerConfig() {
log.info("bootstrapServers: " + kafkaProperties.getBootstrapServers());
Map props = kafkaProperties.buildConsumerProperties();
+ props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, ErrorHandlingDeserializer.class);
+ props.put(ErrorHandlingDeserializer.KEY_DESERIALIZER_CLASS, deserializerKeyClass);
+ props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, ErrorHandlingDeserializer.class);
+ props.put(ErrorHandlingDeserializer.VALUE_DESERIALIZER_CLASS, deserializerValueClass);
return props;
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
index 40dafdd5f2..bbe1255cda 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializer.java
@@ -14,7 +14,7 @@
public class CardCommandConsumerDeserializer implements Deserializer {
private final DecoderFactory decoderFactory = DecoderFactory.get();
- private final DatumReader datumReader = new SpecificDatumReader<>();
+ private final DatumReader datumReader = new SpecificDatumReader<>(CardCommand.class);
@Override
public CardCommand deserialize(String s, byte[] payload) {
From adcd3d782c4cc3e08df09431a8b5ad79435eff36 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Thu, 8 Oct 2020 16:50:54 +0200
Subject: [PATCH 033/155] [OC-1073-smt-481] fixed package name
Signed-off-by: Sjoerd Adema
---
.../autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
index 39b57e17b8..030eaf58cf 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfiguration.java
@@ -1,4 +1,4 @@
-package org.lfenergy.operatorfabric.cards.autoconfiguration;
+package org.lfenergy.operatorfabric.autoconfigure.kafka;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
From 19877c7d585c6c3624979cbf450ad0f839c10a45 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 13 Oct 2020 16:30:26 +0200
Subject: [PATCH 034/155] Split AVRO files according to the Java classes
---
client/cards/src/main/avro/I8n.avsc | 22 ++
client/cards/src/main/avro/card.avsc | 185 ++++++++++
client/cards/src/main/avro/cardCommand.avsc | 365 ++------------------
client/cards/src/main/avro/detail.avsc | 43 +++
client/cards/src/main/avro/recipient.avsc | 34 ++
client/cards/src/main/avro/timespan.avsc | 21 ++
6 files changed, 328 insertions(+), 342 deletions(-)
create mode 100644 client/cards/src/main/avro/I8n.avsc
create mode 100644 client/cards/src/main/avro/card.avsc
create mode 100644 client/cards/src/main/avro/detail.avsc
create mode 100644 client/cards/src/main/avro/recipient.avsc
create mode 100644 client/cards/src/main/avro/timespan.avsc
diff --git a/client/cards/src/main/avro/I8n.avsc b/client/cards/src/main/avro/I8n.avsc
new file mode 100644
index 0000000000..8bd09ccf99
--- /dev/null
+++ b/client/cards/src/main/avro/I8n.avsc
@@ -0,0 +1,22 @@
+{
+ "type": "record",
+ "name": "I18n",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "key",
+ "type":"string"
+ },
+ {
+ "name" : "parameters",
+ "type" : [
+ "null",
+ {
+ "type": "map",
+ "values": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
new file mode 100644
index 0000000000..0e64bdcc41
--- /dev/null
+++ b/client/cards/src/main/avro/card.avsc
@@ -0,0 +1,185 @@
+{
+ "type": "record",
+ "name": "Card",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "parentCardUid",
+ "type": ["null", "string"],
+ "default": null
+ },
+ {
+ "name": "publisher",
+ "type": "string"
+ },
+ {
+ "name": "processVersion",
+ "type": "string"
+ },
+ {
+ "name": "state",
+ "type": ["null","string"],
+ "default": null
+ },
+ {
+ "name": "publishDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "deletionDate",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "lttd",
+ "type": ["null","int"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "startDate",
+ "type": "long",
+ "logicalType": "date"
+ },
+ {
+ "name": "endDate",
+ "type": ["null","long"],
+ "logicalType": "date",
+ "default": null
+ },
+ {
+ "name": "severity",
+ "type": {
+ "name": "SeverityType",
+ "type": "enum",
+ "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
+ }
+ },
+ {
+ "name": "tags",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "timespans",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "timespan",
+ "type": "Timespan"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "details",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": {
+ "name": "detail",
+ "type": "Detail"
+ }
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "title",
+ "type": "I18n"
+ },
+ {
+ "name": "summary",
+ "type": "I18n"
+ },
+ {
+ "name": "recipient",
+ "type": ["null","Recipient"],
+ "default": null
+ },
+ {
+ "name": "userRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "groupRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "externalRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entitiesAllowedToRespond",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "entityRecipients",
+ "type": [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "hasBeenAcknowledged",
+ "type": [
+ "null",
+ "boolean"
+ ],
+ "default": null
+ },
+ {
+ "name": "data",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/cardCommand.avsc b/client/cards/src/main/avro/cardCommand.avsc
index 65a59dbdd9..9d9be39ab9 100644
--- a/client/cards/src/main/avro/cardCommand.avsc
+++ b/client/cards/src/main/avro/cardCommand.avsc
@@ -1,348 +1,29 @@
-[
- {
- "type": "record",
- "name": "Timespan",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "start",
- "type": "int",
- "logicalType": "date"
- },
- {
- "name" : "end",
- "type": [
- "null",
- "int"
- ],
- "logicalType": "date",
- "default" : null
- }
- ]
- },
- {
- "type": "record",
- "name": "I18n",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "key",
- "type": "string"
- },
- {
- "name": "parameters",
- "type": [
- "null",
- {
- "type": "map",
- "values": "string"
- }
- ],
- "default": null
- }
- ]
- },
- {
- "type": "record",
- "name": "Detail",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "title",
- "type": "I18n"
- },
- {
- "name": "titleStyle",
- "type": [
- "null",
- "string"
- ],
- "default": null
- },
- {
- "name": "titlePosition",
- "type": [
- "null",
- {
- "name": "TitlePositionType",
- "type": "enum",
- "symbols": [
- "UP",
- "DOWN",
- "NONE"
- ]
- }
- ],
- "default": null
- },
- {
- "name": "templateName",
- "type": "string"
- },
- {
- "name": "styles",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- }
- ]
- },
- {
- "type": "record",
- "name": "Recipient",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "type",
- "type": {
- "name": "RecipientType",
- "type": "enum",
- "symbols": [
- "DEADEND",
- "GROUP",
- "UNION",
- "USER"
- ]
- }
- },
- {
- "name": "recipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "Recipient"
- }
- ],
- "default": null
- },
- {
- "name": "identity",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
- },
- {
- "type": "record",
- "name": "Card",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- {
- "name": "parentCardUid",
- "type": ["null", "string"],
- "default": null
- },
- {
- "name": "publisher",
- "type": "string"
- },
- {
- "name": "processVersion",
- "type": "string"
- },
- {
- "name": "state",
- "type": ["null","string"],
- "default": null
- },
- {
- "name": "publishDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "deletionDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "lttd",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "startDate",
- "type": "long",
- "logicalType": "date"
- },
- {
- "name": "endDate",
- "type": ["null","long"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "severity",
- "type": {
- "name": "SeverityType",
- "type": "enum",
- "symbols" : ["ALARM", "ACTION", "INFORMATION", "COMPLIANT"]
- }
- },
- {
- "name": "tags",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "timespans",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "timespan",
- "type": "Timespan"
- }
- }
- ],
- "default": null
- },
- {
- "name": "details",
- "type": [
- "null",
- {
- "type": "array",
- "items": {
- "name": "detail",
- "type": "Detail"
- }
- }
- ],
- "default": null
- },
- {
- "name": "title",
- "type": "I18n"
- },
- {
- "name": "summary",
- "type": "I18n"
- },
- {
- "name": "recipient",
- "type": ["null","Recipient"],
- "default": null
- },
- {
- "name": "userRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "groupRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "externalRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entitiesAllowedToRespond",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "entityRecipients",
- "type": [
- "null",
- {
- "type": "array",
- "items": "string"
- }
- ],
- "default": null
- },
- {
- "name": "hasBeenAcknowledged",
- "type": [
- "null",
- "boolean"
- ],
- "default": null
- },
- {
- "name": "data",
- "type": [
- "null",
- "string"
- ],
- "default": null
- }
- ]
- },
- {
- "type": "record",
- "name": "CardCommand",
- "namespace": "org.lfenergy.operatorfabric.avro",
- "fields": [
- { "name": "command",
- "type":
+{
+ "type": "record",
+ "name": "CardCommand",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ { "name": "command",
+ "type":
{
"name": "CommandType",
"type": "enum",
"symbols" : ["UNKNOWN","CREATE_CARD", "UPDATE_CARD", "DELETE_CARD"],
"default": "UNKNOWN"
}
- },
- {
- "name": "process",
- "type": "string"
- },
- {
- "name": "processInstanceId",
- "type": "string"
- },
- {
- "name": "card",
- "type": ["null","Card"],
- "default": null
- }
- ]
- }
-]
+ },
+ {
+ "name": "process",
+ "type": "string"
+ },
+ {
+ "name": "processInstanceId",
+ "type": "string"
+ },
+ {
+ "name": "card",
+ "type": ["null","Card"],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/detail.avsc b/client/cards/src/main/avro/detail.avsc
new file mode 100644
index 0000000000..1592374f52
--- /dev/null
+++ b/client/cards/src/main/avro/detail.avsc
@@ -0,0 +1,43 @@
+{
+ "type": "record",
+ "name": "Detail",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "title",
+ "type":"I18n"
+ },
+ {
+ "name": "titleStyle",
+ "type": ["null", "string" ],
+ "default": null
+ },
+ {
+ "name": "titlePosition",
+ "type": [
+ "null",
+ {
+ "name": "TitlePositionType",
+ "type": "enum",
+ "symbols" : ["UP", "DOWN", "NONE"]
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "templateName",
+ "type": "string"
+ },
+ {
+ "name": "styles",
+ "type" : [
+ "null",
+ {
+ "type": "array",
+ "items": "string"
+ }
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/recipient.avsc b/client/cards/src/main/avro/recipient.avsc
new file mode 100644
index 0000000000..1945341ebe
--- /dev/null
+++ b/client/cards/src/main/avro/recipient.avsc
@@ -0,0 +1,34 @@
+{
+ "type": "record",
+ "name": "Recipient",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "type",
+ "type": {
+ "name": "RecipientType",
+ "type": "enum",
+ "symbols" : ["DEADEND", "GROUP", "UNION","USER"]
+ }
+ },
+ {
+ "name": "recipients",
+ "type" : [
+ "null",
+ {
+ "type": "array",
+ "items": "Recipient"
+ }
+ ],
+ "default": null
+ },
+ {
+ "name": "identity",
+ "type": [
+ "null",
+ "string"
+ ],
+ "default": null
+ }
+ ]
+}
diff --git a/client/cards/src/main/avro/timespan.avsc b/client/cards/src/main/avro/timespan.avsc
new file mode 100644
index 0000000000..2692bceeb7
--- /dev/null
+++ b/client/cards/src/main/avro/timespan.avsc
@@ -0,0 +1,21 @@
+{
+ "type": "record",
+ "name": "Timespan",
+ "namespace": "org.lfenergy.operatorfabric.avro",
+ "fields": [
+ {
+ "name": "start",
+ "type": "int",
+ "logicalType": "date"
+ },
+ {
+ "name" : "end",
+ "type": [
+ "null",
+ "int"
+ ],
+ "logicalType": "date",
+ "default" : null
+ }
+ ]
+}
From 13f69667134276344a1a8549a12ad2150a5ad311 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 13 Oct 2020 21:53:38 +0200
Subject: [PATCH 035/155] Added more unit tests
Signed-off-by: Jeroen Gommans
---
.../kafka/command/BaseCommandHandler.java | 1 -
.../command/DeleteCardCommandHandler.java | 1 -
.../command/UpdateCardCommandHandler.java | 1 -
...va => UpdateCardCommandHandlerShould.java} | 2 +-
.../consumer/BaseAvroDeserializerShould.java | 49 +++++++++++++++++++
...CardCommandConsumerDeserializerShould.java | 19 +++++++
6 files changed, 69 insertions(+), 4 deletions(-)
rename services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/{UpdateCardCommandHandlerTest.java => UpdateCardCommandHandlerShould.java} (98%)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializerShould.java
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializerShould.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 671db9fd4e..16bd4bb4f3 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -8,7 +8,6 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
index 2371d4c138..4d5c5e09bc 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -1,7 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
index 87615c244b..ff0e32dc77 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -1,7 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
similarity index 98%
rename from services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
rename to services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
index 2195fab665..45b3edf073 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerTest.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
@@ -22,7 +22,7 @@
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
-class UpdateCardCommandHandlerTest {
+class UpdateCardCommandHandlerShould {
CardProcessingService cardProcessingService;
ObjectMapper objectMapper;
UpdateCardCommandHandler updateCardCommandHandler;
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializerShould.java
new file mode 100644
index 0000000000..1ca0ede1b4
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/BaseAvroDeserializerShould.java
@@ -0,0 +1,49 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.apache.avro.io.DatumReader;
+import org.apache.kafka.common.errors.SerializationException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.io.IOException;
+
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class BaseAvroDeserializerShould {
+
+ @Mock
+ DatumReader datumReader;
+
+ @InjectMocks
+ private BaseAvroDeserializer baseAvroDeserializer;
+
+ @Test
+ void deserializeNoPayLoad() {
+ assertNull (baseAvroDeserializer.deserialize("something", null));
+ }
+
+ @Test
+ void deserializeWithPayload() throws IOException {
+ byte[] bytes = "something".getBytes();
+ baseAvroDeserializer.deserialize("something", bytes);
+ verify (datumReader).read(any(), any());
+ }
+
+ @Test
+ void deserializeException() throws IOException {
+ byte[] bytes = "something".getBytes();
+ when (datumReader.read(any(), any())).thenThrow(new IOException());
+ Assertions.assertThrows(SerializationException.class, () ->
+ baseAvroDeserializer.deserialize("something", bytes));
+ }
+}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializerShould.java
new file mode 100644
index 0000000000..8b95c11733
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerDeserializerShould.java
@@ -0,0 +1,19 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.consumer;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class CardCommandConsumerDeserializerShould {
+
+ @Test
+ void forCodeCoverage() {
+ CardCommandConsumerDeserializer cut = new CardCommandConsumerDeserializer();
+ assertNotNull(cut);
+ }
+}
From d516d614b524e38dc3b96fae8766a1c8212f27dd Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Tue, 13 Oct 2020 22:15:48 +0200
Subject: [PATCH 036/155] Removed unneeded imports. Abstract class has
protected constructor
Signed-off-by: Jeroen Gommans
---
.../cards/publication/kafka/command/BaseCommandHandler.java | 2 +-
.../cards/publication/kafka/command/CommandHandler.java | 1 -
.../publication/kafka/command/CreateCardCommandHandler.java | 2 --
3 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 16bd4bb4f3..50f6eff0e6 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -19,7 +19,7 @@
public abstract class BaseCommandHandler {
private final ObjectMapper objectMapper;
- public BaseCommandHandler(ObjectMapper objectMapper) {
+ protected BaseCommandHandler(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
// REQUIRE_SETTERS_FOR_GETTERS is needed to prevent the AVRO getSchema() call from being serialized
this.objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
index 083008c086..eadced66d1 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CommandHandler.java
@@ -1,6 +1,5 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.fasterxml.jackson.core.JsonProcessingException;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index 745159b9e8..19405213e2 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -1,8 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
From d37b4b0d482970cca6204f508a0a595678c1a7f4 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 14 Oct 2020 11:41:56 +0200
Subject: [PATCH 037/155] Added more unit tests
Signed-off-by: Jeroen Gommans
---
...onsumerFactoryAutoConfigurationShould.java | 27 +++++++
...erContainerFactoryConfigurationShould.java | 77 +++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfigurationShould.java
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfigurationShould.java
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfigurationShould.java
new file mode 100644
index 0000000000..d6cd314150
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/ConsumerFactoryAutoConfigurationShould.java
@@ -0,0 +1,27 @@
+package org.lfenergy.operatorfabric.autoconfigure.kafka;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.test.context.ActiveProfiles;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class ConsumerFactoryAutoConfigurationShould {
+
+ @Test
+ void consumerFactory() {
+ KafkaProperties kafkaPropertiesMock = mock(KafkaProperties.class);
+
+ ConsumerFactory consumerFactory = new ConsumerFactoryAutoConfiguration(kafkaPropertiesMock).consumerFactory();
+ assertNotNull(consumerFactory);
+ verify(kafkaPropertiesMock).buildConsumerProperties();
+ }
+}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfigurationShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfigurationShould.java
new file mode 100644
index 0000000000..af8d924cbb
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/autoconfigure/kafka/KafkaListenerContainerFactoryConfigurationShould.java
@@ -0,0 +1,77 @@
+package org.lfenergy.operatorfabric.autoconfigure.kafka;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.kafka.command.CommandHandler;
+import org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerListener;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
+import org.springframework.kafka.config.KafkaListenerContainerFactory;
+import org.springframework.kafka.core.ConsumerFactory;
+import org.springframework.kafka.listener.ConcurrentMessageListenerContainer;
+import org.springframework.test.context.ActiveProfiles;
+
+import java.time.Duration;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+class KafkaListenerContainerFactoryConfigurationShould {
+
+ @Mock
+ KafkaProperties kafkaProperties;
+
+ @SuppressWarnings("unused")
+ @Mock
+ ConsumerFactory consumerFactory;
+
+ @InjectMocks
+ KafkaListenerContainerFactoryConfiguration cut;
+
+ @Test
+ void kafkaListenerContainerFactory() {
+ Integer concurrency = 123;
+ Duration pollTimeout= Duration.ofMillis(123123);
+ KafkaProperties.Listener listenerMock = mock (KafkaProperties.Listener.class);
+ when(listenerMock.getPollTimeout()).thenReturn(pollTimeout);
+ when (listenerMock.getConcurrency()).thenReturn(concurrency);
+
+ when (kafkaProperties.getListener()).thenReturn(listenerMock);
+ KafkaListenerContainerFactory> kafkaListenerContainerFactory = cut.kafkaListenerContainerFactory();
+
+ assertNotNull(kafkaListenerContainerFactory);
+
+ ConcurrentMessageListenerContainer container = kafkaListenerContainerFactory.createContainer("dummyTopic");
+ assertThat (container.getConcurrency()).isEqualTo(concurrency);
+ assertThat (container.getContainerProperties().getPollTimeout()).isEqualTo(pollTimeout.toMillis());
+ }
+
+ @Test
+ void kafkaListenerContainerFactoryWithDefaults() {
+ KafkaProperties.Listener listenerMock = mock (KafkaProperties.Listener.class);
+ when (listenerMock.getConcurrency()).thenReturn(null);
+ when (kafkaProperties.getListener()).thenReturn(listenerMock);
+ KafkaListenerContainerFactory> kafkaListenerContainerFactory = cut.kafkaListenerContainerFactory();
+
+ assertNotNull(kafkaListenerContainerFactory);
+
+ ConcurrentMessageListenerContainer container = kafkaListenerContainerFactory.createContainer("dummyTopic");
+ assertThat (container.getConcurrency()).isGreaterThan(0);
+ assertThat(container.getContainerProperties().getPollTimeout()).isGreaterThan(0);
+ }
+
+ @Test
+ void createCardCommandConsumerListener() {
+ List handlersMock = mock (List.class);
+ CardCommandConsumerListener cardCommandConsumerListener = cut.createCardCommandConsumerListener(handlersMock);
+ assertNotNull(cardCommandConsumerListener);
+ }
+}
From 4a5ed931151e38f5295c1b41314ec51f67d044ac Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Thu, 15 Oct 2020 14:54:21 +0200
Subject: [PATCH 038/155] Moved kafka-dev.yml to cards-publication-dev.yml
Signed-off-by: Jeroen Gommans
---
config/dev/cards-publication-dev.yml | 20 ++++++++++++--------
config/dev/kafka-dev.yml | 12 ------------
2 files changed, 12 insertions(+), 20 deletions(-)
delete mode 100644 config/dev/kafka-dev.yml
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index 99f4cb00c8..af6b42d956 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -4,14 +4,18 @@ spring:
application:
name: cards-publication
-logging:
- level:
- org:
- lfenergy:
- operatorfabric:
- cards:
- publication: DEBUG
-
+#Uncomment the Kafka section to enable Kafka
+# kafka:
+# consumer:
+# group-id: opfab-command
+# auto-offset-reset: earliest
+# deserializer:
+# key:
+# delegate:
+# class: org.apache.kafka.common.serialization.StringDeserializer
+# value:
+# delegate:
+# class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
#here we put urls for all feign clients
users:
diff --git a/config/dev/kafka-dev.yml b/config/dev/kafka-dev.yml
deleted file mode 100644
index ddc4896e3a..0000000000
--- a/config/dev/kafka-dev.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-spring:
- kafka:
- consumer:
- group-id: opfab-command
- auto-offset-reset: earliest
- deserializer:
- key:
- delegate:
- class: org.apache.kafka.common.serialization.StringDeserializer
- value:
- delegate:
- class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
From b40ddb85077fd72b7f6f88081065ecc76e647905 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Fri, 16 Oct 2020 23:59:20 +0200
Subject: [PATCH 039/155] [OC-1073-esm-184] added docker-compose.sh
Signed-off-by: Sjoerd Adema
---
config/dev/docker-compose.sh | 8 +++++++
config/dev/docker-compose.yml | 2 +-
.../dev/{ngnix.conf => ngnix.conf.template} | 22 +++++++++----------
3 files changed, 20 insertions(+), 12 deletions(-)
create mode 100755 config/dev/docker-compose.sh
rename config/dev/{ngnix.conf => ngnix.conf.template} (94%)
diff --git a/config/dev/docker-compose.sh b/config/dev/docker-compose.sh
new file mode 100755
index 0000000000..80e0fe4b99
--- /dev/null
+++ b/config/dev/docker-compose.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+[[ -f .env-dev ]] && source .env-dev
+if [ -z "${MY_DOCKER_HOST}" ]; then
+ MY_DOCKER_HOST=172.17.0.1
+fi
+sed "s/\${MY_DOCKER_HOST}/$MY_DOCKER_HOST/g" ./ngnix.conf.template > ./.ngnix.conf
+docker-compose up -d
diff --git a/config/dev/docker-compose.yml b/config/dev/docker-compose.yml
index c9d8c86e28..49a58eabcc 100755
--- a/config/dev/docker-compose.yml
+++ b/config/dev/docker-compose.yml
@@ -34,5 +34,5 @@ services:
- "./favicon.ico:/usr/share/nginx/html/favicon.ico"
- "./web-ui.json:/usr/share/nginx/html/opfab/web-ui.json"
- "../../ui/main/src/assets/i18n:/usr/share/nginx/html/assets/i18n/"
- - "./ngnix.conf:/etc/nginx/conf.d/default.conf"
+ - "./.ngnix.conf:/etc/nginx/conf.d/default.conf"
- "./loggingResults:/etc/nginx/html/logging"
diff --git a/config/dev/ngnix.conf b/config/dev/ngnix.conf.template
similarity index 94%
rename from config/dev/ngnix.conf
rename to config/dev/ngnix.conf.template
index 3930194285..5dc741b642 100644
--- a/config/dev/ngnix.conf
+++ b/config/dev/ngnix.conf.template
@@ -76,7 +76,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2100;
+ proxy_pass http://${MY_DOCKER_HOST}:2100;
}
location /users {
@@ -93,7 +93,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/users;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/users;
}
location ~ "^/users/(.*)" {
@@ -110,7 +110,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/$1;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/$1;
}
location /groups {
@@ -127,7 +127,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/groups;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/groups;
}
location ~ "^/groups/(.*)" {
@@ -144,7 +144,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/$1;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/$1;
}
location /entities {
@@ -161,7 +161,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/entities;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/entities;
}
location ~ "^/entities/(.*)" {
@@ -178,7 +178,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2103/$1;
+ proxy_pass http://${MY_DOCKER_HOST}:2103/$1;
}
@@ -196,7 +196,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2104/;
+ proxy_pass http://${MY_DOCKER_HOST}:2104/;
}
location /cardspub/cards/userCard {
# enables `ng serve` mode
@@ -212,7 +212,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2102/cards/userCard;
+ proxy_pass http://${MY_DOCKER_HOST}:2102/cards/userCard;
}
location /cardspub/cards/userAcknowledgement {
# enables `ng serve` mode
@@ -228,7 +228,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2102/cards/userAcknowledgement;
+ proxy_pass http://${MY_DOCKER_HOST}:2102/cards/userAcknowledgement;
}
location /archives {
# enables `ng serve` mode
@@ -244,7 +244,7 @@ server {
return 204;
}
proxy_set_header Host $http_host;
- proxy_pass http://172.17.0.1:2104;
+ proxy_pass http://${MY_DOCKER_HOST}:2104;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
From d283e835e58aa83cff428435cb90b1e07cffad47 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Mon, 19 Oct 2020 08:37:46 +0200
Subject: [PATCH 040/155] [OC-1194] Add the possibility to send usercard with
response card
Signed-off-by: freddidierRTE
---
.../bundle_userCardExamples/config.json | 21 ++++++-
.../bundle_userCardExamples/i18n/en.json | 5 ++
.../bundle_userCardExamples/i18n/fr.json | 5 ++
.../template/en/question.handlebars | 59 +++++++++++++++++++
.../template/en/usercard_question.handlebars | 23 ++++++++
.../template/fr/question.handlebars | 59 +++++++++++++++++++
.../template/fr/usercard_question.handlebars | 23 ++++++++
.../setPerimeterForUserCardExamples.feature | 4 ++
.../modules/usercard/usercard.component.ts | 24 +++++---
9 files changed, 214 insertions(+), 9 deletions(-)
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/question.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_question.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/question.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_question.handlebars
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
index 33d61b5180..5cff73cea4 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
@@ -39,6 +39,25 @@
}
],
"acknowledgementAllowed": true
- }
+ },
+ "questionState": {
+ "name": "question.title",
+ "color": "#8bcdcd",
+ "userCardTemplate": "usercard_question",
+ "response": {
+ "state": "questionState"
+ },
+ "details": [
+ {
+ "title": {
+ "key": "question.title"
+ },
+ "templateName": "question",
+ "styles": [
+ ]
+ }
+ ],
+ "acknowledgementAllowed": false
+ }
}
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
index dba398fcd4..d15bdd2219 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
@@ -8,5 +8,10 @@
"conference":{
"title":"Conference Call ☏",
"summary":"You are invited to a conference"
+ },
+ "question":{
+ "title":"Question ",
+ "summary":"There is a question for you"
}
+
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
index 84fe88c621..7876c2afc6 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
@@ -7,5 +7,10 @@
"conference":{
"title":"Conférence téléphonique ☏",
"summary":"You êtes invités à une conférence téléphonique"
+ },
+ "question":{
+ "title":"Question",
+ "summary":"Il y a une question pour vous"
}
+
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/question.handlebars
new file mode 100644
index 0000000000..e232b9e513
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/question.handlebars
@@ -0,0 +1,59 @@
+
+ {{card.data.question}}
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_question.handlebars
new file mode 100644
index 0000000000..33e76f0bd4
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_question.handlebars
@@ -0,0 +1,23 @@
+
+
+Question :
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/question.handlebars
new file mode 100644
index 0000000000..895e5daabc
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/question.handlebars
@@ -0,0 +1,59 @@
+
+ {{card.data.question}}
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_question.handlebars
new file mode 100644
index 0000000000..33e76f0bd4
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_question.handlebars
@@ -0,0 +1,23 @@
+
+
+Question :
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
index 0f755ccd59..c0cc9c76f2 100644
--- a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
+++ b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
@@ -20,6 +20,10 @@ Feature: Add perimeters/group for action test
{
"state" : "conferenceState",
"right" : "ReceiveAndWrite"
+ },
+ {
+ "state" : "questionState",
+ "right" : "ReceiveAndWrite"
}
]
}
diff --git a/ui/main/src/app/modules/usercard/usercard.component.ts b/ui/main/src/app/modules/usercard/usercard.component.ts
index 7632e49f49..9642a8c616 100644
--- a/ui/main/src/app/modules/usercard/usercard.component.ts
+++ b/ui/main/src/app/modules/usercard/usercard.component.ts
@@ -28,6 +28,7 @@ import { UserWithPerimeters, RightsEnum, ComputedPerimeter } from '@ofModel/user
import { EntitiesService } from '@ofServices/entities.service';
import { transformToTimestamp } from '../archives/components/archive-filters/archive-filters.component';
import { ProcessesService } from '@ofServices/processes.service';
+import { Entity } from '@ofModel/user.model';
declare const templateGateway: any;
@@ -250,7 +251,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
onSubmitForm(template: TemplateRef) {
const formValue = this.messageForm.value;
- const recipients = this.recipientForm.value['entities'];
+
const processFormVal = formValue['process'];
const selectedProcess = this.processesDefinition.find(process => {
return process.id === processFormVal;
@@ -279,13 +280,20 @@ export class UserCardComponent implements OnDestroy, OnInit {
return;
}
- const entities = new Array();
- if (recipients.length < 1) {
+ const selectedRecipients = this.recipientForm.value['entities'];
+ const recipients = new Array();
+ if (selectedRecipients.length < 1) {
this.errorMessage.display = true;
this.errorMessage.text = 'userCard.error.noRecipientSelected';
return;
- } else {
- recipients.forEach(entity => entities.push(entity.id));
+ } else selectedRecipients.forEach(entity => recipients.push(entity.id));
+
+
+ const entitiesAllowedToRespond = [];
+ if (selectedProcess.states[state].response) {
+ recipients.forEach(entity => {
+ if (!this.currentUserWithPerimeters.userData.entities.includes(entity)) entitiesAllowedToRespond.push(entity);
+ });
}
let startDate = this.messageForm.get('startDate').value;
@@ -310,7 +318,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
publishDate: null,
publisher: this.currentUserWithPerimeters.userData.entities[0],
processVersion: processVersion,
- process: processFormVal,
+ process: selectedProcess.id,
processInstanceId: generatedId,
state: state,
startDate: startDate,
@@ -318,8 +326,8 @@ export class UserCardComponent implements OnDestroy, OnInit {
severity: formValue['severity'],
hasBeenAcknowledged: false,
hasBeenRead: false,
- entityRecipients: entities,
- entitiesAllowedToRespond: [],
+ entityRecipients: recipients,
+ entitiesAllowedToRespond: entitiesAllowedToRespond,
externalRecipients: null,
title: title,
summary: summary,
From d4e19a2aca5597ecd287749b12cf6715fe38ddd3 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Mon, 19 Oct 2020 10:50:46 +0200
Subject: [PATCH 041/155] [OC-1194] Minor improvement Change variable name from
entities to recipients
Signed-off-by: freddidierRTE
---
.../app/modules/usercard/usercard.component.html | 4 ++--
.../src/app/modules/usercard/usercard.component.ts | 13 ++++++-------
ui/main/src/assets/i18n/en.json | 2 +-
ui/main/src/assets/i18n/fr.json | 2 +-
4 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/ui/main/src/app/modules/usercard/usercard.component.html b/ui/main/src/app/modules/usercard/usercard.component.html
index 774d0bb0fa..fb4f5483c1 100644
--- a/ui/main/src/app/modules/usercard/usercard.component.html
+++ b/ui/main/src/app/modules/usercard/usercard.component.html
@@ -50,8 +50,8 @@ userCard.title
-
+
diff --git a/ui/main/src/app/modules/usercard/usercard.component.ts b/ui/main/src/app/modules/usercard/usercard.component.ts
index 9642a8c616..3bf34199e7 100644
--- a/ui/main/src/app/modules/usercard/usercard.component.ts
+++ b/ui/main/src/app/modules/usercard/usercard.component.ts
@@ -61,7 +61,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
});
stateOptions: any[];
- entityOptions = new Array();
+ recipientsOptions = new Array();
dropdownSettings = {};
processOptions = new Array();
@@ -117,7 +117,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
});
this.recipientForm = new FormGroup({
- entities: new FormControl([])
+ recipients: new FormControl([])
});
@@ -137,7 +137,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
loadAllEntities(): void {
this.entitiesService.getEntities().forEach(entity =>
- this.entityOptions.push({ id: entity.id, itemName: entity.name }));
+ this.recipientsOptions.push({ id: entity.id, itemName: entity.name }));
}
@@ -251,10 +251,9 @@ export class UserCardComponent implements OnDestroy, OnInit {
onSubmitForm(template: TemplateRef
) {
const formValue = this.messageForm.value;
-
- const processFormVal = formValue['process'];
+
const selectedProcess = this.processesDefinition.find(process => {
- return process.id === processFormVal;
+ return process.id === formValue['process'];
});
const processVersion = selectedProcess.version;
const state = formValue['state'];
@@ -280,7 +279,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
return;
}
- const selectedRecipients = this.recipientForm.value['entities'];
+ const selectedRecipients = this.recipientForm.value['recipients'];
const recipients = new Array();
if (selectedRecipients.length < 1) {
this.errorMessage.display = true;
diff --git a/ui/main/src/assets/i18n/en.json b/ui/main/src/assets/i18n/en.json
index 08fa1f0054..2db2872808 100755
--- a/ui/main/src/assets/i18n/en.json
+++ b/ui/main/src/assets/i18n/en.json
@@ -161,7 +161,7 @@
"startDate": "Start Date",
"endDate": "End Date",
"comment": "Comment",
- "entities": "Recipients"
+ "recipients": "Recipients"
},
"options": {
"severity": {
diff --git a/ui/main/src/assets/i18n/fr.json b/ui/main/src/assets/i18n/fr.json
index ad7fcf5314..01da2524e1 100755
--- a/ui/main/src/assets/i18n/fr.json
+++ b/ui/main/src/assets/i18n/fr.json
@@ -161,7 +161,7 @@
"startDate": "Date de début ",
"endDate": "Date de fin ",
"comment": "Commentaire",
- "entities": "Destinataire"
+ "recipients": "Destinataire"
},
"options": {
"severity": {
From 73b82ed95fd7cd3dad0ae5e77def6619d4731c94 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Mon, 19 Oct 2020 11:36:24 +0200
Subject: [PATCH 042/155] [OC-1073-esm-207] refactoring BaseCommandHandler
Signed-off-by: Sjoerd Adema
---
.../publication/kafka/CardObjectMapper.java | 34 +++++++++++++++++++
.../kafka/command/BaseCommandHandler.java | 16 ++++-----
.../command/CreateCardCommandHandler.java | 10 ++----
.../command/DeleteCardCommandHandler.java | 9 ++---
.../command/UpdateCardCommandHandler.java | 9 ++---
5 files changed, 46 insertions(+), 32 deletions(-)
create mode 100644 services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
new file mode 100644
index 0000000000..45f8d2ed24
--- /dev/null
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
@@ -0,0 +1,34 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.MapperFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.springframework.stereotype.Component;
+
+import java.util.Map;
+
+@Component
+public class CardObjectMapper {
+
+ private final ObjectMapper objectMapper;
+
+ public CardObjectMapper() {
+ this.objectMapper = new ObjectMapper();
+ objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
+ }
+
+ public String writeValueAsString(Card kafkaCard) throws JsonProcessingException {
+ return objectMapper.writeValueAsString(kafkaCard);
+ }
+
+ public CardPublicationData readValue(String writeValueAsString, Class clazz) throws JsonProcessingException {
+ return objectMapper.readValue(writeValueAsString, clazz);
+ }
+
+ public Map readValue(String writeValueAsString, TypeReference> typeReference) throws JsonProcessingException {
+ return objectMapper.readValue(writeValueAsString, typeReference);
+ }
+}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 671db9fd4e..7adf61b295 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -2,29 +2,25 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.MapperFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.kafka.CardObjectMapper;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.Map;
-@Component
@Slf4j
+@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class BaseCommandHandler {
- private final ObjectMapper objectMapper;
- public BaseCommandHandler(ObjectMapper objectMapper) {
- this.objectMapper = objectMapper;
- // REQUIRE_SETTERS_FOR_GETTERS is needed to prevent the AVRO getSchema() call from being serialized
- this.objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
- }
+ @Autowired
+ private CardObjectMapper objectMapper;
protected CardPublicationData buildCardPublicationData(CardCommand cardCommand) {
Card kafkaCard = cardCommand.getCard();
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
index 745159b9e8..22d9dbc520 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandler.java
@@ -1,7 +1,5 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
@@ -11,17 +9,13 @@
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
-@Component
@Slf4j
+@RequiredArgsConstructor
+@Component
public class CreateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
private final CardProcessingService cardProcessingService;
- public CreateCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
- super(objectMapper);
- this.cardProcessingService = cardProcessingService;
- }
-
@Override
public CommandType getCommandType() {
return CommandType.CREATE_CARD;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
index 2371d4c138..6c06c506dc 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandler.java
@@ -1,6 +1,5 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
@@ -9,17 +8,13 @@
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.springframework.stereotype.Component;
-@Component
@Slf4j
+@RequiredArgsConstructor
+@Component
public class DeleteCardCommandHandler extends BaseCommandHandler implements CommandHandler {
private final CardProcessingService cardProcessingService;
- public DeleteCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
- super(objectMapper);
- this.cardProcessingService = cardProcessingService;
- }
-
@Override
public CommandType getCommandType() {
return CommandType.DELETE_CARD;
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
index 87615c244b..8404ee885c 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandler.java
@@ -1,6 +1,5 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
-import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lfenergy.operatorfabric.avro.CardCommand;
@@ -10,17 +9,13 @@
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
-@Component
@Slf4j
+@RequiredArgsConstructor
+@Component
public class UpdateCardCommandHandler extends BaseCommandHandler implements CommandHandler {
private final CardProcessingService cardProcessingService;
- public UpdateCardCommandHandler(CardProcessingService cardProcessingService, ObjectMapper objectMapper) {
- super(objectMapper);
- this.cardProcessingService = cardProcessingService;
- }
-
@Override
public CommandType getCommandType() {
return CommandType.UPDATE_CARD;
From fcb02501f9c73532a39c6110eb83618af5594ab4 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Mon, 19 Oct 2020 17:09:29 +0200
Subject: [PATCH 043/155] [OC-1113] Remove multiple tabs in card's details
Signed-off-by: freddidierRTE
---
ui/main/src/app/model/card.model.ts | 11 --
ui/main/src/app/model/processes.model.ts | 12 +-
ui/main/src/app/modules/cards/cards.module.ts | 3 -
.../card-details/card-details.component.ts | 21 ++-
.../closeable-card-details.component.ts | 8 +-
.../components/detail/detail.component.html | 148 ++++++++++--------
.../components/detail/detail.component.scss | 17 ++
.../components/detail/detail.component.ts | 53 +++----
.../components/details/details.component.html | 20 ---
.../components/details/details.component.scss | 29 ----
.../details/details.component.spec.ts | 38 -----
.../components/details/details.component.ts | 67 --------
.../card-preview/card-preview.component.ts | 3 +-
.../store/selectors/card.selectors.spec.ts | 43 -----
.../src/app/store/selectors/card.selectors.ts | 3 -
ui/main/src/tests/helpers.ts | 45 ++----
16 files changed, 162 insertions(+), 359 deletions(-)
delete mode 100644 ui/main/src/app/modules/cards/components/details/details.component.html
delete mode 100644 ui/main/src/app/modules/cards/components/details/details.component.scss
delete mode 100644 ui/main/src/app/modules/cards/components/details/details.component.spec.ts
delete mode 100644 ui/main/src/app/modules/cards/components/details/details.component.ts
delete mode 100644 ui/main/src/app/store/selectors/card.selectors.spec.ts
diff --git a/ui/main/src/app/model/card.model.ts b/ui/main/src/app/model/card.model.ts
index 187768a95b..cfde08cbd8 100644
--- a/ui/main/src/app/model/card.model.ts
+++ b/ui/main/src/app/model/card.model.ts
@@ -32,7 +32,6 @@ export class Card {
readonly title?: I18n,
readonly summary?: I18n,
readonly data?: any,
- readonly details?: Detail[],
readonly userRecipients?: string[],
readonly groupRecipients?: string[],
readonly entityRecipients?: string[],
@@ -51,16 +50,6 @@ export enum TitlePosition {
}
-export class Detail {
- /* istanbul ignore next */
- constructor(
- readonly titlePosition: TitlePosition,
- readonly title: I18n,
- readonly titleStyle: string,
- readonly templateName: string,
- readonly styles: string[]) {
- }
-}
export class Recipient {
constructor(
diff --git a/ui/main/src/app/model/processes.model.ts b/ui/main/src/app/model/processes.model.ts
index 40e3ba98b8..0f3067b273 100644
--- a/ui/main/src/app/model/processes.model.ts
+++ b/ui/main/src/app/model/processes.model.ts
@@ -8,7 +8,7 @@
*/
-import {Card, Detail} from '@ofModel/card.model';
+import {Card} from '@ofModel/card.model';
import {I18n} from '@ofModel/i18n.model';
import {Map as OfMap} from '@ofModel/map';
@@ -91,6 +91,16 @@ export class State {
}
}
+export class Detail {
+ /* istanbul ignore next */
+ constructor(
+ readonly title: I18n,
+ readonly templateName: string,
+ readonly styles: string[]) {
+ }
+}
+
+
export class Response {
/* istanbul ignore next */
constructor(
diff --git a/ui/main/src/app/modules/cards/cards.module.ts b/ui/main/src/app/modules/cards/cards.module.ts
index 2585da9093..f52b846349 100644
--- a/ui/main/src/app/modules/cards/cards.module.ts
+++ b/ui/main/src/app/modules/cards/cards.module.ts
@@ -12,7 +12,6 @@ import {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NgModule, NO_ERRORS_SCHEMA}
import {CommonModule} from '@angular/common';
import {CardComponent} from './components/card/card.component';
import {CardDetailsComponent} from './components/card-details/card-details.component';
-import {DetailsComponent} from './components/details/details.component';
import {DetailComponent} from './components/detail/detail.component';
import {TranslateModule} from '@ngx-translate/core';
import {ProcessesService} from '@ofServices/processes.service';
@@ -26,7 +25,6 @@ import {CloseableCardDetailsComponent} from './components/card-details/closeable
declarations: [CardComponent
, CardDetailsComponent
, CloseableCardDetailsComponent
- , DetailsComponent
, DetailComponent],
imports: [
CommonModule,
@@ -38,7 +36,6 @@ import {CloseableCardDetailsComponent} from './components/card-details/closeable
exports: [CardComponent
, CardDetailsComponent
, CloseableCardDetailsComponent
- , DetailsComponent
, DetailComponent
],
schemas: [
diff --git a/ui/main/src/app/modules/cards/components/card-details/card-details.component.ts b/ui/main/src/app/modules/cards/components/card-details/card-details.component.ts
index c06e9e3fb5..2d8d8da0dc 100644
--- a/ui/main/src/app/modules/cards/components/card-details/card-details.component.ts
+++ b/ui/main/src/app/modules/cards/components/card-details/card-details.component.ts
@@ -8,7 +8,7 @@
*/
import {Component, OnDestroy, OnInit} from '@angular/core';
-import {Card, Detail} from '@ofModel/card.model';
+import {Card} from '@ofModel/card.model';
import {Store} from '@ngrx/store';
import {AppState} from '@ofStore/index';
import * as cardSelectors from '@ofStore/selectors/card.selectors';
@@ -19,24 +19,25 @@ import {UserService} from '@ofServices/user.service';
import {User} from '@ofModel/user.model';
import {selectCurrentUrl} from '@ofStore/selectors/router.selectors';
import {AppService} from '@ofServices/app.service';
+import {State as CardState, Detail} from '@ofModel/processes.model';
@Component({
selector: 'of-card-details',
template: `
-
-
-
+
- `
+ `
})
export class CardDetailsComponent implements OnInit, OnDestroy {
card: Card;
childCards: Card[];
user: User;
- details: Detail[];
+ cardState: CardState;
unsubscribe$: Subject = new Subject();
protected _currentPath: string;
@@ -54,15 +55,11 @@ export class CardDetailsComponent implements OnInit, OnDestroy {
this.card = card;
this.childCards = childCards;
if (!!card) {
- this.details = [];
- if (!!card.details) this.details = [...card.details];
this.businessconfigService.queryProcess(this.card.process, this.card.processVersion)
.pipe(takeUntil(this.unsubscribe$))
.subscribe(businessconfig => {
- if (!!businessconfig) {
- const state = businessconfig.extractState(this.card);
- if (!!state) this.details.push(...state.details);
- }
+ if (!!businessconfig) this.cardState = businessconfig.extractState(this.card);
+
},
error => console.log(`something went wrong while trying to fetch process for`
+ ` ${this.card.process} with ${this.card.processVersion} version.`)
diff --git a/ui/main/src/app/modules/cards/components/card-details/closeable-card-details.component.ts b/ui/main/src/app/modules/cards/components/card-details/closeable-card-details.component.ts
index 05e9d2b5d9..64aa7bd2f3 100644
--- a/ui/main/src/app/modules/cards/components/card-details/closeable-card-details.component.ts
+++ b/ui/main/src/app/modules/cards/components/card-details/closeable-card-details.component.ts
@@ -9,15 +9,13 @@ import {AppService} from '@ofServices/app.service';
@Component({
selector: 'of-closeable-card-details',
template: `
-
- `,
styleUrls: ['./closeable-card-details.component.scss']
})
export class CloseableCardDetailsComponent extends CardDetailsComponent {
diff --git a/ui/main/src/app/modules/cards/components/detail/detail.component.html b/ui/main/src/app/modules/cards/components/detail/detail.component.html
index a62db5689d..df9ab60510 100644
--- a/ui/main/src/app/modules/cards/components/detail/detail.component.html
+++ b/ui/main/src/app/modules/cards/components/detail/detail.component.html
@@ -8,79 +8,95 @@
-
-
-
-
-
-
- response.answers :
-
- {{entity.name}}
-
-
-
-
-
-
-
-
-
-
- ×
-
-
+
+
+
+ {{i18nPrefix+cardState.details[0].title.key}}
+
+
-
-
{{btnText}}
+
+
-
{{btnAckText}}
+
+
+
+
- {{'button.delete'}}
-
+
response.answers :
+
+ {{entity.name}}
+
-
-
-
- button.cancel
- button.delete
-
-
+
-
-
-
-
button.ok
+
+
+
+
+
+ ×
+
+
+
+
+ {{btnText}}
+
+ {{btnAckText}}
+
+ {{'button.delete'}}
+
+
+
+
+
+ button.cancel
+ button.delete
+
+
+
+
+
+
+ button.ok
+
+
+
+
+
+
+ button.ok
+
+
-
+
-
-
-
- button.ok
-
-
+
+
+
diff --git a/ui/main/src/app/modules/cards/components/detail/detail.component.scss b/ui/main/src/app/modules/cards/components/detail/detail.component.scss
index 2219ef504b..e24a4ef9a5 100644
--- a/ui/main/src/app/modules/cards/components/detail/detail.component.scss
+++ b/ui/main/src/app/modules/cards/components/detail/detail.component.scss
@@ -31,3 +31,20 @@
.btn{
color: var(--opfab-lightcard-detail-textcolor);
}
+
+.calc-height-details {
+ overflow-x: hidden;
+ overflow-y: auto;
+}
+
+.opfab-line-undertab{
+ border-color:var(--opfab-card-tab-border-color);
+}
+
+.opfab-tab{
+ border-color:var(--opfab-card-tab-border-color);
+ border-radius: 4px;
+ color: var(--opfab-card-tab-selected-text-color);
+ background-color: var(--opfab-card-tab-selected-bgcolor);
+}
+
diff --git a/ui/main/src/app/modules/cards/components/detail/detail.component.ts b/ui/main/src/app/modules/cards/components/detail/detail.component.ts
index 3629683d5d..9285dcfcfd 100644
--- a/ui/main/src/app/modules/cards/components/detail/detail.component.ts
+++ b/ui/main/src/app/modules/cards/components/detail/detail.component.ts
@@ -20,7 +20,7 @@ import {
TemplateRef,
ViewChild
} from '@angular/core';
-import {Card, Detail} from '@ofModel/card.model';
+import {Card} from '@ofModel/card.model';
import {ProcessesService} from '@ofServices/processes.service';
import {HandlebarsService} from '../../services/handlebars.service';
import {DomSanitizer, SafeHtml, SafeResourceUrl} from '@angular/platform-browser';
@@ -47,6 +47,7 @@ import {Entity} from '@ofModel/entity.model';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {NgbModalRef} from '@ng-bootstrap/ng-bootstrap/modal/modal-ref';
import {ConfigService} from '@ofServices/config.service';
+import {State as CardState, Detail} from '@ofModel/processes.model';
declare const templateGateway: any;
@@ -103,7 +104,7 @@ const enum EntityMsgColor {
})
export class DetailComponent implements OnChanges, OnInit, OnDestroy, AfterViewChecked, DoCheck {
- @Input() detail: Detail;
+ @Input() cardState: CardState;
@Input() card: Card;
@Input() childCards: Card[];
@Input() user: User;
@@ -112,7 +113,6 @@ export class DetailComponent implements OnChanges, OnInit, OnDestroy, AfterViewC
@ViewChild('cardDeletedWithNoErrorPopup', null) cardDeletedWithNoErrorPopupRef: TemplateRef
;
@ViewChild('impossibleToDeleteCardPopup', null) impossibleToDeleteCardPopupRef: TemplateRef;
- public active = false;
public isActionEnabled = false;
public lttdExpiredIsTrue: boolean;
public isDeleteCardAllowed = false;
@@ -501,10 +501,11 @@ export class DetailComponent implements OnChanges, OnInit, OnDestroy, AfterViewC
}
private initializeHrefsOfCssLink() {
- if (this.detail && this.detail.styles) {
+ const styles = this.cardState.details[0].styles;
+ if (!!styles) {
const process = this.card.process;
const processVersion = this.card.processVersion;
- this.detail.styles.forEach(style => {
+ styles.forEach(style => {
const cssUrl = this.businessconfigService.computeBusinessconfigCssUrl(process, style, processVersion);
// needed to instantiate href of link for css in component rendering
const safeCssUrl = this.sanitizer.bypassSecurityTrustResourceUrl(cssUrl);
@@ -513,31 +514,29 @@ export class DetailComponent implements OnChanges, OnInit, OnDestroy, AfterViewC
}
}
+
+
private initializeHandlebarsTemplates() {
templateGateway.childCards = this.childCards;
- this.businessconfigService.queryProcessFromCard(this.card).pipe(
- takeUntil(this.unsubscribe$),
- switchMap(process => {
-
- const state = process.extractState(this.card);
- this._responseData = state.response;
- this._acknowledgementAllowed = state.acknowledgementAllowed;
- return this.handlebars.executeTemplate(this.detail.templateName,
- new DetailContext(this.card, this._userContext, this._responseData));
- })
- )
- .subscribe(
- html => {
- this._htmlContent = this.sanitizer.bypassSecurityTrustHtml(html);
- setTimeout(() => { // wait for DOM rendering
- this.reinsertScripts();
- }, 10);
- }, () => {
- console.log('WARNING impossible to load template ', this.detail.templateName);
- this._htmlContent = this.sanitizer.bypassSecurityTrustHtml('');
- }
- );
+ this._responseData = this.cardState.response;
+ this._acknowledgementAllowed = this.cardState.acknowledgementAllowed;
+ const templateName = this.cardState.details[0].templateName;
+ if (!!templateName) {
+ this.handlebars.executeTemplate(templateName,
+ new DetailContext(this.card, this._userContext, this._responseData))
+ .subscribe(
+ html => {
+ this._htmlContent = this.sanitizer.bypassSecurityTrustHtml(html);
+ setTimeout(() => { // wait for DOM rendering
+ this.reinsertScripts();
+ }, 10);
+ }, () => {
+ console.log('WARNING impossible to load template ', templateName);
+ this._htmlContent = this.sanitizer.bypassSecurityTrustHtml('');
+ }
+ );
+ } else console.log('WARNING No template for state ', this.card.state);
}
get htmlContent() {
diff --git a/ui/main/src/app/modules/cards/components/details/details.component.html b/ui/main/src/app/modules/cards/components/details/details.component.html
deleted file mode 100644
index f6eccf7db1..0000000000
--- a/ui/main/src/app/modules/cards/components/details/details.component.html
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{i18nPrefix+detailC.detail.title.key}}
-
-
-
-
-
-
diff --git a/ui/main/src/app/modules/cards/components/details/details.component.scss b/ui/main/src/app/modules/cards/components/details/details.component.scss
deleted file mode 100644
index 15a5e1d519..0000000000
--- a/ui/main/src/app/modules/cards/components/details/details.component.scss
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Copyright (c) 2018-2020, RTE (http://www.rte-france.com)
- * See AUTHORS.txt
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- * SPDX-License-Identifier: MPL-2.0
- * This file is part of the OperatorFabric project.
- */
-
-
-
-.calc-height-details {
- overflow-x: hidden;
- overflow-y: auto;
-}
-
-.opfab-line-undertab{
- border-color:var(--opfab-card-tab-border-color);
-}
-
-.opfab-tab{
- border-color:var(--opfab-card-tab-border-color);
- border-radius: 4px;
-}
-
-.opfab-tab-selected {
- color: var(--opfab-card-tab-selected-text-color);
- background-color: var(--opfab-card-tab-selected-bgcolor);
-}
\ No newline at end of file
diff --git a/ui/main/src/app/modules/cards/components/details/details.component.spec.ts b/ui/main/src/app/modules/cards/components/details/details.component.spec.ts
deleted file mode 100644
index bee6edc6c7..0000000000
--- a/ui/main/src/app/modules/cards/components/details/details.component.spec.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-/* Copyright (c) 2018-2020, RTE (http://www.rte-france.com)
- * See AUTHORS.txt
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- * SPDX-License-Identifier: MPL-2.0
- * This file is part of the OperatorFabric project.
- */
-
-
-
-import {async, ComponentFixture, TestBed} from '@angular/core/testing';
-
-import {DetailsComponent} from './details.component';
-import {TranslateModule} from "@ngx-translate/core";
-
-describe('DetailsComponent', () => {
- let component: DetailsComponent;
- let fixture: ComponentFixture;
-
- beforeEach(async(() => {
- TestBed.configureTestingModule({
- imports: [TranslateModule.forRoot()],
- declarations: [DetailsComponent]
- })
- .compileComponents();
- }));
-
- beforeEach(() => {
- fixture = TestBed.createComponent(DetailsComponent);
- component = fixture.componentInstance;
- fixture.detectChanges();
- });
-
- it('should create', () => {
- expect(component).toBeTruthy();
- });
-});
diff --git a/ui/main/src/app/modules/cards/components/details/details.component.ts b/ui/main/src/app/modules/cards/components/details/details.component.ts
deleted file mode 100644
index a5ba294822..0000000000
--- a/ui/main/src/app/modules/cards/components/details/details.component.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-/* Copyright (c) 2018-2020, RTE (http://www.rte-france.com)
- * See AUTHORS.txt
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- * SPDX-License-Identifier: MPL-2.0
- * This file is part of the OperatorFabric project.
- */
-
-
-import {AfterViewInit, Component, ContentChildren, Input, OnChanges, QueryList, SimpleChanges} from '@angular/core';
-import {DetailComponent} from '../detail/detail.component';
-import {Card} from '@ofModel/card.model';
-import {ResizableComponent} from 'app/modules/utilities/components/resizable/resizable.component';
-
-@Component({
- selector: 'of-details',
- templateUrl: './details.component.html',
- styleUrls: ['./details.component.scss']
-})
-export class DetailsComponent extends ResizableComponent implements AfterViewInit, OnChanges {
-
- @ContentChildren(DetailComponent) details: QueryList;
- @Input() card: Card;
- private _i18nPrefix: string;
-
- constructor() {
- super();
- }
-
- ngAfterViewInit(): void {
- this.updateAsync();
- this.details.changes.subscribe(
- () => {
- this.updateAsync();
- }
- );
- }
-
- private updateAsync() {
- setTimeout(() => {
- const activeDetail = this.details.filter((tab) => tab.active);
- // if there is no active tab set, activate the first
- if (activeDetail.length === 0) {
- this.selectDetail(this.details.first);
- }
- });
- }
-
- selectDetail(detail: DetailComponent) {
- // deactivate all tabs
- this.details.toArray().forEach(_detail => _detail.active = false);
-
- // activate the tab the user has clicked on.
- if (detail)
- detail.active = true;
- }
-
- public get i18nPrefix() {
- return this._i18nPrefix;
- }
-
- ngOnChanges(changes: SimpleChanges): void {
- if (changes['card'].currentValue)
- this._i18nPrefix = changes['card'].currentValue.process + '.' + changes['card'].currentValue.processVersion + '.';
- }
-}
diff --git a/ui/main/src/app/modules/usercard/components/card-preview/card-preview.component.ts b/ui/main/src/app/modules/usercard/components/card-preview/card-preview.component.ts
index cf054720af..b9aa770f04 100644
--- a/ui/main/src/app/modules/usercard/components/card-preview/card-preview.component.ts
+++ b/ui/main/src/app/modules/usercard/components/card-preview/card-preview.component.ts
@@ -9,7 +9,8 @@
import {Component, ElementRef, Input, OnDestroy, OnInit} from '@angular/core';
-import {Card, Detail} from '@ofModel/card.model';
+import {Card} from '@ofModel/card.model';
+import {Detail} from '@ofModel/processes.model';
import {ProcessesService} from '@ofServices/processes.service';
import {HandlebarsService} from '../../../cards/services/handlebars.service';
import {DomSanitizer, SafeHtml, SafeResourceUrl} from '@angular/platform-browser';
diff --git a/ui/main/src/app/store/selectors/card.selectors.spec.ts b/ui/main/src/app/store/selectors/card.selectors.spec.ts
deleted file mode 100644
index 93ff9d3920..0000000000
--- a/ui/main/src/app/store/selectors/card.selectors.spec.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Copyright (c) 2018-2020, RTE (http://www.rte-france.com)
- * See AUTHORS.txt
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- * SPDX-License-Identifier: MPL-2.0
- * This file is part of the OperatorFabric project.
- */
-
-
-
-import {AppState} from '@ofStore/index';
-import {cardInitialState, CardState} from '@ofStates/card.state';
-import {emptyAppState4Test , getOneRandomCard} from '@tests/helpers';
-import {
- selectCardState,
- selectCardStateSelected,
- selectCardStateSelectedDetails,
- selectCardStateSelectedId
-} from '@ofSelectors/card.selectors';
-
-describe('CardSelectors', () => {
- const emptyAppState: AppState = emptyAppState4Test;
- const selectedState: CardState = {
- ...cardInitialState,
- selected: getOneRandomCard()
- };
-
- it('manage empty card state', () => {
- const testAppState = {...emptyAppState, card: cardInitialState};
- expect(selectCardState(testAppState)).toEqual(cardInitialState);
- expect(selectCardStateSelected(testAppState)).toBeNull();
- expect(selectCardStateSelectedDetails(testAppState)).toBeNull();
- expect(selectCardStateSelectedId(testAppState)).toBeNull();
- });
- it('manage selected card state', () => {
- const testAppState = {...emptyAppState, card: selectedState};
- expect(selectCardState(testAppState)).toEqual(selectedState);
- expect(selectCardStateSelected(testAppState)).toEqual(selectedState.selected);
- expect(selectCardStateSelectedDetails(testAppState)).toEqual(selectedState.selected.details);
- expect(selectCardStateSelectedId(testAppState)).toEqual(selectedState.selected.id);
- });
-});
diff --git a/ui/main/src/app/store/selectors/card.selectors.ts b/ui/main/src/app/store/selectors/card.selectors.ts
index 655220405c..8c501b5822 100644
--- a/ui/main/src/app/store/selectors/card.selectors.ts
+++ b/ui/main/src/app/store/selectors/card.selectors.ts
@@ -18,9 +18,6 @@ export const selectCardState = (state: AppState) => state.card;
export const selectCardStateSelected = createSelector(selectCardState, (cardState: CardState) => cardState.selected);
export const selectCardStateSelectedWithChildCards =
createSelector(selectCardState, (cardState: CardState) => [cardState.selected, cardState.selectedChildCards]);
-export const selectCardStateSelectedDetails = createSelector(selectCardStateSelected, (card: Card) => {
- return card == null ? null : card.details;
-});
export const selectCardStateSelectedId = createSelector(selectCardStateSelected, (card: Card) => {
return card == null ? null : card.id;
});
\ No newline at end of file
diff --git a/ui/main/src/tests/helpers.ts b/ui/main/src/tests/helpers.ts
index a41adbae65..6292acf06a 100644
--- a/ui/main/src/tests/helpers.ts
+++ b/ui/main/src/tests/helpers.ts
@@ -10,8 +10,8 @@
import {LightCard, Severity} from '@ofModel/light-card.model';
import {CardOperation, CardOperationType} from '@ofModel/card-operation.model';
-import {Process, State, Menu, MenuEntry, MenuEntryLinkTypeEnum} from '@ofModel/processes.model';
-import {Card, Detail, TitlePosition} from '@ofModel/card.model';
+import {Detail, Process, State, Menu, MenuEntry, MenuEntryLinkTypeEnum} from '@ofModel/processes.model';
+import {Card} from '@ofModel/card.model';
import {I18n} from '@ofModel/i18n.model';
import {Map as OfMap, Map} from '@ofModel/map';
import {Page} from '@ofModel/page.model';
@@ -87,7 +87,7 @@ export function getOneRandomProcess(processTemplate?:any): Process {
let stateCount = getPositiveRandomNumberWithinRange(1,3);
for(let j=0; j getRandomAlphanumericValue(5, 13);
- const styles = generateRandomArray(1, 5, genString);
- return new Detail(titlePosition, titleKey, titleStyle, templateName, styles);
-}
export function generateRandomArray(min = 1, max = 2, func: () => T): Array {
const size = generateRandomPositiveIntegerWithinRangeWithOneAsMinimum(min, max);
From 62faf9527b573971ddfecd953ddfad2963dd76cf Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Tue, 20 Oct 2020 13:36:41 +0200
Subject: [PATCH 044/155] [OC-1073-esm-207] just uncomment consumer-group
property to enable Kafka
Signed-off-by: Sjoerd Adema
---
config/dev/cards-publication-dev.yml | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index af6b42d956..fbd935f10e 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -3,19 +3,18 @@ server:
spring:
application:
name: cards-publication
-
-#Uncomment the Kafka section to enable Kafka
-# kafka:
-# consumer:
+ kafka:
+ consumer:
+ #Uncomment the Kafka group-id to enable Kafka
# group-id: opfab-command
-# auto-offset-reset: earliest
-# deserializer:
-# key:
-# delegate:
-# class: org.apache.kafka.common.serialization.StringDeserializer
-# value:
-# delegate:
-# class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
+ auto-offset-reset: earliest
+ deserializer:
+ key:
+ delegate:
+ class: org.apache.kafka.common.serialization.StringDeserializer
+ value:
+ delegate:
+ class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.CardCommandConsumerDeserializer
#here we put urls for all feign clients
users:
From f306166b248a874cd63c4111b0b7c7d156aee1d1 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Tue, 20 Oct 2020 13:39:19 +0200
Subject: [PATCH 045/155] [OC-1073-esm-207] replace date with time-millis and
removed unused field
Signed-off-by: Sjoerd Adema
---
client/cards/src/main/avro/card.avsc | 20 +++++++-------------
client/cards/src/main/avro/timespan.avsc | 8 ++++----
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/client/cards/src/main/avro/card.avsc b/client/cards/src/main/avro/card.avsc
index 0e64bdcc41..8dd99906dd 100644
--- a/client/cards/src/main/avro/card.avsc
+++ b/client/cards/src/main/avro/card.avsc
@@ -23,31 +23,25 @@
},
{
"name": "publishDate",
- "type": ["null","int"],
- "logicalType": "date",
- "default": null
- },
- {
- "name": "deletionDate",
- "type": ["null","int"],
- "logicalType": "date",
+ "type": ["null","long"],
+ "logicalType": "timestamp-millis",
"default": null
},
{
"name": "lttd",
- "type": ["null","int"],
- "logicalType": "date",
+ "type": ["null","long"],
+ "logicalType": "timestamp-millis",
"default": null
},
{
"name": "startDate",
"type": "long",
- "logicalType": "date"
+ "logicalType": "timestamp-millis"
},
{
"name": "endDate",
"type": ["null","long"],
- "logicalType": "date",
+ "logicalType": "timestamp-millis",
"default": null
},
{
@@ -70,7 +64,7 @@
"default": null
},
{
- "name": "timespans",
+ "name": "timeSpans",
"type": [
"null",
{
diff --git a/client/cards/src/main/avro/timespan.avsc b/client/cards/src/main/avro/timespan.avsc
index 2692bceeb7..5444645b8c 100644
--- a/client/cards/src/main/avro/timespan.avsc
+++ b/client/cards/src/main/avro/timespan.avsc
@@ -5,16 +5,16 @@
"fields": [
{
"name": "start",
- "type": "int",
- "logicalType": "date"
+ "type": "long",
+ "logicalType": "timestamp-millis"
},
{
"name" : "end",
"type": [
"null",
- "int"
+ "long"
],
- "logicalType": "date",
+ "logicalType": "timestamp-millis",
"default" : null
}
]
From 9b54e90116a2c4e33c0afa0d6c72bacbae24ad12 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Tue, 20 Oct 2020 13:40:26 +0200
Subject: [PATCH 046/155] [OC-1073-esm-207] register modules for objectmapper
Signed-off-by: Sjoerd Adema
---
.../cards/publication/kafka/CardObjectMapper.java | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
index 45f8d2ed24..a6b1c83b9a 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/CardObjectMapper.java
@@ -4,8 +4,12 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.cards.publication.configuration.json.CardsModule;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.lfenergy.operatorfabric.springtools.json.InstantModule;
import org.springframework.stereotype.Component;
import java.util.Map;
@@ -18,6 +22,10 @@ public class CardObjectMapper {
public CardObjectMapper() {
this.objectMapper = new ObjectMapper();
objectMapper.enable(MapperFeature.REQUIRE_SETTERS_FOR_GETTERS);
+ objectMapper.registerModule(new Jdk8Module());
+ objectMapper.registerModule(new JavaTimeModule());
+ objectMapper.registerModule(new CardsModule());
+ objectMapper.registerModule(new InstantModule());
}
public String writeValueAsString(Card kafkaCard) throws JsonProcessingException {
From 0b278be4c8434705ecacec16dd6292c503d22324 Mon Sep 17 00:00:00 2001
From: Sjoerd Adema
Date: Tue, 20 Oct 2020 20:35:26 +0200
Subject: [PATCH 047/155] [OC-1073-esm-207] unit tests fixed
Signed-off-by: Sjoerd Adema
---
.../kafka/command/BaseCommandHandler.java | 5 +-
.../kafka/command/BaseCommandHandlerTest.java | 86 +++++++++++++++++++
.../CreateCardCommandHandlerShould.java | 73 +++++-----------
.../DeleteCardCommandHandlerShould.java | 46 +++++-----
.../UpdateCardCommandHandlerShould.java | 49 +++++------
5 files changed, 154 insertions(+), 105 deletions(-)
create mode 100644 services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandlerTest.java
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
index 7adf61b295..4d9a522645 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandler.java
@@ -17,7 +17,7 @@
@Slf4j
@NoArgsConstructor(access = AccessLevel.PROTECTED)
-public abstract class BaseCommandHandler {
+public class BaseCommandHandler {
@Autowired
private CardObjectMapper objectMapper;
@@ -37,11 +37,10 @@ protected CardPublicationData buildCardPublicationData(CardCommand cardCommand)
cardData = objectMapper.readValue(cardDataString, new TypeReference>() {
});
}
- card.setData(cardData);
+ card.setData(cardData);
} catch (JsonProcessingException e) {
log.error("Unable to serialize card {} into CardPublicationData. Message: {}", kafkaCard, e.getMessage());
}
-
return card;
}
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandlerTest.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandlerTest.java
new file mode 100644
index 0000000000..150da9c232
--- /dev/null
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/BaseCommandHandlerTest.java
@@ -0,0 +1,86 @@
+package org.lfenergy.operatorfabric.cards.publication.kafka.command;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInstance;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.lfenergy.operatorfabric.avro.Card;
+import org.lfenergy.operatorfabric.avro.CardCommand;
+import org.lfenergy.operatorfabric.cards.publication.kafka.CardObjectMapper;
+import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+@ActiveProfiles(profiles = {"native", "test"})
+@TestInstance(TestInstance.Lifecycle.PER_CLASS)
+class BaseCommandHandlerTest {
+
+ private final String ANY_STRING = "any_string";
+ private final String PROCESS = "a_process";
+ private final String PROCESS_INSTANCE_ID = "a_process_instance_id";
+ private final String DATA_KEY = "key";
+ private final String DATA_VALUE = "value";
+
+ private CardObjectMapper objectMapper;
+
+ private BaseCommandHandler cut;
+
+ private CardCommand cardCommand;
+
+ private Card card;
+
+ @BeforeAll
+ void setUp() throws JsonProcessingException {
+ objectMapper = mock(CardObjectMapper.class);
+ cut = new BaseCommandHandler();
+ ReflectionTestUtils.setField(cut, "objectMapper", objectMapper);
+ CardPublicationData cardPublicationData = CardPublicationData.builder()
+ .build();
+ cardCommand = mock(CardCommand.class);
+ card = mock(Card.class);
+ when(cardCommand.getCard()).thenReturn(card);
+ when(cardCommand.getProcess()).thenReturn(PROCESS);
+ when(cardCommand.getProcessInstanceId()).thenReturn(PROCESS_INSTANCE_ID);
+ when(objectMapper.writeValueAsString(card)).thenReturn(ANY_STRING);
+ when(objectMapper.readValue(ANY_STRING, CardPublicationData.class)).thenReturn(cardPublicationData);
+ }
+
+ @Test
+ void testBuildCardPublicationData_withoutDataProperty() throws JsonProcessingException {
+ String cardDataAsString = null;
+ when(card.getData()).thenReturn(cardDataAsString);
+ CardPublicationData result = cut.buildCardPublicationData(cardCommand);
+ Map data = (Map) result.getData();
+ Assertions.assertThat(data.size()).isEqualTo(0);
+ Assertions.assertThat(result.getProcess()).isEqualTo(PROCESS);
+ Assertions.assertThat(result.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID);
+ }
+
+ @Test
+ void testBuildCardPublicationData_withDataProperty() throws JsonProcessingException {
+ String cardDataAsString = "justAString";
+ Map cardData = Collections.singletonMap(DATA_KEY, DATA_VALUE);
+ when(card.getData()).thenReturn(cardDataAsString);
+ when(objectMapper.readValue(anyString(), (TypeReference>) any())).thenReturn(cardData);
+ CardPublicationData result = cut.buildCardPublicationData(cardCommand);
+ Map data = (Map) result.getData();
+ Assertions.assertThat(data.size()).isEqualTo(1);
+ Assertions.assertThat(data.get(DATA_KEY)).isEqualTo(DATA_VALUE);
+ Assertions.assertThat(result.getProcess()).isEqualTo(PROCESS);
+ Assertions.assertThat(result.getProcessInstanceId()).isEqualTo(PROCESS_INSTANCE_ID);
+ }
+
+}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
index d8b0c00b40..4c95e1ce1a 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/CreateCardCommandHandlerShould.java
@@ -1,8 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
@@ -10,43 +8,48 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
-import org.lfenergy.operatorfabric.cards.publication.configuration.json.JacksonConfig;
+import org.lfenergy.operatorfabric.cards.publication.kafka.CardObjectMapper;
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.springframework.data.mongodb.core.aggregation.VariableOperators;
import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.util.ReflectionTestUtils;
import reactor.core.publisher.Mono;
-import java.math.BigDecimal;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.reset;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class CreateCardCommandHandlerShould {
- CardProcessingService cardProcessingService;
- ObjectMapper objectMapper;
- CreateCardCommandHandler createCardCommandHandler;
+ private CardProcessingService cardProcessingService;
+
+ private CardObjectMapper objectMapper;
+
+ private CreateCardCommandHandler cut;
@BeforeAll
public void setUp() {
cardProcessingService = mock(CardProcessingService.class);
- objectMapper = mock(ObjectMapper.class);
- createCardCommandHandler = new CreateCardCommandHandler(cardProcessingService, objectMapper);
+ objectMapper = mock(CardObjectMapper.class);
+ cut = new CreateCardCommandHandler(cardProcessingService);
+ ReflectionTestUtils.setField(cut, "objectMapper", objectMapper);
}
@Test
void getCommandType() {
- assertThat(createCardCommandHandler.getCommandType(), is(CommandType.CREATE_CARD));
+ assertThat(cut.getCommandType(), is(CommandType.CREATE_CARD));
}
@Test
@@ -59,43 +62,9 @@ void executeCommand() throws JsonProcessingException {
when(objectMapper.writeValueAsString(any())).thenReturn("");
when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
- createCardCommandHandler.executeCommand(cardCommandMock);
-
- verify(cardProcessingService).processCards(any());
- }
-
- @Test
- void executeCommandNoCard() throws JsonProcessingException {
- reset (cardProcessingService);
- CreateCardCommandHandler createCardCommandHandlerRealMapper = new CreateCardCommandHandler(cardProcessingService, new ObjectMapper());
-
- CardCommand cardCommandMock = mock(CardCommand.class);
- Card cardMock = mock(Card.class);
- when(cardCommandMock.getCard()).thenReturn(cardMock);
- createCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
+ cut.executeCommand(cardCommandMock);
- verify(cardProcessingService, times(0)).processCards(any());
+ verify(cardProcessingService, times(1)).processCards(any());
}
- @Test
- void executeCommandCardData() throws JsonProcessingException {
- reset (cardProcessingService);
- CardCommand cardCommandMock = mock(CardCommand.class);
- CardPublicationData cardPublicationDataMock = new CardPublicationData (); // CardPublicationData.class);
- Map map = new HashMap<>();
- map.put("Key", new BigDecimal(12));
- Card cardMock = mock(Card.class);
-
- when(cardMock.getData()).thenReturn("");
- when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(objectMapper.writeValueAsString(any())).thenReturn("");
- when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
- when(objectMapper.readValue(anyString(), (TypeReference) any())).thenReturn(map);
- when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
-
- createCardCommandHandler.executeCommand(cardCommandMock);
-
- verify(cardProcessingService).processCards(any());
- assertThat(cardPublicationDataMock.getData(), is(map));
- }
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
index a5d710fd09..91c81f5d70 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/DeleteCardCommandHandlerShould.java
@@ -1,7 +1,6 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
@@ -9,35 +8,44 @@
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
-import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
+import org.lfenergy.operatorfabric.cards.publication.kafka.CardObjectMapper;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
-import reactor.core.publisher.Mono;
+import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class DeleteCardCommandHandlerShould {
- CardProcessingService cardProcessingService;
- ObjectMapper objectMapper;
- DeleteCardCommandHandler deleteCardCommandHandler;
+ private CardProcessingService cardProcessingService;
+
+ private CardObjectMapper objectMapper;
+
+ private DeleteCardCommandHandler cut;
@BeforeAll
public void setUp() {
cardProcessingService = mock(CardProcessingService.class);
- objectMapper = mock(ObjectMapper.class);
- deleteCardCommandHandler = new DeleteCardCommandHandler(cardProcessingService, objectMapper);
+ objectMapper = mock(CardObjectMapper.class);
+ cut = new DeleteCardCommandHandler(cardProcessingService);
+ ReflectionTestUtils.setField(cut, "objectMapper", objectMapper);
}
@Test
void getCommandType() {
- assertThat(deleteCardCommandHandler.getCommandType().equals(CommandType.DELETE_CARD));
+ assertThat(cut.getCommandType().equals(CommandType.DELETE_CARD));
}
@Test
@@ -48,23 +56,9 @@ void executeCommand() throws JsonProcessingException {
when(cardCommandMock.getCard()).thenReturn(cardMock);
when(objectMapper.writeValueAsString(any())).thenReturn("");
when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
- deleteCardCommandHandler.executeCommand(cardCommandMock);
+ cut.executeCommand(cardCommandMock);
- verify(cardProcessingService).deleteCard(any());
+ verify(cardProcessingService, times(1)).deleteCard(any());
}
- @Test
- void executeCommandNoCard() throws JsonProcessingException {
- DeleteCardCommandHandler deleteCardCommandHandlerRealMapper = new DeleteCardCommandHandler(cardProcessingService, new ObjectMapper());
-
- CardCommand cardCommandMock = mock(CardCommand.class);
- CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
- Card cardMock = mock(Card.class);
- when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(objectMapper.writeValueAsString(any())).thenReturn("");
- when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
- when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
- deleteCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
- verify(cardProcessingService, times(0)).processCards(any());
- }
}
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
index 45b3edf073..ac57659e73 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/kafka/command/UpdateCardCommandHandlerShould.java
@@ -1,42 +1,57 @@
package org.lfenergy.operatorfabric.cards.publication.kafka.command;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.lfenergy.operatorfabric.avro.Card;
import org.lfenergy.operatorfabric.avro.CardCommand;
import org.lfenergy.operatorfabric.avro.CommandType;
+import org.lfenergy.operatorfabric.cards.publication.kafka.CardObjectMapper;
import org.lfenergy.operatorfabric.cards.publication.model.CardCreationReportData;
import org.lfenergy.operatorfabric.cards.publication.model.CardPublicationData;
import org.lfenergy.operatorfabric.cards.publication.services.CardProcessingService;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.util.ReflectionTestUtils;
import reactor.core.publisher.Mono;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
@ActiveProfiles(profiles = {"native", "test"})
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class UpdateCardCommandHandlerShould {
- CardProcessingService cardProcessingService;
- ObjectMapper objectMapper;
- UpdateCardCommandHandler updateCardCommandHandler;
+ private CardProcessingService cardProcessingService;
+
+ private CardObjectMapper objectMapper;
+
+ private UpdateCardCommandHandler cut;
@BeforeAll
public void setUp() {
cardProcessingService = mock(CardProcessingService.class);
- objectMapper = mock(ObjectMapper.class);
- updateCardCommandHandler = new UpdateCardCommandHandler(cardProcessingService, objectMapper);
+ objectMapper = mock(CardObjectMapper.class);
+ cut = new UpdateCardCommandHandler(cardProcessingService);
+ ReflectionTestUtils.setField(cut, "objectMapper", objectMapper);
+ }
+
+ @BeforeEach
+ public void beforeEach() {
}
@Test
void getCommandType() {
- assertThat(updateCardCommandHandler.getCommandType().equals(CommandType.UPDATE_CARD));
+ assertThat(cut.getCommandType().equals(CommandType.UPDATE_CARD));
}
@Test
@@ -48,23 +63,9 @@ void executeCommand() throws JsonProcessingException {
when(objectMapper.writeValueAsString(any())).thenReturn("");
when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
- updateCardCommandHandler.executeCommand(cardCommandMock);
+ cut.executeCommand(cardCommandMock);
- verify(cardProcessingService).processCards(any());
+ verify(cardProcessingService, times(1)).processCards(any());
}
- @Test
- void executeCommandNoCard() throws JsonProcessingException {
- UpdateCardCommandHandler updateCardCommandHandlerRealMapper = new UpdateCardCommandHandler(cardProcessingService, new ObjectMapper());
-
- CardCommand cardCommandMock = mock(CardCommand.class);
- CardPublicationData cardPublicationDataMock = mock (CardPublicationData.class);
- Card cardMock = mock(Card.class);
- when(cardCommandMock.getCard()).thenReturn(cardMock);
- when(objectMapper.writeValueAsString(any())).thenReturn("");
- when(objectMapper.readValue(anyString(), eq(CardPublicationData.class))).thenReturn(cardPublicationDataMock);
- when(cardProcessingService.processCards(any())).thenReturn(Mono.just(new CardCreationReportData()));
- updateCardCommandHandlerRealMapper.executeCommand(cardCommandMock);
- verify(cardProcessingService, times(0)).processCards(any());
- }
}
From 2d027db5d2fe308595e813f115df79953aa3d610 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 21 Oct 2020 08:16:05 +0200
Subject: [PATCH 048/155] [OC-1176] Add edit user card feature
Signed-off-by: freddidierRTE
---
.../template/en/usercard_message.handlebars | 2 +-
.../template/en/usercard_process.handlebars | 2 +
.../template/fr/usercard_message.handlebars | 2 +-
.../template/fr/usercard_process.handlebars | 2 +
.../en/usercard_conference.handlebars | 10 +--
.../template/en/usercard_message.handlebars | 2 +-
.../template/en/usercard_question.handlebars | 2 +-
.../fr/usercard_conference.handlebars | 10 +--
.../template/fr/usercard_message.handlebars | 2 +-
.../template/fr/usercard_question.handlebars | 2 +-
.../multi-filter-2.component.html | 2 +-
.../multi-filter-2.component.ts | 24 ++++++-
ui/main/src/app/model/card.model.ts | 53 ++++++++++++++
.../components/detail/detail.component.html | 4 +-
.../components/detail/detail.component.ts | 37 ++++++----
.../cards/services/handlebars.service.ts | 4 +-
.../card-preview/card-preview.component.ts | 2 -
.../usercard/newcard-template.services.ts | 53 --------------
.../usercard/usercard-routing.module.ts | 4 ++
.../modules/usercard/usercard.component.html | 6 +-
.../modules/usercard/usercard.component.ts | 69 +++++++++++++++----
.../app/modules/usercard/usercard.module.ts | 4 +-
ui/main/src/app/services/app.service.ts | 3 +-
ui/main/src/app/services/card.service.ts | 6 +-
ui/main/src/assets/i18n/en.json | 4 +-
ui/main/src/assets/i18n/fr.json | 4 +-
26 files changed, 196 insertions(+), 119 deletions(-)
delete mode 100644 ui/main/src/app/modules/usercard/newcard-template.services.ts
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_message.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_message.handlebars
index bb2e0129ba..1b9b300906 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_message.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_message.handlebars
@@ -4,7 +4,7 @@
Message
-
+
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_process.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_process.handlebars
index 03ec8862e1..d7e702d7bb 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_process.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/usercard_process.handlebars
@@ -32,6 +32,8 @@ Status of the state
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars
new file mode 100644
index 0000000000..5c908a074a
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars
@@ -0,0 +1,72 @@
+Incident description :
+
+
+
+
+
+
+Impacted services :
+
+
+ Other impacts :
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars
new file mode 100644
index 0000000000..c283b772ff
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars
@@ -0,0 +1,142 @@
+
+
Incident SI en cours
+
+
+
+
+
+
+
+ Description de l'incident : {{keepSpacesAndEndOfLine card.data.message}}
+
+
+
+
+
+ Services impactés vu SI :
+
+
+
+
+
+
+
+
+
+
Merci de saisir les impacts que vous identifiez de votre coté
+
+
+
+
+
+
+
+Autres impacts :
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars
new file mode 100644
index 0000000000..d86846ba75
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars
@@ -0,0 +1,72 @@
+Description de l'incident :
+
+
+
+
+
+
+Service impactés :
+
+
+ Autres impacts :
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
index ee6c6b1f9e..ea1ee96beb 100644
--- a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
+++ b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
@@ -24,11 +24,16 @@ Feature: Add perimeters/group for action test
{
"state" : "questionState",
"right" : "ReceiveAndWrite"
+ },
+ {
+ "state" : "incidentInProgressState",
+ "right" : "ReceiveAndWrite"
}
]
}
"""
+
Scenario: Create perimeterUserCardExamples
Given url opfabUrl + 'users/perimeters'
And header Authorization = 'Bearer ' + authToken
@@ -37,16 +42,24 @@ Feature: Add perimeters/group for action test
Then status 201
- Scenario: Add perimeterQuestion for groups Dispatcher
+ Scenario: Add perimeterUserCardExamples for groups Dispatcher
Given url opfabUrl + 'users/groups/Dispatcher/perimeters'
And header Authorization = 'Bearer ' + authToken
And request ["perimeterUserCardExamples"]
When method patch
Then status 200
- Scenario: Add perimeterQuestion for groups Planner
+ Scenario: Add perimeterUserCardExamples for groups Planner
Given url opfabUrl + 'users/groups/Planner/perimeters'
And header Authorization = 'Bearer ' + authToken
And request ["perimeterUserCardExamples"]
When method patch
Then status 200
+
+ Scenario: Add perimeterUserCardExamples for groups Supervisor
+ Given url opfabUrl + 'users/groups/Supervisor/perimeters'
+ And header Authorization = 'Bearer ' + authToken
+ And request ["perimeterUserCardExamples"]
+ When method patch
+ Then status 200
+
From 2b33b83e675ad9e6c5c437cbe5e8c359349be4ec Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 18 Nov 2020 08:54:16 +0100
Subject: [PATCH 119/155] Updated cards-publication yaml files
Signed-off-by: Jeroen Gommans
---
config/dev/cards-publication-dev.yml | 14 +++++++-------
config/docker/cards-publication-docker.yml | 20 ++++++++++++++------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/config/dev/cards-publication-dev.yml b/config/dev/cards-publication-dev.yml
index 82f48f2089..dbda80427d 100755
--- a/config/dev/cards-publication-dev.yml
+++ b/config/dev/cards-publication-dev.yml
@@ -6,17 +6,17 @@ spring:
deserializer:
value:
delegate:
- class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.KafkaAvroWithoutRegistryDeserializer
-# class: io.confluent.kafka.serializers.KafkaAvroDeserializer
+ class: io.confluent.kafka.serializers.KafkaAvroDeserializer
+# class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.KafkaAvroWithoutRegistryDeserializer
serializer:
value:
delegate:
class: io.confluent.kafka.serializers.KafkaAvroSerializer
-
+# class: org.lfenergy.operatorfabric.cards.publication.kafka.producer.KafkaAvroWithoutRegistrySerializer
# uncomment kafka.consumer.group-id to enable Kafka
- kafka:
- consumer:
- group-id: opfab-command
+# kafka:
+# consumer:
+# group-id: opfab-command
opfab:
kafka:
@@ -43,4 +43,4 @@ externalRecipients-url: "{\
}"
# WARNING : If you set this parameter to false , all users have the rights to respond to all cards
-checkPerimeterForResponseCard: false
+checkPerimeterForResponseCard: true
diff --git a/config/docker/cards-publication-docker.yml b/config/docker/cards-publication-docker.yml
index a23e1b2f93..7e11257644 100644
--- a/config/docker/cards-publication-docker.yml
+++ b/config/docker/cards-publication-docker.yml
@@ -6,19 +6,27 @@ spring:
value:
delegate:
class: io.confluent.kafka.serializers.KafkaAvroDeserializer
- # uncomment to enable Kafka
+# class: org.lfenergy.operatorfabric.cards.publication.kafka.consumer.KafkaAvroWithoutRegistryDeserializer
+ serializer:
+ value:
+ delegate:
+ class: io.confluent.kafka.serializers.KafkaAvroSerializer
+# class: org.lfenergy.operatorfabric.cards.publication.kafka.producer.KafkaAvroWithoutRegistrySerializer
+# uncomment kafka.consumer.group-id to enable Kafka
# kafka:
# consumer:
# group-id: opfab-command
-schema:
- registry:
- url: http://localhost:8081
-
opfab:
kafka:
topics:
- topicname: opfab
+ card:
+ topicname: opfab
+ response-card:
+ topicname: opfab-response
+ schema:
+ registry:
+ url: http://localhost:8081
#here we put urls for all feign clients
users:
From 98fce37f2ad75ef90de9091e9a0219eba6946061 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 09:56:16 +0100
Subject: [PATCH 120/155] [OC-1230] Correct sonar warning (ref-sonar:
java:S1118)
Signed-off-by: freddidierRTE
---
.../configuration/mongo/HoursAndMinutesReadConverter.java | 4 ++++
.../configuration/mongo/RecurrenceReadConverter.java | 4 ++++
.../configuration/mongo/HoursAndMinutesReadConverter.java | 5 +++++
.../configuration/mongo/HoursAndMinutesWriterConverter.java | 5 +++++
.../configuration/mongo/RecurrenceReadConverter.java | 4 ++++
.../configuration/mongo/RecurrenceWriterConverter.java | 5 +++++
6 files changed, 27 insertions(+)
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/HoursAndMinutesReadConverter.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/HoursAndMinutesReadConverter.java
index 4c89cf1d21..0d967fad2f 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/HoursAndMinutesReadConverter.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/HoursAndMinutesReadConverter.java
@@ -17,6 +17,10 @@
public class HoursAndMinutesReadConverter {
+ private HoursAndMinutesReadConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
public static HoursAndMinutes convert(Document source) {
Integer hours = source.getInteger("hours");
Integer minutes = source.getInteger("minutes");
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/RecurrenceReadConverter.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/RecurrenceReadConverter.java
index e5a40ad494..e241465bba 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/RecurrenceReadConverter.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/RecurrenceReadConverter.java
@@ -21,6 +21,10 @@
public class RecurrenceReadConverter {
+ private RecurrenceReadConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
public static Recurrence convert(Document source) {
String timeZone= source.getString("timeZone");
List daysOfWeek = (List) source.get("daysOfWeek");
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesReadConverter.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesReadConverter.java
index 8654495ff1..575aafed41 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesReadConverter.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesReadConverter.java
@@ -17,6 +17,11 @@
public class HoursAndMinutesReadConverter {
+
+ private HoursAndMinutesReadConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
public static HoursAndMinutes convert(Document source) {
Integer hours = source.getInteger("hours");
Integer minutes = source.getInteger("minutes");
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesWriterConverter.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesWriterConverter.java
index 95a14a5fe8..08f25c4bc9 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesWriterConverter.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/HoursAndMinutesWriterConverter.java
@@ -14,6 +14,11 @@
public class HoursAndMinutesWriterConverter {
+ private HoursAndMinutesWriterConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
+
public static Document convert(HoursAndMinutes source) {
Document result = new Document();
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceReadConverter.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceReadConverter.java
index fcbd4e7d30..e0a32c1d3a 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceReadConverter.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceReadConverter.java
@@ -22,6 +22,10 @@
public class RecurrenceReadConverter {
+ private RecurrenceReadConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
public static Recurrence convert(Document source) {
String timeZone= source.getString("timeZone");
List daysOfWeek = (List) source.get("daysOfWeek");
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceWriterConverter.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceWriterConverter.java
index f9b8339ac6..00ac8ef1f6 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceWriterConverter.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/configuration/mongo/RecurrenceWriterConverter.java
@@ -24,6 +24,11 @@ public class RecurrenceWriterConverter {
private static String defaultTimeZone = "Europe/Paris";
+ private RecurrenceWriterConverter() {
+ throw new IllegalStateException("Utility class");
+ }
+
+
public static Document convert(RecurrencePublicationData source) {
Document result = new Document();
From 68eb83d525112d70eff84cd361d44be2dcbb3d45 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 09:58:59 +0100
Subject: [PATCH 121/155] [OC-1230] Add example of recurrent remind in usercard
Signed-off-by: freddidierRTE
---
.../bundle_userCardExamples/config.json | 19 ++++-
.../bundle_userCardExamples/i18n/en.json | 4 ++
.../bundle_userCardExamples/i18n/fr.json | 4 ++
.../template/en/task.handlebars | 46 +++++++++++++
.../template/en/usercard_task.handlebars | 69 +++++++++++++++++++
.../template/fr/task.handlebars | 46 +++++++++++++
.../template/fr/usercard_task.handlebars | 69 +++++++++++++++++++
.../setPerimeterForUserCardExamples.feature | 5 ++
8 files changed, 261 insertions(+), 1 deletion(-)
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/task.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/task.handlebars
create mode 100644 src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_task.handlebars
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
index d34a20c2e5..c9ddbd0082 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
@@ -59,6 +59,23 @@
}
],
"acknowledgementAllowed": false
- }
+ },
+ "taskState": {
+ "name": "task.title",
+ "color": "#8bcdcd",
+ "userCardTemplate": "usercard_task",
+ "secondsBeforeTimeSpanForReminder" : 300,
+ "details": [
+ {
+ "title": {
+ "key": "task.title"
+ },
+ "templateName": "task",
+ "styles": [
+ ]
+ }
+ ],
+ "acknowledgementAllowed": true
+ }
}
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
index d15bdd2219..8e8409c73f 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/en.json
@@ -12,6 +12,10 @@
"question":{
"title":"Question ",
"summary":"There is a question for you"
+ },
+ "task":{
+ "title":"Task ",
+ "summary":"There is something to do"
}
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
index 7876c2afc6..d06804951f 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/i18n/fr.json
@@ -11,6 +11,10 @@
"question":{
"title":"Question",
"summary":"Il y a une question pour vous"
+ },
+ "task":{
+ "title":"Tâche ",
+ "summary":"Il y a quelque chose à faire "
}
}
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/task.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/task.handlebars
new file mode 100644
index 0000000000..6079eabfb0
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/task.handlebars
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+ You have the following task to do :
+
+
+
+
+
+{{keepSpacesAndEndOfLine card.data.taskDescription }}
+
+
+
+
+
+At {{card.data.hours}}:{{card.data.minutes}} on
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
new file mode 100644
index 0000000000..04f7906ec6
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
@@ -0,0 +1,69 @@
+
+
+Task description :
+
+
+
+
+Repeat every :
+
+
+
+
+ At :
+ H
+ Min
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/task.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/task.handlebars
new file mode 100644
index 0000000000..fd121ae3f1
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/task.handlebars
@@ -0,0 +1,46 @@
+
+
+
+
+
+
+
+
+
+
+ You avez la tâche suivante à réaliser :
+
+
+
+
+
+{{keepSpacesAndEndOfLine card.data.taskDescription }}
+
+
+
+
+
+A {{card.data.hours}}:{{card.data.minutes}} le
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_task.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_task.handlebars
new file mode 100644
index 0000000000..adbd37d038
--- /dev/null
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_task.handlebars
@@ -0,0 +1,69 @@
+
+
+Description de la tâche:
+
+
+
+
+Se répète chaque :
+
+
+
+
+ A :
+ H
+ Min
+
+
+
\ No newline at end of file
diff --git a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
index ee6c6b1f9e..092aea33d5 100644
--- a/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
+++ b/src/test/utils/karate/cards/setPerimeterForUserCardExamples.feature
@@ -24,6 +24,11 @@ Feature: Add perimeters/group for action test
{
"state" : "questionState",
"right" : "ReceiveAndWrite"
+ },
+ ,
+ {
+ "state" : "taskState",
+ "right" : "ReceiveAndWrite"
}
]
}
From 6c75de600a07b4cde448f2427e4e3688e6da5776 Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 18 Nov 2020 11:41:13 +0100
Subject: [PATCH 122/155] Updated Kafka documentation
Signed-off-by: Jeroen Gommans
---
.../clients/impl/ExternalAppClientImpl.java | 2 +-
.../impl/ExternalAppClientImplShould.java | 2 +-
.../configuration/configuration.adoc | 26 ++++++++++++++-----
src/docs/asciidoc/dev_env/kafka.adoc | 23 +++++++++++-----
4 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImpl.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImpl.java
index 0dffb53b5a..ddfe531aaa 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImpl.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImpl.java
@@ -63,7 +63,7 @@ public void sendCardToExternalApplication(CardPublicationData card) {
}
private void callExternalApplication(CardPublicationData card, String externalRecipientUrl) {
- if (externalRecipientUrl.startsWith("kafka://")) {
+ if (externalRecipientUrl.startsWith("kafka:")) {
callExternalKafkaApplication(card, externalRecipientUrl);
} else{
callExternalHttpApplication(card, externalRecipientUrl);
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImplShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImplShould.java
index 9606bd2346..29e0c8a5b0 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImplShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/clients/impl/ExternalAppClientImplShould.java
@@ -50,7 +50,7 @@ class ExternalAppClientImplShould {
private final String externalRecipientHttp = "http_recipient";
private final Map externalRecipientsMapping = new HashMap() {
{
- put (externalRecipientKafka, "kafka://");
+ put (externalRecipientKafka, "kafka:");
put (externalRecipientHttp, "http://");
}
};
diff --git a/src/docs/asciidoc/deployment/configuration/configuration.adoc b/src/docs/asciidoc/deployment/configuration/configuration.adoc
index 458a6559ac..1d54b1491d 100644
--- a/src/docs/asciidoc/deployment/configuration/configuration.adoc
+++ b/src/docs/asciidoc/deployment/configuration/configuration.adoc
@@ -105,11 +105,14 @@ The cards-publication service has these specific properties :
|checkPerimeterForResponseCard|true|no|If false, OperatorFabric will not check that a user has write rights on a process/state to respond to a card
|spring.kafka.consumer.group-id |null|no| If set, support for receiving cards via Kafka is enabled
-|spring.deserializer.key.delegate.class |io.confluent.kafka.serializers.
-|KafkaAvroDeserializer|yes| Deserializer used to convert the received bytes into objects
-|opfab.kafka.topics.topicname |opfab|no|Name of the topic to read the messages from
-|schema.registry.url|http://localhost:8081|yes|URL of the schema registry. Can be set to the empty string "" is no registry is used
+|spring.deserializer.value.delegate.class|io.confluent.kafka.serializers.
+KafkaAvroDeserializer|yes| Deserializer used to convert the received bytes into objects
+|spring.serializer.value.delegate.class |io.confluent.kafka.serializers.
+KafkaAvroSerializer|yes|Serializer used to convert cards to bytes
|spring.kafka.producer.bootstrap-servers|http://localhost:9092|no|comma seperated list of URL(s) of the broker(s) / bootstrap server(s)
+|opfab.kafka.topics.card.topicname |opfab|no|Name of the topic to read the messages from
+|opfab.kafka.topics.response-card.topicname |opfab|no|Name of the topic to place the response cards to
+|opfab.kafka.schema.registry.url|http://localhost:8081|yes|URL of the schema registry. Can be set to the empty string "" is no registry is used
|===
@@ -162,6 +165,17 @@ See link:{spring_kafka_doc}[Spring for Apache Kafka] for more information on the
With the default settings, the Kafka consumer expects a broker running on http//127.0.0.1:9092 and a schema registry on http://127.0.0.1:8081.
-Response cards are not (yet) returned via Kafka, but by the URL specified in the cards-publication yml file.
+Operator Fabric is also able to publish response cards to a Kafka topic. The default topic name `opfab-response`. You can specify which response cards
+are to be returned via Kafka by setting the `externalRecipients-url` in the `cards-publication` yaml file. Instead of setting `http://` URL you should set it to `kafka:`
-Note that enabling Kafka does not disable the REST interface.
+[source, yaml]
+----
+externalRecipients-url: "{\
+ processAction: \"http://localhost:8090/test\", \
+ mykafka: \"kafka:topicname\"
+ }"
+----
+
+Note that `topicname` is a placeholder for now. All response cards are returned via the same Kafka topic.
+
+Also note enabling Kafka does not disable the REST interface.
diff --git a/src/docs/asciidoc/dev_env/kafka.adoc b/src/docs/asciidoc/dev_env/kafka.adoc
index 08ef8f9157..cc7734b0c2 100644
--- a/src/docs/asciidoc/dev_env/kafka.adoc
+++ b/src/docs/asciidoc/dev_env/kafka.adoc
@@ -24,7 +24,7 @@ To enable Kafka support you need to set the `kafka.consumer.group_id property` i
group-id: opfab-command
----
-The default topic from which the messages are consumed is called 'opfab'. This setting can be modified by setting 'opfab.kafka.topics.topicname'.
+The default topic from which the messages are consumed is called 'opfab'. This setting can be modified by setting 'opfab.kafka.card.topics.topicname'.
Make sure you also set the registry to either an empty string (`""`) or to the server providing the schema registry service.
With the default settings, the Kafka consumer expects a broker running on http//127.0.0.1:9092 and a schema registry on http://127.0.0.1:8081.
@@ -42,8 +42,8 @@ the implementation of the deserializers and mapping of Kafka topics to OperatorF
for the various Kafka configuration options.
=== Kafka OperatorFabric AVRO schema
-The AVRO schema, the byte format in which messages are transffered using Kafka topics, can be found at `client/src/main/avro`.
-Message are wrapped in a the CardCommand object before being sent to a Kafka topic.
+The AVRO schema, the byte format in which messages are transferred using Kafka topics, can be found at `client/src/main/avro`.
+Message are wrapped in a CardCommand object before being sent to a Kafka topic.
This object is an almost one-to-one mapping of the OperatorFabric card, see also <>. The exceptions are `Process` and
`Process Instance Identifier`, which are moved to the top-level CardCommand.
@@ -52,7 +52,7 @@ This object is an almost one-to-one mapping of the OperatorFabric card, see also
=== Setting a new deserializer
By default, OperatorFabric uses the `io.confluent.kafka.serializers.KafkaAvroDeserializer` from link:{confluent}[Confluent]. However, you can write your own
deserializer. To use your own deserializer, make sure
-`spring.kafka.deserializer.value` points to your deserializer.
+`spring.deserializer.value.delegate.class` points to your deserializer.
== Kafka card producer
@@ -107,5 +107,16 @@ the dump below.
----
== Response Cards
-OperatorFabric <> are currently returned only via REST. At the time of writing it is not possible to return
-response cards via Kafka.
+OperatorFabric <> can be sent by REST of put on a Kafka topic. The Kafka response card configuration follows the
+convention to configure a REST endpoint. Instead of setting the 'http://host/api' URL, you set it to 'kafka:response-topic' in the `externalRecipients-url:`
+section from the cards-publication.yml file:
+
+[source, yaml]
+----
+externalRecipients-url: "{\
+ processAction: \"http://localhost:8090/test\", \
+ mykafka: \"kafka:topicname\"
+ }"
+----
+
+Note that `topicname` is a placeholder for now. All response cards are returned via the same Kafka topic.
From 8157fc3f65fd1f017cdfcffa0c56ef7d15803d10 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 14:28:55 +0100
Subject: [PATCH 123/155] [OC-1210] Add a method in templateGateway.js to get
entity names
Signed-off-by: freddidierRTE
---
.../reference_doc/response_cards.adoc | 8 +++++-
.../template/en/question.handlebars | 5 ++--
.../template/fr/question.handlebars | 4 +--
.../template/en/incidentInProgress.handlebars | 4 +--
.../template/fr/incidentInProgress.handlebars | 4 +--
ui/main/src/app/services/entities.service.ts | 10 +++++++
ui/main/src/assets/js/templateGateway.js | 28 +++++++++++++++----
7 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/src/docs/asciidoc/reference_doc/response_cards.adoc b/src/docs/asciidoc/reference_doc/response_cards.adoc
index 28958bc734..61ab568f1e 100644
--- a/src/docs/asciidoc/reference_doc/response_cards.adoc
+++ b/src/docs/asciidoc/reference_doc/response_cards.adoc
@@ -156,4 +156,10 @@ For each user response, a child card containing the response is emitted and stor
- To integrate the child cards when loading the card you need to call to _templateGateway.applyChildCards()_. (OperatorFabric is not calling the method on card loading)
-You can find an example in the file src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars.
+=== Entity name
+
+If you want to show the name of an entity that send the response, you need to get the id of the entity via the publisher field of the child card and then you can get the name of the entity by calling _templateGateway.getEntityName(entityId)_
+
+=== Example
+
+You can find an example in the file src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars.
\ No newline at end of file
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars
index 100e4a90af..70c7186438 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/en/question.handlebars
@@ -32,8 +32,9 @@
responses += ' ';
templateGateway.childCards.forEach( (c, i) => {
- console.log("data child = ", c.data);
- responses += ` ${c.publisher} `
+
+ const entityName = templateGateway.getEntityName(c.publisher);
+ responses += ` ${entityName} `
if (c.data.choice1) responses += " OK ";
else responses += " NOK ";
if (c.data.choice2) responses += " OK ";
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/fr/question.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/fr/question.handlebars
index 97c28eb237..57b7a1c34e 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/fr/question.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_defaultProcess/template/fr/question.handlebars
@@ -34,8 +34,8 @@
responses += ' ';
templateGateway.childCards.forEach( (c, i) => {
- console.log("data child = ", c.data);
- responses += ` ${c.publisher} `
+ const entityName = templateGateway.getEntityName(c.publisher);
+ responses += ` ${entityName} `
if (c.data.choice1) responses += " OK ";
else responses += " NOK ";
if (c.data.choice2) responses += " OK ";
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/incidentInProgress.handlebars
index d4937a59c8..adf8f808fd 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/incidentInProgress.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/incidentInProgress.handlebars
@@ -82,8 +82,8 @@ Other impacts :
responses += ' ';
templateGateway.childCards.forEach((c, i) => {
- console.log("data child = ", c.data);
- responses += ` ${c.publisher} `
+ const entityName = templateGateway.getEntityName(c.publisher);
+ responses += ` ${entityName} `
if (c.data.impacts.SA) responses += ` OUI `;
else responses += ` NON `;
if (c.data.impacts.SB) responses += ` OUI `;
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars
index c283b772ff..a4acea2fea 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/incidentInProgress.handlebars
@@ -82,8 +82,8 @@ Autres impacts :
responses += ' ';
templateGateway.childCards.forEach((c, i) => {
- console.log("data child = ", c.data);
- responses += ` ${c.publisher} `
+ const entityName = templateGateway.getEntityName(c.publisher);
+ responses += ` ${entityName} `
if (c.data.impacts.SA) responses += ` OUI `;
else responses += ` NON `;
if (c.data.impacts.SB) responses += ` OUI `;
diff --git a/ui/main/src/app/services/entities.service.ts b/ui/main/src/app/services/entities.service.ts
index 1aa6500f52..2ce2d9c4f1 100644
--- a/ui/main/src/app/services/entities.service.ts
+++ b/ui/main/src/app/services/entities.service.ts
@@ -18,6 +18,9 @@ import { Entity } from '@ofModel/entity.model';
import { takeUntil } from 'rxjs/internal/operators/takeUntil';
import { tap } from 'rxjs/operators';
+
+declare const templateGateway: any;
+
@Injectable({
providedIn: 'root'
})
@@ -71,6 +74,7 @@ export class EntitiesService extends ErrorService implements CrudService {
(entities) => {
if (!!entities) {
this._entities = entities;
+ this.setEntityNamesInTemplateGateway();
console.log(new Date().toISOString(), 'List of entities loaded');
}
}, (error) => console.error(new Date().toISOString(), 'an error occurred', error)
@@ -86,4 +90,10 @@ export class EntitiesService extends ErrorService implements CrudService {
return (name ? name : idEntity);
}
+ private setEntityNamesInTemplateGateway(): void {
+ const entityNames = new Map();
+ this._entities.forEach(entity => entityNames.set(entity.id, entity.name));
+ templateGateway.setEntityNames(entityNames);
+ }
+
}
diff --git a/ui/main/src/assets/js/templateGateway.js b/ui/main/src/assets/js/templateGateway.js
index dd48fbcbc9..79cacfb0a2 100644
--- a/ui/main/src/assets/js/templateGateway.js
+++ b/ui/main/src/assets/js/templateGateway.js
@@ -7,13 +7,31 @@
* This file is part of the OperatorFabric project.
*/
-function ext_action(responseData){
- console.log(new Date().toISOString(),`opfab action called - ${responseData.lock} - ${responseData.state}`)
-}
-let templateGateway = {
+const templateGateway = {
+ opfabEntityNames : null,
+
validyForm: function(formData=null) {
+ console.log(new Date().toISOString() , ` Template.js : no validyForm method define in template , valid set to true`);
return this.isValid = undefined;
},
+
+ setEntityNames: function(entityNames){
+ this.opfabEntityNames = entityNames;
+ },
+
+ getEntityName: function(entityId) {
+ if (!this.opfabEntityNames) {
+ console.log(new Date().toISOString() , ` Template.js : no entities information loaded`);
+ return entityId;
+ }
+ if (!this.opfabEntityNames.has(entityId)) {
+ console.log(new Date().toISOString() , ` Template.js : entityId ${entityId} is unknown`);
+ return entityId;
+ }
+ return this.opfabEntityNames.get(entityId);
+ },
childCards: []
-};
\ No newline at end of file
+
+};
+
From 368b17ee1bef042f2dceafa9702a5d6daef57208 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 14:54:01 +0100
Subject: [PATCH 124/155] [OC-1238] remove card question from entity in example
Signed-off-by: freddidierRTE
---
.../karate/cards/post6CardsSeverity.feature | 46 -------------------
1 file changed, 46 deletions(-)
diff --git a/src/test/utils/karate/cards/post6CardsSeverity.feature b/src/test/utils/karate/cards/post6CardsSeverity.feature
index 97655f0f4e..b200fe7fa0 100644
--- a/src/test/utils/karate/cards/post6CardsSeverity.feature
+++ b/src/test/utils/karate/cards/post6CardsSeverity.feature
@@ -376,49 +376,3 @@ When method post
Then status 201
And match response.count == 1
-
-
-##################################################################
-
-# Push a question card sent by a user from ENTITY1
-
- * def getCard =
- """
- function() {
-
- startDate = new Date().valueOf() + 4*60*60*1000;
- lttdDate = new Date().valueOf() + 60*1000*60;
- endDate = new Date().valueOf() + 8*60*60*1000;
-
- var card = {
- "publisher" : "ENTITY1",
- "processVersion" : "1",
- "process" :"defaultProcess",
- "processInstanceId" : "processInstanceSentByENTITY1",
- "state": "questionState",
- "groupRecipients": ["Dispatcher", "Planner"],
- "entitiesAllowedToRespond": ["ENTITY1","ENTITY2"],
- "severity" : "ACTION",
- "startDate" : startDate,
- "summary" : {"key" : "message.summary"},
- "title" : {"key" : "question.title"},
- "data" : {"message":" Action Card"},
- "lttd" : lttdDate,
- "timeSpans" : [
- {"start" : startDate ,"end" : endDate}
- ],
- "publisherType" : "ENTITY"
- }
-
- return JSON.stringify(card);
-
- }
- """
- * def card = call getCard
-
- Given url opfabPublishCardUrl + 'cards'
- And request card
- And header Content-Type = 'application/json'
- When method post
- Then status 201
- And match response.count == 1
From cd695399cea9e6a7ef8ab238a55a9f9d17139af7 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 14:55:29 +0100
Subject: [PATCH 125/155] [OC-1238] Permit to use keepChildCards in user card
Signed-off-by: freddidierRTE
---
.../template/en/usercard_incidentInProgress.handlebars | 1 +
.../template/fr/usercard_incidentInProgress.handlebars | 1 +
ui/main/src/app/model/card.model.ts | 3 +++
ui/main/src/app/modules/usercard/usercard.component.ts | 2 ++
4 files changed, 7 insertions(+)
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars
index 5c908a074a..a1d5037bc8 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_incidentInProgress.handlebars
@@ -48,6 +48,7 @@ Impacted services :
const card = {
summary: { key: "incidentInProgress.summary" },
title: { key: "incidentInProgress.title" },
+ keepChildCards: true,
data: {
message: message,
impacts :
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars
index d86846ba75..7973b24150 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/fr/usercard_incidentInProgress.handlebars
@@ -48,6 +48,7 @@ Service impactés :
const card = {
summary: { key: "incidentInProgress.summary" },
title: { key: "incidentInProgress.title" },
+ keepChildCards: true,
data: {
message: message,
impacts :
diff --git a/ui/main/src/app/model/card.model.ts b/ui/main/src/app/model/card.model.ts
index c68f8ee83f..a2d6063b7c 100644
--- a/ui/main/src/app/model/card.model.ts
+++ b/ui/main/src/app/model/card.model.ts
@@ -40,6 +40,7 @@ export class Card {
readonly recipient?: Recipient,
readonly parentCardId?: string,
readonly initialParentCardUid?: string,
+ readonly keepChildCards?: boolean,
readonly publisherType?: PublisherType | string,
public timeSpans?: TimeSpan[]
) {
@@ -68,6 +69,7 @@ export class CardForPublishing {
readonly recipient?: Recipient,
readonly parentCardId?: string,
readonly initialParentCardUid?: string,
+ readonly keepChildCards?: boolean,
readonly publisherType?: PublisherType | string,
readonly timeSpans?: TimeSpan[]
) {
@@ -134,6 +136,7 @@ export function fromCardToCardForPublishing(card: Card): CardForPublishing {
card.recipient,
card.parentCardId,
card.initialParentCardUid,
+ card.keepChildCards,
card.publisherType,
card.timeSpans
);
diff --git a/ui/main/src/app/modules/usercard/usercard.component.ts b/ui/main/src/app/modules/usercard/usercard.component.ts
index 3c43035fcc..cb23b65445 100644
--- a/ui/main/src/app/modules/usercard/usercard.component.ts
+++ b/ui/main/src/app/modules/usercard/usercard.component.ts
@@ -338,6 +338,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
const title = (!!specificInformation.card.title) ? specificInformation.card.title : 'UNDEFINED';
const summary = (!!specificInformation.card.summary) ? specificInformation.card.summary : 'UNDEFINED';
+ const keepChildCards = (!!specificInformation.card.keepChildCards) ? specificInformation.card.keepChildCards : false;
let timeSpans = [];
if (!!specificInformation.viewCardInAgenda) timeSpans = [new TimeSpan(startDate , endDate )];
@@ -366,6 +367,7 @@ export class UserCardComponent implements OnDestroy, OnInit {
title: title,
summary: summary,
timeSpans : timeSpans,
+ keepChildCards: keepChildCards,
data: specificInformation.card.data,
} as Card;
From b7ef9b02523fb4d741edd469f4081f48ece6955e Mon Sep 17 00:00:00 2001
From: Jeroen Gommans
Date: Wed, 18 Nov 2020 16:12:53 +0100
Subject: [PATCH 126/155] Added defaults for Kafka topics
Signed-off-by: Jeroen Gommans
---
.../publication/kafka/consumer/CardCommandConsumerListener.java | 2 +-
.../cards/publication/kafka/producer/ResponseCardProducer.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
index ad0e6b9b0f..03f3200646 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/consumer/CardCommandConsumerListener.java
@@ -31,7 +31,7 @@ public CardCommandConsumerListener(List commandHandlerList) {
.collect(Collectors.toMap(CommandHandler::getCommandType, it -> it));
}
- @KafkaListener(topics = "${opfab.kafka.topics.card.topicname}", containerFactory = "kafkaListenerContainerFactory")
+ @KafkaListener(topics = "${opfab.kafka.topics.card.topicname:opfab}", containerFactory = "kafkaListenerContainerFactory")
public void receivedCommand(@Payload ConsumerRecord record) {
log.info("Key: {}, Value: {}, Partition: {}, Offset: {}",
record.key(), record.value(), record.partition(), record.offset());
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/producer/ResponseCardProducer.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/producer/ResponseCardProducer.java
index eac73da623..ad2b3f79e0 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/producer/ResponseCardProducer.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/kafka/producer/ResponseCardProducer.java
@@ -29,7 +29,7 @@ public class ResponseCardProducer {
private final KafkaTemplate kafkaTemplate;
private final CardCommandFactory cardCommandFactory;
- @Value("${opfab.kafka.topics.response-card.topicname}")
+ @Value("${opfab.kafka.topics.response-card.topicname:opfab-response}")
private String topic;
public void send(CardPublicationData cardPublicationData) {
From 456e9dc1e0bd8396d140aaacfe29c55cd91e0cf3 Mon Sep 17 00:00:00 2001
From: freddidierRTE
Date: Wed, 18 Nov 2020 17:55:12 +0100
Subject: [PATCH 127/155] [OC-1239] Change secondsBeforeTimeSpanForReminder
field form process object to card object
Signed-off-by: freddidierRTE
---
.../model/ProcessStatesData.java | 1 -
.../src/main/modeling/swagger.yaml | 3 -
.../mongo/LightCardReadConverter.java | 33 +++++----
.../model/ArchivedCardConsultationData.java | 1 +
.../model/CardConsultationData.java | 1 +
.../model/LightCardConsultationData.java | 3 +
.../model/ArchivedCardPublicationData.java | 3 +
.../model/CardPublicationData.java | 3 +
.../model/LightCardPublicationData.java | 2 +
.../src/main/modeling/swagger.yaml | 6 +-
.../services/CardProcessServiceShould.java | 1 +
.../reference_doc/card_notification.adoc | 3 +-
.../businessconfig/getABusinessconfig.feature | 2 +-
.../resources/bundle_api_test/config.json | 1 -
.../resources/bundle_api_test_v2/config.json | 1 -
.../karate/cards/cardsWithTimespans.feature | 2 +
.../bundle_userCardExamples/config.json | 2 -
.../en/usercard_conference.handlebars | 1 +
.../template/en/usercard_task.handlebars | 6 +-
.../fr/usercard_conference.handlebars | 1 +
.../template/fr/usercard_task.handlebars | 8 ++-
ui/main/src/app/model/card.model.ts | 3 +
ui/main/src/app/model/light-card.model.ts | 3 +-
ui/main/src/app/model/processes.model.ts | 1 -
.../modules/usercard/usercard.component.ts | 2 +
.../app/services/reminder/reminder.service.ts | 16 +----
.../services/reminder/reminderList.spec.ts | 70 +++++++++++++------
.../src/app/services/reminder/reminderList.ts | 10 +--
28 files changed, 114 insertions(+), 75 deletions(-)
diff --git a/services/core/businessconfig/src/main/java/org/lfenergy/operatorfabric/businessconfig/model/ProcessStatesData.java b/services/core/businessconfig/src/main/java/org/lfenergy/operatorfabric/businessconfig/model/ProcessStatesData.java
index ecacb721de..5366373e0a 100644
--- a/services/core/businessconfig/src/main/java/org/lfenergy/operatorfabric/businessconfig/model/ProcessStatesData.java
+++ b/services/core/businessconfig/src/main/java/org/lfenergy/operatorfabric/businessconfig/model/ProcessStatesData.java
@@ -27,7 +27,6 @@ public class ProcessStatesData implements ProcessStates {
private String color;
private String name;
private String userCardTemplate;
- private Long secondsBeforeTimeSpanForReminder;
@Override
public void setDetails(List extends Detail> details) {
diff --git a/services/core/businessconfig/src/main/modeling/swagger.yaml b/services/core/businessconfig/src/main/modeling/swagger.yaml
index e621ffd515..53f220db8f 100755
--- a/services/core/businessconfig/src/main/modeling/swagger.yaml
+++ b/services/core/businessconfig/src/main/modeling/swagger.yaml
@@ -404,9 +404,6 @@ definitions:
userCardTemplate:
type: string
description : Name of the template to use when creating a new card
- secondsBeforeTimeSpanForReminder:
- type: long
- description : Seconds before start date in timespan to activate a remind.
uiVisibility:
type: object
properties:
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/LightCardReadConverter.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/LightCardReadConverter.java
index 37034688a0..20d90667cc 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/LightCardReadConverter.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/configuration/mongo/LightCardReadConverter.java
@@ -7,8 +7,6 @@
* This file is part of the OperatorFabric project.
*/
-
-
package org.lfenergy.operatorfabric.cards.consultation.configuration.mongo;
import lombok.extern.slf4j.Slf4j;
@@ -23,26 +21,27 @@
import java.util.List;
/**
- * Spring converter registered in mongo conversions
- * Converts {@link Document} to {@link LightCard} using {@link LightCardConsultationData} builder.
+ *
+ * Spring converter registered in mongo conversions
+ *
+ *
+ * Converts {@link Document} to {@link LightCard} using
+ * {@link LightCardConsultationData} builder.
+ *
*
*/
@Slf4j
public class LightCardReadConverter implements Converter {
private I18nReadConverter i18nReadConverter = new I18nReadConverter();
private TimeSpanReadConverter timeSpanConverter = new TimeSpanReadConverter();
+
@Override
public LightCardConsultationData convert(Document source) {
LightCardConsultationData.LightCardConsultationDataBuilder builder = LightCardConsultationData.builder();
- builder
- .publisher(source.getString("publisher"))
- .parentCardId(source.getString("parentCardId"))
+ builder.publisher(source.getString("publisher")).parentCardId(source.getString("parentCardId"))
.initialParentCardUid(source.getString("initialParentCardUid"))
- .processVersion(source.getString("processVersion"))
- .uid(source.getString("uid"))
- .id(source.getString("_id"))
- .process(source.getString("process"))
- .state(source.getString("state"))
+ .processVersion(source.getString("processVersion")).uid(source.getString("uid"))
+ .id(source.getString("_id")).process(source.getString("process")).state(source.getString("state"))
.processInstanceId(source.getString("processInstanceId"))
.lttd(source.getDate("lttd") == null ? null : source.getDate("lttd").toInstant())
.startDate(source.getDate("startDate") == null ? null : source.getDate("startDate").toInstant())
@@ -51,14 +50,14 @@ public LightCardConsultationData convert(Document source) {
.severity(SeverityEnum.valueOf(source.getString("severity")))
.usersAcks(source.getList("usersAcks", String.class))
.publisherType(PublisherTypeEnum.valueOf(source.getString("publisherType")))
- ;
+ .secondsBeforeTimeSpanForReminder(source.getInteger("secondsBeforeTimeSpanForReminder"));
Document titleDoc = (Document) source.get("title");
- if(titleDoc!=null)
+ if (titleDoc != null)
builder.title(i18nReadConverter.convert(titleDoc));
Document summaryDoc = (Document) source.get("summary");
- if(summaryDoc!=null)
+ if (summaryDoc != null)
builder.summary(i18nReadConverter.convert(summaryDoc));
List tags = (List) source.get("tags");
@@ -67,7 +66,7 @@ public LightCardConsultationData convert(Document source) {
builder.tag(t);
}
List entitiesAllowedToRespond = (List) source.get("entitiesAllowedToRespond");
- if (entitiesAllowedToRespond != null){
+ if (entitiesAllowedToRespond != null) {
for (String entities : entitiesAllowedToRespond) {
builder.tag(entities);
}
@@ -75,7 +74,7 @@ public LightCardConsultationData convert(Document source) {
List timeSpans = (List) source.get("timeSpans");
if (timeSpans != null)
for (Document d : timeSpans) {
- builder.timeSpan((TimeSpanConsultationData)timeSpanConverter.convert(d));
+ builder.timeSpan((TimeSpanConsultationData) timeSpanConverter.convert(d));
}
return builder.build();
}
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/ArchivedCardConsultationData.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/ArchivedCardConsultationData.java
index cbf3917c6c..9d4ea0cf36 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/ArchivedCardConsultationData.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/ArchivedCardConsultationData.java
@@ -101,4 +101,5 @@ public class ArchivedCardConsultationData implements Card {
@Transient
private Boolean hasBeenRead;
private PublisherTypeEnum publisherType;
+ private Integer secondsBeforeTimeSpanForReminder;
}
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/CardConsultationData.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/CardConsultationData.java
index f7472affda..3434b6ad0a 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/CardConsultationData.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/CardConsultationData.java
@@ -102,6 +102,7 @@ public class CardConsultationData implements Card {
@Transient
private Boolean hasBeenRead;
private PublisherTypeEnum publisherType;
+ private Integer secondsBeforeTimeSpanForReminder;
}
diff --git a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/LightCardConsultationData.java b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/LightCardConsultationData.java
index ea14d14e6a..58a625c707 100644
--- a/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/LightCardConsultationData.java
+++ b/services/core/cards-consultation/src/main/java/org/lfenergy/operatorfabric/cards/consultation/model/LightCardConsultationData.java
@@ -77,6 +77,8 @@ public class LightCardConsultationData implements LightCard {
private PublisherTypeEnum publisherType;
+ private Integer secondsBeforeTimeSpanForReminder;
+
/**
* return timespans, may return null
* @return
@@ -119,6 +121,7 @@ public static LightCardConsultationData copy(Card other) {
.hasBeenRead(other.getHasBeenRead())
.entitiesAllowedToRespond(other.getEntitiesAllowedToRespond())
.publisherType(other.getPublisherType())
+ .secondsBeforeTimeSpanForReminder(other.getSecondsBeforeTimeSpanForReminder());
;
if(other.getTags()!=null && ! other.getTags().isEmpty())
builder.tags(other.getTags());
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/ArchivedCardPublicationData.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/ArchivedCardPublicationData.java
index e32b129707..8bf69662da 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/ArchivedCardPublicationData.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/ArchivedCardPublicationData.java
@@ -86,6 +86,8 @@ public class ArchivedCardPublicationData implements Card {
private PublisherTypeEnum publisherType;
+ private Integer secondsBeforeTimeSpanForReminder;
+
public ArchivedCardPublicationData(CardPublicationData card){
this.id = card.getUid();
this.parentCardId = card.getParentCardId();
@@ -115,6 +117,7 @@ public ArchivedCardPublicationData(CardPublicationData card){
this.entitiesAllowedToRespond = card.getEntitiesAllowedToRespond() == null ? null : new ArrayList<>(card.getEntitiesAllowedToRespond());
this.processStateKey = process + "." + state;
this.publisherType = card.getPublisherType();
+ this.secondsBeforeTimeSpanForReminder = card.getSecondsBeforeTimeSpanForReminder();
}
}
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
index 0840db06aa..c405f38442 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/CardPublicationData.java
@@ -128,6 +128,8 @@ public class CardPublicationData implements Card {
@Builder.Default
private PublisherTypeEnum publisherType = PublisherTypeEnum.EXTERNAL;
+ private Integer secondsBeforeTimeSpanForReminder;
+
public void prepare(Instant publishDate) {
this.publishDate = publishDate;
this.id = process + "." + processInstanceId;
@@ -159,6 +161,7 @@ public LightCardPublicationData toLightCard() {
.title(((I18nPublicationData) this.getTitle()).copy())
.summary(((I18nPublicationData) this.getSummary()).copy())
.publisherType(this.getPublisherType())
+ .secondsBeforeTimeSpanForReminder(this.secondsBeforeTimeSpanForReminder);
;
if(this.getTimeSpans()!=null)
result.timeSpansSet(new HashSet<>(this.getTimeSpans()));
diff --git a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/LightCardPublicationData.java b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/LightCardPublicationData.java
index 3da103f02f..5cfceb500d 100644
--- a/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/LightCardPublicationData.java
+++ b/services/core/cards-publication/src/main/java/org/lfenergy/operatorfabric/cards/publication/model/LightCardPublicationData.java
@@ -78,6 +78,8 @@ public class LightCardPublicationData implements LightCard {
private PublisherTypeEnum publisherType;
+ private Integer secondsBeforeTimeSpanForReminder;
+
/**
* return timespans, may be null
* @return
diff --git a/services/core/cards-publication/src/main/modeling/swagger.yaml b/services/core/cards-publication/src/main/modeling/swagger.yaml
index 2afe5b436a..1cbbee0af6 100755
--- a/services/core/cards-publication/src/main/modeling/swagger.yaml
+++ b/services/core/cards-publication/src/main/modeling/swagger.yaml
@@ -409,7 +409,9 @@ definitions:
type: boolean
description: Is true if the card was read by current user
publisherType:
- $ref: '#/definitions/PublisherTypeEnum'
+ $ref: '#/definitions/PublisherTypeEnum'
+ secondsBeforeTimeSpanForReminder:
+ type: integer
required:
- publisher
- process
@@ -575,6 +577,8 @@ definitions:
description: The uid of the initial parent card if it's a child card (optional). When a card is updated, its id is still the same but not its uid, that's why we store this field initialParentCardUid.
publisherType:
$ref: '#/definitions/PublisherTypeEnum'
+ secondsBeforeTimeSpanForReminder:
+ type: integer
required:
- uid
- id
diff --git a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/CardProcessServiceShould.java b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/CardProcessServiceShould.java
index ab7110e611..a2fe2796a4 100644
--- a/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/CardProcessServiceShould.java
+++ b/services/core/cards-publication/src/test/java/org/lfenergy/operatorfabric/cards/publication/services/CardProcessServiceShould.java
@@ -368,6 +368,7 @@ void preserveData() {
.process("process1")
.state("state1")
.publisherType(PublisherTypeEnum.EXTERNAL)
+ .secondsBeforeTimeSpanForReminder(new Integer(1000))
.build();
cardProcessingService.processCards(Flux.just(newCard)).subscribe();
CardPublicationData persistedCard = cardRepository.findById(newCard.getId()).block();
diff --git a/src/docs/asciidoc/reference_doc/card_notification.adoc b/src/docs/asciidoc/reference_doc/card_notification.adoc
index 9bfe84da63..a517c5b41a 100644
--- a/src/docs/asciidoc/reference_doc/card_notification.adoc
+++ b/src/docs/asciidoc/reference_doc/card_notification.adoc
@@ -29,7 +29,6 @@ To offer the possibility for the user to acknowledged card, it has to be configu
For certain process and state, it is possible to configure a reminder. The reminder "reactivate" the card in the feed at a certain time before the beginning of the start date of the first timeSpan of the card. "Reactivate" means set the card to the status "unread" and "unacknowledged".
-The time for "reactivation" is defined with the parameter "secondsBeforeTimeSpanForReminder" in the definition of the state of the concerned process.
-You can see an example in /src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
+The time for "reactivation" is defined with the parameter "secondsBeforeTimeSpanForReminder" in the card .
This function is experimental and not production ready yet.
\ No newline at end of file
diff --git a/src/test/api/karate/businessconfig/getABusinessconfig.feature b/src/test/api/karate/businessconfig/getABusinessconfig.feature
index 73edd58a51..93766f38d8 100644
--- a/src/test/api/karate/businessconfig/getABusinessconfig.feature
+++ b/src/test/api/karate/businessconfig/getABusinessconfig.feature
@@ -16,7 +16,7 @@ Feature: Bundle
And match response.uiVisibility.monitoring == true
And match response.uiVisibility.logging == true
And match response.uiVisibility.calendar == true
- And match response.states.messageState.secondsBeforeTimeSpanForReminder == 500
+
Scenario: check bundle without authentication
diff --git a/src/test/api/karate/businessconfig/resources/bundle_api_test/config.json b/src/test/api/karate/businessconfig/resources/bundle_api_test/config.json
index e8ff6af255..d8185a5e1a 100644
--- a/src/test/api/karate/businessconfig/resources/bundle_api_test/config.json
+++ b/src/test/api/karate/businessconfig/resources/bundle_api_test/config.json
@@ -8,7 +8,6 @@
},
"states":{
"messageState" : {
- "secondsBeforeTimeSpanForReminder" : 500,
"details" : [{
"title" : { "key" : "detail.title"},
"templateName" : "template",
diff --git a/src/test/api/karate/businessconfig/resources/bundle_api_test_v2/config.json b/src/test/api/karate/businessconfig/resources/bundle_api_test_v2/config.json
index 630724b6f9..fee4199b3f 100644
--- a/src/test/api/karate/businessconfig/resources/bundle_api_test_v2/config.json
+++ b/src/test/api/karate/businessconfig/resources/bundle_api_test_v2/config.json
@@ -8,7 +8,6 @@
},
"states":{
"messageState" : {
- "secondsBeforeTimeSpanForReminder" : 500,
"details" : [{
"title" : { "key" : "detail.title"},
"templateName" : "template",
diff --git a/src/test/api/karate/cards/cardsWithTimespans.feature b/src/test/api/karate/cards/cardsWithTimespans.feature
index 8cb383d0c5..ed130f0bc1 100644
--- a/src/test/api/karate/cards/cardsWithTimespans.feature
+++ b/src/test/api/karate/cards/cardsWithTimespans.feature
@@ -21,6 +21,7 @@ Feature: Cards with timespans
"summary" : {"key" : "defaultProcess.summary"},
"title" : {"key" : "defaultProcess.title"},
"data" : {"message":"a message"},
+ "secondsBeforeTimeSpanForReminder" :1000,
"timeSpans" : [
{"start" : 1553186770681 ,"end" :1553186770682 , "recurrence" :
{
@@ -52,6 +53,7 @@ Feature: Cards with timespans
And match response.card.data.message == 'a message'
And match response.card.timeSpans[0].start == 1553186770681
And match response.card.timeSpans[0].end == 1553186770682
+ And match response.card.secondsBeforeTimeSpanForReminder == 1000
And match response.card.timeSpans[0].recurrence.timeZone == "test"
And match response.card.timeSpans[0].recurrence.daysOfWeek[1] == 3
And match response.card.timeSpans[0].recurrence.hoursAndMinutes[1].hours == 12
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
index 1717e51253..b6087c00fb 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/config.json
@@ -27,7 +27,6 @@
"name": "conference.title",
"color": "#FAF0AF",
"userCardTemplate": "usercard_conference",
- "secondsBeforeTimeSpanForReminder": 300,
"details": [
{
"title": {
@@ -61,7 +60,6 @@
"name": "task.title",
"color": "#8bcdcd",
"userCardTemplate": "usercard_task",
- "secondsBeforeTimeSpanForReminder" : 300,
"details": [
{
"title": {
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_conference.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_conference.handlebars
index 87346bb383..bdcb7a7e3e 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_conference.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_conference.handlebars
@@ -57,6 +57,7 @@
const card = {
summary : {key : "conference.summary"},
title : {key : "conference.title"},
+ secondsBeforeTimeSpanForReminder: 300,
data : {
message: message,
conf_subject:conf_subject,
diff --git a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
index 04f7906ec6..4fab3de1c7 100644
--- a/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
+++ b/src/test/utils/karate/businessconfig/resources/bundle_userCardExamples/template/en/usercard_task.handlebars
@@ -25,7 +25,9 @@ Repeat every :
At :
H
- Min
+ Min , remind the task
+
+ minutes before.