P2p lists (#21)

* Fix wb-lists
This commit is contained in:
Kostya 2020-02-19 18:25:27 +03:00 committed by GitHub
parent 8ba6244bdd
commit d5ee1b8644
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 24 deletions

@ -1 +1 @@
Subproject commit ea4aa042f482551d624fd49a570d28488f479e93
Subproject commit 8ad24ac7dc831a280cf8622086d73867d0a04b93

View File

@ -24,7 +24,7 @@
<dockerfile.base.service.tag>bc95d0d6dc13c693acd2b274531a7d604b877bf3</dockerfile.base.service.tag>
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
<shared.resources.version>0.3.6</shared.resources.version>
<wb.list.proto.version>1.27-be77f75</wb.list.proto.version>
<wb.list.proto.version>1.29-4fe14c3</wb.list.proto.version>
<kafka.streams.version>2.1.0</kafka.streams.version>
<kafka.clients.version>2.1.0</kafka.clients.version>
<kafka.common.lib.version>0.0.9</kafka.common.lib.version>

View File

@ -84,21 +84,22 @@ public class WbListServiceHandler implements WbListServiceSrv.Iface {
}
private Optional<com.rbkmoney.wb.list.manager.model.Row> getCascadeRow(Row row) {
if (row.getId().isSetPaymentId()) {
if (row.isSetId() && row.getId().isSetPaymentId()) {
PaymentId paymentId = row.getId().getPaymentId();
return Optional.ofNullable(
listRepository.get(KeyGenerator.generateKey(row.getListType(), row.getListName(), row.getValue()))
.orElse(listRepository.get(KeyGenerator.generateKey(row.getListType(), row.getListName(), row.getValue(), paymentId.getPartyId()))
.orElse(listRepository.get(KeyGenerator.generateKey(row.getListType(), row.getListName(), row.getValue(), paymentId.getPartyId(), paymentId.getShopId()))
.orElse(null))));
} else if (row.getId().isSetP2pId()) {
return cascadeGetRow(row.getListType(), row.getListName(), row.getValue(), paymentId.getPartyId(), paymentId.getShopId());
} else if (row.isSetId() && row.getId().isSetP2pId()) {
P2pId p2pId = row.getId().getP2pId();
return Optional.ofNullable(
listRepository.get(KeyGenerator.generateKey(row.getListType(), row.getListName(), row.getValue(), RowType.P_2_P))
.orElse(listRepository.get(KeyGenerator.generateKey(row.getListType(), row.getListName(), row.getValue(), RowType.P_2_P, p2pId.getIdentityId()))
.orElse(null)));
return cascadeGetRow(row.getListType(), row.getListName(), row.getValue(), RowType.P_2_P, p2pId.getIdentityId());
}
throw new UnknownRowTypeException();
return cascadeGetRow(row.list_type, row.list_name, row.value, row.getPartyId(), row.getShopId());
}
private Optional<com.rbkmoney.wb.list.manager.model.Row> cascadeGetRow(ListType list_type, String list_name, String value, String partyId, String shopId) {
return Optional.ofNullable(
listRepository.get(KeyGenerator.generateKey(list_type, list_name, value))
.orElse(listRepository.get(KeyGenerator.generateKey(list_type, list_name, value, partyId))
.orElse(listRepository.get(KeyGenerator.generateKey(list_type, list_name, value, partyId, shopId))
.orElse(null))));
}
}

View File

@ -4,22 +4,24 @@ import com.rbkmoney.damsel.wb_list.ListType;
import com.rbkmoney.damsel.wb_list.P2pId;
import com.rbkmoney.damsel.wb_list.PaymentId;
import com.rbkmoney.wb.list.manager.constant.RowType;
import com.rbkmoney.wb.list.manager.exception.UnknownRowTypeException;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.util.StringUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class KeyGenerator {
private static final String DELIMITER = "_";
public static String generateKey(com.rbkmoney.damsel.wb_list.Row row) {
if (row.getId().isSetPaymentId()) {
if (row.isSetId() && row.getId().isSetPaymentId()) {
PaymentId paymentId = row.getId().getPaymentId();
return generateKey(row.getListType(), row.getListName(), row.getValue(), paymentId.getPartyId(), paymentId.getShopId());
} else if (row.getId().isSetP2pId()) {
} else if (row.isSetId() && row.getId().isSetP2pId()) {
P2pId p2pId = row.getId().getP2pId();
return generateKey(row.getListType(), row.getListName(), row.getValue(), RowType.P_2_P, p2pId.getIdentityId());
}
throw new UnknownRowTypeException();
return generateKey(row.getListType(), row.getListName(), row.getValue(), row.getPartyId(), row.getShopId());
}
public static String generateKey(ListType listType, String listName, String value, String... params) {

View File

@ -14,7 +14,6 @@ import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringDeserializer;
import org.apache.thrift.TException;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
@ -92,10 +91,9 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
assertEquals(2, eventList.size());
Producer<String, ChangeCommand> producer = createProducer();
Row row = createRow();
Row row = createRowOld();
changeCommand = createCommand(row);
row.getId().getPaymentId()
.setShopId(null);
row.setShopId(null);
ProducerRecord<String, ChangeCommand> producerRecord = new ProducerRecord<>(topic, changeCommand.getRow().getValue(), changeCommand);
producer.send(producerRecord).get();
@ -105,8 +103,7 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
exist = iface.isExist(row);
assertTrue(exist);
row.getId().getPaymentId()
.setShopId(SHOP_ID);
row.setShopId(SHOP_ID);
exist = iface.isExist(row);
assertTrue(exist);
@ -207,6 +204,14 @@ public class WbListManagerApplicationTest extends KafkaAbstractTest {
return row;
}
@NotNull
private com.rbkmoney.damsel.wb_list.Row createRowOld() {
Row row = createListRow()
.setShopId(SHOP_ID)
.setPartyId(PARTY_ID);
return row;
}
@NotNull
private Row createListRow() {
Row row = new Row();