Make IdGenerator interface (#51)

* Make IdGenerator interface

* Bump version

* Added BenderGenerator

* Added @Override

Co-authored-by: Inal Arsanukaev <aiz@empayre.com>
This commit is contained in:
Inal Arsanukaev 2022-11-15 17:45:15 +03:00 committed by GitHub
parent c6c9ff11fe
commit ed09f7e71f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 25 deletions

View File

@ -12,7 +12,7 @@
</parent>
<artifactId>adapter-flow-lib</artifactId>
<version>0.1.18</version>
<version>0.1.19</version>
<packaging>jar</packaging>
<name>adapter-flow-lib</name>

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -42,7 +42,7 @@ public class HandlerConfig {
@Bean
public IdGenerator idGenerator(BenderSrv.Iface iface) {
return new IdGenerator(iface);
return new BenderGenerator(iface);
}
@Bean