mirror of
https://github.com/valitydev/daway.git
synced 2024-11-06 00:25:19 +00:00
modify changeset -> claimEffetcs for get party additional info (#49)
Co-authored-by: ggmaleva <ggmaleva@yandex.ru>
This commit is contained in:
parent
ff061ead23
commit
5a2592a4d8
@ -1,35 +0,0 @@
|
||||
package dev.vality.daway.handler.event.stock.impl.partymngmnt;
|
||||
|
||||
import dev.vality.damsel.payment_processing.PartyChange;
|
||||
import dev.vality.damsel.payment_processing.PartyModification;
|
||||
import dev.vality.geck.filter.Filter;
|
||||
import dev.vality.geck.filter.PathConditionFilter;
|
||||
import dev.vality.geck.filter.condition.IsNullCondition;
|
||||
import dev.vality.geck.filter.rule.PathConditionRule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractPartyModificationHandler implements PartyManagementHandler {
|
||||
|
||||
private final Filter partyMidificationFilter = new PathConditionFilter(
|
||||
new PathConditionRule("claim_created.changeset", new IsNullCondition().not()));
|
||||
|
||||
@Override
|
||||
public boolean accept(PartyChange change) {
|
||||
return partyMidificationFilter.match(change);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Filter<PartyChange> getFilter() {
|
||||
return partyMidificationFilter;
|
||||
}
|
||||
|
||||
protected List<PartyModification> getPartyModification(PartyChange change) {
|
||||
List<PartyModification> partyModifications = null;
|
||||
if (change.isSetClaimCreated() && change.getClaimCreated().isSetChangeset()) {
|
||||
partyModifications = change.getClaimCreated().getChangeset();
|
||||
}
|
||||
return partyModifications;
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,14 @@
|
||||
package dev.vality.daway.handler.event.stock.impl.partymngmnt.party;
|
||||
|
||||
import dev.vality.damsel.payment_processing.AdditionalInfoModificationUnit;
|
||||
import dev.vality.damsel.domain.PartyContactInfo;
|
||||
import dev.vality.damsel.payment_processing.AdditionalInfoEffect;
|
||||
import dev.vality.damsel.payment_processing.AdditionalInfoEffectUnit;
|
||||
import dev.vality.damsel.payment_processing.ClaimEffect;
|
||||
import dev.vality.damsel.payment_processing.PartyChange;
|
||||
import dev.vality.damsel.payment_processing.PartyModification;
|
||||
import dev.vality.daway.dao.party.iface.PartyDao;
|
||||
import dev.vality.daway.domain.tables.pojos.Party;
|
||||
import dev.vality.daway.factory.machine.event.MachineEventCopyFactory;
|
||||
import dev.vality.daway.handler.event.stock.impl.partymngmnt.AbstractPartyModificationHandler;
|
||||
import dev.vality.daway.handler.event.stock.impl.partymngmnt.AbstractClaimChangedHandler;
|
||||
import dev.vality.machinegun.eventsink.MachineEvent;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -16,14 +18,14 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class PartyModificationAdditionalInfoHandler extends AbstractPartyModificationHandler {
|
||||
public class PartyModificationAdditionalInfoHandler extends AbstractClaimChangedHandler {
|
||||
|
||||
|
||||
public static final String PARTY_MODIFICATION_ADDITIONAL_INFO_EVENT = "party_modification_additional_info";
|
||||
public static final String PARTY_ADDITIONAL_INFO_EVENT = "party_additional_info";
|
||||
private final PartyDao partyDao;
|
||||
private final MachineEventCopyFactory<Party, Integer> partyIntegerMachineEventCopyFactory;
|
||||
|
||||
@ -31,28 +33,43 @@ public class PartyModificationAdditionalInfoHandler extends AbstractPartyModific
|
||||
@Transactional(propagation = Propagation.REQUIRED)
|
||||
public void handle(PartyChange change, MachineEvent event, Integer changeId) {
|
||||
long sequenceId = event.getEventId();
|
||||
List<PartyModification> partyModifications = getPartyModification(change);
|
||||
if (partyModifications.stream().anyMatch(PartyModification::isSetAdditionalInfoModification)) {
|
||||
AdditionalInfoModificationUnit additionalInfoModification = partyModifications.stream()
|
||||
.filter(PartyModification::isSetAdditionalInfoModification)
|
||||
.findFirst()
|
||||
.map(PartyModification::getAdditionalInfoModification)
|
||||
.orElseThrow(() -> new IllegalArgumentException(""));
|
||||
List<ClaimEffect> claimEffects = getClaimStatus(change).getAccepted().getEffects();
|
||||
if (claimEffects.stream().anyMatch(ClaimEffect::isSetAdditionalInfoEffect)) {
|
||||
List<AdditionalInfoEffect> additionalInfoEffects = claimEffects.stream()
|
||||
.filter(ClaimEffect::isSetAdditionalInfoEffect)
|
||||
.map(ClaimEffect::getAdditionalInfoEffect)
|
||||
.map(AdditionalInfoEffectUnit::getEffect)
|
||||
.toList();
|
||||
String partyId = event.getSourceId();
|
||||
log.info("Start party modification additional info handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
|
||||
log.info("Start party additional info effect handling, sequenceId={}, partyId={}, changeId={}", sequenceId, partyId,
|
||||
changeId);
|
||||
Party partyOld = partyDao.get(partyId);
|
||||
Party partyNew = partyIntegerMachineEventCopyFactory.create(event, sequenceId, changeId, partyOld, null);
|
||||
|
||||
partyNew.setName(additionalInfoModification.getPartyName());
|
||||
partyNew.setComment(additionalInfoModification.getComment());
|
||||
String managerContactEmails = StringUtils.collectionToDelimitedString(
|
||||
additionalInfoModification.getManagerContactEmails(), ",");
|
||||
partyNew.setManagerContactEmails(managerContactEmails);
|
||||
|
||||
partyDao.saveWithUpdateCurrent(partyNew, partyOld.getId(), PARTY_MODIFICATION_ADDITIONAL_INFO_EVENT);
|
||||
fillPartyAdditionalInfo(additionalInfoEffects, partyNew);
|
||||
partyDao.saveWithUpdateCurrent(partyNew, partyOld.getId(), PARTY_ADDITIONAL_INFO_EVENT);
|
||||
}
|
||||
}
|
||||
|
||||
private static void fillPartyAdditionalInfo(List<AdditionalInfoEffect> additionalInfoEffects, Party partyNew) {
|
||||
Optional<String> partyName = additionalInfoEffects.stream()
|
||||
.filter(AdditionalInfoEffect::isSetPartyName)
|
||||
.map(AdditionalInfoEffect::getPartyName)
|
||||
.findFirst();
|
||||
partyName.ifPresent(partyNew::setName);
|
||||
Optional<String> partyComment = additionalInfoEffects.stream()
|
||||
.filter(AdditionalInfoEffect::isSetPartyComment)
|
||||
.map(AdditionalInfoEffect::getPartyComment)
|
||||
.findFirst();
|
||||
partyComment.ifPresent(partyNew::setComment);
|
||||
Optional<PartyContactInfo> contactInfo = additionalInfoEffects.stream()
|
||||
.filter(AdditionalInfoEffect::isSetContactInfo)
|
||||
.map(AdditionalInfoEffect::getContactInfo)
|
||||
.findFirst();
|
||||
contactInfo.ifPresent(partyContactInfo -> {
|
||||
String managerContactEmails = StringUtils.collectionToDelimitedString(
|
||||
partyContactInfo.getManagerContactEmails(), ",");
|
||||
partyNew.setManagerContactEmails(managerContactEmails);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -625,28 +625,42 @@ public class TestData {
|
||||
return userInteraction;
|
||||
}
|
||||
|
||||
public static PartyChange createPartyChangeWithPartyModificationAdditionalInfo(String name, String comment, String... emails) {
|
||||
AdditionalInfoModificationUnit additionalInfoModificationUnit = new AdditionalInfoModificationUnit();
|
||||
additionalInfoModificationUnit.setPartyName(name);
|
||||
additionalInfoModificationUnit.setComment(comment);
|
||||
additionalInfoModificationUnit.setManagerContactEmails(Arrays.stream(emails).toList());
|
||||
PartyModification partyModification = new PartyModification();
|
||||
partyModification.setAdditionalInfoModification(additionalInfoModificationUnit);
|
||||
Claim claim = createClaim();
|
||||
claim.setChangeset(List.of(partyModification));
|
||||
public static PartyChange createPartyChangeWithPartyAdditionalInfoEffect(String name, String comment, String... emails) {
|
||||
AdditionalInfoEffect additionalInfoPartyNameEffect = AdditionalInfoEffect.party_name(name);
|
||||
ClaimEffect claimEffectPartyName = createAdditionalInfoEffect(additionalInfoPartyNameEffect);
|
||||
AdditionalInfoEffect additionalInfoCommentEffect = AdditionalInfoEffect.party_comment(comment);
|
||||
ClaimEffect claimEffectComment = createAdditionalInfoEffect(additionalInfoCommentEffect);
|
||||
AdditionalInfoEffect additionalInfoContactInfoEffect = AdditionalInfoEffect.contact_info(
|
||||
new PartyContactInfo()
|
||||
.setManagerContactEmails(Arrays.stream(emails).toList())
|
||||
.setRegistrationEmail("test@test.com")
|
||||
);
|
||||
ClaimEffect claimEffectContactInfo = createAdditionalInfoEffect(additionalInfoContactInfoEffect);
|
||||
ClaimAccepted claimAccepted = new ClaimAccepted();
|
||||
claimAccepted.setEffects(List.of(claimEffectPartyName, claimEffectComment, claimEffectContactInfo));
|
||||
ClaimStatusChanged claimStatusChanged = createClaimStatusChanged();
|
||||
claimStatusChanged.setStatus(ClaimStatus.accepted(claimAccepted));
|
||||
PartyChange partyChange = new PartyChange();
|
||||
partyChange.setClaimCreated(claim);
|
||||
partyChange.setClaimStatusChanged(claimStatusChanged);
|
||||
return partyChange;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ClaimEffect createAdditionalInfoEffect(AdditionalInfoEffect additionalInfoPartyNameEffect) {
|
||||
AdditionalInfoEffectUnit additionalInfoEffectPartyNameUnit = new AdditionalInfoEffectUnit();
|
||||
additionalInfoEffectPartyNameUnit.setEffect(additionalInfoPartyNameEffect);
|
||||
ClaimEffect claimEffectPartyName = new ClaimEffect();
|
||||
claimEffectPartyName.setAdditionalInfoEffect(additionalInfoEffectPartyNameUnit);
|
||||
return claimEffectPartyName;
|
||||
}
|
||||
|
||||
public static Claim createClaim() {
|
||||
Claim claim = new Claim();
|
||||
claim.setId(1);
|
||||
claim.setCreatedAt("2023-07-03T10:15:30Z");
|
||||
claim.setStatus(ClaimStatus.accepted(new ClaimAccepted()));
|
||||
claim.setRevision(1);
|
||||
return claim;
|
||||
|
||||
public static ClaimStatusChanged createClaimStatusChanged() {
|
||||
ClaimStatusChanged claimStatusChanged = new ClaimStatusChanged();
|
||||
claimStatusChanged.setId(1);
|
||||
claimStatusChanged.setChangedAt("2023-07-03T10:15:30Z");
|
||||
claimStatusChanged.setRevision(1);
|
||||
return claimStatusChanged;
|
||||
}
|
||||
|
||||
public static ValidationResult testValidationResult() {
|
||||
|
@ -52,7 +52,7 @@ class PartyModificationAdditionalInfoHandlerTest {
|
||||
dslContext.insertInto(PARTY)
|
||||
.set(dslContext.newRecord(PARTY, party))
|
||||
.execute();
|
||||
PartyChange partyChange = TestData.createPartyChangeWithPartyModificationAdditionalInfo(partyName, comment, email);
|
||||
PartyChange partyChange = TestData.createPartyChangeWithPartyAdditionalInfoEffect(partyName, comment, email);
|
||||
PartyEventData partyEventData = new PartyEventData();
|
||||
partyEventData.setChanges(List.of(partyChange));
|
||||
MachineEvent machineEvent = TestData.createPartyEventDataMachineEvent(partyEventData, party.getPartyId());
|
||||
|
@ -4,13 +4,17 @@ import dev.vality.damsel.domain.PartyContactInfo;
|
||||
import dev.vality.damsel.payment_processing.PartyChange;
|
||||
import dev.vality.damsel.payment_processing.PartyCreated;
|
||||
import dev.vality.damsel.payment_processing.PartyEventData;
|
||||
import dev.vality.daway.TestData;
|
||||
import dev.vality.daway.config.SerializationConfig;
|
||||
import dev.vality.daway.dao.party.iface.PartyDao;
|
||||
import dev.vality.daway.domain.tables.pojos.Party;
|
||||
import dev.vality.daway.factory.machine.event.PartyMachineEventCopyFactoryImpl;
|
||||
import dev.vality.daway.handler.event.stock.impl.partymngmnt.party.PartyCreatedHandler;
|
||||
import dev.vality.daway.handler.event.stock.impl.partymngmnt.party.PartyModificationAdditionalInfoHandler;
|
||||
import dev.vality.machinegun.eventsink.MachineEvent;
|
||||
import dev.vality.machinegun.msgpack.Value;
|
||||
import dev.vality.sink.common.serialization.impl.PartyEventDataSerializer;
|
||||
import dev.vality.testcontainers.annotations.util.RandomBeans;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -25,13 +29,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(classes = {PartyMachineEventCopyFactoryImpl.class,
|
||||
PartyCreatedHandler.class, SerializationConfig.class, PartyManagementService.class})
|
||||
PartyCreatedHandler.class, SerializationConfig.class, PartyManagementService.class,
|
||||
PartyModificationAdditionalInfoHandler.class})
|
||||
class PartyManagementServiceTest {
|
||||
|
||||
@Autowired
|
||||
@ -40,9 +45,12 @@ class PartyManagementServiceTest {
|
||||
@MockBean
|
||||
PartyDao partyDao;
|
||||
|
||||
private final Party party = RandomBeans.random(Party.class);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
when(partyDao.save(any())).thenReturn(Optional.of(1L));
|
||||
when(partyDao.get(anyString())).thenReturn(party);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -76,4 +84,22 @@ class PartyManagementServiceTest {
|
||||
message.setData(data);
|
||||
return message;
|
||||
}
|
||||
|
||||
@Test
|
||||
void handlePartyModificationAdditionalInfoEvent() {
|
||||
String partyName = "partyName";
|
||||
String comment = "comment";
|
||||
String email = "test@mail";
|
||||
PartyChange partyChange = TestData.createPartyChangeWithPartyAdditionalInfoEffect(partyName, comment, email);
|
||||
PartyEventData partyEventData = new PartyEventData();
|
||||
partyEventData.setChanges(List.of(partyChange));
|
||||
MachineEvent machineEvent = TestData.createPartyEventDataMachineEvent(partyEventData, party.getPartyId());
|
||||
List<MachineEvent> machineEvents = new ArrayList<>();
|
||||
machineEvents.add(machineEvent);
|
||||
|
||||
partyManagementService.handleEvents(machineEvents);
|
||||
|
||||
Mockito.verify(partyDao, times(1)).saveWithUpdateCurrent(any(), anyLong(), anyString());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user