-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SELC-5740] Fix: Added custom code to parse different format of date (#…
…199)
- Loading branch information
1 parent
ca3ce97
commit cd8647b
Showing
8 changed files
with
70 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/DateCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Instant> { | ||
|
||
@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(), timestamp.getInc()); | ||
} | ||
return null; | ||
} | ||
|
||
|
||
@Override | ||
public void encode(BsonWriter bsonWriter, Instant aLong, EncoderContext encoderContext) { | ||
|
||
} | ||
|
||
@Override | ||
public Class<Instant> getEncoderClass() { | ||
return Instant.class; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
apps/user-group-cdc/src/main/java/it/pagopa/selfcare/user/event/config/MongoConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters