mirror of
https://github.com/valitydev/adapter-flow-lib.git
synced 2024-11-06 00:05:22 +00:00
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:
parent
c6c9ff11fe
commit
ed09f7e71f
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>adapter-flow-lib</artifactId>
|
<artifactId>adapter-flow-lib</artifactId>
|
||||||
<version>0.1.18</version>
|
<version>0.1.19</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>adapter-flow-lib</name>
|
<name>adapter-flow-lib</name>
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,28 +1,7 @@
|
|||||||
package dev.vality.adapter.flow.lib.service;
|
package dev.vality.adapter.flow.lib.service;
|
||||||
|
|
||||||
import dev.vality.bender.BenderSrv;
|
public interface IdGenerator {
|
||||||
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
|
Long get(String invoiceId);
|
||||||
public class 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
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class HandlerConfig {
|
|||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public IdGenerator idGenerator(BenderSrv.Iface iface) {
|
public IdGenerator idGenerator(BenderSrv.Iface iface) {
|
||||||
return new IdGenerator(iface);
|
return new BenderGenerator(iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
Loading…
Reference in New Issue
Block a user