From ed09f7e71f6eead422aee4f9e008d2ba1f3be5a8 Mon Sep 17 00:00:00 2001 From: Inal Arsanukaev Date: Tue, 15 Nov 2022 17:45:15 +0300 Subject: [PATCH] Make IdGenerator interface (#51) * Make IdGenerator interface * Bump version * Added BenderGenerator * Added @Override Co-authored-by: Inal Arsanukaev --- pom.xml | 2 +- .../flow/lib/service/BenderGenerator.java | 29 +++++++++++++++++++ .../adapter/flow/lib/service/IdGenerator.java | 25 ++-------------- .../flow/lib/flow/config/HandlerConfig.java | 2 +- 4 files changed, 33 insertions(+), 25 deletions(-) create mode 100644 src/main/java/dev/vality/adapter/flow/lib/service/BenderGenerator.java diff --git a/pom.xml b/pom.xml index 9d11feb..be40bac 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ adapter-flow-lib - 0.1.18 + 0.1.19 jar adapter-flow-lib diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/BenderGenerator.java b/src/main/java/dev/vality/adapter/flow/lib/service/BenderGenerator.java new file mode 100644 index 0000000..27a8468 --- /dev/null +++ b/src/main/java/dev/vality/adapter/flow/lib/service/BenderGenerator.java @@ -0,0 +1,29 @@ +package dev.vality.adapter.flow.lib.service; + +import dev.vality.bender.BenderSrv; +import dev.vality.bender.GenerationResult; +import dev.vality.bender.GenerationSchema; +import dev.vality.bender.SequenceSchema; +import dev.vality.msgpack.Nil; +import dev.vality.msgpack.Value; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; + +@RequiredArgsConstructor +public class BenderGenerator implements IdGenerator { + + private static final String SEQ_ID = "orderId"; + + private final BenderSrv.Iface benderClient; + + @org.springframework.beans.factory.annotation.Value("adapter.prefix") + private String adapterPrefix; + + @SneakyThrows + @Override + public Long get(String invoiceId) { + GenerationSchema schema = GenerationSchema.sequence(new SequenceSchema().setSequenceId(SEQ_ID)); + GenerationResult result = benderClient.generateID(adapterPrefix + invoiceId, schema, Value.nl(new Nil())); + return Long.parseLong(result.getInternalId()); + } +} diff --git a/src/main/java/dev/vality/adapter/flow/lib/service/IdGenerator.java b/src/main/java/dev/vality/adapter/flow/lib/service/IdGenerator.java index b9f2ff7..8a48f6b 100644 --- a/src/main/java/dev/vality/adapter/flow/lib/service/IdGenerator.java +++ b/src/main/java/dev/vality/adapter/flow/lib/service/IdGenerator.java @@ -1,28 +1,7 @@ package dev.vality.adapter.flow.lib.service; -import dev.vality.bender.BenderSrv; -import dev.vality.bender.GenerationResult; -import dev.vality.bender.GenerationSchema; -import dev.vality.bender.SequenceSchema; -import dev.vality.msgpack.Nil; -import dev.vality.msgpack.Value; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; +public interface IdGenerator { -@RequiredArgsConstructor -public class IdGenerator { + Long get(String invoiceId); - private static final String SEQ_ID = "orderId"; - - private final BenderSrv.Iface benderClient; - - @org.springframework.beans.factory.annotation.Value("adapter.prefix") - private String adapterPrefix; - - @SneakyThrows - public Long get(String invoiceId) { - GenerationSchema schema = GenerationSchema.sequence(new SequenceSchema().setSequenceId(SEQ_ID)); - GenerationResult result = benderClient.generateID(adapterPrefix + invoiceId, schema, Value.nl(new Nil())); - return Long.parseLong(result.getInternalId()); - } } diff --git a/src/test/java/dev/vality/adapter/flow/lib/flow/config/HandlerConfig.java b/src/test/java/dev/vality/adapter/flow/lib/flow/config/HandlerConfig.java index e70949e..cf003ab 100644 --- a/src/test/java/dev/vality/adapter/flow/lib/flow/config/HandlerConfig.java +++ b/src/test/java/dev/vality/adapter/flow/lib/flow/config/HandlerConfig.java @@ -42,7 +42,7 @@ public class HandlerConfig { @Bean public IdGenerator idGenerator(BenderSrv.Iface iface) { - return new IdGenerator(iface); + return new BenderGenerator(iface); } @Bean