diff --git a/pom.xml b/pom.xml
index 7dc4d5f..82b822c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -124,17 +124,16 @@
dev.vality
damsel
- 1.652-ecf4977
dev.vality
fistful-proto
- 1.179-54f1d58
+ 1.180-8b04c7f
dev.vality
swag-wallets-webhook-events
- 1.38-719220c-server
+ 1.50-5299faf-epic-BG-165-server
com.google.guava
diff --git a/src/main/java/dev/vality/wallets/hooker/converter/DestinationToDestinationMessageConverter.java b/src/main/java/dev/vality/wallets/hooker/converter/DestinationToDestinationMessageConverter.java
index 809c4ad..82558f1 100644
--- a/src/main/java/dev/vality/wallets/hooker/converter/DestinationToDestinationMessageConverter.java
+++ b/src/main/java/dev/vality/wallets/hooker/converter/DestinationToDestinationMessageConverter.java
@@ -17,6 +17,7 @@ public dev.vality.swag.wallets.webhook.events.model.Destination convert(Destinat
var destination = new dev.vality.swag.wallets.webhook.events.model.Destination();
destination.setExternalID(event.getExternalId());
destination.setName(event.getName());
+ destination.setParty(event.getPartyId());
// todo metadata null?
destination.setMetadata(null);
log.info("destinationDamsel has been converted, destination={}", destination);
diff --git a/src/main/java/dev/vality/wallets/hooker/converter/ResourceToJsonStringDestinationConverter.java b/src/main/java/dev/vality/wallets/hooker/converter/ResourceToJsonStringDestinationConverter.java
index 9861daa..88ee7e2 100644
--- a/src/main/java/dev/vality/wallets/hooker/converter/ResourceToJsonStringDestinationConverter.java
+++ b/src/main/java/dev/vality/wallets/hooker/converter/ResourceToJsonStringDestinationConverter.java
@@ -24,7 +24,7 @@ public String convert(Resource resource) {
case BANK_CARD:
BankCard bankCard = new BankCard();
ResourceBankCard resourceBankCard = resource.getBankCard();
- bankCard.setType(DestinationResource.TypeEnum.BANKCARD);
+ bankCard.setType(DestinationResource.TypeEnum.BANK_CARD);
bankCard.bin(resourceBankCard.getBankCard().getBin());
bankCard.cardNumberMask(resourceBankCard.getBankCard().getMaskedPan());
if (resourceBankCard.getBankCard().getPaymentSystem() != null) {
@@ -33,7 +33,7 @@ public String convert(Resource resource) {
return JsonUtil.toString(bankCard);
case CRYPTO_WALLET:
CryptoWallet cryptoWallet = new CryptoWallet();
- cryptoWallet.setType(DestinationResource.TypeEnum.CRYPTOWALLET);
+ cryptoWallet.setType(DestinationResource.TypeEnum.CRYPTO_WALLET);
ResourceCryptoWallet resourceCryptoWallet = resource.getCryptoWallet();
cryptoWallet.setCryptoWalletId(resourceCryptoWallet.getCryptoWallet().getId());
cryptoWallet.setCurrency(
@@ -47,7 +47,7 @@ public String convert(Resource resource) {
var swagDigitalWallet = resource.getDigitalWallet().getDigitalWallet();
digitalWallet.setDigitalWalletId(swagDigitalWallet.getId());
digitalWallet.setDigitalWalletProvider(swagDigitalWallet.getPaymentService().getId());
- digitalWallet.setType(DestinationResource.TypeEnum.DIGITALWALLET);
+ digitalWallet.setType(DestinationResource.TypeEnum.DIGITAL_WALLET);
return JsonUtil.toString(digitalWallet);
case GENERIC:
return initGenericType(resource);
diff --git a/src/main/java/dev/vality/wallets/hooker/converter/WebHookConverter.java b/src/main/java/dev/vality/wallets/hooker/converter/WebHookConverter.java
index 11c4f1f..6d69f84 100644
--- a/src/main/java/dev/vality/wallets/hooker/converter/WebHookConverter.java
+++ b/src/main/java/dev/vality/wallets/hooker/converter/WebHookConverter.java
@@ -1,12 +1,11 @@
package dev.vality.wallets.hooker.converter;
-import dev.vality.wallets.hooker.dao.identity.IdentityKeyDao;
+import dev.vality.wallets.hooker.dao.party.PartyKeyDao;
import dev.vality.wallets.hooker.dao.webhook.WebHookToEventsDao;
-import dev.vality.wallets.hooker.utils.WebHookConverterUtils;
import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.IdentityKey;
import dev.vality.wallets.hooker.domain.tables.pojos.Webhook;
import dev.vality.wallets.hooker.domain.tables.pojos.WebhookToEvents;
+import dev.vality.wallets.hooker.utils.WebHookConverterUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.convert.converter.Converter;
@@ -20,12 +19,12 @@
@Slf4j
public class WebHookConverter implements Converter {
- private final IdentityKeyDao identityKeyDao;
+ private final PartyKeyDao partyKeyDao;
private final WebHookToEventsDao webHookToEventsDao;
@Override
public dev.vality.fistful.webhooker.Webhook convert(Webhook webhook) {
- IdentityKey identityKey = identityKeyDao.getByIdentity(webhook.getIdentityId());
+ var partyKey = partyKeyDao.getByParty(webhook.getPartyId());
Set eventTypes = webHookToEventsDao.get(webhook.getId()).stream()
.map(WebhookToEvents::getEventType)
.collect(Collectors.toSet());
@@ -33,9 +32,9 @@ public dev.vality.fistful.webhooker.Webhook convert(Webhook webhook) {
var webhookDamsel = new dev.vality.fistful.webhooker.Webhook();
webhookDamsel.setId(webhook.getId());
webhookDamsel.setEnabled(webhook.getEnabled());
- webhookDamsel.setIdentityId(webhook.getIdentityId());
+ webhookDamsel.setPartyId(webhook.getPartyId());
webhookDamsel.setWalletId(webhook.getWalletId());
- webhookDamsel.setPubKey(identityKey.getPubKey());
+ webhookDamsel.setPubKey(partyKey.getPubKey());
webhookDamsel.setUrl(webhook.getUrl());
webhookDamsel.setEventFilter(WebHookConverterUtils.generateEventFilter(eventTypes));
diff --git a/src/main/java/dev/vality/wallets/hooker/converter/WebHookModelToWebHookConverter.java b/src/main/java/dev/vality/wallets/hooker/converter/WebHookModelToWebHookConverter.java
index 66df937..0dbdd08 100644
--- a/src/main/java/dev/vality/wallets/hooker/converter/WebHookModelToWebHookConverter.java
+++ b/src/main/java/dev/vality/wallets/hooker/converter/WebHookModelToWebHookConverter.java
@@ -18,7 +18,7 @@ public Webhook convert(WebHookModel event) {
Webhook webhook = new Webhook();
webhook.setId(event.getId());
webhook.setEnabled(event.getEnabled());
- webhook.setIdentityId(event.getIdentityId());
+ webhook.setPartyId(event.getPartyId());
webhook.setWalletId(event.getWalletId());
webhook.setPubKey(event.getPubKey());
webhook.setEventFilter(WebHookConverterUtils.generateEventFilter(event.getEventTypes()));
diff --git a/src/main/java/dev/vality/wallets/hooker/converter/WebHookParamsToWebHookConverter.java b/src/main/java/dev/vality/wallets/hooker/converter/WebHookParamsToWebHookConverter.java
index 1321edb..4afd37c 100644
--- a/src/main/java/dev/vality/wallets/hooker/converter/WebHookParamsToWebHookConverter.java
+++ b/src/main/java/dev/vality/wallets/hooker/converter/WebHookParamsToWebHookConverter.java
@@ -16,7 +16,7 @@ public class WebHookParamsToWebHookConverter implements Converter listRecordRowMapper;
-
- public DestinationReferenceDaoImpl(DataSource dataSource) {
- super(dataSource);
- this.listRecordRowMapper =
- new RecordRowMapper<>(DESTINATION_IDENTITY_REFERENCE, DestinationIdentityReference.class);
- }
-
- @Override
- public void create(DestinationIdentityReference reference) {
- InsertReturningStep insertReturningStep = getDslContext()
- .insertInto(DESTINATION_IDENTITY_REFERENCE)
- .set(getDslContext()
- .newRecord(DESTINATION_IDENTITY_REFERENCE, reference))
- .onConflict(DESTINATION_IDENTITY_REFERENCE.DESTINATION_ID)
- .doNothing();
- execute(insertReturningStep);
-
- log.info("destinationIdentityReference has been created, destinationIdentityReference={} ",
- reference.toString());
- }
-
- @Override
- public DestinationIdentityReference get(String id) {
- DestinationIdentityReference reference = fetchOne(getDslContext()
- .select(DESTINATION_IDENTITY_REFERENCE.DESTINATION_ID,
- DESTINATION_IDENTITY_REFERENCE.IDENTITY_ID,
- DESTINATION_IDENTITY_REFERENCE.EVENT_ID,
- DESTINATION_IDENTITY_REFERENCE.EXTERNAL_ID)
- .from(DESTINATION_IDENTITY_REFERENCE)
- .where(DESTINATION_IDENTITY_REFERENCE.DESTINATION_ID.eq(id)),
- listRecordRowMapper);
-
- if (reference != null) {
- log.info("destinationIdentityReference has been got, destinationIdentityReference={}",
- reference.toString());
- }
-
- return reference;
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDao.java b/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDao.java
deleted file mode 100644
index 2eb57fc..0000000
--- a/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDao.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package dev.vality.wallets.hooker.dao.identity;
-
-import dev.vality.wallets.hooker.domain.tables.pojos.IdentityKey;
-
-public interface IdentityKeyDao {
-
- void create(IdentityKey identityKey);
-
- IdentityKey get(Long id);
-
- IdentityKey getByIdentity(String identityId);
-
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDaoImpl.java
deleted file mode 100644
index d6b8958..0000000
--- a/src/main/java/dev/vality/wallets/hooker/dao/identity/IdentityKeyDaoImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package dev.vality.wallets.hooker.dao.identity;
-
-import dev.vality.mapper.RecordRowMapper;
-import dev.vality.wallets.hooker.dao.AbstractDao;
-import dev.vality.wallets.hooker.domain.tables.pojos.IdentityKey;
-import dev.vality.wallets.hooker.domain.tables.records.IdentityKeyRecord;
-import org.jooq.InsertReturningStep;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-
-import static dev.vality.wallets.hooker.domain.tables.IdentityKey.IDENTITY_KEY;
-
-@Component
-public class IdentityKeyDaoImpl extends AbstractDao implements IdentityKeyDao {
-
- private final RowMapper listRecordRowMapper;
-
- public IdentityKeyDaoImpl(DataSource dataSource) {
- super(dataSource);
- this.listRecordRowMapper = new RecordRowMapper<>(IDENTITY_KEY, IdentityKey.class);
- }
-
- @Override
- public void create(IdentityKey identityKey) {
- InsertReturningStep identityKeyRecordInsertReturningStep = getDslContext()
- .insertInto(IDENTITY_KEY)
- .set(getDslContext()
- .newRecord(IDENTITY_KEY, identityKey))
- .onConflict(IDENTITY_KEY.IDENTITY_ID)
- .doNothing();
- execute(identityKeyRecordInsertReturningStep);
- }
-
- @Override
- public IdentityKey get(Long id) {
- return fetchOne(getDslContext()
- .select(IDENTITY_KEY.ID, IDENTITY_KEY.IDENTITY_ID, IDENTITY_KEY.PUB_KEY, IDENTITY_KEY.PRIV_KEY)
- .from(IDENTITY_KEY)
- .where(IDENTITY_KEY.ID.eq(id)),
- listRecordRowMapper);
- }
-
- @Override
- public IdentityKey getByIdentity(String identityId) {
- return fetchOne(getDslContext()
- .select(IDENTITY_KEY.ID, IDENTITY_KEY.IDENTITY_ID, IDENTITY_KEY.PUB_KEY, IDENTITY_KEY.PRIV_KEY)
- .from(IDENTITY_KEY)
- .where(IDENTITY_KEY.IDENTITY_ID.eq(identityId)),
- listRecordRowMapper);
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDao.java b/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDao.java
new file mode 100644
index 0000000..92175ff
--- /dev/null
+++ b/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDao.java
@@ -0,0 +1,13 @@
+package dev.vality.wallets.hooker.dao.party;
+
+import dev.vality.wallets.hooker.domain.tables.pojos.PartyKey;
+
+public interface PartyKeyDao {
+
+ void create(PartyKey partyKey);
+
+ PartyKey get(Long id);
+
+ PartyKey getByParty(String partyId);
+
+}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDaoImpl.java
new file mode 100644
index 0000000..b5f01e4
--- /dev/null
+++ b/src/main/java/dev/vality/wallets/hooker/dao/party/PartyKeyDaoImpl.java
@@ -0,0 +1,51 @@
+package dev.vality.wallets.hooker.dao.party;
+
+import dev.vality.mapper.RecordRowMapper;
+import dev.vality.wallets.hooker.dao.AbstractDao;
+import dev.vality.wallets.hooker.domain.tables.pojos.PartyKey;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Component;
+
+import javax.sql.DataSource;
+
+import static dev.vality.wallets.hooker.domain.tables.PartyKey.PARTY_KEY;
+
+@Component
+public class PartyKeyDaoImpl extends AbstractDao implements PartyKeyDao {
+
+ private final RowMapper listRecordRowMapper;
+
+ public PartyKeyDaoImpl(DataSource dataSource) {
+ super(dataSource);
+ this.listRecordRowMapper = new RecordRowMapper<>(PARTY_KEY, PartyKey.class);
+ }
+
+ @Override
+ public void create(PartyKey partyKey) {
+ var insertPartyKey = getDslContext()
+ .insertInto(PARTY_KEY)
+ .set(getDslContext()
+ .newRecord(PARTY_KEY, partyKey))
+ .onConflict(PARTY_KEY.PARTY_ID)
+ .doNothing();
+ execute(insertPartyKey);
+ }
+
+ @Override
+ public PartyKey get(Long id) {
+ return fetchOne(getDslContext()
+ .select(PARTY_KEY.ID, PARTY_KEY.PARTY_ID, PARTY_KEY.PUB_KEY, PARTY_KEY.PRIV_KEY)
+ .from(PARTY_KEY)
+ .where(PARTY_KEY.ID.eq(id)),
+ listRecordRowMapper);
+ }
+
+ @Override
+ public PartyKey getByParty(String partyId) {
+ return fetchOne(getDslContext()
+ .select(PARTY_KEY.ID, PARTY_KEY.PARTY_ID, PARTY_KEY.PUB_KEY, PARTY_KEY.PRIV_KEY)
+ .from(PARTY_KEY)
+ .where(PARTY_KEY.PARTY_ID.eq(partyId)),
+ listRecordRowMapper);
+ }
+}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDao.java b/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDao.java
deleted file mode 100644
index 30e5e3c..0000000
--- a/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDao.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package dev.vality.wallets.hooker.dao.wallet;
-
-import dev.vality.wallets.hooker.domain.tables.pojos.WalletIdentityReference;
-
-public interface WalletReferenceDao {
-
- void create(WalletIdentityReference reference);
-
- WalletIdentityReference get(String id);
-
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImpl.java
deleted file mode 100644
index 092af9a..0000000
--- a/src/main/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImpl.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package dev.vality.wallets.hooker.dao.wallet;
-
-import dev.vality.mapper.RecordRowMapper;
-import dev.vality.wallets.hooker.dao.AbstractDao;
-import dev.vality.wallets.hooker.domain.tables.pojos.WalletIdentityReference;
-import dev.vality.wallets.hooker.domain.tables.records.WalletIdentityReferenceRecord;
-import lombok.extern.slf4j.Slf4j;
-import org.jooq.InsertReturningStep;
-import org.springframework.jdbc.core.RowMapper;
-import org.springframework.stereotype.Component;
-
-import javax.sql.DataSource;
-
-import static dev.vality.wallets.hooker.domain.tables.WalletIdentityReference.WALLET_IDENTITY_REFERENCE;
-
-@Component
-@Slf4j
-public class WalletReferenceDaoImpl extends AbstractDao implements WalletReferenceDao {
-
- private final RowMapper listRecordRowMapper;
-
- public WalletReferenceDaoImpl(DataSource dataSource) {
- super(dataSource);
- this.listRecordRowMapper = new RecordRowMapper<>(WALLET_IDENTITY_REFERENCE, WalletIdentityReference.class);
- }
-
- @Override
- public void create(WalletIdentityReference reference) {
- InsertReturningStep insertReturningStep = getDslContext()
- .insertInto(WALLET_IDENTITY_REFERENCE)
- .set(getDslContext()
- .newRecord(WALLET_IDENTITY_REFERENCE, reference))
- .onConflict(WALLET_IDENTITY_REFERENCE.WALLET_ID)
- .doNothing();
- execute(insertReturningStep);
-
- log.info("walletIdentityReference has been created, walletIdentityReference={} ", reference.toString());
- }
-
- @Override
- public WalletIdentityReference get(String id) {
- WalletIdentityReference walletIdentityReference = fetchOne(getDslContext()
- .select(WALLET_IDENTITY_REFERENCE.WALLET_ID, WALLET_IDENTITY_REFERENCE.IDENTITY_ID)
- .from(WALLET_IDENTITY_REFERENCE)
- .where(WALLET_IDENTITY_REFERENCE.WALLET_ID.eq(id)),
- listRecordRowMapper);
-
- if (walletIdentityReference != null) {
- log.info("walletIdentityReference has been got, walletIdentityReference={}",
- walletIdentityReference.toString());
- }
-
- return walletIdentityReference;
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDao.java b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDao.java
index 85b3c04..cd92c87 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDao.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDao.java
@@ -14,9 +14,7 @@ public interface WebHookDao {
WebHookModel getById(long id);
- List getModelByIdentityAndWalletId(String identityId, String walletId, EventType eventType);
+ List getByParty(String partyId);
- List getByIdentity(String identityId);
-
- List getByIdentityAndEventType(String identityId, EventType eventType);
+ List getByPartyAndEventType(String partyId, EventType eventType);
}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImpl.java
index a0bbf82..b6a02c2 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImpl.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImpl.java
@@ -1,26 +1,23 @@
package dev.vality.wallets.hooker.dao.webhook;
+import com.zaxxer.hikari.HikariDataSource;
import dev.vality.mapper.RecordRowMapper;
import dev.vality.wallets.hooker.dao.AbstractDao;
-import dev.vality.wallets.hooker.dao.condition.ConditionParameterSource;
-import dev.vality.wallets.hooker.dao.identity.IdentityKeyDao;
+import dev.vality.wallets.hooker.dao.party.PartyKeyDao;
import dev.vality.wallets.hooker.dao.webhook.mapper.WebHookModelRowMapper;
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.IdentityKey;
+import dev.vality.wallets.hooker.domain.tables.pojos.PartyKey;
import dev.vality.wallets.hooker.domain.tables.pojos.Webhook;
import dev.vality.wallets.hooker.domain.tables.pojos.WebhookToEvents;
import dev.vality.wallets.hooker.domain.tables.records.WebhookRecord;
import dev.vality.wallets.hooker.service.crypt.KeyPair;
import dev.vality.wallets.hooker.service.crypt.Signer;
-import com.zaxxer.hikari.HikariDataSource;
import dev.vality.wallets.hooker.utils.LogUtils;
import lombok.extern.slf4j.Slf4j;
-import org.jooq.Operator;
import org.jooq.Query;
import org.jooq.Record7;
import org.jooq.SelectOnConditionStep;
-import org.jooq.impl.DSL;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
@@ -29,10 +26,9 @@
import java.util.List;
import java.util.stream.Collectors;
-import static dev.vality.wallets.hooker.domain.tables.IdentityKey.IDENTITY_KEY;
+import static dev.vality.wallets.hooker.domain.tables.PartyKey.PARTY_KEY;
import static dev.vality.wallets.hooker.domain.tables.Webhook.WEBHOOK;
import static dev.vality.wallets.hooker.domain.tables.WebhookToEvents.WEBHOOK_TO_EVENTS;
-import static org.jooq.Comparator.EQUALS;
@Component
@Slf4j
@@ -42,37 +38,36 @@ public class WebHookDaoImpl extends AbstractDao implements WebHookDao {
private final RowMapper webhookRowMapper;
private final RowMapper webHookModelRowMapper;
private final WebHookToEventsDao webHookToEventsDao;
- private final IdentityKeyDao identityKeyDao;
+ private final PartyKeyDao partyKeyDao;
private final Signer signer;
@Autowired
- public WebHookDaoImpl(HikariDataSource dataSource, WebHookToEventsDao webHookToEventsDao,
- IdentityKeyDao identityKeyDao,
+ public WebHookDaoImpl(HikariDataSource dataSource,
+ WebHookToEventsDao webHookToEventsDao,
+ PartyKeyDao partyKeyDao,
Signer signer) {
super(dataSource);
this.webHookToEventsDao = webHookToEventsDao;
- this.identityKeyDao = identityKeyDao;
this.signer = signer;
this.webhookRowMapper = new RecordRowMapper<>(WEBHOOK, Webhook.class);
this.webHookModelRowMapper = new WebHookModelRowMapper();
+ this.partyKeyDao = partyKeyDao;
}
@Override
public Webhook create(WebHookModel webHookModel) {
- String identityId = webHookModel.getIdentityId();
+ String partyId = webHookModel.getPartyId();
- IdentityKey identityKey = identityKeyDao.getByIdentity(identityId);
+ var partyKey = partyKeyDao.getByParty(partyId);
- if (identityKey == null) {
+ if (partyKey == null) {
+ partyKey = new PartyKey();
+ partyKey.setPartyId(partyId);
KeyPair keyPair = signer.generateKeys();
- String publKey = keyPair.getPublKey();
-
- identityKey = new IdentityKey();
- identityKey.setIdentityId(identityId);
- identityKey.setPubKey(publKey);
- identityKey.setPrivKey(keyPair.getPrivKey());
+ partyKey.setPubKey(keyPair.getPublKey());
+ partyKey.setPrivKey(keyPair.getPrivKey());
- identityKeyDao.create(identityKey);
+ partyKeyDao.create(partyKey);
}
WebhookRecord record = getDslContext().newRecord(WEBHOOK, webHookModel);
@@ -83,7 +78,7 @@ public Webhook create(WebHookModel webHookModel) {
.doNothing()
.returning(
WEBHOOK.ID,
- WEBHOOK.IDENTITY_ID,
+ WEBHOOK.PARTY_ID,
WEBHOOK.ENABLED,
WEBHOOK.URL,
WEBHOOK.WALLET_ID
@@ -116,15 +111,15 @@ public WebHookModel getById(long id) {
Query query = getDslContext()
.select(
WEBHOOK.ID,
- WEBHOOK.IDENTITY_ID,
+ WEBHOOK.PARTY_ID,
WEBHOOK.ENABLED,
WEBHOOK.URL,
WEBHOOK.WALLET_ID,
- IDENTITY_KEY.PUB_KEY,
- IDENTITY_KEY.PRIV_KEY
+ PARTY_KEY.PUB_KEY,
+ PARTY_KEY.PRIV_KEY
)
.from(WEBHOOK)
- .leftJoin(IDENTITY_KEY).on(WEBHOOK.IDENTITY_ID.eq(IDENTITY_KEY.IDENTITY_ID))
+ .leftJoin(PARTY_KEY).on(WEBHOOK.PARTY_ID.eq(PARTY_KEY.PARTY_ID))
.where(WEBHOOK.ID.eq(id));
WebHookModel webHookModel = fetchOne(query, webHookModelRowMapper);
@@ -136,59 +131,42 @@ public WebHookModel getById(long id) {
.collect(Collectors.toSet())
);
- log.info("webhook has been got, webHookModel={} ", webHookModel.toString());
+ log.info("webhook has been got, webHookModel={} ", webHookModel);
}
return webHookModel;
}
- @Override
- public List getModelByIdentityAndWalletId(String identityId, String walletId, EventType eventType) {
- Query query = createSelectForWebHookModel()
- .where(
- appendConditions(
- DSL.trueCondition(),
- Operator.AND,
- new ConditionParameterSource()
- .addValue(WEBHOOK.IDENTITY_ID, identityId, EQUALS)
- .addValue(WEBHOOK.WALLET_ID, walletId, EQUALS)
- )
- )
- .and(WEBHOOK_TO_EVENTS.EVENT_TYPE.eq(eventType))
- .limit(LIMIT);
- return getWebHookModels(query);
- }
-
private SelectOnConditionStep<
Record7> createSelectForWebHookModel() {
return getDslContext()
.select(
WEBHOOK.ID,
- WEBHOOK.IDENTITY_ID,
+ WEBHOOK.PARTY_ID,
WEBHOOK.ENABLED,
WEBHOOK.URL,
WEBHOOK.WALLET_ID,
- IDENTITY_KEY.PUB_KEY,
- IDENTITY_KEY.PRIV_KEY
+ PARTY_KEY.PUB_KEY,
+ PARTY_KEY.PRIV_KEY
)
.from(WEBHOOK)
.leftJoin(WEBHOOK_TO_EVENTS).on(WEBHOOK.ID.eq(WEBHOOK_TO_EVENTS.HOOK_ID))
- .leftJoin(IDENTITY_KEY).on(WEBHOOK.IDENTITY_ID.eq(IDENTITY_KEY.IDENTITY_ID));
+ .leftJoin(PARTY_KEY).on(WEBHOOK.PARTY_ID.eq(PARTY_KEY.PARTY_ID));
}
@Override
- public List getByIdentity(String identityId) {
+ public List getByParty(String partyId) {
Query query = getDslContext()
.selectFrom(WEBHOOK)
- .where(WEBHOOK.IDENTITY_ID.eq(identityId))
+ .where(WEBHOOK.PARTY_ID.eq(partyId))
.limit(LIMIT);
- return getSafeWebHook(query, () -> log.info("webhooks has been got, identityId={}", identityId));
+ return getSafeWebHook(query, () -> log.info("webhooks has been got, partyId={}", partyId));
}
@Override
- public List getByIdentityAndEventType(String identityId, EventType eventType) {
+ public List getByPartyAndEventType(String partyId, EventType eventType) {
Query query = createSelectForWebHookModel()
- .where(WEBHOOK.IDENTITY_ID.eq(identityId)
+ .where(WEBHOOK.PARTY_ID.eq(partyId)
.and(WEBHOOK_TO_EVENTS.EVENT_TYPE.eq(eventType)))
.limit(LIMIT);
return getWebHookModels(query);
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookToEventsDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookToEventsDaoImpl.java
index 8fbe4a7..6d57d1d 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookToEventsDaoImpl.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/webhook/WebHookToEventsDaoImpl.java
@@ -14,7 +14,6 @@
import javax.sql.DataSource;
import java.util.List;
-import static dev.vality.wallets.hooker.domain.tables.WalletIdentityReference.WALLET_IDENTITY_REFERENCE;
import static dev.vality.wallets.hooker.domain.tables.WebhookToEvents.WEBHOOK_TO_EVENTS;
@Component
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/webhook/mapper/WebHookModelRowMapper.java b/src/main/java/dev/vality/wallets/hooker/dao/webhook/mapper/WebHookModelRowMapper.java
index ad59e01..6bd92a0 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/webhook/mapper/WebHookModelRowMapper.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/webhook/mapper/WebHookModelRowMapper.java
@@ -6,7 +6,7 @@
import java.sql.ResultSet;
import java.sql.SQLException;
-import static dev.vality.wallets.hooker.domain.tables.IdentityKey.IDENTITY_KEY;
+import static dev.vality.wallets.hooker.domain.tables.PartyKey.PARTY_KEY;
import static dev.vality.wallets.hooker.domain.tables.Webhook.WEBHOOK;
public class WebHookModelRowMapper implements RowMapper {
@@ -15,13 +15,13 @@ public class WebHookModelRowMapper implements RowMapper {
public WebHookModel mapRow(ResultSet rs, int i) throws SQLException {
return WebHookModel.builder()
.id(rs.getLong(WEBHOOK.ID.getName()))
- .identityId(rs.getString(WEBHOOK.IDENTITY_ID.getName()))
+ .partyId(rs.getString(WEBHOOK.PARTY_ID.getName()))
.walletId(rs.getString(WEBHOOK.WALLET_ID.getName()))
.eventTypes(null)
.url(rs.getString(WEBHOOK.URL.getName()))
.enabled(rs.getBoolean(WEBHOOK.ENABLED.getName()))
- .pubKey(rs.getString(IDENTITY_KEY.PUB_KEY.getName()))
- .privateKey(rs.getString(IDENTITY_KEY.PRIV_KEY.getName()))
+ .pubKey(rs.getString(PARTY_KEY.PUB_KEY.getName()))
+ .privateKey(rs.getString(PARTY_KEY.PRIV_KEY.getName()))
.build();
}
}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDao.java b/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDao.java
index 401b1c0..d73b6ed 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDao.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDao.java
@@ -1,11 +1,11 @@
package dev.vality.wallets.hooker.dao.withdrawal;
-import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalIdentityWalletReference;
+import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalReference;
public interface WithdrawalReferenceDao {
- void create(WithdrawalIdentityWalletReference reference);
+ void create(WithdrawalReference reference);
- WithdrawalIdentityWalletReference get(String id);
+ WithdrawalReference get(String id);
}
diff --git a/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDaoImpl.java b/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDaoImpl.java
index b14e863..9dffc0d 100644
--- a/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDaoImpl.java
+++ b/src/main/java/dev/vality/wallets/hooker/dao/withdrawal/WithdrawalReferenceDaoImpl.java
@@ -2,60 +2,57 @@
import dev.vality.mapper.RecordRowMapper;
import dev.vality.wallets.hooker.dao.AbstractDao;
-import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalIdentityWalletReference;
-import dev.vality.wallets.hooker.domain.tables.records.WithdrawalIdentityWalletReferenceRecord;
+import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalReference;
import lombok.extern.slf4j.Slf4j;
-import org.jooq.InsertReturningStep;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
-import static dev.vality.wallets.hooker.domain.tables.WithdrawalIdentityWalletReference.WITHDRAWAL_IDENTITY_WALLET_REFERENCE;
+import static dev.vality.wallets.hooker.domain.tables.WithdrawalReference.WITHDRAWAL_REFERENCE;
@Component
@Slf4j
public class WithdrawalReferenceDaoImpl extends AbstractDao implements WithdrawalReferenceDao {
- private final RowMapper listRecordRowMapper;
+ private final RowMapper listRecordRowMapper;
public WithdrawalReferenceDaoImpl(DataSource dataSource) {
super(dataSource);
this.listRecordRowMapper =
- new RecordRowMapper<>(WITHDRAWAL_IDENTITY_WALLET_REFERENCE, WithdrawalIdentityWalletReference.class);
+ new RecordRowMapper<>(WITHDRAWAL_REFERENCE, WithdrawalReference.class);
}
@Override
- public void create(WithdrawalIdentityWalletReference reference) {
- InsertReturningStep insertReturningStep = getDslContext()
- .insertInto(WITHDRAWAL_IDENTITY_WALLET_REFERENCE)
+ public void create(WithdrawalReference reference) {
+ var insertReturningStep = getDslContext()
+ .insertInto(WITHDRAWAL_REFERENCE)
.set(getDslContext()
- .newRecord(WITHDRAWAL_IDENTITY_WALLET_REFERENCE, reference))
- .onConflict(WITHDRAWAL_IDENTITY_WALLET_REFERENCE.WITHDRAWAL_ID)
+ .newRecord(WITHDRAWAL_REFERENCE, reference))
+ .onConflict(WITHDRAWAL_REFERENCE.WITHDRAWAL_ID)
.doNothing();
execute(insertReturningStep);
-
- log.info("withdrawalIdentityWalletReference has been created, withdrawalIdentityWalletReference={} ",
+ log.info("WithdrawalReference has been created, withdrawalReference={} ",
reference.toString());
}
@Override
- public WithdrawalIdentityWalletReference get(String id) {
- WithdrawalIdentityWalletReference withdrawalIdentityWalletReference = fetchOne(getDslContext()
- .select(WITHDRAWAL_IDENTITY_WALLET_REFERENCE.WITHDRAWAL_ID,
- WITHDRAWAL_IDENTITY_WALLET_REFERENCE.WALLET_ID,
- WITHDRAWAL_IDENTITY_WALLET_REFERENCE.IDENTITY_ID,
- WITHDRAWAL_IDENTITY_WALLET_REFERENCE.EVENT_ID,
- WITHDRAWAL_IDENTITY_WALLET_REFERENCE.EXTERNAL_ID)
- .from(WITHDRAWAL_IDENTITY_WALLET_REFERENCE)
- .where(WITHDRAWAL_IDENTITY_WALLET_REFERENCE.WITHDRAWAL_ID.eq(id)),
+ public WithdrawalReference get(String id) {
+ var withdrawalReference = fetchOne(getDslContext()
+ .select(WITHDRAWAL_REFERENCE.WITHDRAWAL_ID,
+ WITHDRAWAL_REFERENCE.WALLET_ID,
+ WITHDRAWAL_REFERENCE.PARTY_ID,
+ WITHDRAWAL_REFERENCE.EVENT_ID,
+ WITHDRAWAL_REFERENCE.EXTERNAL_ID)
+ .from(WITHDRAWAL_REFERENCE)
+ .where(WITHDRAWAL_REFERENCE.WITHDRAWAL_ID.eq(id)),
listRecordRowMapper);
- if (withdrawalIdentityWalletReference != null) {
- log.info("withdrawalIdentityWalletReference has been got, withdrawalIdentityWalletReference={}",
- withdrawalIdentityWalletReference.toString());
+ if (withdrawalReference != null) {
+ log.info("withdrawalReference has been got, withdrawalReference={}",
+ withdrawalReference);
}
- return withdrawalIdentityWalletReference;
+ return withdrawalReference;
}
}
diff --git a/src/main/java/dev/vality/wallets/hooker/domain/WebHookModel.java b/src/main/java/dev/vality/wallets/hooker/domain/WebHookModel.java
index 41bd904..648fa45 100644
--- a/src/main/java/dev/vality/wallets/hooker/domain/WebHookModel.java
+++ b/src/main/java/dev/vality/wallets/hooker/domain/WebHookModel.java
@@ -15,7 +15,7 @@ public class WebHookModel {
@ToString.Include
private Long id;
@ToString.Include
- private String identityId;
+ private String partyId;
@ToString.Include
private String walletId;
@ToString.Include
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAccountChangeHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAccountChangeHandler.java
index 85aaeea..10fefc3 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAccountChangeHandler.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAccountChangeHandler.java
@@ -1,17 +1,12 @@
package dev.vality.wallets.hooker.handler.destination;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
import dev.vality.fistful.destination.AccountChange;
import dev.vality.fistful.destination.TimestampedChange;
import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.wallets.hooker.dao.destination.DestinationMessageDaoImpl;
-import dev.vality.wallets.hooker.dao.destination.DestinationReferenceDao;
import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.DestinationIdentityReference;
import dev.vality.wallets.hooker.domain.tables.pojos.DestinationMessage;
import dev.vality.wallets.hooker.exception.HandleEventException;
import dev.vality.wallets.hooker.handler.destination.generator.DestinationCreatedHookMessageGenerator;
@@ -22,23 +17,16 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
-import java.io.IOException;
-
@Slf4j
@Component
@RequiredArgsConstructor
public class DestinationAccountChangeHandler implements DestinationEventHandler {
- public static final String EXTERNAL_ID = "externalID";
-
- private final DestinationReferenceDao destinationReferenceDao;
private final DestinationMessageDaoImpl destinationMessageDao;
private final DestinationCreatedHookMessageGenerator destinationCreatedHookMessageGenerator;
private final WebHookDao webHookDao;
private final WebHookMessageSenderService webHookMessageSenderService;
- private final ObjectMapper objectMapper;
-
@Override
public boolean accept(TimestampedChange change) {
return change.getChange().isSetAccount()
@@ -50,15 +38,14 @@ public void handle(TimestampedChange change, MachineEvent event) {
try {
String destinationId = event.getSourceId();
AccountChange account = change.getChange().getAccount();
- String identityId = account.getCreated().getIdentity();
+ String partyId = account.getCreated().getPartyId();
- log.info("Start handling DestinationAccountCreatedChange: destinationId={}, identityId={}",
- destinationId, identityId);
+ log.info("Start handling DestinationAccountCreatedChange: destinationId={}, partyId={}",
+ destinationId, partyId);
DestinationMessage destinationMessage = destinationMessageDao.get(destinationId);
- createDestinationReference(event, identityId, getExternalId(destinationMessage));
- webHookDao.getByIdentityAndEventType(identityId, EventType.DESTINATION_CREATED)
+ webHookDao.getByPartyAndEventType(partyId, EventType.DESTINATION_CREATED)
.stream()
.map(webhook -> generateDestinationCreateHookMsg(
destinationMessage,
@@ -68,21 +55,15 @@ public void handle(TimestampedChange change, MachineEvent event) {
event.getCreatedAt()))
.forEach(webHookMessageSenderService::send);
- log.info("Finish handling DestinationAccountCreatedChange: destinationId={}, identityId={}",
- destinationId, identityId);
+ log.info("Finish handling DestinationAccountCreatedChange: destinationId={}, partyId={}",
+ destinationId, partyId);
- } catch (IOException e) {
+ } catch (Exception e) {
log.error("Error while handling DestinationAccountCreatedChange: {}", change, e);
throw new HandleEventException("Error while handling DestinationAccountCreatedChange", e);
}
}
- private String getExternalId(DestinationMessage destinationMessage) throws JsonProcessingException {
- JsonNode jsonNode = objectMapper.readTree(destinationMessage.getMessage());
- JsonNode externalID = jsonNode.get(EXTERNAL_ID);
- return externalID != null ? externalID.asText() : null;
- }
-
private WebhookMessage generateDestinationCreateHookMsg(
DestinationMessage destinationMessage,
WebHookModel webhook,
@@ -96,14 +77,4 @@ private WebhookMessage generateDestinationCreateHookMsg(
.build();
return destinationCreatedHookMessageGenerator.generate(destinationMessage, webhook, messageGenParams);
}
-
- private void createDestinationReference(MachineEvent event, String identityId, String externalID) {
- DestinationIdentityReference destinationIdentityReference = new DestinationIdentityReference();
- destinationIdentityReference.setDestinationId(event.getSourceId());
- destinationIdentityReference.setIdentityId(identityId);
- destinationIdentityReference.setEventId(String.valueOf(event.getEventId()));
- destinationIdentityReference.setExternalId(externalID);
-
- destinationReferenceDao.create(destinationIdentityReference);
- }
}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAuthorizedHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAuthorizedHandler.java
deleted file mode 100644
index 3995714..0000000
--- a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationAuthorizedHandler.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package dev.vality.wallets.hooker.handler.destination;
-
-import dev.vality.fistful.destination.StatusChange;
-import dev.vality.fistful.destination.TimestampedChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.wallets.hooker.dao.destination.DestinationReferenceDao;
-import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
-import dev.vality.wallets.hooker.domain.WebHookModel;
-import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.DestinationIdentityReference;
-import dev.vality.wallets.hooker.handler.destination.generator.DestinationStatusChangeHookMessageGenerator;
-import dev.vality.wallets.hooker.model.MessageGenParams;
-import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
-import dev.vality.webhook.dispatcher.WebhookMessage;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class DestinationAuthorizedHandler implements DestinationEventHandler {
-
- private final DestinationReferenceDao destinationReferenceDao;
- private final DestinationStatusChangeHookMessageGenerator destinationStatusChangeHookMessageGenerator;
- private final WebHookMessageSenderService webHookMessageSenderService;
- private final WebHookDao webHookDao;
-
- @Override
- public boolean accept(TimestampedChange change) {
- return change.getChange().isSetStatus()
- && change.getChange().getStatus().isSetChanged()
- && change.getChange().getStatus().getChanged().isSetAuthorized();
- }
-
- @Override
- public void handle(TimestampedChange change, MachineEvent event) {
- String destinationId = event.getSourceId();
- log.info("Start handling DestinationAuthorizedChange: destinationId={}", destinationId);
-
- DestinationIdentityReference destinationIdentityReference = destinationReferenceDao.get(destinationId);
-
- webHookDao.getByIdentityAndEventType(destinationIdentityReference.getIdentityId(),
- EventType.DESTINATION_AUTHORIZED)
- .stream()
- .map(webhook -> generateDestinationChangeHookMsg(
- change.getChange().getStatus(),
- webhook,
- event.getSourceId(),
- event.getEventId(),
- Long.valueOf(destinationIdentityReference.getEventId()),
- event.getCreatedAt(),
- destinationIdentityReference.getExternalId()))
- .forEach(webHookMessageSenderService::send);
-
- log.info("Finish handling DestinationAuthorizedChange: destinationId={}", destinationId);
- }
-
- private WebhookMessage generateDestinationChangeHookMsg(
- StatusChange status,
- WebHookModel webhook,
- String sourcedId,
- long eventId,
- Long parentId,
- String createdAt,
- String externalId) {
- MessageGenParams messageGenParams = MessageGenParams.builder()
- .sourceId(sourcedId)
- .eventId(eventId)
- .parentId(parentId)
- .createdAt(createdAt)
- .externalId(externalId)
- .build();
-
- return destinationStatusChangeHookMessageGenerator.generate(status, webhook, messageGenParams);
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationUnauthorizedHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationUnauthorizedHandler.java
deleted file mode 100644
index 7e81618..0000000
--- a/src/main/java/dev/vality/wallets/hooker/handler/destination/DestinationUnauthorizedHandler.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package dev.vality.wallets.hooker.handler.destination;
-
-import dev.vality.fistful.destination.StatusChange;
-import dev.vality.fistful.destination.TimestampedChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.wallets.hooker.dao.destination.DestinationReferenceDao;
-import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
-import dev.vality.wallets.hooker.domain.WebHookModel;
-import dev.vality.wallets.hooker.handler.destination.generator.DestinationStatusChangeHookMessageGenerator;
-import dev.vality.wallets.hooker.model.MessageGenParams;
-import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.DestinationIdentityReference;
-import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
-import dev.vality.webhook.dispatcher.WebhookMessage;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class DestinationUnauthorizedHandler implements DestinationEventHandler {
-
- private final DestinationReferenceDao destinationReferenceDao;
- private final DestinationStatusChangeHookMessageGenerator destinationStatusChangeHookMessageGenerator;
- private final WebHookMessageSenderService webHookMessageSenderService;
- private final WebHookDao webHookDao;
-
- @Override
- public boolean accept(TimestampedChange change) {
- return change.getChange().isSetStatus()
- && change.getChange().getStatus().isSetChanged()
- && change.getChange().getStatus().getChanged().isSetUnauthorized();
- }
-
- @Override
- public void handle(TimestampedChange change, MachineEvent event) {
- String destinationId = event.getSourceId();
- log.info("Start handling DestinationUnauthorizedChange: destinationId={}", destinationId);
-
- DestinationIdentityReference destinationIdentityReference = destinationReferenceDao.get(event.getSourceId());
-
- webHookDao.getByIdentityAndEventType(destinationIdentityReference.getIdentityId(),
- EventType.DESTINATION_UNAUTHORIZED)
- .stream()
- .map(webhook -> generateDestinationStatusChangeHookMsg(
- change.getChange().getStatus(),
- webhook,
- event.getSourceId(),
- event.getEventId(),
- Long.valueOf(destinationIdentityReference.getEventId()),
- event.getCreatedAt(),
- destinationIdentityReference.getExternalId()))
- .forEach(webHookMessageSenderService::send);
-
- log.info("Finish handling DestinationUnauthorizedChange: destinationId={}", destinationId);
- }
-
- private WebhookMessage generateDestinationStatusChangeHookMsg(
- StatusChange statusChange, WebHookModel webhook,
- String sourceId,
- long eventId,
- Long parentId,
- String createdAt,
- String externalId) {
- MessageGenParams messageGenParams = MessageGenParams.builder()
- .sourceId(sourceId)
- .eventId(eventId)
- .parentId(parentId)
- .createdAt(createdAt)
- .externalId(externalId)
- .build();
-
- return destinationStatusChangeHookMessageGenerator.generate(statusChange, webhook, messageGenParams);
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGenerator.java b/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGenerator.java
index aca324c..16e40e9 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGenerator.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGenerator.java
@@ -26,7 +26,7 @@
public class DestinationCreatedHookMessageGenerator extends BaseHookMessageGenerator {
public static final String DESTINATION = "destination";
- public static final String IDENTITY = "identity";
+ public static final String PARTY = "party";
private final WebHookMessageGeneratorServiceImpl generatorService;
private final ObjectMapper objectMapper;
private final AdditionalHeadersGenerator additionalHeadersGenerator;
@@ -48,14 +48,7 @@ protected WebhookMessage generateMessage(
WebHookModel model,
MessageGenParams messageGenParams) {
try {
- DestinationCreated destinationCreated = new DestinationCreated();
- destinationCreated.setEventID(messageGenParams.getEventId().toString());
- destinationCreated.setEventType(Event.EventTypeEnum.DESTINATIONCREATED);
- OffsetDateTime parse = OffsetDateTime.parse(
- messageGenParams.getCreatedAt(),
- DateTimeFormatter.ISO_DATE_TIME);
- destinationCreated.setOccuredAt(parse);
- destinationCreated.setTopic(Event.TopicEnum.DESTINATIONTOPIC);
+ DestinationCreated destinationCreated = buildDestinationCreated(messageGenParams);
String requestBody = objectMapper.writeValueAsString(destinationCreated);
String messageString = initResultMessage(event, model, requestBody);
@@ -66,7 +59,7 @@ protected WebhookMessage generateMessage(
webhookMessage.setEventId(messageGenParams.getEventId());
log.info("Webhook message from destination_event_created was generated, destinationId={}, model={}",
- messageGenParams.getSourceId(), model.toString());
+ messageGenParams.getSourceId(), model);
return webhookMessage;
} catch (Exception e) {
@@ -78,10 +71,22 @@ protected WebhookMessage generateMessage(
}
+ private DestinationCreated buildDestinationCreated(MessageGenParams messageGenParams) {
+ DestinationCreated destinationCreated = new DestinationCreated();
+ destinationCreated.setEventID(messageGenParams.getEventId().toString());
+ destinationCreated.setEventType(Event.EventTypeEnum.DESTINATION_CREATED);
+ OffsetDateTime parse = OffsetDateTime.parse(
+ messageGenParams.getCreatedAt(),
+ DateTimeFormatter.ISO_DATE_TIME);
+ destinationCreated.setOccuredAt(parse);
+ destinationCreated.setTopic(Event.TopicEnum.DESTINATION_TOPIC);
+ return destinationCreated;
+ }
+
private String initResultMessage(DestinationMessage event, WebHookModel model, String requestBody)
throws JsonProcessingException {
JsonNode jsonNodeRoot = objectMapper.readTree(event.getMessage());
- JsonNode resultDestinationNode = ((ObjectNode) jsonNodeRoot).put(IDENTITY, model.getIdentityId());
+ JsonNode resultDestinationNode = ((ObjectNode) jsonNodeRoot).put(PARTY, model.getPartyId());
JsonNode requestBodyJson = objectMapper.readTree(requestBody);
JsonNode messageResult = ((ObjectNode) requestBodyJson).set(DESTINATION, resultDestinationNode);
return objectMapper.writeValueAsString(messageResult);
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGenerator.java b/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGenerator.java
deleted file mode 100644
index e4fcf90..0000000
--- a/src/main/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGenerator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-package dev.vality.wallets.hooker.handler.destination.generator;
-
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import dev.vality.fistful.destination.StatusChange;
-import dev.vality.swag.wallets.webhook.events.model.DestinationAuthorized;
-import dev.vality.swag.wallets.webhook.events.model.DestinationUnauthorized;
-import dev.vality.swag.wallets.webhook.events.model.Event;
-import dev.vality.wallets.hooker.domain.WebHookModel;
-import dev.vality.wallets.hooker.exception.GenerateMessageException;
-import dev.vality.wallets.hooker.handler.AdditionalHeadersGenerator;
-import dev.vality.wallets.hooker.model.MessageGenParams;
-import dev.vality.wallets.hooker.service.WebHookMessageGeneratorServiceImpl;
-import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.service.BaseHookMessageGenerator;
-import dev.vality.webhook.dispatcher.WebhookMessage;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import java.time.OffsetDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.Map;
-
-@Slf4j
-@Component
-public class DestinationStatusChangeHookMessageGenerator extends BaseHookMessageGenerator {
-
- private final WebHookMessageGeneratorServiceImpl generatorService;
- private final ObjectMapper objectMapper;
- private final AdditionalHeadersGenerator additionalHeadersGenerator;
-
- public DestinationStatusChangeHookMessageGenerator(
- WebHookMessageGeneratorServiceImpl generatorService,
- ObjectMapper objectMapper, AdditionalHeadersGenerator additionalHeadersGenerator,
- @Value("${parent.not.exist.id}") Long parentId) {
- super(parentId);
- this.generatorService = generatorService;
- this.objectMapper = objectMapper;
- this.additionalHeadersGenerator = additionalHeadersGenerator;
- }
-
- @Override
- protected WebhookMessage generateMessage(
- StatusChange statusChange,
- WebHookModel model,
- MessageGenParams messageGenParams) {
- try {
- String message = generateMessage(
- statusChange,
- messageGenParams.getSourceId(),
- messageGenParams.getEventId(),
- messageGenParams.getCreatedAt(),
- messageGenParams.getExternalId());
-
- Map additionalHeaders = additionalHeadersGenerator.generate(model, message);
-
- WebhookMessage webhookMessage = generatorService.generate(statusChange, model, messageGenParams);
- webhookMessage.setParentEventId(initParentId(model, messageGenParams.getParentId()));
- webhookMessage.setAdditionalHeaders(additionalHeaders);
- webhookMessage.setRequestBody(message.getBytes());
-
- log.info(
- "Webhook message from destination_event_status_changed was generated, " +
- "destinationId={}, statusChange={}, model={}",
- messageGenParams.getSourceId(), statusChange.toString(), model.toString());
-
- return webhookMessage;
- } catch (Exception e) {
- log.error("Error when generate webhookMessage e: ", e);
- throw new GenerateMessageException("Error when generate webhookMessage", e);
- }
-
- }
-
- private String generateMessage(
- StatusChange statusChange,
- String destinationId,
- Long eventId,
- String createdAt,
- String externalId) throws JsonProcessingException {
-
- if (statusChange.getChanged().isSetAuthorized()) {
- DestinationAuthorized destination = new DestinationAuthorized();
- destination.setDestinationID(destinationId);
- destination.setEventID(eventId.toString());
- destination.setEventType(Event.EventTypeEnum.DESTINATIONAUTHORIZED);
- destination.setOccuredAt(OffsetDateTime.parse(createdAt, DateTimeFormatter.ISO_DATE_TIME));
- destination.setTopic(Event.TopicEnum.DESTINATIONTOPIC);
- destination.setExternalID(externalId);
- return objectMapper.writeValueAsString(destination);
- } else if (statusChange.getChanged().isSetUnauthorized()) {
- DestinationUnauthorized destination = new DestinationUnauthorized();
- destination.setDestinationID(destinationId);
- destination.setEventID(eventId.toString());
- destination.setEventType(Event.EventTypeEnum.DESTINATIONUNAUTHORIZED);
- destination.setOccuredAt(OffsetDateTime.parse(createdAt, DateTimeFormatter.ISO_DATE_TIME));
- destination.setTopic(Event.TopicEnum.DESTINATIONTOPIC);
- destination.setExternalID(externalId);
- return objectMapper.writeValueAsString(destination);
- } else {
- log.error("Unknown statusChange: {}", statusChange);
- throw new GenerateMessageException("Unknown statusChange!");
- }
- }
-
- private Long initParentId(WebHookModel model, Long parentId) {
- if (model.getEventTypes() != null && model.getEventTypes().contains(EventType.DESTINATION_CREATED)) {
- return parentId;
- }
-
- return parentIsNotExistId;
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletAccountCreatedHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletAccountCreatedHandler.java
deleted file mode 100644
index 778be95..0000000
--- a/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletAccountCreatedHandler.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package dev.vality.wallets.hooker.handler.wallet;
-
-import dev.vality.fistful.wallet.TimestampedChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.wallets.hooker.dao.wallet.WalletReferenceDao;
-import dev.vality.wallets.hooker.domain.tables.pojos.WalletIdentityReference;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class WalletAccountCreatedHandler implements WalletEventHandler {
-
- private final WalletReferenceDao walletReferenceDao;
-
- @Override
- public boolean accept(TimestampedChange change) {
- return change.getChange().isSetAccount()
- && change.getChange().getAccount().isSetCreated();
- }
-
- @Override
- public void handle(TimestampedChange change, MachineEvent event) {
- String walletId = event.getSourceId();
- String identityId = change.getChange().getAccount().getCreated().getIdentity();
-
- log.info("Start handling WalletAccountCreatedChange: walletId={}, identityId={}", walletId, identityId);
-
- WalletIdentityReference reference = new WalletIdentityReference();
- reference.setWalletId(walletId);
- reference.setIdentityId(identityId);
-
- walletReferenceDao.create(reference);
-
- log.info("Finish handling WalletAccountCreatedChange: walletId={}, identityId={}", walletId, identityId);
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletEventHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletEventHandler.java
deleted file mode 100644
index ee808ff..0000000
--- a/src/main/java/dev/vality/wallets/hooker/handler/wallet/WalletEventHandler.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package dev.vality.wallets.hooker.handler.wallet;
-
-import dev.vality.fistful.wallet.TimestampedChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.wallets.hooker.handler.EventHandler;
-
-public interface WalletEventHandler extends EventHandler {
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalChangeStatusHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalChangeStatusHandler.java
index 8d32d0b..1328f90 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalChangeStatusHandler.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalChangeStatusHandler.java
@@ -7,7 +7,7 @@
import dev.vality.wallets.hooker.dao.withdrawal.WithdrawalReferenceDao;
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalIdentityWalletReference;
+import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalReference;
import dev.vality.wallets.hooker.exception.HandleEventException;
import dev.vality.wallets.hooker.handler.withdrawal.generator.WithdrawalStatusChangedHookMessageGenerator;
import dev.vality.wallets.hooker.model.MessageGenParams;
@@ -37,10 +37,10 @@ public void handleChangeStatus(
String withdrawalId,
EventType eventType) {
try {
- WithdrawalIdentityWalletReference reference = waitReferenceWithdrawal(withdrawalId);
+ var reference = waitReferenceWithdrawal(withdrawalId);
Long parentId = Long.valueOf(reference.getEventId());
- webHookDao.getByIdentityAndEventType(reference.getIdentityId(), eventType).stream()
+ webHookDao.getByPartyAndEventType(reference.getPartyId(), eventType).stream()
.filter(webHook -> webHook.getWalletId() == null
|| webHook.getWalletId().equals(reference.getWalletId()))
.map(webhook -> generateWithdrawalStatusChangeHookMsg(
@@ -59,20 +59,20 @@ public void handleChangeStatus(
}
}
- private WithdrawalIdentityWalletReference waitReferenceWithdrawal(String withdrawalId) {
- WithdrawalIdentityWalletReference withdrawalIdentityWalletReference = withdrawalReferenceDao.get(withdrawalId);
- while (withdrawalIdentityWalletReference == null) {
+ private WithdrawalReference waitReferenceWithdrawal(String withdrawalId) {
+ var withdrawalReference = withdrawalReferenceDao.get(withdrawalId);
+ while (withdrawalReference == null) {
log.info("Waiting withdrawal create: '{}'", withdrawalId);
try {
Thread.sleep(waitingPollPeriod);
- withdrawalIdentityWalletReference = withdrawalReferenceDao.get(withdrawalId);
+ withdrawalReference = withdrawalReferenceDao.get(withdrawalId);
} catch (InterruptedException e) {
log.error("Error when waiting withdrawal create: {} e: ", withdrawalId, e);
Thread.currentThread().interrupt();
}
}
- return withdrawalIdentityWalletReference;
+ return withdrawalReference;
}
private WebhookMessage generateWithdrawalStatusChangeHookMsg(
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalCreatedHandler.java b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalCreatedHandler.java
index 88b9593..1bca230 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalCreatedHandler.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/WithdrawalCreatedHandler.java
@@ -3,15 +3,11 @@
import dev.vality.fistful.withdrawal.TimestampedChange;
import dev.vality.fistful.withdrawal.Withdrawal;
import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.wallets.hooker.dao.destination.DestinationReferenceDao;
-import dev.vality.wallets.hooker.dao.wallet.WalletReferenceDao;
import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
import dev.vality.wallets.hooker.dao.withdrawal.WithdrawalReferenceDao;
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.wallets.hooker.domain.tables.pojos.DestinationIdentityReference;
-import dev.vality.wallets.hooker.domain.tables.pojos.WalletIdentityReference;
-import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalIdentityWalletReference;
+import dev.vality.wallets.hooker.domain.tables.pojos.WithdrawalReference;
import dev.vality.wallets.hooker.exception.HandleEventException;
import dev.vality.wallets.hooker.handler.withdrawal.generator.WithdrawalCreatedHookMessageGenerator;
import dev.vality.wallets.hooker.model.MessageGenParams;
@@ -19,7 +15,6 @@
import dev.vality.webhook.dispatcher.WebhookMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.List;
@@ -29,12 +24,7 @@
@RequiredArgsConstructor
public class WithdrawalCreatedHandler implements WithdrawalEventHandler {
- @Value("${waiting.reference.period}")
- private int waitingPollPeriod;
-
private final WithdrawalReferenceDao withdrawalReferenceDao;
- private final DestinationReferenceDao destinationReferenceDao;
- private final WalletReferenceDao walletReferenceDao;
private final WebHookDao webHookDao;
private final WithdrawalCreatedHookMessageGenerator withdrawalCreatedHookMessageGenerator;
private final WebHookMessageSenderService webHookMessageSenderService;
@@ -52,41 +42,30 @@ public void handle(TimestampedChange change, MachineEvent event) {
String withdrawalId = event.getSourceId();
String destinationId = withdrawal.getDestinationId();
String walletId = withdrawal.getWalletId();
+ String partyId = withdrawal.getPartyId();
- log.info("Start handling WithdrawalCreatedChange: destinationId={}, withdrawal={}, walletId={}",
- destinationId, withdrawal, walletId);
-
- DestinationIdentityReference destinationIdentityReference = destinationReferenceDao.get(destinationId);
- WalletIdentityReference walletIdentityReference = walletReferenceDao.get(walletId);
-
- while (destinationIdentityReference == null || walletIdentityReference == null) {
- log.info("Waiting destination: {} or wallet: {} !", destinationId, walletId);
- try {
- Thread.sleep(waitingPollPeriod);
- destinationIdentityReference = destinationReferenceDao.get(destinationId);
- walletIdentityReference = walletReferenceDao.get(walletId);
- } catch (InterruptedException e) {
- log.error("Error when waiting destination: {} or wallet: {} e: ", destinationId, walletId, e);
- Thread.currentThread().interrupt();
- }
- }
-
+ log.info("Start handling WithdrawalCreatedChange: destinationId={}, withdrawal={}, walletId={}, partyId={}",
+ destinationId, withdrawal, walletId, partyId);
createReference(
withdrawal,
- destinationIdentityReference,
String.valueOf(eventId),
withdrawalId);
- findWebhookModels(destinationIdentityReference, walletIdentityReference)
+ List webHookModels = webHookDao.getByPartyAndEventType(
+ partyId,
+ EventType.WITHDRAWAL_CREATED);
+
+ MessageGenParams msgGenParams = MessageGenParams.builder()
+ .sourceId(withdrawalId)
+ .eventId(eventId)
+ .createdAt(event.getCreatedAt())
+ .externalId(withdrawal.getExternalId())
+ .build();
+
+ webHookModels
.stream()
.filter(webhook -> webhook.getWalletId() == null || webhook.getWalletId().equals(walletId))
- .map(webhook -> generateWithdrawalCreatedHookMsg(
- withdrawal,
- webhook,
- withdrawalId,
- eventId,
- event.getCreatedAt(),
- withdrawal.getExternalId()))
+ .map(webhook -> generateWithdrawalCreatedHookMsg(withdrawal, webhook, msgGenParams))
.forEach(webHookMessageSenderService::send);
log.info("Finish handling WithdrawalCreatedChange: destinationId={}, withdrawalId={}, walletId={}",
@@ -97,52 +76,24 @@ public void handle(TimestampedChange change, MachineEvent event) {
}
}
- private List findWebhookModels(
- DestinationIdentityReference destinationIdentityReference,
- WalletIdentityReference walletIdentityReference) {
- List webHookModels = webHookDao.getByIdentityAndEventType(
- destinationIdentityReference.getIdentityId(),
- EventType.WITHDRAWAL_CREATED);
-
- if (!destinationIdentityReference.getIdentityId().equals(walletIdentityReference.getIdentityId())) {
- List webHookModelsWallets = webHookDao.getByIdentityAndEventType(
- walletIdentityReference.getIdentityId(),
- EventType.WITHDRAWAL_CREATED);
- webHookModels.addAll(webHookModelsWallets);
- }
-
- return webHookModels;
- }
-
private void createReference(
Withdrawal withdrawal,
- DestinationIdentityReference destinationIdentityReference,
String eventId,
String withdrawalId) {
- WithdrawalIdentityWalletReference withdrawalIdentityWalletReference = new WithdrawalIdentityWalletReference();
- withdrawalIdentityWalletReference.setIdentityId(destinationIdentityReference.getIdentityId());
- withdrawalIdentityWalletReference.setWalletId(withdrawal.getWalletId());
- withdrawalIdentityWalletReference.setWithdrawalId(withdrawalId);
- withdrawalIdentityWalletReference.setEventId(eventId);
- withdrawalIdentityWalletReference.setExternalId(withdrawal.getExternalId());
-
- withdrawalReferenceDao.create(withdrawalIdentityWalletReference);
+ WithdrawalReference withdrawalReference = new WithdrawalReference();
+ withdrawalReference.setPartyId(withdrawal.getPartyId());
+ withdrawalReference.setWalletId(withdrawal.getWalletId());
+ withdrawalReference.setWithdrawalId(withdrawalId);
+ withdrawalReference.setEventId(eventId);
+ withdrawalReference.setExternalId(withdrawal.getExternalId());
+
+ withdrawalReferenceDao.create(withdrawalReference);
}
private WebhookMessage generateWithdrawalCreatedHookMsg(
Withdrawal withdrawal,
WebHookModel webhook,
- String withdrawalId,
- long eventId,
- String createdAt,
- String externalId) {
- MessageGenParams msgGenParams = MessageGenParams.builder()
- .sourceId(withdrawalId)
- .eventId(eventId)
- .createdAt(createdAt)
- .externalId(externalId)
- .build();
-
- return withdrawalCreatedHookMessageGenerator.generate(withdrawal, webhook, msgGenParams);
+ MessageGenParams messageGenParams) {
+ return withdrawalCreatedHookMessageGenerator.generate(withdrawal, webhook, messageGenParams);
}
}
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalCreatedHookMessageGenerator.java b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalCreatedHookMessageGenerator.java
index 18013d4..1a54045 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalCreatedHookMessageGenerator.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalCreatedHookMessageGenerator.java
@@ -51,12 +51,12 @@ protected WebhookMessage generateMessage(Withdrawal event, WebHookModel model, M
withdrawal.setExternalID(event.getExternalId());
WithdrawalStarted withdrawalStarted = new WithdrawalStarted();
withdrawalStarted.setWithdrawal(withdrawal);
- withdrawalStarted.setEventType(Event.EventTypeEnum.WITHDRAWALSTARTED);
+ withdrawalStarted.setEventType(Event.EventTypeEnum.WITHDRAWAL_STARTED);
withdrawalStarted.setEventID(messageGenParams.getEventId().toString());
withdrawalStarted.setOccuredAt(OffsetDateTime.parse(
messageGenParams.getCreatedAt(),
DateTimeFormatter.ISO_DATE_TIME));
- withdrawalStarted.setTopic(Event.TopicEnum.WITHDRAWALTOPIC);
+ withdrawalStarted.setTopic(Event.TopicEnum.WITHDRAWAL_TOPIC);
String requestBody = objectMapper.writeValueAsString(withdrawalStarted);
diff --git a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalStatusChangedHookMessageGenerator.java b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalStatusChangedHookMessageGenerator.java
index 65bbd70..7887277 100644
--- a/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalStatusChangedHookMessageGenerator.java
+++ b/src/main/java/dev/vality/wallets/hooker/handler/withdrawal/generator/WithdrawalStatusChangedHookMessageGenerator.java
@@ -91,19 +91,19 @@ private String initRequestBody(
WithdrawalFailed withdrawalFailed = new WithdrawalFailed()
.withdrawalID(withdrawalId)
.externalID(externalId);
- withdrawalFailed.setEventType(Event.EventTypeEnum.WITHDRAWALFAILED);
+ withdrawalFailed.setEventType(Event.EventTypeEnum.WITHDRAWAL_FAILED);
withdrawalFailed.setEventID(eventId.toString());
withdrawalFailed.setOccuredAt(OffsetDateTime.parse(createdAt, DateTimeFormatter.ISO_DATE_TIME));
- withdrawalFailed.setTopic(Event.TopicEnum.WITHDRAWALTOPIC);
+ withdrawalFailed.setTopic(Event.TopicEnum.WITHDRAWAL_TOPIC);
return objectMapper.writeValueAsString(withdrawalFailed);
} else if (status.isSetSucceeded()) {
WithdrawalSucceeded withdrawalSucceeded = new WithdrawalSucceeded()
.withdrawalID(withdrawalId)
.externalID(externalId);
- withdrawalSucceeded.setEventType(Event.EventTypeEnum.WITHDRAWALSUCCEEDED);
+ withdrawalSucceeded.setEventType(Event.EventTypeEnum.WITHDRAWAL_SUCCEEDED);
withdrawalSucceeded.setEventID(eventId.toString());
withdrawalSucceeded.setOccuredAt(OffsetDateTime.parse(createdAt));
- withdrawalSucceeded.setTopic(Event.TopicEnum.WITHDRAWALTOPIC);
+ withdrawalSucceeded.setTopic(Event.TopicEnum.WITHDRAWAL_TOPIC);
return objectMapper.writeValueAsString(withdrawalSucceeded);
} else {
log.error("Unknown WithdrawalStatus status: {} withdrawalId: {}", status, withdrawalId);
diff --git a/src/main/java/dev/vality/wallets/hooker/kafka/listener/WalletEventListener.java b/src/main/java/dev/vality/wallets/hooker/kafka/listener/WalletEventListener.java
deleted file mode 100644
index a90ce58..0000000
--- a/src/main/java/dev/vality/wallets/hooker/kafka/listener/WalletEventListener.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package dev.vality.wallets.hooker.kafka.listener;
-
-import dev.vality.machinegun.eventsink.SinkEvent;
-import dev.vality.wallets.hooker.service.kafka.WalletEventService;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.kafka.annotation.KafkaListener;
-import org.springframework.kafka.support.Acknowledgment;
-import org.springframework.kafka.support.KafkaHeaders;
-import org.springframework.messaging.handler.annotation.Header;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-import static java.util.stream.Collectors.toList;
-
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class WalletEventListener {
-
- private final WalletEventService walletEventService;
-
- @KafkaListener(
- autoStartup = "${kafka.topic.wallet.listener.enabled}",
- topics = "${kafka.topic.wallet.name}",
- containerFactory = "walletEventListenerContainerFactory")
- public void listen(
- List batch,
- @Header(KafkaHeaders.RECEIVED_PARTITION) int partition,
- @Header(KafkaHeaders.OFFSET) int offset,
- Acknowledgment ack) {
- log.info("Listening Wallet: partition={}, offset={}, batch.size()={}", partition, offset, batch.size());
- walletEventService.handleEvents(batch.stream().map(SinkEvent::getEvent).collect(toList()));
- ack.acknowledge();
- log.info("Ack Wallet: partition={}, offset={}", partition, offset);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeDeserializer.java b/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeDeserializer.java
deleted file mode 100644
index ebb40e1..0000000
--- a/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeDeserializer.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package dev.vality.wallets.hooker.kafka.serde;
-
-import dev.vality.fistful.wallet.TimestampedChange;
-import dev.vality.sink.common.serialization.impl.AbstractThriftBinaryDeserializer;
-import org.springframework.stereotype.Service;
-
-@Service
-public class WalletChangeDeserializer extends AbstractThriftBinaryDeserializer {
-
- @Override
- public TimestampedChange deserialize(byte[] bin) {
- return deserialize(bin, new TimestampedChange());
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeMachineEventParser.java b/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeMachineEventParser.java
deleted file mode 100644
index 8c65075..0000000
--- a/src/main/java/dev/vality/wallets/hooker/kafka/serde/WalletChangeMachineEventParser.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package dev.vality.wallets.hooker.kafka.serde;
-
-import dev.vality.fistful.wallet.TimestampedChange;
-import dev.vality.sink.common.parser.impl.MachineEventParser;
-import dev.vality.sink.common.serialization.BinaryDeserializer;
-import org.springframework.stereotype.Service;
-
-@Service
-public class WalletChangeMachineEventParser extends MachineEventParser {
-
- public WalletChangeMachineEventParser(BinaryDeserializer deserializer) {
- super(deserializer);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/dev/vality/wallets/hooker/service/WebHookerService.java b/src/main/java/dev/vality/wallets/hooker/service/WebHookerService.java
index 8e06f8b..fe042ae 100644
--- a/src/main/java/dev/vality/wallets/hooker/service/WebHookerService.java
+++ b/src/main/java/dev/vality/wallets/hooker/service/WebHookerService.java
@@ -27,14 +27,14 @@ public class WebHookerService implements WebhookManagerSrv.Iface {
private final WebHookModelToWebHookConverter webHookModelToWebHookConverter;
@Override
- public List getList(String identityId) {
- log.info("Start get webhooks, identityId={}", identityId);
+ public List getList(String partyId) {
+ log.info("Start get webhooks, partyId={}", partyId);
- List webhooks = webHookDao.getByIdentity(identityId).stream()
+ List webhooks = webHookDao.getByParty(partyId).stream()
.map(webHookConverter::convert)
.collect(Collectors.toList());
- log.info("Finish get webhooks, identityId={}, size={}", identityId, webhooks.size());
+ log.info("Finish get webhooks, partyId={}, size={}", partyId, webhooks.size());
return webhooks;
}
diff --git a/src/main/java/dev/vality/wallets/hooker/service/kafka/WalletEventService.java b/src/main/java/dev/vality/wallets/hooker/service/kafka/WalletEventService.java
deleted file mode 100644
index 6b517e5..0000000
--- a/src/main/java/dev/vality/wallets/hooker/service/kafka/WalletEventService.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package dev.vality.wallets.hooker.service.kafka;
-
-import dev.vality.fistful.wallet.TimestampedChange;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.sink.common.parser.impl.MachineEventParser;
-import dev.vality.wallets.hooker.dao.EventLogDao;
-import dev.vality.wallets.hooker.handler.wallet.WalletEventHandler;
-import dev.vality.wallets.hooker.domain.enums.EventTopic;
-import dev.vality.wallets.hooker.domain.tables.pojos.EventLog;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Optional;
-
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class WalletEventService {
-
- private final List walletEventHandlers;
- private final MachineEventParser parser;
- private final EventLogDao eventLogDao;
-
- @Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.READ_COMMITTED)
- public void handleEvents(List machineEvents) {
- machineEvents.forEach(this::handleIfAccept);
- }
-
- private void handleIfAccept(MachineEvent machineEvent) {
- Optional duplicate = eventLogDao.get(
- machineEvent.getSourceId(),
- machineEvent.getEventId(),
- EventTopic.wallet);
-
- if (duplicate.isPresent()) {
- return;
- }
-
- TimestampedChange change = parser.parse(machineEvent);
-
- if (change.isSetChange()) {
- walletEventHandlers.stream()
- .filter(handler -> handler.accept(change))
- .forEach(handler -> handler.handle(change, machineEvent));
- }
-
- eventLogDao.create(
- machineEvent.getSourceId(),
- machineEvent.getEventId(),
- EventTopic.wallet);
- }
-}
diff --git a/src/main/java/dev/vality/wallets/hooker/utils/EventTypeUtils.java b/src/main/java/dev/vality/wallets/hooker/utils/EventTypeUtils.java
index 9e09cad..662701d 100644
--- a/src/main/java/dev/vality/wallets/hooker/utils/EventTypeUtils.java
+++ b/src/main/java/dev/vality/wallets/hooker/utils/EventTypeUtils.java
@@ -34,10 +34,6 @@ private static EventType resolveEventType(dev.vality.fistful.webhooker.EventType
DestinationEventType destination = type.getDestination();
if (destination.isSetCreated()) {
return EventType.DESTINATION_CREATED;
- } else if (destination.isSetAuthorized()) {
- return EventType.DESTINATION_AUTHORIZED;
- } else if (destination.isSetUnauthorized()) {
- return EventType.DESTINATION_UNAUTHORIZED;
}
}
throw new UnknownEventTypeException(type.toString());
diff --git a/src/main/java/dev/vality/wallets/hooker/utils/WebHookConverterUtils.java b/src/main/java/dev/vality/wallets/hooker/utils/WebHookConverterUtils.java
index 0b2d679..7a681e4 100644
--- a/src/main/java/dev/vality/wallets/hooker/utils/WebHookConverterUtils.java
+++ b/src/main/java/dev/vality/wallets/hooker/utils/WebHookConverterUtils.java
@@ -25,22 +25,13 @@ public static EventFilter generateEventFilter(Set EventType.withdrawal(WithdrawalEventType.started(new WithdrawalStarted()));
+ case WITHDRAWAL_FAILED -> EventType.withdrawal(WithdrawalEventType.failed(new WithdrawalFailed()));
+ case WITHDRAWAL_SUCCEEDED -> EventType.withdrawal(WithdrawalEventType.succeeded(new WithdrawalSucceeded()));
+ case DESTINATION_CREATED -> EventType.destination(DestinationEventType.created(new DestinationCreated()));
+ default -> throw new UnknownEventTypeException();
+ };
}
}
diff --git a/src/main/resources/db/migration/V6__change_identity_id_to_party_id.sql b/src/main/resources/db/migration/V6__change_identity_id_to_party_id.sql
new file mode 100644
index 0000000..525b45a
--- /dev/null
+++ b/src/main/resources/db/migration/V6__change_identity_id_to_party_id.sql
@@ -0,0 +1,23 @@
+ALTER TABLE whook.webhook ALTER identity_id DROP NOT NULL;
+ALTER TABLE whook.webhook DROP COLUMN identity_id;
+ALTER TABLE whook.webhook ADD COLUMN party_id character varying;
+
+CREATE TABLE IF NOT EXISTS whook.party_key
+(
+ id bigserial NOT NULL,
+ party_id character varying(40) NOT NULL,
+ pub_key character VARYING NOT NULL,
+ priv_key character VARYING NOT NULL,
+ CONSTRAINT pk_party_key PRIMARY KEY (id),
+ CONSTRAINT key_party_id_key UNIQUE (party_id)
+);
+
+CREATE TABLE whook.withdrawal_reference
+(
+ withdrawal_id character varying(40) NOT NULL,
+ party_id character varying(40) NOT NULL,
+ wallet_id character varying(40) NOT NULL,
+ event_id character varying(40) NOT NULL,
+ external_id character varying,
+ CONSTRAINT withdrawal_reference_pkey PRIMARY KEY (withdrawal_id)
+);
diff --git a/src/main/resources/db/migration/V7__drop_redundant.sql b/src/main/resources/db/migration/V7__drop_redundant.sql
new file mode 100644
index 0000000..f8a6ba3
--- /dev/null
+++ b/src/main/resources/db/migration/V7__drop_redundant.sql
@@ -0,0 +1,7 @@
+DROP INDEX IF EXISTS webhook_identity_id_key;
+
+DROP TABLE IF EXISTS
+ whook.identity_key,
+ whook.wallet_identity_reference,
+ whook.destination_identity_reference,
+ whook.withdrawal_identity_wallet_reference;
diff --git a/src/test/java/dev/vality/wallets/hooker/dao/destination/DestinationReferenceDaoImplTest.java b/src/test/java/dev/vality/wallets/hooker/dao/destination/DestinationReferenceDaoImplTest.java
deleted file mode 100644
index d679a3c..0000000
--- a/src/test/java/dev/vality/wallets/hooker/dao/destination/DestinationReferenceDaoImplTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package dev.vality.wallets.hooker.dao.destination;
-
-import dev.vality.wallets.hooker.config.PostgresqlSpringBootITest;
-import dev.vality.wallets.hooker.domain.tables.pojos.DestinationIdentityReference;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-@PostgresqlSpringBootITest
-public class DestinationReferenceDaoImplTest {
-
- @Autowired
- private DestinationReferenceDao destinationReferenceDao;
-
- @Test
- public void create() {
- DestinationIdentityReference reference = new DestinationIdentityReference();
- reference.setIdentityId("identity");
- reference.setEventId("eventId");
- String destination = "destination";
- reference.setDestinationId(destination);
- reference.setExternalId("externalId");
- destinationReferenceDao.create(reference);
-
- DestinationIdentityReference destinationIdentityReference = destinationReferenceDao.get(destination);
-
- assertEquals(reference, destinationIdentityReference);
- }
-}
diff --git a/src/test/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImplTest.java b/src/test/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImplTest.java
deleted file mode 100644
index 48b5866..0000000
--- a/src/test/java/dev/vality/wallets/hooker/dao/wallet/WalletReferenceDaoImplTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package dev.vality.wallets.hooker.dao.wallet;
-
-import dev.vality.wallets.hooker.config.PostgresqlSpringBootITest;
-import dev.vality.wallets.hooker.domain.tables.pojos.WalletIdentityReference;
-import lombok.extern.slf4j.Slf4j;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-@Slf4j
-@PostgresqlSpringBootITest
-class WalletReferenceDaoImplTest {
-
- @Autowired
- private WalletReferenceDao walletReferenceDao;
-
- @Test
- void create() {
- WalletIdentityReference reference = new WalletIdentityReference();
- reference.setIdentityId("identity");
- String walletId = "walletId";
- reference.setWalletId(walletId);
- walletReferenceDao.create(reference);
-
- WalletIdentityReference walletIdentityReference = walletReferenceDao.get(walletId);
-
- assertEquals(reference, walletIdentityReference);
- }
-}
\ No newline at end of file
diff --git a/src/test/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImplTest.java b/src/test/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImplTest.java
index fdd22a7..609a5d3 100644
--- a/src/test/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImplTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/dao/webhook/WebHookDaoImplTest.java
@@ -4,7 +4,6 @@
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.domain.enums.EventType;
import dev.vality.wallets.hooker.domain.tables.pojos.Webhook;
-import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,20 +15,20 @@
@PostgresqlSpringBootITest
public class WebHookDaoImplTest {
- public static final String IDENTITY_ID = "123";
+ public static final String PARTY_ID = "123";
public static final String WALLET_123 = "wallet_123";
@Autowired
private WebHookDao webHookDao;
@Test
- public void create() {
+ void create() {
LinkedHashSet eventTypes = new LinkedHashSet<>();
eventTypes.add(EventType.WITHDRAWAL_CREATED);
eventTypes.add(EventType.WITHDRAWAL_SUCCEEDED);
WebHookModel webhook = WebHookModel.builder()
.enabled(true)
- .identityId(IDENTITY_ID)
+ .partyId(PARTY_ID)
.url("/qwe")
.walletId(WALLET_123)
.eventTypes(eventTypes)
@@ -38,7 +37,7 @@ public void create() {
WebHookModel webHookModel = webHookDao.getById(webhook1.getId());
- assertEquals(IDENTITY_ID, webHookModel.getIdentityId());
+ assertEquals(PARTY_ID, webHookModel.getPartyId());
assertEquals(WALLET_123, webHookModel.getWalletId());
assertEquals(eventTypes, webHookModel.getEventTypes());
assertFalse(webHookModel.getPubKey().isEmpty());
@@ -55,27 +54,22 @@ public void create() {
eventTypes.add(EventType.DESTINATION_AUTHORIZED);
webhook = WebHookModel.builder()
.enabled(true)
- .identityId(IDENTITY_ID)
+ .partyId(PARTY_ID)
.url("/qwe")
.walletId(null)
.eventTypes(eventTypes)
.build();
Webhook webhook2 = webHookDao.create(webhook);
- List modelByIdentityAndWalletId =
- webHookDao.getByIdentityAndEventType(IDENTITY_ID, EventType.DESTINATION_CREATED);
+ List modelByPartyAndWalletId =
+ webHookDao.getByPartyAndEventType(PARTY_ID, EventType.DESTINATION_CREATED);
- assertEquals(1, modelByIdentityAndWalletId.size());
- assertNotNull(modelByIdentityAndWalletId.get(0).getEventTypes());
+ assertEquals(1, modelByPartyAndWalletId.size());
+ assertNotNull(modelByPartyAndWalletId.get(0).getEventTypes());
webHookDao.create(webhook);
- modelByIdentityAndWalletId = webHookDao.getByIdentityAndEventType(IDENTITY_ID, EventType.DESTINATION_CREATED);
- assertEquals(2, modelByIdentityAndWalletId.size());
- assertNotNull(modelByIdentityAndWalletId.get(0).getEventTypes());
-
- modelByIdentityAndWalletId =
- webHookDao.getModelByIdentityAndWalletId(IDENTITY_ID, WALLET_123, EventType.DESTINATION_CREATED);
-
- assertEquals(0, modelByIdentityAndWalletId.size());
+ modelByPartyAndWalletId = webHookDao.getByPartyAndEventType(PARTY_ID, EventType.DESTINATION_CREATED);
+ assertEquals(2, modelByPartyAndWalletId.size());
+ assertNotNull(modelByPartyAndWalletId.get(0).getEventTypes());
}
}
\ No newline at end of file
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/WalletEventSinkEventHandlerTest.java b/src/test/java/dev/vality/wallets/hooker/handler/DestinationEventHandlerTest.java
similarity index 73%
rename from src/test/java/dev/vality/wallets/hooker/handler/WalletEventSinkEventHandlerTest.java
rename to src/test/java/dev/vality/wallets/hooker/handler/DestinationEventHandlerTest.java
index a2f2b1b..1231ede 100644
--- a/src/test/java/dev/vality/wallets/hooker/handler/WalletEventSinkEventHandlerTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/handler/DestinationEventHandlerTest.java
@@ -3,9 +3,9 @@
import dev.vality.wallets.hooker.config.PostgresqlSpringBootITest;
import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
import dev.vality.wallets.hooker.domain.WebHookModel;
+import dev.vality.wallets.hooker.domain.enums.EventType;
import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
import dev.vality.wallets.hooker.service.kafka.DestinationEventService;
-import dev.vality.wallets.hooker.service.kafka.WalletEventService;
import dev.vality.wallets.hooker.service.kafka.WithdrawalEventService;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
@@ -24,13 +24,7 @@
@PostgresqlSpringBootITest
@TestPropertySource(properties = "fistful.pollingEnabled=false")
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
-class WalletEventSinkEventHandlerTest {
-
- @Autowired
- private WalletEventService walletEventService;
-
- @Autowired
- private WithdrawalEventService withdrawalEventService;
+class DestinationEventHandlerTest {
@Autowired
private DestinationEventService destinationEventService;
@@ -42,21 +36,29 @@ class WalletEventSinkEventHandlerTest {
private WebHookMessageSenderService webHookMessageSenderService;
@Test
- void handle() {
+ void failHandleDestinationCreated() {
WebHookModel webhook = TestBeanFactory.createWebhookModel();
webHookDao.create(webhook);
destinationEventService.handleEvents(List.of(TestBeanFactory.createDestination()));
destinationEventService.handleEvents(List.of(TestBeanFactory.createDestinationAccount()));
- walletEventService.handleEvents(List.of(TestBeanFactory.createWalletEvent()));
- withdrawalEventService.handleEvents(List.of(TestBeanFactory.createWithdrawalEvent()));
- verify(webHookMessageSenderService, times(1))
+ verify(webHookMessageSenderService, times(0))
.send(any());
+ }
- withdrawalEventService.handleEvents(List.of(TestBeanFactory.createWithdrawalSucceeded()));
- verify(webHookMessageSenderService, times(2))
+ @Test
+ void handleDestinationCreatedAndAccountChange() {
+ WebHookModel webhook = TestBeanFactory.createWebhookModel();
+ webhook.getEventTypes().add(EventType.DESTINATION_CREATED);
+
+ webHookDao.create(webhook);
+
+ destinationEventService.handleEvents(List.of(TestBeanFactory.createDestination()));
+ destinationEventService.handleEvents(List.of(TestBeanFactory.createDestinationAccount()));
+
+ verify(webHookMessageSenderService, times(1))
.send(any());
}
}
\ No newline at end of file
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/TestBeanFactory.java b/src/test/java/dev/vality/wallets/hooker/handler/TestBeanFactory.java
index a30aab3..33a175e 100644
--- a/src/test/java/dev/vality/wallets/hooker/handler/TestBeanFactory.java
+++ b/src/test/java/dev/vality/wallets/hooker/handler/TestBeanFactory.java
@@ -4,7 +4,6 @@
import dev.vality.fistful.base.*;
import dev.vality.fistful.destination.Destination;
import dev.vality.fistful.destination.TimestampedChange;
-import dev.vality.fistful.wallet.AccountChange;
import dev.vality.fistful.withdrawal.CreatedChange;
import dev.vality.fistful.withdrawal.StatusChange;
import dev.vality.fistful.withdrawal.Withdrawal;
@@ -22,15 +21,18 @@
public class TestBeanFactory {
public static final String SOURCE_WALLET_ID = "sourceWalletId";
- public static final String IDENTITY_ID = "identityId";
+ public static final String PARTY_ID = "partyId";
public static final String DESTINATION = "destination";
public static final String WITHDRAWAL_ID = "withdrawalId";
- public static final long WALLET_ID = 21L;
public static MachineEvent createDestination() {
Destination destination = new Destination();
+ destination.setId("destinationId");
destination.setName("name");
destination.setExternalId("externalId");
+ destination.setRealm(Realm.test);
+ destination.setPartyId(PARTY_ID);
+ destination.setCreatedAt("2025-03-22T06:12:27Z");
BankCard bankCard = new BankCard();
bankCard.setBin("1234");
bankCard.setMaskedPan("421");
@@ -55,9 +57,10 @@ public static MachineEvent createDestination() {
public static MachineEvent createDestinationAccount() {
Account account = new Account();
- account.setId("account");
+ account.setAccountId(123L);
account.setCurrency(new CurrencyRef().setSymbolicCode("RUB"));
- account.setIdentity(IDENTITY_ID);
+ account.setPartyId(PARTY_ID);
+ account.setRealm(Realm.test);
dev.vality.fistful.destination.AccountChange accountChange =
new dev.vality.fistful.destination.AccountChange();
accountChange.setCreated(account);
@@ -81,6 +84,10 @@ public static MachineEvent createWithdrawalEvent() {
withdrawal.setExternalId("extId");
withdrawal.setWalletId(SOURCE_WALLET_ID);
withdrawal.setId(WITHDRAWAL_ID);
+ withdrawal.setCreatedAt("2025-03-22T06:12:27Z");
+ withdrawal.setPartyId(PARTY_ID);
+ withdrawal.setId(WITHDRAWAL_ID);
+ withdrawal.setDomainRevision(1L);
Cash body = new Cash();
body.setAmount(1000);
@@ -104,30 +111,6 @@ public static MachineEvent createWithdrawalEvent() {
timestampedChange);
}
- public static MachineEvent createWalletEvent() {
- Account account = new Account();
- account.setId("accountId");
- CurrencyRef currency = new CurrencyRef();
- currency.setSymbolicCode("RUB");
- account.setIdentity(IDENTITY_ID);
- account.setCurrency(currency);
- AccountChange accountChange = new AccountChange();
- accountChange.setCreated(account);
- dev.vality.fistful.wallet.Change change = new dev.vality.fistful.wallet.Change();
- change.setAccount(accountChange);
-
- dev.vality.fistful.wallet.TimestampedChange timestampedChange =
- new dev.vality.fistful.wallet.TimestampedChange()
- .setOccuredAt("2016-03-22T06:12:27Z")
- .setChange(change);
-
- return machineEvent(
- SOURCE_WALLET_ID,
- WALLET_ID,
- new ThriftSerializer<>(),
- timestampedChange);
- }
-
public static MachineEvent createWithdrawalSucceeded() {
dev.vality.fistful.withdrawal.Change change = new dev.vality.fistful.withdrawal.Change();
change.setStatusChanged(new StatusChange().setStatus(Status.succeeded(new Succeeded())));
@@ -150,7 +133,7 @@ public static WebHookModel createWebhookModel() {
eventTypes.add(EventType.WITHDRAWAL_SUCCEEDED);
return WebHookModel.builder()
.enabled(true)
- .identityId(TestBeanFactory.IDENTITY_ID)
+ .partyId(TestBeanFactory.PARTY_ID)
.url("/qwe")
.walletId(TestBeanFactory.SOURCE_WALLET_ID)
.eventTypes(eventTypes)
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/WaitingDestinationAndWalletHandlerTest.java b/src/test/java/dev/vality/wallets/hooker/handler/WaitingDestinationAndWalletHandlerTest.java
deleted file mode 100644
index b656f98..0000000
--- a/src/test/java/dev/vality/wallets/hooker/handler/WaitingDestinationAndWalletHandlerTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package dev.vality.wallets.hooker.handler;
-
-import dev.vality.fistful.destination.*;
-import dev.vality.kafka.common.serialization.ThriftSerializer;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import dev.vality.machinegun.msgpack.Value;
-import dev.vality.wallets.hooker.config.PostgresqlSpringBootITest;
-import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
-import dev.vality.wallets.hooker.domain.WebHookModel;
-import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
-import dev.vality.wallets.hooker.service.kafka.DestinationEventService;
-import dev.vality.wallets.hooker.service.kafka.WalletEventService;
-import dev.vality.wallets.hooker.service.kafka.WithdrawalEventService;
-import org.junit.jupiter.api.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.bean.override.mockito.MockitoBean;
-
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-@PostgresqlSpringBootITest
-class WaitingDestinationAndWalletHandlerTest {
-
- @Autowired
- private WalletEventService walletEventService;
-
- @Autowired
- private WithdrawalEventService withdrawalEventService;
-
- @Autowired
- private DestinationEventService destinationEventService;
-
- @Autowired
- private WebHookDao webHookDao;
-
- @MockitoBean
- private WebHookMessageSenderService webHookMessageSenderService;
-
- @Test
- void handleWaitingDestinationAndWallet() throws InterruptedException {
- WebHookModel webhook = TestBeanFactory.createWebhookModel();
-
- webHookDao.create(webhook);
- destinationEventService.handleEvents(List.of(TestBeanFactory.createDestination()));
- destinationEventService.handleEvents(List.of(TestBeanFactory.createDestinationAccount()));
-
- MachineEvent destination = TestBeanFactory.createDestination();
- dev.vality.fistful.destination.Change change = new dev.vality.fistful.destination.Change();
- change.setStatus(StatusChange.changed(Status.authorized(new Authorized())));
- destination.setData(Value.bin(new ThriftSerializer<>().serialize("", new TimestampedChange()
- .setChange(change)
- .setOccuredAt("2016-03-22T06:12:27Z"))));
- destinationEventService.handleEvents(List.of(destination));
-
- change.setStatus(StatusChange.changed(Status.unauthorized(new Unauthorized())));
- destination.setData(Value.bin(new ThriftSerializer<>().serialize("", new TimestampedChange()
- .setChange(change)
- .setOccuredAt("2016-03-22T06:12:27Z"))));
- destinationEventService.handleEvents(List.of(destination));
- walletEventService.handleEvents(List.of(TestBeanFactory.createWalletEvent()));
-
- CountDownLatch latch = new CountDownLatch(1);
- new Thread(() -> {
- MachineEvent event = TestBeanFactory.createWithdrawalSucceeded();
- withdrawalEventService.handleEvents(List.of(event));
- latch.countDown();
- }).start();
-
- withdrawalEventService.handleEvents(List.of(TestBeanFactory.createWithdrawalEvent()));
- verify(webHookMessageSenderService, times(1))
- .send(any());
-
- latch.await();
- }
-
-}
\ No newline at end of file
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/WaitingWithdrawalReferenceEventHandlerTest.java b/src/test/java/dev/vality/wallets/hooker/handler/WithdrawalEventHandlerTest.java
similarity index 57%
rename from src/test/java/dev/vality/wallets/hooker/handler/WaitingWithdrawalReferenceEventHandlerTest.java
rename to src/test/java/dev/vality/wallets/hooker/handler/WithdrawalEventHandlerTest.java
index 4d7c208..c580946 100644
--- a/src/test/java/dev/vality/wallets/hooker/handler/WaitingWithdrawalReferenceEventHandlerTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/handler/WithdrawalEventHandlerTest.java
@@ -1,11 +1,10 @@
package dev.vality.wallets.hooker.handler;
+import dev.vality.machinegun.eventsink.MachineEvent;
import dev.vality.wallets.hooker.config.PostgresqlSpringBootITest;
import dev.vality.wallets.hooker.dao.webhook.WebHookDao;
import dev.vality.wallets.hooker.domain.WebHookModel;
import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
-import dev.vality.wallets.hooker.service.kafka.DestinationEventService;
-import dev.vality.wallets.hooker.service.kafka.WalletEventService;
import dev.vality.wallets.hooker.service.kafka.WithdrawalEventService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,21 +14,15 @@
import java.util.concurrent.CountDownLatch;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.verify;
@PostgresqlSpringBootITest
-class WaitingWithdrawalReferenceEventHandlerTest {
-
- @Autowired
- private WalletEventService walletEventService;
+class WithdrawalEventHandlerTest {
@Autowired
private WithdrawalEventService withdrawalEventService;
- @Autowired
- private DestinationEventService destinationEventService;
-
@Autowired
private WebHookDao webHookDao;
@@ -37,23 +30,21 @@ class WaitingWithdrawalReferenceEventHandlerTest {
private WebHookMessageSenderService webHookMessageSenderService;
@Test
- void handleWaitingWithdrawalReference() throws InterruptedException {
+ void handleWithdrawalCreatedAndAndStatusChange() throws InterruptedException {
WebHookModel webhook = TestBeanFactory.createWebhookModel();
- webHookDao.create(webhook);
- destinationEventService.handleEvents(List.of(TestBeanFactory.createDestination()));
+ webHookDao.create(webhook);
CountDownLatch latch = new CountDownLatch(1);
-
new Thread(() -> {
- withdrawalEventService.handleEvents(List.of(TestBeanFactory.createWithdrawalEvent()));
- verify(webHookMessageSenderService, times(1))
- .send(any());
+ MachineEvent event = TestBeanFactory.createWithdrawalSucceeded();
+ withdrawalEventService.handleEvents(List.of(event));
latch.countDown();
}).start();
- destinationEventService.handleEvents(List.of(TestBeanFactory.createDestinationAccount()));
- walletEventService.handleEvents(List.of(TestBeanFactory.createWalletEvent()));
+ withdrawalEventService.handleEvents(List.of(TestBeanFactory.createWithdrawalEvent()));
+ verify(webHookMessageSenderService, timeout(1000L).times(2))
+ .send(any());
latch.await();
}
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGeneratorTest.java b/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGeneratorTest.java
index 61aebe3..0d8790c 100644
--- a/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGeneratorTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationCreatedHookMessageGeneratorTest.java
@@ -1,6 +1,7 @@
package dev.vality.wallets.hooker.handler.destination.generator;
import com.fasterxml.jackson.databind.ObjectMapper;
+import dev.vality.swag.wallets.webhook.events.model.BankCard;
import dev.vality.swag.wallets.webhook.events.model.Destination;
import dev.vality.swag.wallets.webhook.events.model.DestinationCreated;
import dev.vality.swag.wallets.webhook.events.model.DestinationResource;
@@ -29,7 +30,7 @@ public class DestinationCreatedHookMessageGeneratorTest {
public static final long EVENT_ID = 1L;
public static final String URL = "/url";
public static final String WALLET_ID = "wallet_id";
- public static final String IDENTITY_ID = "identity_id";
+ public static final String PARTY_ID = "party_id";
public static final String SOURCE_ID = "sourceId";
public static final String DESTINATION_ID = "destination_id";
@@ -52,7 +53,7 @@ void generate() throws IOException {
model.setId(1L);
model.setEventTypes(Set.of(EventType.DESTINATION_CREATED));
model.setEnabled(true);
- model.setIdentityId(IDENTITY_ID);
+ model.setPartyId(PARTY_ID);
model.setUrl(URL);
model.setWalletId(WALLET_ID);
@@ -61,9 +62,14 @@ void generate() throws IOException {
model.setPubKey(keyPair.getPublKey());
Destination destination = new Destination();
- destination.setIdentity(IDENTITY_ID);
destination.setId(DESTINATION_ID);
- destination.setResource(new DestinationResource().type(DestinationResource.TypeEnum.BANKCARD));
+ BankCard bankCard = new BankCard();
+ bankCard.setBin("123456");
+ bankCard.setCardNumberMask("1234*******6789");
+ bankCard.setLastDigits("1234");
+ bankCard.setType(DestinationResource.TypeEnum.BANK_CARD);
+ bankCard.setPaymentSystem("visa");
+ destination.setResource(bankCard);
destination.setCurrency("RUB");
DestinationMessage event = new DestinationMessage();
@@ -90,6 +96,8 @@ void generate() throws IOException {
byte[] requestBody = generate.getRequestBody();
DestinationCreated value = objectMapper.readValue(requestBody, DestinationCreated.class);
- assertNotNull(IDENTITY_ID, value.getDestination().getIdentity());
+ assertNotNull(PARTY_ID, value.getDestination().getParty());
+ assertEquals(DestinationResource.TypeEnum.BANK_CARD, value.getDestination().getResource().getType());
+ assertEquals(DESTINATION_ID, value.getDestination().getId());
}
}
diff --git a/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGeneratorTest.java b/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGeneratorTest.java
deleted file mode 100644
index 42c32ac..0000000
--- a/src/test/java/dev/vality/wallets/hooker/handler/destination/generator/DestinationStatusChangeHookMessageGeneratorTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package dev.vality.wallets.hooker.handler.destination.generator;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
-import dev.vality.fistful.destination.Authorized;
-import dev.vality.fistful.destination.Status;
-import dev.vality.fistful.destination.StatusChange;
-import dev.vality.fistful.destination.Unauthorized;
-import dev.vality.swag.wallets.webhook.events.model.DestinationAuthorized;
-import dev.vality.swag.wallets.webhook.events.model.DestinationUnauthorized;
-import dev.vality.wallets.hooker.config.ObjectMapperConfig;
-import dev.vality.wallets.hooker.domain.WebHookModel;
-import dev.vality.wallets.hooker.exception.GenerateMessageException;
-import dev.vality.wallets.hooker.handler.AdditionalHeadersGenerator;
-import dev.vality.wallets.hooker.model.MessageGenParams;
-import dev.vality.wallets.hooker.service.WebHookMessageGeneratorServiceImpl;
-import dev.vality.wallets.hooker.service.crypt.AsymSigner;
-import dev.vality.wallets.hooker.service.crypt.KeyPair;
-import dev.vality.wallets.hooker.service.crypt.Signer;
-import dev.vality.wallets.hooker.domain.enums.EventType;
-import dev.vality.webhook.dispatcher.WebhookMessage;
-import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
-
-import java.io.IOException;
-import java.util.Set;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.when;
-
-public class DestinationStatusChangeHookMessageGeneratorTest {
-
- public static final long EVENT_ID = 1L;
- public static final String URL = "/url";
- public static final String WALLET_ID = "wallet_id";
- public static final String IDENTITY_ID = "identity_id";
- public static final String SOURCE_ID = "sourceId";
- public static final long PARENT_ID = 0L;
- public static final String T_08_43_42_Z = "2019-07-02T08:43:42Z";
-
- ObjectMapper objectMapper = new ObjectMapperConfig().objectMapper();
-
- Signer signer = new AsymSigner();
-
- WebHookMessageGeneratorServiceImpl generatorService =
- new WebHookMessageGeneratorServiceImpl<>(PARENT_ID);
- DestinationStatusChangeHookMessageGenerator destinationCreatedHookMessageGenerator =
- new DestinationStatusChangeHookMessageGenerator(
- generatorService,
- objectMapper,
- new AdditionalHeadersGenerator(signer),
- -1L);
-
- @Test
- void generate() throws IOException {
- WebHookModel model = new WebHookModel();
- model.setId(1L);
- model.setEventTypes(Set.of(EventType.DESTINATION_AUTHORIZED));
- model.setEnabled(true);
- model.setIdentityId(IDENTITY_ID);
- model.setUrl(URL);
- model.setWalletId(WALLET_ID);
-
- KeyPair keyPair = signer.generateKeys();
- model.setPrivateKey(keyPair.getPrivKey());
- model.setPubKey(keyPair.getPublKey());
-
- StatusChange statusChange = new StatusChange();
- statusChange.setChanged(Status.authorized(new Authorized()));
-
- MessageGenParams genParamAuth = MessageGenParams.builder()
- .sourceId(SOURCE_ID)
- .eventId(EVENT_ID)
- .parentId(0L)
- .createdAt("2019-07-02T08:43:42Z")
- .externalId("externalId")
- .build();
- WebhookMessage generate = destinationCreatedHookMessageGenerator.generate(statusChange, model, genParamAuth);
-
- byte[] requestBody = generate.getRequestBody();
- DestinationAuthorized destinationAuthorized = objectMapper.readValue(requestBody, DestinationAuthorized.class);
- assertEquals(SOURCE_ID, destinationAuthorized.getDestinationID());
- assertEquals("externalId", destinationAuthorized.getExternalID());
-
- statusChange = new StatusChange();
- statusChange.setChanged(Status.unauthorized(new Unauthorized()));
-
- MessageGenParams genParamUnauth = MessageGenParams.builder()
- .sourceId(SOURCE_ID)
- .eventId(EVENT_ID)
- .parentId(666L)
- .createdAt("2019-07-02T08:43:42Z")
- .externalId("externalId")
- .build();
- model.setEventTypes(Set.of(EventType.DESTINATION_AUTHORIZED, EventType.DESTINATION_CREATED));
- generate = destinationCreatedHookMessageGenerator.generate(statusChange, model, genParamUnauth);
-
-
- requestBody = generate.getRequestBody();
- DestinationUnauthorized destinationUnauthorized =
- objectMapper.readValue(requestBody, DestinationUnauthorized.class);
- assertEquals(SOURCE_ID, destinationUnauthorized.getDestinationID());
- assertEquals(666L, generate.getParentEventId());
- assertEquals("externalId", destinationUnauthorized.getExternalID());
- }
-
- @Test
- void generateException() {
- WebHookMessageGeneratorServiceImpl mock = Mockito.mock(WebHookMessageGeneratorServiceImpl.class);
- DestinationStatusChangeHookMessageGenerator destinationCreatedHookMessageGenerator =
- new DestinationStatusChangeHookMessageGenerator(
- mock,
- new ObjectMapper(),
- new AdditionalHeadersGenerator(signer),
- -1L);
-
- StatusChange event = new StatusChange();
- WebHookModel model = new WebHookModel();
- MessageGenParams genParam = MessageGenParams.builder()
- .sourceId(SOURCE_ID)
- .eventId(EVENT_ID)
- .parentId(PARENT_ID)
- .createdAt(T_08_43_42_Z)
- .build();
- when(mock.generate(event, model, genParam)).thenThrow(new RuntimeException("test exception!"));
- assertThrows(GenerateMessageException.class,
- () -> destinationCreatedHookMessageGenerator.generate(event, model, genParam));
- }
-}
diff --git a/src/test/java/dev/vality/wallets/hooker/kafka/WebhookServiceTest.java b/src/test/java/dev/vality/wallets/hooker/kafka/WebhookServiceTest.java
index 8af5d01..5704e66 100644
--- a/src/test/java/dev/vality/wallets/hooker/kafka/WebhookServiceTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/kafka/WebhookServiceTest.java
@@ -3,11 +3,10 @@
import dev.vality.fistful.webhooker.*;
import dev.vality.kafka.common.serialization.ThriftSerializer;
import dev.vality.wallets.hooker.config.KafkaPostgresqlSpringBootITest;
+import dev.vality.wallets.hooker.handler.TestBeanFactory;
import dev.vality.wallets.hooker.service.WebHookMessageSenderService;
import dev.vality.wallets.hooker.service.kafka.DestinationEventService;
-import dev.vality.wallets.hooker.service.kafka.WalletEventService;
import dev.vality.wallets.hooker.service.kafka.WithdrawalEventService;
-import dev.vality.wallets.hooker.handler.TestBeanFactory;
import dev.vality.webhook.dispatcher.WebhookMessage;
import org.apache.kafka.clients.consumer.*;
import org.apache.kafka.common.serialization.StringDeserializer;
@@ -32,7 +31,6 @@ class WebhookServiceTest {
private static final String TEST = "/test";
private static final String URL_2 = TEST + "/qwe";
- private static final String KEY = "key";
@Value("${kafka.topic.hook.name}")
private String topicName;
@@ -43,25 +41,18 @@ class WebhookServiceTest {
@Autowired
private WebhookManagerSrv.Iface requestHandler;
- @Autowired
- private WebHookMessageSenderService webHookMessageSenderService;
-
@Autowired
private DestinationEventService destinationEventService;
- @Autowired
- private WalletEventService walletEventService;
-
@Autowired
private WithdrawalEventService withdrawalEventService;
@Test
- void startTest() throws TException {
+ void testFlow() throws TException {
+ DestinationEventType created = DestinationEventType.created(new DestinationCreated());
WebhookParams webhookParams = new WebhookParams()
- .setEventFilter(new EventFilter()
- .setTypes(Set.of(EventType.destination(DestinationEventType.created(new DestinationCreated())),
- EventType.destination(DestinationEventType.authorized(new DestinationAuthorized())))))
- .setIdentityId(TestBeanFactory.IDENTITY_ID)
+ .setEventFilter(new EventFilter().setTypes(Set.of(EventType.destination(created))))
+ .setPartyId(TestBeanFactory.PARTY_ID)
.setUrl(TEST);
Webhook webhook = requestHandler.create(webhookParams);
@@ -73,18 +64,17 @@ void startTest() throws TException {
webhookParams.setUrl(URL_2);
requestHandler.create(webhookParams);
- List list = requestHandler.getList(webhookParams.getIdentityId());
+ List list = requestHandler.getList(webhookParams.getPartyId());
assertEquals(2L, list.size());
destinationEventService.handleEvents(List.of(TestBeanFactory.createDestination()));
destinationEventService.handleEvents(List.of(TestBeanFactory.createDestinationAccount()));
- walletEventService.handleEvents(List.of(TestBeanFactory.createWalletEvent()));
webhookParams = new WebhookParams()
.setEventFilter(new EventFilter()
.setTypes(Set.of(EventType.withdrawal(WithdrawalEventType.started(new WithdrawalStarted())),
EventType.withdrawal(WithdrawalEventType.succeeded(new WithdrawalSucceeded())))))
- .setIdentityId(TestBeanFactory.IDENTITY_ID)
+ .setPartyId(TestBeanFactory.PARTY_ID)
.setWalletId(TestBeanFactory.SOURCE_WALLET_ID)
.setUrl(TEST);
requestHandler.create(webhookParams);
@@ -97,7 +87,6 @@ void startTest() throws TException {
consumer.subscribe(List.of(topicName));
ConsumerRecords poll = consumer.poll(Duration.ofMillis(5000));
Iterable> records = poll.records(topicName);
- records.forEach(System.out::println);
assertEquals(4L, poll.count());
diff --git a/src/test/java/dev/vality/wallets/hooker/service/WebHookerServiceTest.java b/src/test/java/dev/vality/wallets/hooker/service/WebHookerServiceTest.java
index d31cfff..cd9153f 100644
--- a/src/test/java/dev/vality/wallets/hooker/service/WebHookerServiceTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/service/WebHookerServiceTest.java
@@ -47,16 +47,16 @@ void getList() {
ArrayList webhooks = new ArrayList<>();
dev.vality.wallets.hooker.domain.tables.pojos.Webhook webhook =
new dev.vality.wallets.hooker.domain.tables.pojos.Webhook();
- webhook.setIdentityId(id);
+ webhook.setPartyId(id);
webhooks.add(webhook);
- Mockito.when(webHookDao.getByIdentity(id)).thenReturn(webhooks);
+ Mockito.when(webHookDao.getByParty(id)).thenReturn(webhooks);
Webhook hook = new Webhook();
- hook.setIdentityId(id);
+ hook.setPartyId(id);
Mockito.when(webHookConverter.convert(webhook)).thenReturn(hook);
List listWebHooks = webHookerService.getList(id);
assertFalse(listWebHooks.isEmpty());
- assertEquals(id, listWebHooks.get(0).identity_id);
+ assertEquals(id, listWebHooks.get(0).party_id);
}
}
\ No newline at end of file
diff --git a/src/test/java/dev/vality/wallets/hooker/utils/EventTypeUtilsTest.java b/src/test/java/dev/vality/wallets/hooker/utils/EventTypeUtilsTest.java
index 5df49d7..325ec11 100644
--- a/src/test/java/dev/vality/wallets/hooker/utils/EventTypeUtilsTest.java
+++ b/src/test/java/dev/vality/wallets/hooker/utils/EventTypeUtilsTest.java
@@ -9,10 +9,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class EventTypeUtilsTest {
+class EventTypeUtilsTest {
@Test
- public void convertEventTypes() {
+ void convertEventTypes() {
EventFilter eventFilter = new EventFilter();
LinkedHashSet types = new LinkedHashSet<>();
DestinationEventType value = new DestinationEventType();