IMP-261: bump damsel (remove payout blocks) (#23)

This commit is contained in:
Baikov Dmitrii 2024-07-12 15:32:41 +03:00 committed by GitHub
parent c19a0d14d7
commit ec5a5e08dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 30 additions and 325 deletions

View File

@ -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

View File

@ -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 }}

22
pom.xml
View File

@ -6,7 +6,8 @@
<parent>
<groupId>dev.vality</groupId>
<artifactId>service-parent-pom</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<relativePath/>
</parent>
<artifactId>dominator</artifactId>
@ -92,6 +93,10 @@
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
@ -157,11 +162,6 @@
<artifactId>dominator-proto</artifactId>
<version>1.7-41bee97</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>payout-manager-proto</artifactId>
<version>1.36-063163d</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
<artifactId>kafka-common-lib</artifactId>
@ -184,7 +184,7 @@
<dependency>
<groupId>dev.vality</groupId>
<artifactId>damsel</artifactId>
<version>1.636-b869c09</version>
<version>1.641-6051aa9</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
@ -214,10 +214,12 @@
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>serializer</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>dev.vality.geck</groupId>
<artifactId>filter</artifactId>
<version>1.0.1</version>
</dependency>
<!-- Test -->
@ -270,7 +272,7 @@
<plugin>
<groupId>dev.vality.maven.plugins</groupId>
<artifactId>pg-embedded-plugin</artifactId>
<version>1.0.1</version>
<version>2.0.0</version>
<configuration>
<port>${local.pg.port}</port>
<dbName>${db.name}</dbName>
@ -319,7 +321,7 @@
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.3.9</version>
<version>42.7.3</version>
</dependency>
</dependencies>
</plugin>
@ -344,7 +346,7 @@
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes>
schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_payout.*|get_refund.*
schema_version|.*func|get_adjustment.*|get_cashflow.*|get_payment.*|get_refund.*
</excludes>
<inputSchema>${db.schema}</inputSchema>
</database>

View File

@ -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<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> 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)
);
}
}

View File

@ -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<Contract, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> 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<PayoutTool> currentPayoutTools = payoutToolDao.getByContractId(oldId);
currentPayoutTools.forEach(payoutTool -> {
payoutTool.setId(null);
payoutTool.setContractId(dbContractId);
});
PayoutToolInfoChanged payoutToolInfoChanged =
contractEffectUnit.getEffect().getPayoutToolInfoChanged();
Optional<PayoutTool> payoutToolForChangeOptional = currentPayoutTools.stream()
.filter(payoutTool -> payoutTool.getPayoutToolId().equals(payoutToolInfoChanged.getPayoutToolId()))
.findAny();
List<PayoutTool> 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);
}
}

View File

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

View File

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

View File

@ -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<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> 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");
}
}

View File

@ -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<Shop, Integer> claimEffectCopyFactory;
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
long sequenceId = event.getEventId();
List<ClaimEffect> 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");
}
}

View File

@ -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> T stringToObject(byte[] stringObject, Class<T> 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);
}

View File

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