diff --git a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/UserGroupCdcService.java b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/UserGroupCdcService.java index 3964281d..c3cd24a9 100644 --- a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/UserGroupCdcService.java +++ b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/UserGroupCdcService.java @@ -15,7 +15,6 @@ import io.quarkus.runtime.Startup; import io.quarkus.runtime.configuration.ConfigUtils; import io.smallrye.mutiny.Multi; -import io.smallrye.mutiny.Uni; import it.pagopa.selfcare.user.client.EventHubRestClient; import it.pagopa.selfcare.user.event.entity.UserGroupEntity; import it.pagopa.selfcare.user.event.mapper.UserGroupNotificationMapper; @@ -30,16 +29,17 @@ import org.eclipse.microprofile.rest.client.inject.RestClient; import java.time.Duration; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Objects; import static com.mongodb.client.model.Projections.fields; import static com.mongodb.client.model.Projections.include; import static it.pagopa.selfcare.user.UserUtils.mapPropsForTrackEvent; import static it.pagopa.selfcare.user.event.constant.CdcStartAtConstant.*; -import static it.pagopa.selfcare.user.model.TrackEventInput.toTrackEventInput; import static it.pagopa.selfcare.user.model.TrackEventInput.toTrackEventInputForUserGroup; import static it.pagopa.selfcare.user.model.constants.EventsMetric.*; -import static it.pagopa.selfcare.user.model.constants.EventsName.EVENT_USER_CDC_NAME; import static it.pagopa.selfcare.user.model.constants.EventsName.EVENT_USER_GROUP_CDC_NAME; import static java.util.Arrays.asList; diff --git a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/DateCodec.java b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/DateCodec.java new file mode 100644 index 00000000..14634e81 --- /dev/null +++ b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/DateCodec.java @@ -0,0 +1,37 @@ +package it.pagopa.selfcare.user.event.config; + +import org.bson.BsonReader; +import org.bson.BsonTimestamp; +import org.bson.BsonType; +import org.bson.BsonWriter; +import org.bson.codecs.Codec; +import org.bson.codecs.DecoderContext; +import org.bson.codecs.EncoderContext; + +import java.time.Instant; + +public class DateCodec implements Codec { + + @Override + public Instant decode(BsonReader reader, DecoderContext decoderContext) { + BsonType currentType = reader.getCurrentBsonType(); + if (currentType.equals(BsonType.DATE_TIME)) { + return Instant.ofEpochMilli(reader.readDateTime()); + } else if (currentType.equals(BsonType.TIMESTAMP)) { + BsonTimestamp timestamp = reader.readTimestamp(); + return Instant.ofEpochSecond(timestamp.getTime() / 1000, timestamp.getInc() * 1000L); + } + return null; + } + + + @Override + public void encode(BsonWriter bsonWriter, Instant aLong, EncoderContext encoderContext) { + + } + + @Override + public Class getEncoderClass() { + return Instant.class; + } +} \ No newline at end of file diff --git a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/MongoConfig.java b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/MongoConfig.java new file mode 100644 index 00000000..2b3228b6 --- /dev/null +++ b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/MongoConfig.java @@ -0,0 +1,20 @@ +package it.pagopa.selfcare.user.event.config; + +import jakarta.enterprise.context.ApplicationScoped; + +import jakarta.enterprise.inject.Produces; +import org.bson.codecs.configuration.CodecRegistries; +import org.bson.codecs.configuration.CodecRegistry; +import com.mongodb.MongoClientSettings; + +@ApplicationScoped +public class MongoConfig { + + @Produces + public CodecRegistry produceCodecRegistry() { + CodecRegistry defaultCodecRegistry = MongoClientSettings.getDefaultCodecRegistry(); + CodecRegistry customCodecRegistry = CodecRegistries.fromCodecs(new DateCodec()); + + return CodecRegistries.fromRegistries(customCodecRegistry, defaultCodecRegistry); + } +} diff --git a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/entity/UserGroupEntity.java b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/entity/UserGroupEntity.java index d1994d87..6e3687e6 100644 --- a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/entity/UserGroupEntity.java +++ b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/entity/UserGroupEntity.java @@ -4,18 +4,23 @@ import io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntity; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; import lombok.experimental.FieldNameConstants; +import org.bson.types.ObjectId; import java.time.Instant; import java.util.Set; @EqualsAndHashCode(callSuper = true) @Data +@Getter +@Setter @MongoEntity(collection = "userGroups") @FieldNameConstants(asEnum = true) public class UserGroupEntity extends ReactivePanacheMongoEntity { - private String id; + private ObjectId id; private String institutionId; private String productId; private String name; diff --git a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/UserGroupNotificationMapper.java b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/UserGroupNotificationMapper.java index f22d38cf..d0c8fe7c 100644 --- a/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/UserGroupNotificationMapper.java +++ b/apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/mapper/UserGroupNotificationMapper.java @@ -3,9 +3,11 @@ import it.pagopa.selfcare.user.event.entity.UserGroupEntity; import it.pagopa.selfcare.user.model.UserGroupNotificationToSend; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; @Mapper(componentModel = "cdi") public interface UserGroupNotificationMapper { + @Mapping(target = "id", expression = "java(userGroupEntity.getId().toString())") UserGroupNotificationToSend toUserGroupNotificationToSend(UserGroupEntity userGroupEntity); } diff --git a/apps/user-group-cdc/src/main/resources/application.properties b/apps/user-group-cdc/src/main/resources/application.properties index 85dc252f..1026d48b 100644 --- a/apps/user-group-cdc/src/main/resources/application.properties +++ b/apps/user-group-cdc/src/main/resources/application.properties @@ -18,4 +18,4 @@ user-group-cdc.retry=${USER_GROUP_CDC-RETRY:3} quarkus.rest-client.event-hub.url=${EVENT_HUB_BASE_PATH:test} eventhub.rest-client.keyName=${SHARED_ACCESS_KEY_NAME:test} -eventhub.rest-client.key=${EVENTHUB-SC-USERS-GROUP-SELFCARE-WO-KEY-LC:test} \ No newline at end of file +eventhub.rest-client.key=${EVENTHUB-SC-USER-GROUPS-SELFCARE-WO-KEY-LC:test} \ No newline at end of file diff --git a/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/UserUtils.java b/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/UserUtils.java index d9975c66..01eaf6f5 100644 --- a/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/UserUtils.java +++ b/libs/user-sdk-event/src/main/java/it/pagopa/selfcare/user/UserUtils.java @@ -62,6 +62,7 @@ public static Map mapPropsForTrackEvent(TrackEventInput trackEve Optional.ofNullable(trackEventInput.getProductId()).ifPresent(value -> propertiesMap.put("productId", value)); Optional.ofNullable(trackEventInput.getInstitutionId()).ifPresent(value -> propertiesMap.put("institutionId", value)); Optional.ofNullable(trackEventInput.getProductRole()).ifPresent(value -> propertiesMap.put("productRole", value)); + Optional.ofNullable(trackEventInput.getGroupMembers()).ifPresent(value -> propertiesMap.put("groupMembers", value.toString())); Optional.ofNullable(trackEventInput.getException()).ifPresent(value -> propertiesMap.put("exec", value)); return propertiesMap; }