diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 6fc64c7..4af9d57 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -7,4 +7,4 @@ on:
jobs:
build:
- uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v2
+ uses: valitydev/java-workflow/.github/workflows/maven-service-build.yml@v3
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 911ca7a..385233c 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -9,7 +9,7 @@ on:
jobs:
build-and-deploy:
- uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v2
+ uses: valitydev/java-workflow/.github/workflows/maven-service-deploy.yml@v3
secrets:
github-token: ${{ secrets.GITHUB_TOKEN }}
mm-webhook-url: ${{ secrets.MATTERMOST_WEBHOOK_URL }}
diff --git a/pom.xml b/pom.xml
index e30963a..d8e8526 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,8 @@
dev.vality
service-parent-pom
- 3.0.0
+ 3.0.2
+
dominator
@@ -92,6 +93,10 @@
org.flywaydb
flyway-core
+
+ org.flywaydb
+ flyway-database-postgresql
+
org.jooq
jooq
@@ -157,11 +162,6 @@
dominator-proto
1.7-41bee97
-
- dev.vality
- payout-manager-proto
- 1.36-063163d
-
dev.vality
kafka-common-lib
@@ -184,7 +184,7 @@
dev.vality
damsel
- 1.636-b869c09
+ 1.641-6051aa9
dev.vality
@@ -214,10 +214,12 @@
dev.vality.geck
serializer
+ 1.0.1
dev.vality.geck
filter
+ 1.0.1
@@ -270,7 +272,7 @@
dev.vality.maven.plugins
pg-embedded-plugin
- 1.0.1
+ 2.0.0
${local.pg.port}
${db.name}
@@ -319,7 +321,7 @@
org.postgresql
postgresql
- 42.3.9
+ 42.7.3
@@ -344,7 +346,7 @@
org.jooq.meta.postgres.PostgresDatabase
.*
- schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_payout.*|get_refund.*
+ schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_refund.*
${db.schema}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolCreatedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolCreatedHandler.java
deleted file mode 100644
index 6b1f148..0000000
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolCreatedHandler.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
-
-import com.empayre.dominator.service.ContractReferenceService;
-import dev.vality.damsel.domain.PayoutTool;
-import dev.vality.damsel.payment_processing.ClaimEffect;
-import dev.vality.damsel.payment_processing.ContractEffectUnit;
-import dev.vality.damsel.payment_processing.PartyChange;
-import com.empayre.dominator.dao.party.iface.ContractDao;
-import com.empayre.dominator.dao.party.iface.PayoutToolDao;
-import com.empayre.dominator.domain.tables.pojos.Contract;
-import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
-import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
-import com.empayre.dominator.util.ContractUtil;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class ContractPayoutToolCreatedHandler extends AbstractClaimChangedHandler {
-
- private final ContractDao contractDao;
- private final PayoutToolDao payoutToolDao;
- private final ContractReferenceService contractReferenceService;
- private final ClaimEffectCopyFactory claimEffectCopyFactory;
-
- @Override
- @Transactional(propagation = Propagation.REQUIRED)
- public void handle(PartyChange change, MachineEvent event, Integer changeId) {
- long sequenceId = event.getEventId();
- List claimEffects = getClaimStatus(change).getAccepted().getEffects();
- for (int i = 0; i < claimEffects.size(); i++) {
- ClaimEffect claimEffect = claimEffects.get(i);
- if (claimEffect.isSetContractEffect()
- && claimEffect.getContractEffect().getEffect().isSetPayoutToolCreated()) {
- handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
- }
- }
- }
-
- private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
- Integer claimEffectId) {
- ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
- PayoutTool payoutToolCreated = contractEffectUnit.getEffect().getPayoutToolCreated();
- String contractId = contractEffectUnit.getContractId();
- String partyId = event.getSourceId();
- log.info("Start contract payout tool created handling, sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId);
- Contract contractSourceOld = contractDao.get(partyId, contractId);
- Contract contractNew =
- claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
-
- contractDao.save(contractNew).ifPresentOrElse(
- dbContractId -> {
- Long oldId = contractSourceOld.getId();
- contractDao.updateNotCurrent(oldId);
- contractReferenceService.updateContractReference(oldId, dbContractId);
- payoutToolDao.save(List.of(ContractUtil.convertPayoutTool(payoutToolCreated, dbContractId)));
- log.info("Contract contract payout tool created has been saved, " +
- "sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId);
- },
- () -> log.info("Contract contract payout tool created duplicated, " +
- "sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId)
- );
- }
-}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolInfoChangedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolInfoChangedHandler.java
deleted file mode 100644
index 52f72d9..0000000
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/contract/ContractPayoutToolInfoChangedHandler.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.empayre.dominator.handler.event.stock.impl.partymngmnt.contract;
-
-import com.empayre.dominator.service.ContractReferenceService;
-import dev.vality.damsel.payment_processing.ClaimEffect;
-import dev.vality.damsel.payment_processing.ContractEffectUnit;
-import dev.vality.damsel.payment_processing.PartyChange;
-import dev.vality.damsel.payment_processing.PayoutToolInfoChanged;
-import com.empayre.dominator.dao.party.iface.ContractDao;
-import com.empayre.dominator.dao.party.iface.PayoutToolDao;
-import com.empayre.dominator.domain.tables.pojos.Contract;
-import com.empayre.dominator.domain.tables.pojos.PayoutTool;
-import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
-import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
-import com.empayre.dominator.util.ContractUtil;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class ContractPayoutToolInfoChangedHandler extends AbstractClaimChangedHandler {
-
- private final ContractDao contractDao;
- private final PayoutToolDao payoutToolDao;
- private final ContractReferenceService contractReferenceService;
- private final ClaimEffectCopyFactory claimEffectCopyFactory;
-
- @Override
- @Transactional(propagation = Propagation.REQUIRED)
- public void handle(PartyChange change, MachineEvent event, Integer changeId) {
- long sequenceId = event.getEventId();
- List claimEffects = getClaimStatus(change).getAccepted().getEffects();
- for (int i = 0; i < claimEffects.size(); i++) {
- ClaimEffect claimEffect = claimEffects.get(i);
- if (claimEffect.isSetContractEffect()
- && claimEffect.getContractEffect().getEffect().isSetPayoutToolInfoChanged()) {
- handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
- }
- }
- }
-
- private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect claimEffect,
- Integer claimEffectId) {
- ContractEffectUnit contractEffectUnit = claimEffect.getContractEffect();
- String contractId = contractEffectUnit.getContractId();
- String partyId = event.getSourceId();
- log.info("Start contract payout tool info changed handling, " +
- "sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId);
- Contract contractSourceOld = contractDao.get(partyId, contractId);
- Contract contractNew =
- claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, contractSourceOld);
-
- contractDao.save(contractNew).ifPresentOrElse(
- dbContractId -> {
- Long oldId = contractSourceOld.getId();
- contractDao.updateNotCurrent(oldId);
- contractReferenceService.updateAdjustments(oldId, dbContractId);
- updatePayoutTools(contractEffectUnit, oldId, dbContractId);
- log.info("Contract payout tool info changed has been saved, " +
- "sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId);
- },
- () -> log.info("Contract payout tool info changed duplicated, " +
- "sequenceId={}, partyId={}, contractId={}, changeId={}",
- sequenceId, partyId, contractId, changeId)
- );
- }
-
- private void updatePayoutTools(ContractEffectUnit contractEffectUnit, Long oldId, Long dbContractId) {
- List currentPayoutTools = payoutToolDao.getByContractId(oldId);
- currentPayoutTools.forEach(payoutTool -> {
- payoutTool.setId(null);
- payoutTool.setContractId(dbContractId);
- });
- PayoutToolInfoChanged payoutToolInfoChanged =
- contractEffectUnit.getEffect().getPayoutToolInfoChanged();
- Optional payoutToolForChangeOptional = currentPayoutTools.stream()
- .filter(payoutTool -> payoutTool.getPayoutToolId().equals(payoutToolInfoChanged.getPayoutToolId()))
- .findAny();
- List modifiedPayoutTools;
- if (payoutToolForChangeOptional.isPresent()) {
- PayoutTool payoutToolForChange = payoutToolForChangeOptional.get();
- PayoutTool newPayoutTool = ContractUtil.buildPayoutTool(dbContractId,
- payoutToolInfoChanged.getPayoutToolId(),
- payoutToolForChange.getCreatedAt(),
- payoutToolForChange.getCurrencyCode(),
- payoutToolInfoChanged.getInfo()
- );
- modifiedPayoutTools = Stream.concat(
- Stream.of(newPayoutTool),
- currentPayoutTools.stream()
- .filter(p -> !p.getPayoutToolId().equals(payoutToolInfoChanged.getPayoutToolId()))
- ).collect(Collectors.toList());
- } else {
- modifiedPayoutTools = currentPayoutTools;
- }
- payoutToolDao.save(modifiedPayoutTools);
- }
-}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopContractChangedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopContractChangedHandler.java
index f3d155f..908623f 100644
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopContractChangedHandler.java
+++ b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopContractChangedHandler.java
@@ -52,7 +52,6 @@ public class ShopContractChangedHandler extends AbstractClaimChangedHandler {
Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
shopNew.setContractId(contractChanged.getContractId());
- shopNew.setPayoutToolId(contractChanged.getPayoutToolId());
shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "contractChanged");
}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopCreatedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopCreatedHandler.java
index 11bb5fc..9740218 100644
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopCreatedHandler.java
+++ b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopCreatedHandler.java
@@ -111,10 +111,6 @@ public class ShopCreatedHandler extends AbstractClaimChangedHandler {
ShopUtil.fillShopAccount(shop, shopCreated.getAccount());
}
shop.setContractId(shopCreated.getContractId());
- shop.setPayoutToolId(shopCreated.getPayoutToolId());
- if (shopCreated.isSetPayoutSchedule()) {
- shop.setPayoutScheduleId(shopCreated.getPayoutSchedule().getId());
- }
return shop;
}
}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutScheduleChangedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutScheduleChangedHandler.java
deleted file mode 100644
index 02f4b56..0000000
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutScheduleChangedHandler.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
-
-import dev.vality.damsel.payment_processing.ClaimEffect;
-import dev.vality.damsel.payment_processing.PartyChange;
-import dev.vality.damsel.payment_processing.ScheduleChanged;
-import dev.vality.damsel.payment_processing.ShopEffectUnit;
-import com.empayre.dominator.dao.party.iface.ShopDao;
-import com.empayre.dominator.domain.tables.pojos.Shop;
-import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
-import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class ShopPayoutScheduleChangedHandler extends AbstractClaimChangedHandler {
-
- private final ShopDao shopDao;
- private final ClaimEffectCopyFactory claimEffectCopyFactory;
-
- @Override
- @Transactional(propagation = Propagation.REQUIRED)
- public void handle(PartyChange change, MachineEvent event, Integer changeId) {
- long sequenceId = event.getEventId();
- List claimEffects = getClaimStatus(change).getAccepted().getEffects();
- for (int i = 0; i < claimEffects.size(); i++) {
- ClaimEffect claimEffect = claimEffects.get(i);
- if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutScheduleChanged()) {
- handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
- }
- }
- }
-
- private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
- Integer claimEffectId) {
- ShopEffectUnit shopEffect = e.getShopEffect();
- ScheduleChanged payoutScheduleChanged = shopEffect.getEffect().getPayoutScheduleChanged();
- String shopId = shopEffect.getShopId();
- String partyId = event.getSourceId();
- log.info("Start shop payoutScheduleChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
- sequenceId, partyId, shopId, changeId);
-
- final Shop shopOld = shopDao.get(partyId, shopId);
- Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
-
- if (payoutScheduleChanged.isSetSchedule()) {
- shopNew.setPayoutScheduleId(payoutScheduleChanged.getSchedule().getId());
- } else {
- shopNew.setPayoutScheduleId(null);
- }
-
- shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "payoutScheduleChanged");
- }
-}
diff --git a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutToolChangedHandler.java b/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutToolChangedHandler.java
deleted file mode 100644
index a5c0f7e..0000000
--- a/src/main/java/com/empayre/dominator/handler/event/stock/impl/partymngmnt/shop/ShopPayoutToolChangedHandler.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.empayre.dominator.handler.event.stock.impl.partymngmnt.shop;
-
-import com.empayre.dominator.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
-import dev.vality.damsel.payment_processing.ClaimEffect;
-import dev.vality.damsel.payment_processing.PartyChange;
-import dev.vality.damsel.payment_processing.ShopEffectUnit;
-import com.empayre.dominator.dao.party.iface.ShopDao;
-import com.empayre.dominator.domain.tables.pojos.Shop;
-import com.empayre.dominator.factory.claim.effect.ClaimEffectCopyFactory;
-import dev.vality.machinegun.eventsink.MachineEvent;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
-import java.util.List;
-
-@Slf4j
-@Component
-@RequiredArgsConstructor
-public class ShopPayoutToolChangedHandler extends AbstractClaimChangedHandler {
-
- private final ShopDao shopDao;
- private final ClaimEffectCopyFactory claimEffectCopyFactory;
-
- @Override
- @Transactional(propagation = Propagation.REQUIRED)
- public void handle(PartyChange change, MachineEvent event, Integer changeId) {
- long sequenceId = event.getEventId();
- List claimEffects = getClaimStatus(change).getAccepted().getEffects();
- for (int i = 0; i < claimEffects.size(); i++) {
- ClaimEffect claimEffect = claimEffects.get(i);
- if (claimEffect.isSetShopEffect() && claimEffect.getShopEffect().getEffect().isSetPayoutToolChanged()) {
- handleEvent(event, changeId, sequenceId, claimEffects.get(i), i);
- }
- }
- }
-
- private void handleEvent(MachineEvent event, Integer changeId, long sequenceId, ClaimEffect e,
- Integer claimEffectId) {
- ShopEffectUnit shopEffect = e.getShopEffect();
- String payoutToolChanged = shopEffect.getEffect().getPayoutToolChanged();
- String shopId = shopEffect.getShopId();
- String partyId = event.getSourceId();
- log.info("Start shop payoutToolChanged handling, sequenceId={}, partyId={}, shopId={}, changeId={}",
- sequenceId, partyId, shopId, changeId);
-
- final Shop shopOld = shopDao.get(partyId, shopId);
- Shop shopNew = claimEffectCopyFactory.create(event, sequenceId, claimEffectId, changeId, shopOld);
-
- shopNew.setPayoutToolId(payoutToolChanged);
-
- shopDao.saveWithUpdateCurrent(shopNew, shopOld.getId(), "payoutToolChanged");
- }
-}
diff --git a/src/main/java/com/empayre/dominator/util/JsonUtil.java b/src/main/java/com/empayre/dominator/util/JsonUtil.java
index dd89441..45626e0 100644
--- a/src/main/java/com/empayre/dominator/util/JsonUtil.java
+++ b/src/main/java/com/empayre/dominator/util/JsonUtil.java
@@ -14,9 +14,12 @@ import java.util.List;
import java.util.Objects;
public class JsonUtil {
- private static final ObjectMapper objectMapper = new ObjectMapper();
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
public static String thriftBaseToJsonString(TBase thriftBase) {
+ if (thriftBase == null) {
+ return null;
+ }
try {
return new TBaseProcessor().process(thriftBase, new JsonHandler()).toString();
} catch (IOException e) {
@@ -25,6 +28,9 @@ public class JsonUtil {
}
public static JsonNode thriftBaseToJsonNode(TBase thriftBase) {
+ if (thriftBase == null) {
+ return null;
+ }
try {
return new TBaseProcessor().process(thriftBase, new JsonHandler());
} catch (IOException e) {
@@ -33,16 +39,22 @@ public class JsonUtil {
}
public static String objectToJsonString(Object o) {
+ if (o == null) {
+ return null;
+ }
try {
- return objectMapper.writeValueAsString(o);
+ return OBJECT_MAPPER.writeValueAsString(o);
} catch (JsonProcessingException e) {
throw new RuntimeException("Couldn't convert object to json string: " + o, e);
}
}
public static T stringToObject(byte[] stringObject, Class type) {
+ if (stringObject == null) {
+ return null;
+ }
try {
- return objectMapper.readValue(stringObject, type);
+ return OBJECT_MAPPER.readValue(stringObject, type);
} catch (IOException e) {
throw new IllegalStateException("Couldn't convert json string to object: ", e);
}
@@ -59,7 +71,7 @@ public class JsonUtil {
if (Objects.isNull(object)) {
return new byte[0];
}
- return objectMapper.writeValueAsBytes(object);
+ return OBJECT_MAPPER.writeValueAsBytes(object);
} catch (IOException e) {
throw new IllegalStateException("Couldn't convert object to byte array: ", e);
}
diff --git a/src/test/java/com/empayre/dominator/generator/TestDataGenerator.java b/src/test/java/com/empayre/dominator/generator/TestDataGenerator.java
index 7f3ec04..f0a1c23 100644
--- a/src/test/java/com/empayre/dominator/generator/TestDataGenerator.java
+++ b/src/test/java/com/empayre/dominator/generator/TestDataGenerator.java
@@ -188,10 +188,6 @@ public class TestDataGenerator {
.setWithdrawals(
new WithdrawalProvisionTerms()
.setCurrencies(CurrencySelector.value(Set.of(new CurrencyRef().setSymbolicCode("RUB"))))
- .setPayoutMethods(PayoutMethodSelector.value(Set.of(
- new PayoutMethodRef()
- .setId(PayoutMethod.wallet_info)
- )))
.setCashFlow(CashFlowSelector.value(createCashFlowPostings()))
);
}