Merge branch 'master' into ft/JD-640

# Conflicts:
#	pom.xml
This commit is contained in:
ggmaleva 2021-08-31 15:41:05 +03:00
commit 83abd14a02
No known key found for this signature in database
GPG Key ID: 0E412B78565B108F
53 changed files with 1949 additions and 23 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View File

@ -33,7 +33,7 @@
<db.password>postgres</db.password>
<db.schema>af</db.schema>
<wb.list.proto.version>1.37-8cd59c1</wb.list.proto.version>
<fraudbusters.proto.version>1.95-e2836da</fraudbusters.proto.version>
<fraudbusters.proto.version>1.96-81934f5</fraudbusters.proto.version>
<kafka.common.lib.version>0.1.4</kafka.common.lib.version>
<fraudo.version>0.0.17</fraudo.version>
<geck.version>0.6.11</geck.version>

View File

@ -1,14 +1,8 @@
package com.rbkmoney.fraudbusters.management.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class RestTemplateConfig {

View File

@ -0,0 +1,54 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.damsel.fraudbusters.*;
import com.rbkmoney.swag.fraudbusters.management.model.ApplyRuleOnHistoricalDataSetRequest;
import com.rbkmoney.swag.fraudbusters.management.model.PaymentReference;
import lombok.AllArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.util.stream.Collectors;
@Component
@AllArgsConstructor
public class ApplyRuleOnHistoricalRequestToEmulationRuleApplyRequestConverter
implements Converter<ApplyRuleOnHistoricalDataSetRequest, EmulationRuleApplyRequest> {
public static final String EMULATION_TEMPLATE = "emulation_template";
private final PaymentApiToPaymentConverter paymentApiToPaymentConverter;
@NonNull
@Override
public EmulationRuleApplyRequest convert(ApplyRuleOnHistoricalDataSetRequest request) {
var emulationRule = new EmulationRule();
PaymentReference reference = request.getReference();
if (reference != null && StringUtils.hasText(reference.getPartyId())) {
emulationRule.setCascadingEmulation(new CascasdingTemplateEmulation()
.setRef(new TemplateReference()
.setPartyId(reference.getPartyId())
.setShopId(reference.getShopId())
.setTemplateId(EMULATION_TEMPLATE))
.setTemplate(new com.rbkmoney.damsel.fraudbusters.Template()
.setId(EMULATION_TEMPLATE)
.setTemplate(request.getTemplate().getBytes()))
.setRuleSetTimestamp(request.getRuleSetTimestamp() != null
? request.getRuleSetTimestamp().toString()
: null));
} else {
emulationRule.setTemplateEmulation(new OnlyTemplateEmulation()
.setTemplate(new com.rbkmoney.damsel.fraudbusters.Template()
.setId(EMULATION_TEMPLATE)
.setTemplate(request.getTemplate().getBytes())));
}
return new EmulationRuleApplyRequest()
.setEmulationRule(emulationRule)
.setTransactions(request.getRecords().stream()
.map(paymentApiToPaymentConverter::convert)
.collect(Collectors.toSet()));
}
}

View File

@ -0,0 +1,40 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.swag.fraudbusters.management.model.CheckedDataSet;
import com.rbkmoney.swag.fraudbusters.management.model.MerchantInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class CheckedDataSetModelToCheckedDataSetApiConverter
implements Converter<CheckedDataSetModel, CheckedDataSet> {
private final CheckedPaymentModelToCheckedDataSetRowConverter paymentModelToCheckedDataSetRowConverter;
@Override
public CheckedDataSet convert(CheckedDataSetModel testDataSetModel) {
return new CheckedDataSet()
.id(String.valueOf(testDataSetModel.getId()))
.checkingTimestamp(testDataSetModel.getCheckingTimestamp())
.createdAt(testDataSetModel.getCreatedAt())
.testDataSetId(String.valueOf(testDataSetModel.getTestDataSetId()))
.initiator(testDataSetModel.getInitiator())
.merchantInfo(new MerchantInfo()
.partyId(testDataSetModel.getPartyId())
.shopId(testDataSetModel.getShopId()))
.template(testDataSetModel.getTemplate())
.rows(CollectionUtils.isEmpty(testDataSetModel.getCheckedPaymentModels())
? List.of()
: testDataSetModel.getCheckedPaymentModels().stream()
.map(paymentModelToCheckedDataSetRowConverter::convert)
.collect(Collectors.toList()));
}
}

View File

@ -0,0 +1,28 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import com.rbkmoney.swag.fraudbusters.management.model.CheckedDataSetRow;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class CheckedPaymentModelToCheckedDataSetRowConverter
implements Converter<CheckedPaymentModel, CheckedDataSetRow> {
private final PaymentModelToPaymentApiConverter paymentModelToPaymentApiConverter;
@Override
public CheckedDataSetRow convert(CheckedPaymentModel checkedPaymentModel) {
var testPaymentModel = checkedPaymentModel.getPaymentModel();
return new CheckedDataSetRow()
.id(String.valueOf(checkedPaymentModel.getTestDataSetCheckingResultId()))
.resultStatus(checkedPaymentModel.getResultStatus())
.ruleChecked(checkedPaymentModel.getRuleChecked())
.checkedTemplate(checkedPaymentModel.getCheckedTemplate())
.notificationRule(checkedPaymentModel.getNotificationRule())
.payment(paymentModelToPaymentApiConverter.convert(testPaymentModel));
}
}

View File

@ -0,0 +1,33 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.swag.fraudbusters.management.model.DataSet;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class DataSetModelToDataSetApiConverter implements Converter<DataSetModel, DataSet> {
private final PaymentModelToDataSetRowConverter testPaymentModelToDataSetRowConverter;
@Override
public DataSet convert(DataSetModel dataSetModel) {
return new DataSet()
.id(dataSetModel.getId())
.name(dataSetModel.getName())
.lastModificationAt(dataSetModel.getLastModificationTime())
.lastModificationInitiator(dataSetModel.getLastModificationInitiator())
.rows(CollectionUtils.isEmpty(dataSetModel.getPaymentModelList())
? List.of()
: dataSetModel.getPaymentModelList().stream()
.map(testPaymentModelToDataSetRowConverter::convert)
.collect(Collectors.toList()));
}
}

View File

@ -0,0 +1,51 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.fraudbusters.management.exception.UnknownPaymentException;
import com.rbkmoney.swag.fraudbusters.management.model.DataSetRow;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
public class DataSetRowToTestPaymentModelConverter implements Converter<DataSetRow, PaymentModel> {
@Override
public PaymentModel convert(DataSetRow dataSetRow) {
var payment = dataSetRow.getPayment();
if (payment == null) {
throw new UnknownPaymentException();
}
var clientInfo = payment.getClientInfo();
var error = payment.getError();
var merchantInfo = payment.getMerchantInfo();
return PaymentModel.builder()
.id(dataSetRow.getId() != null ? Long.valueOf(dataSetRow.getId()) : null)
.eventTime(payment.getEventTime())
.amount(payment.getAmount())
.currency(payment.getCurrency())
.cardToken(payment.getCardToken())
.country(payment.getPaymentCountry())
.email(clientInfo != null ? clientInfo.getEmail() : null)
.fingerprint(clientInfo != null ? clientInfo.getFingerprint() : null)
.errorCode(error != null ? error.getErrorCode() : null)
.errorReason(error != null ? error.getErrorReason() : null)
.ip(clientInfo != null ? clientInfo.getIp() : null)
.paymentId(payment.getId())
.payerType(payment.getPayerType())
.paymentSystem(payment.getPaymentSystem())
.paymentTool(payment.getPaymentTool())
.mobile(payment.getMobile())
.recurrent(payment.getRecurrent())
.partyId(merchantInfo != null ? merchantInfo.getPartyId() : null)
.shopId(merchantInfo != null ? merchantInfo.getShopId() : null)
.providerId(payment.getProvider() != null ? payment.getProvider().getProviderId() : null)
.terminalId(payment.getProvider() != null ? payment.getProvider().getTerminalId() : null)
.paymentCountry(payment.getPaymentCountry())
.status(payment.getStatus().name())
.testDataSetId(dataSetRow.getId() != null ? Long.valueOf(dataSetRow.getId()) : null)
.bin(payment.getBin())
.lastDigits(payment.getLastDigits())
.build();
}
}

View File

@ -0,0 +1,39 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.swag.fraudbusters.management.model.DataSet;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class DataSetToTestDataSetModelConverter implements Converter<DataSet, DataSetModel> {
private final DataSetRowToTestPaymentModelConverter dataSetRowToTestPaymentModelConverter;
@Override
public DataSetModel convert(DataSet dataSet) {
return DataSetModel.builder()
.id(dataSet.getId() != null ? dataSet.getId() : null)
.name(dataSet.getName())
.lastModificationInitiator(dataSet.getLastModificationInitiator())
.lastModificationTime(dataSet.getLastModificationAt())
.paymentModelList(CollectionUtils.isEmpty(dataSet.getRows())
? null
: mapDataSetToTestPaymentModels(dataSet))
.build();
}
private List<PaymentModel> mapDataSetToTestPaymentModels(DataSet dataSet) {
return dataSet.getRows().stream()
.map(dataSetRowToTestPaymentModelConverter::convert)
.collect(Collectors.toList());
}
}

View File

@ -6,7 +6,6 @@ import com.rbkmoney.swag.fraudbusters.management.model.PaymentReference;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component

View File

@ -1,7 +1,5 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.damsel.fraudbusters.WithdrawalStatus;
import com.rbkmoney.geck.common.util.TBaseUtil;
import com.rbkmoney.swag.fraudbusters.management.model.InspectResult;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;

View File

@ -0,0 +1,48 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.damsel.fraudbusters.HistoricalDataSetCheckResult;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import java.util.stream.Collectors;
@Component
@RequiredArgsConstructor
public class HistoricalDataSetCheckResultToTestCheckedDataSetModelConverter
implements Converter<HistoricalDataSetCheckResult, CheckedDataSetModel> {
private final PaymentToTestPaymentModelConverter paymentToTestPaymentModelConverter;
@NonNull
@Override
public CheckedDataSetModel convert(HistoricalDataSetCheckResult historicalDataSetCheckResult) {
var testCheckedDataSetModel = new CheckedDataSetModel();
testCheckedDataSetModel.setCheckedPaymentModels(historicalDataSetCheckResult
.getHistoricalTransactionCheck().stream()
.map(this::mapToCheckedPaymentModel)
.collect(Collectors.toList()));
return testCheckedDataSetModel;
}
private CheckedPaymentModel mapToCheckedPaymentModel(
com.rbkmoney.damsel.fraudbusters.HistoricalTransactionCheck historicalTransactionCheck) {
return CheckedPaymentModel.builder()
.testPaymentId(Long.valueOf(historicalTransactionCheck.getTransaction().getId()))
.checkedTemplate(historicalTransactionCheck.getCheckResult().getCheckedTemplate())
.resultStatus(historicalTransactionCheck.getCheckResult()
.getConcreteCheckResult().getResultStatus().getSetField().getFieldName())
.ruleChecked(
historicalTransactionCheck.getCheckResult().getConcreteCheckResult().getRuleChecked())
.notificationRule(historicalTransactionCheck.getCheckResult().getConcreteCheckResult()
.getNotificationsRule())
.paymentModel(
paymentToTestPaymentModelConverter.convert(historicalTransactionCheck.getTransaction()))
.build();
}
}

View File

@ -0,0 +1,88 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.Cash;
import com.rbkmoney.damsel.domain.CurrencyRef;
import com.rbkmoney.damsel.domain.PaymentTool;
import com.rbkmoney.damsel.fraudbusters.Error;
import com.rbkmoney.damsel.fraudbusters.*;
import com.rbkmoney.swag.fraudbusters.management.model.Payment;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import java.util.Optional;
@Component
public class PaymentApiToPaymentConverter
implements Converter<Payment, com.rbkmoney.damsel.fraudbusters.Payment> {
@NonNull
@Override
public com.rbkmoney.damsel.fraudbusters.Payment convert(Payment payment) {
return new com.rbkmoney.damsel.fraudbusters.Payment()
.setId(payment.getId())
.setClientInfo(createClientInfo(payment))
.setCost(createCash(payment))
.setStatus(PaymentStatus.valueOf(payment.getStatus().getValue()))
.setError(createError(payment))
.setEventTime(payment.getEventTime() != null
? payment.getEventTime().toString()
: null)
.setMobile(Optional.ofNullable(payment.getMobile()).orElse(false))
.setRecurrent(Optional.ofNullable(payment.getRecurrent()).orElse(false))
.setPayerType(payment.getPayerType() != null
? PayerType.valueOf(payment.getPayerType())
: PayerType.payment_resource)
.setPaymentTool(createPaymentTool(payment))
.setProviderInfo(createProviderInfo(payment))
.setReferenceInfo(ReferenceInfo.merchant_info(createMerchantInfo(payment)));
}
private Cash createCash(Payment payment) {
return new Cash()
.setAmount(payment.getAmount())
.setCurrency(new CurrencyRef()
.setSymbolicCode(payment.getCurrency()));
}
private PaymentTool createPaymentTool(Payment payment) {
return PaymentTool.bank_card(new BankCard()
.setBin(payment.getBin())
.setLastDigits(payment.getLastDigits())
.setToken(payment.getCardToken()));
}
private ProviderInfo createProviderInfo(Payment payment) {
return payment.getProvider() != null
? new ProviderInfo()
.setTerminalId(payment.getProvider().getProviderId())
.setCountry(payment.getProvider().getCountry())
.setProviderId(payment.getProvider().getProviderId())
: new ProviderInfo();
}
private MerchantInfo createMerchantInfo(Payment payment) {
return new MerchantInfo()
.setShopId(payment.getMerchantInfo().getShopId())
.setPartyId(payment.getMerchantInfo().getPartyId());
}
private Error createError(com.rbkmoney.swag.fraudbusters.management.model.Payment payment) {
return payment.getError() != null
? new Error()
.setErrorCode(payment.getError().getErrorCode())
.setErrorReason(payment.getError().getErrorReason())
: null;
}
private ClientInfo createClientInfo(com.rbkmoney.swag.fraudbusters.management.model.Payment payment) {
return payment.getClientInfo() != null
? new ClientInfo()
.setIp(payment.getClientInfo().getIp())
.setEmail(payment.getClientInfo().getEmail())
.setFingerprint(payment.getClientInfo().getFingerprint())
: null;
}
}

View File

@ -0,0 +1,22 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.swag.fraudbusters.management.model.DataSetRow;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class PaymentModelToDataSetRowConverter implements Converter<PaymentModel, DataSetRow> {
private final PaymentModelToPaymentApiConverter paymentModelToPaymentApiConverter;
@Override
public DataSetRow convert(PaymentModel paymentModel) {
return new DataSetRow()
.id(String.valueOf(paymentModel.getTestDataSetId()))
.payment(paymentModelToPaymentApiConverter.convert(paymentModel));
}
}

View File

@ -0,0 +1,51 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.swag.fraudbusters.management.model.Error;
import com.rbkmoney.swag.fraudbusters.management.model.*;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Component
@RequiredArgsConstructor
public class PaymentModelToPaymentApiConverter implements Converter<PaymentModel, Payment> {
@Override
public Payment convert(PaymentModel paymentModel) {
return new Payment()
.id(String.valueOf(paymentModel.getId()))
.paymentId(paymentModel.getPaymentId())
.eventTime(paymentModel.getEventTime())
.amount(paymentModel.getAmount())
.currency(paymentModel.getCurrency())
.cardToken(paymentModel.getCardToken())
.bin(paymentModel.getBin())
.lastDigits(paymentModel.getLastDigits())
.paymentCountry(paymentModel.getPaymentCountry())
.clientInfo(new ClientInfo()
.email(paymentModel.getEmail())
.ip(paymentModel.getIp())
.fingerprint(paymentModel.getFingerprint()))
.error(StringUtils.hasText(paymentModel.getErrorCode())
? new Error()
.errorReason(paymentModel.getErrorReason())
.errorCode(paymentModel.getErrorCode())
: null)
.payerType(paymentModel.getPayerType())
.paymentSystem(paymentModel.getPaymentSystem())
.paymentTool(paymentModel.getPaymentTool())
.mobile(paymentModel.getMobile())
.recurrent(paymentModel.getRecurrent())
.merchantInfo(new MerchantInfo()
.shopId(paymentModel.getShopId())
.partyId(paymentModel.getPartyId()))
.provider(new ProviderInfo()
.terminalId(paymentModel.getTerminalId())
.providerId(paymentModel.getProviderId())
.country(paymentModel.getCountry()))
.status(Payment.StatusEnum.valueOf(paymentModel.getStatus()));
}
}

View File

@ -46,6 +46,8 @@ public class PaymentToApiPaymentConverter
.paymentCountry(bankCard.isSetIssuerCountry() ? bankCard.getIssuerCountry().name() : null)
.paymentSystem(bankCard.isSetPaymentSystem() ? bankCard.getPaymentSystem().getId() : null)
.paymentTool(paymentTool.getFieldValue().toString())
.bin(bankCard.getBin())
.lastDigits(bankCard.getLastDigits())
.provider(payment.isSetProviderInfo()
? new ProviderInfo().providerId(payment.getProviderInfo().getProviderId())
.country(payment.getProviderInfo().getCountry())

View File

@ -0,0 +1,83 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import static com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel.*;
@Component
public class PaymentToTestPaymentModelConverter
implements Converter<com.rbkmoney.damsel.fraudbusters.Payment, PaymentModel> {
@NonNull
@Override
public PaymentModel convert(com.rbkmoney.damsel.fraudbusters.Payment payment) {
PaymentModelBuilder builder = builder();
if (payment.isSetReferenceInfo()) {
updateReferenceInfo(builder, payment.getReferenceInfo());
}
if (payment.getPaymentTool().isSetBankCard()) {
updateBankCardData(builder, payment.getPaymentTool().getBankCard());
}
if (payment.isSetProviderInfo()) {
updateProviderInfo(builder, payment.getProviderInfo());
}
if (payment.isSetClientInfo()) {
updateClientInfo(builder, payment.getClientInfo());
}
if (payment.isSetError()) {
updateError(builder, payment.getError());
}
return builder
.currency(payment.getCost().getCurrency().getSymbolicCode())
.amount(payment.getCost().getAmount())
.eventTime(payment.getEventTime() != null
? DateTimeUtils.toDate(payment.getEventTime())
: null)
.paymentId(payment.getId())
.status(payment.getStatus() != null
? payment.getStatus().name()
: null)
.paymentTool(payment.getPaymentTool().getFieldValue().toString())
.payerType(payment.getPayerType().name())
.build();
}
private void updateError(PaymentModelBuilder builder, com.rbkmoney.damsel.fraudbusters.Error error) {
builder.errorCode(error.getErrorCode())
.errorReason(error.getErrorReason());
}
private void updateClientInfo(PaymentModelBuilder builder,
com.rbkmoney.damsel.fraudbusters.ClientInfo clientInfo) {
builder.ip(clientInfo.getIp())
.fingerprint(clientInfo.getFingerprint())
.email(clientInfo.getEmail());
}
private void updateProviderInfo(PaymentModelBuilder builder,
com.rbkmoney.damsel.fraudbusters.ProviderInfo providerInfo) {
builder.terminalId(providerInfo.getTerminalId())
.providerId(providerInfo.getProviderId())
.country(providerInfo.getCountry());
}
private void updateBankCardData(PaymentModelBuilder builder,
com.rbkmoney.damsel.domain.BankCard bankCard) {
builder.paymentSystem(bankCard.isSetPaymentSystem() ? bankCard.getPaymentSystem().getId() : null)
.paymentCountry(bankCard.isSetIssuerCountry() ? bankCard.getIssuerCountry().name() : null)
.cardToken(bankCard.getToken())
.bin(bankCard.getBin())
.lastDigits(bankCard.getLastDigits());
}
private void updateReferenceInfo(PaymentModelBuilder builder,
com.rbkmoney.damsel.fraudbusters.ReferenceInfo referenceInfo) {
builder.partyId(referenceInfo.getMerchantInfo().getPartyId())
.shopId(referenceInfo.getMerchantInfo().getShopId());
}
}

View File

@ -3,7 +3,6 @@ package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import com.rbkmoney.swag.fraudbusters.management.model.Error;
import com.rbkmoney.swag.fraudbusters.management.model.*;
import lombok.RequiredArgsConstructor;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;

View File

@ -51,7 +51,7 @@ public abstract class AbstractDao extends AbstractGenericDao {
Integer size,
SelectSeekStep1<T, String> orderQuery) {
SelectForUpdateStep<T> seekQuery;
if (!StringUtils.isEmpty(lastId)) {
if (StringUtils.hasText(lastId)) {
seekQuery = orderQuery
.seek(lastId)
.limit(size);

View File

@ -0,0 +1,13 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import java.util.Optional;
public interface DataSetCheckingResultDao {
Optional<Long> insert(CheckedDataSetModel dataSetModel);
CheckedDataSetModel getById(Long id);
}

View File

@ -0,0 +1,102 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.dao.AbstractDao;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.mapper.CheckedPaymentModelRowMapper;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.mapper.DataSetRowMapper;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import org.jooq.Query;
import org.jooq.Record;
import org.jooq.SelectConditionStep;
import org.jooq.SelectOnConditionStep;
import org.jooq.impl.DSL;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.sql.DataSource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.rbkmoney.fraudbusters.management.domain.Tables.*;
import static org.jooq.impl.DSL.select;
@Component
public class DataSetCheckingResultDaoImpl extends AbstractDao implements DataSetCheckingResultDao {
public DataSetCheckingResultDaoImpl(DataSource dataSource) {
super(dataSource);
}
private final CheckedPaymentModelRowMapper checkedPaymentModelRowMapper = new CheckedPaymentModelRowMapper();
private final DataSetRowMapper dataSetRowMapper = new DataSetRowMapper();
@Override
@Transactional
public Optional<Long> insert(CheckedDataSetModel dataSetModel) {
dataSetModel.setCreatedAt(LocalDateTime.now());
Query query = getDslContext().insertInto(TEST_DATA_SET_CHECKING_RESULT)
.set(getDslContext().newRecord(TEST_DATA_SET_CHECKING_RESULT, dataSetModel))
.onConflict(TEST_DATA_SET_CHECKING_RESULT.ID)
.doUpdate()
.set(getDslContext().newRecord(TEST_DATA_SET_CHECKING_RESULT, dataSetModel))
.returning(TEST_DATA_SET_CHECKING_RESULT.ID);
var keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
Optional<Long> checkedDataSetModelId = Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
List<Query> queries = dataSetModel.getCheckedPaymentModels().stream()
.peek(testCheckedPaymentModel -> testCheckedPaymentModel
.setTestDataSetCheckingResultId(checkedDataSetModelId.get()))
.map(payment -> getDslContext().newRecord(TEST_PAYMENT_CHECKING_RESULT, payment))
.map(testCheckedPaymentModel -> getDslContext().insertInto(TEST_PAYMENT_CHECKING_RESULT)
.set(getDslContext().newRecord(TEST_PAYMENT_CHECKING_RESULT, testCheckedPaymentModel))
.onConflict(TEST_PAYMENT_CHECKING_RESULT.ID)
.doUpdate()
.set(getDslContext().newRecord(TEST_PAYMENT_CHECKING_RESULT, testCheckedPaymentModel)))
.collect(Collectors.toList());
batchExecute(queries);
return checkedDataSetModelId;
}
@Override
public CheckedDataSetModel getById(Long id) {
var dslContext = getDslContext();
Query query = dslContext.select(TEST_DATA_SET.fields())
.select(TEST_DATA_SET_CHECKING_RESULT.fields())
.select(TEST_DATA_SET_CHECKING_RESULT.ID.as(DataSetRowMapper.TEST_DATA_SET_ID_JOIN))
.from(TEST_DATA_SET)
.leftJoin(TEST_DATA_SET_CHECKING_RESULT)
.on(TEST_DATA_SET.ID.eq(TEST_DATA_SET_CHECKING_RESULT.TEST_DATA_SET_ID))
.where(TEST_DATA_SET.ID.eq(id)
.and(TEST_DATA_SET_CHECKING_RESULT.ID.eq(
select(DSL.max(TEST_DATA_SET_CHECKING_RESULT.ID))
.from(TEST_DATA_SET_CHECKING_RESULT)
.where(TEST_DATA_SET_CHECKING_RESULT.TEST_DATA_SET_ID.eq(id)))
.or(TEST_DATA_SET_CHECKING_RESULT.ID.isNull()))
);
CheckedDataSetModel testCheckedPaymentModel = fetchOne(query, dataSetRowMapper);
SelectConditionStep<Record> where = null;
SelectOnConditionStep<Record> selectJoin = dslContext.select(TEST_PAYMENT.fields())
.select(TEST_PAYMENT_CHECKING_RESULT.fields())
.from(TEST_PAYMENT)
.leftJoin(TEST_PAYMENT_CHECKING_RESULT)
.on(TEST_PAYMENT.ID.eq(TEST_PAYMENT_CHECKING_RESULT.TEST_PAYMENT_ID));
if (testCheckedPaymentModel.getId() != null && testCheckedPaymentModel.getId() != 0) {
where = selectJoin.where(TEST_PAYMENT_CHECKING_RESULT.TEST_DATA_SET_CHECKING_RESULT_ID
.equal(testCheckedPaymentModel.getId()));
} else {
where = selectJoin.where(TEST_PAYMENT.TEST_DATA_SET_ID.equal(testCheckedPaymentModel.getTestDataSetId()));
}
List<CheckedPaymentModel> checkedPaymentModels = fetch(where, checkedPaymentModelRowMapper);
testCheckedPaymentModel.setCheckedPaymentModels(checkedPaymentModels);
return testCheckedPaymentModel;
}
}

View File

@ -0,0 +1,20 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
public interface DataSetDao {
Optional<Long> insert(DataSetModel dataSetModel);
void remove(Long id);
DataSetModel getById(Long id);
List<DataSetModel> filter(LocalDateTime from, LocalDateTime to, FilterRequest filterRequest);
}

View File

@ -0,0 +1,88 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.dao.AbstractDao;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.domain.tables.records.TestDataSetRecord;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import com.rbkmoney.mapper.RecordRowMapper;
import org.jooq.*;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_DATA_SET;
@Component
public class DataSetDaoImpl extends AbstractDao implements DataSetDao {
private final RowMapper<DataSetModel> listRecordRowMapper;
public DataSetDaoImpl(DataSource dataSource) {
super(dataSource);
listRecordRowMapper = new RecordRowMapper<>(TEST_DATA_SET, DataSetModel.class);
}
@Override
public Optional<Long> insert(DataSetModel dataSetModel) {
dataSetModel.setLastModificationTime(null);
Query query = getDslContext().insertInto(TEST_DATA_SET)
.set(getDslContext().newRecord(TEST_DATA_SET, dataSetModel))
.onConflict(TEST_DATA_SET.NAME)
.doUpdate()
.set(getDslContext().newRecord(TEST_DATA_SET, dataSetModel))
.returning(TEST_DATA_SET.ID);
var keyHolder = new GeneratedKeyHolder();
execute(query, keyHolder);
return Optional.ofNullable(keyHolder.getKey()).map(Number::longValue);
}
@Override
public void remove(Long id) {
DeleteConditionStep<TestDataSetRecord> where = getDslContext()
.delete(TEST_DATA_SET)
.where(TEST_DATA_SET.ID.eq(id));
execute(where);
}
@Override
public DataSetModel getById(Long id) {
Query query = getDslContext()
.selectFrom(TEST_DATA_SET)
.where(TEST_DATA_SET.ID.eq(id));
return fetchOne(query, listRecordRowMapper);
}
@Override
public List<DataSetModel> filter(LocalDateTime from, LocalDateTime to, FilterRequest filterRequest) {
SelectWhereStep<TestDataSetRecord> where = getDslContext()
.selectFrom(TEST_DATA_SET);
SelectConditionStep<TestDataSetRecord> whereQuery =
!StringUtils.hasLength(filterRequest.getSearchValue())
? where.where(TEST_DATA_SET.LAST_MODIFICATION_TIME.between(from, to))
: where.where(TEST_DATA_SET.NAME.like(filterRequest.getSearchValue())
.and(TEST_DATA_SET.LAST_MODIFICATION_TIME.between(from, to)));
SelectSeekStep2<TestDataSetRecord, LocalDateTime, Long> queryOrdered =
addSortCondition(TEST_DATA_SET.ID, TEST_DATA_SET.LAST_MODIFICATION_TIME, filterRequest.getSortOrder(),
whereQuery);
return fetch(
addSeekIfNeed(
filterRequest.getLastId() != null ? Long.valueOf(filterRequest.getLastId()) : null,
filterRequest.getSortBy() != null ? DateTimeUtils.toDate(filterRequest.getSortBy()) : null,
filterRequest.getSize(),
queryOrdered
),
listRecordRowMapper
);
}
}

View File

@ -0,0 +1,19 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import java.util.List;
public interface PaymentDao {
void insert(PaymentModel dataSetModel);
void insertBatch(List<PaymentModel> dataSetModels);
void remove(Long id);
List<PaymentModel> getByDataSetId(Long id);
void removeByDataSetId(Long id);
}

View File

@ -0,0 +1,77 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.dao.AbstractDao;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.fraudbusters.management.domain.tables.records.TestPaymentRecord;
import com.rbkmoney.mapper.RecordRowMapper;
import org.jooq.DeleteConditionStep;
import org.jooq.Query;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.List;
import java.util.stream.Collectors;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_PAYMENT;
@Component
public class PaymentDaoImpl extends AbstractDao implements PaymentDao {
private final RowMapper<PaymentModel> listRecordRowMapper;
public PaymentDaoImpl(DataSource dataSource) {
super(dataSource);
listRecordRowMapper = new RecordRowMapper<>(TEST_PAYMENT, PaymentModel.class);
}
@Override
public void insert(PaymentModel paymentModel) {
paymentModel.setLastModificationDate(null);
Query query = getDslContext().insertInto(TEST_PAYMENT)
.set(getDslContext().newRecord(TEST_PAYMENT, paymentModel))
.onConflict(TEST_PAYMENT.ID)
.doUpdate()
.set(getDslContext().newRecord(TEST_PAYMENT, paymentModel));
execute(query);
}
@Override
public void insertBatch(List<PaymentModel> dataSetModels) {
List<Query> queries = dataSetModels.stream()
.map(payment -> getDslContext().newRecord(TEST_PAYMENT, payment))
.map(paymentRecord -> getDslContext()
.insertInto(TEST_PAYMENT)
.set(paymentRecord)
.onConflict(TEST_PAYMENT.ID)
.doUpdate()
.set(getDslContext().newRecord(TEST_PAYMENT, paymentRecord)))
.collect(Collectors.toList());
batchExecute(queries);
}
@Override
public void remove(Long id) {
DeleteConditionStep<TestPaymentRecord> where = getDslContext()
.delete(TEST_PAYMENT)
.where(TEST_PAYMENT.ID.eq(id));
execute(where);
}
@Override
public void removeByDataSetId(Long id) {
DeleteConditionStep<TestPaymentRecord> where = getDslContext()
.delete(TEST_PAYMENT)
.where(TEST_PAYMENT.TEST_DATA_SET_ID.eq(id));
execute(where);
}
@Override
public List<PaymentModel> getByDataSetId(Long id) {
Query query = getDslContext()
.selectFrom(TEST_PAYMENT)
.where(TEST_PAYMENT.TEST_DATA_SET_ID.eq(id));
return fetch(query, listRecordRowMapper);
}
}

View File

@ -0,0 +1,70 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset.mapper;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_PAYMENT;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_PAYMENT_CHECKING_RESULT;
public class CheckedPaymentModelRowMapper implements RowMapper<CheckedPaymentModel> {
@Override
public CheckedPaymentModel mapRow(ResultSet resultSet, int i) throws SQLException {
return CheckedPaymentModel.builder()
.resultStatus(resultSet.getString(TEST_PAYMENT_CHECKING_RESULT.RESULT_STATUS.getName()))
.checkedTemplate(resultSet.getString(TEST_PAYMENT_CHECKING_RESULT.CHECKED_TEMPLATE.getName()))
.ruleChecked(resultSet.getString(TEST_PAYMENT_CHECKING_RESULT.RULE_CHECKED.getName()))
.testPaymentId(resultSet.getLong(TEST_PAYMENT_CHECKING_RESULT.TEST_PAYMENT_ID.getName()))
.paymentModel(PaymentModel.builder()
.paymentCountry(resultSet.getString(TEST_PAYMENT.PAYMENT_COUNTRY.getName()))
.paymentId(resultSet.getString(TEST_PAYMENT.PAYMENT_ID.getName()))
.testDataSetId(resultSet.getLong(TEST_PAYMENT.TEST_DATA_SET_ID.getName()))
.paymentSystem(resultSet.getString(TEST_PAYMENT.PAYMENT_SYSTEM.getName()))
.amount(resultSet.getLong(TEST_PAYMENT.AMOUNT.getName()))
.country(resultSet.getString(TEST_PAYMENT.COUNTRY.getName()))
.currency(resultSet.getString(TEST_PAYMENT.CURRENCY.getName()))
.cardToken(resultSet.getString(TEST_PAYMENT.CARD_TOKEN.getName()))
.email(resultSet.getString(TEST_PAYMENT.EMAIL.getName()))
.errorCode(resultSet.getString(TEST_PAYMENT.ERROR_CODE.getName()))
.errorReason(resultSet.getString(TEST_PAYMENT.ERROR_REASON.getName()))
.eventTime(resultSet.getObject(TEST_PAYMENT.EVENT_TIME.getName(), LocalDateTime.class))
.fingerprint(resultSet.getString(TEST_PAYMENT.FINGERPRINT.getName()))
.id(resultSet.getLong(TEST_PAYMENT.ID.getName()))
.paymentTool(resultSet.getString(TEST_PAYMENT.PAYMENT_TOOL.getName()))
.ip(resultSet.getString(TEST_PAYMENT.IP.getName()))
.lastModificationDate(
resultSet.getObject(TEST_PAYMENT.LAST_MODIFICATION_TIME.getName(), LocalDateTime.class))
.lastModificationInitiator(
resultSet.getString(TEST_PAYMENT.LAST_MODIFICATION_INITIATOR.getName()))
.mobile(resultSet.getBoolean(TEST_PAYMENT.MOBILE.getName()))
.recurrent(resultSet.getBoolean(TEST_PAYMENT.RECURRENT.getName()))
.payerType(resultSet.getString(TEST_PAYMENT.PAYER_TYPE.getName()))
.partyId(resultSet.getString(TEST_PAYMENT.PARTY_ID.getName()))
.shopId(resultSet.getString(TEST_PAYMENT.SHOP_ID.getName()))
.providerId(resultSet.getString(TEST_PAYMENT.PROVIDER_ID.getName()))
.status(resultSet.getString(TEST_PAYMENT.STATUS.getName()))
.terminalId(resultSet.getString(TEST_PAYMENT.TERMINAL_ID.getName()))
.bin(resultSet.getString(TEST_PAYMENT.BIN.getName()))
.lastDigits(resultSet.getString(TEST_PAYMENT.LAST_DIGITS.getName()))
.build()
)
.notificationRule(getNotificationRule(resultSet))
.build();
}
private List<String> getNotificationRule(java.sql.ResultSet r) throws SQLException {
if (r.getArray(TEST_PAYMENT_CHECKING_RESULT.NOTIFICATIONS_RULE.getName()) != null) {
return Arrays.asList(
(String[]) r.getArray(TEST_PAYMENT_CHECKING_RESULT.NOTIFICATIONS_RULE.getName())
.getArray());
}
return null;
}
}

View File

@ -0,0 +1,32 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset.mapper;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalDateTime;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_DATA_SET;
import static com.rbkmoney.fraudbusters.management.domain.Tables.TEST_DATA_SET_CHECKING_RESULT;
public class DataSetRowMapper implements RowMapper<CheckedDataSetModel> {
public static final String TEST_DATA_SET_ID_JOIN = "test_data_set_id_join";
@Override
public CheckedDataSetModel mapRow(ResultSet resultSet, int i) throws SQLException {
return CheckedDataSetModel.builder()
.template(resultSet.getString(TEST_DATA_SET_CHECKING_RESULT.TEMPLATE.getName()))
.checkingTimestamp(resultSet.getObject(TEST_DATA_SET_CHECKING_RESULT.CHECKING_TIMESTAMP.getName(),
LocalDateTime.class))
.createdAt(resultSet.getObject(TEST_DATA_SET_CHECKING_RESULT.CREATED_AT.getName(), LocalDateTime.class))
.partyId(resultSet.getString(TEST_DATA_SET_CHECKING_RESULT.PARTY_ID.getName()))
.shopId(resultSet.getString(TEST_DATA_SET_CHECKING_RESULT.SHOP_ID.getName()))
.testDataSetId(resultSet.getLong(TEST_DATA_SET.ID.getName()))
.id(resultSet.getLong(TEST_DATA_SET_ID_JOIN))
.initiator(resultSet.getString(TEST_DATA_SET_CHECKING_RESULT.INITIATOR.getName()))
.build();
}
}

View File

@ -5,7 +5,6 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDate;
import java.time.LocalDateTime;
@Data

View File

@ -0,0 +1,29 @@
package com.rbkmoney.fraudbusters.management.domain.payment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CheckedDataSetModel {
private Long id;
private Long testDataSetId;
private LocalDateTime createdAt;
private String initiator;
private String template;
private String partyId;
private String shopId;
private LocalDateTime checkingTimestamp;
private List<CheckedPaymentModel> checkedPaymentModels;
}

View File

@ -0,0 +1,25 @@
package com.rbkmoney.fraudbusters.management.domain.payment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CheckedPaymentModel {
private PaymentModel paymentModel;
private Long testDataSetCheckingResultId;
private Long testPaymentId;
private String checkedTemplate;
private String resultStatus;
private String ruleChecked;
private List<String> notificationRule;
}

View File

@ -0,0 +1,24 @@
package com.rbkmoney.fraudbusters.management.domain.payment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class DataSetModel {
private String id;
private String name;
private String template;
private LocalDateTime lastModificationTime;
private String lastModificationInitiator;
private List<PaymentModel> paymentModelList;
}

View File

@ -0,0 +1,60 @@
package com.rbkmoney.fraudbusters.management.domain.payment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class PaymentModel {
private Long id;
private Long testDataSetId;
private LocalDateTime lastModificationDate;
private String lastModificationInitiator;
private String paymentId;
private LocalDateTime eventTime;
private Long amount;
private String currency;
private String cardToken;
private String bin;
private String lastDigits;
private String status;
private String payerType;
private String paymentSystem;
private String paymentCountry;
private String paymentTool;
private Boolean mobile;
private Boolean recurrent;
private String partyId;
private String shopId;
private String ip;
private String fingerprint;
private String email;
private String errorCode;
private String errorReason;
private String providerId;
private String terminalId;
private String country;
//TODO выпилить когда починят JavaDoc plugin
public static class PaymentModelBuilder {
}
}

View File

@ -0,0 +1,24 @@
package com.rbkmoney.fraudbusters.management.exception;
public class UnknownPaymentException extends RuntimeException {
public UnknownPaymentException() {
}
public UnknownPaymentException(String message) {
super(message);
}
public UnknownPaymentException(String message, Throwable cause) {
super(message, cause);
}
public UnknownPaymentException(Throwable cause) {
super(cause);
}
public UnknownPaymentException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -0,0 +1,143 @@
package com.rbkmoney.fraudbusters.management.resource.payment;
import com.rbkmoney.damsel.fraudbusters.HistoricalDataServiceSrv;
import com.rbkmoney.damsel.fraudbusters.HistoricalDataSetCheckResult;
import com.rbkmoney.fraudbusters.management.converter.payment.*;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsDataSetService;
import com.rbkmoney.fraudbusters.management.utils.PagingDataUtils;
import com.rbkmoney.fraudbusters.management.utils.UserInfoService;
import com.rbkmoney.swag.fraudbusters.management.api.PaymentsDataSetApi;
import com.rbkmoney.swag.fraudbusters.management.model.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.TException;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@RestController
@RequiredArgsConstructor
public class PaymentDataSetsResource implements PaymentsDataSetApi {
private final UserInfoService userInfoService;
private final PaymentsDataSetService paymentsDataSetService;
private final DataSetModelToDataSetApiConverter dataSetModelToDataSetApiConverter;
private final CheckedDataSetModelToCheckedDataSetApiConverter checkedDataSetModelToCheckedDataSetApiConverter;
private final DataSetToTestDataSetModelConverter dataSetToTestDataSetModelConverter;
private final HistoricalDataServiceSrv.Iface historicalDataServiceSrv;
private final ApplyRuleOnHistoricalRequestToEmulationRuleApplyRequestConverter applyConverter;
private final HistoricalDataSetCheckResultToTestCheckedDataSetModelConverter dataSetCheckResultToDaoModelConverter;
@Override
@PreAuthorize("hasAnyRole('fraud-officer')")
public ResponseEntity<CheckedDataSet> getCheckedDataSet(String id) {
String userName = userInfoService.getUserName();
log.info("getCheckedDataSet initiator: {} id: {}", userName, id);
var dataSet = paymentsDataSetService.getCheckedDataSet(id);
log.info("getCheckedDataSet succeeded checkedDataSet: {}", dataSet);
return ResponseEntity.ok(checkedDataSetModelToCheckedDataSetApiConverter.convert(dataSet));
}
@Override
@PreAuthorize("hasAnyRole('fraud-officer')")
public ResponseEntity<String> applyRuleOnHistoricalDataSet(@Valid ApplyRuleOnHistoricalDataSetRequest request) {
String userName = userInfoService.getUserName();
log.info("applyRuleOnHistoricalDataSet initiator: {} request: {}", userName, request);
try {
var historicalDataSetCheckResult = historicalDataServiceSrv
.applyRuleOnHistoricalDataSet(applyConverter.convert(request));
CheckedDataSetModel dataSetModel =
createCheckedDataSet(request, userName, historicalDataSetCheckResult);
Long resultId = paymentsDataSetService.insertCheckedDataSet(dataSetModel, userName);
log.info("applyRuleOnHistoricalDataSet resultId: {}", resultId);
return ResponseEntity.ok().body(String.valueOf(resultId));
} catch (TException e) {
throw new RuntimeException(e);
}
}
@Override
public ResponseEntity<DataSetsResponse> filterDataSets(@Valid String continuationId, @Valid String sortOrder,
@Valid String sortBy, @Valid Integer size,
@Valid String from, @Valid String to,
@Valid String dataSetName) {
var filterRequest = new FilterRequest(dataSetName, continuationId, null, size, sortBy,
PagingDataUtils.getSortOrder(sortOrder));
String userName = userInfoService.getUserName();
log.info("filterDataSets initiator: {} filterRequest: {}", userName, filterRequest);
List<DataSetModel> dataSetModels = paymentsDataSetService.filterDataSets(from, to, filterRequest);
return ResponseEntity.ok(new DataSetsResponse()
.continuationId(buildContinuationId(size, dataSetModels))
.result(dataSetModels.stream()
.map(dataSetModelToDataSetApiConverter::convert)
.collect(Collectors.toList())
));
}
@Override
@PreAuthorize("hasAnyRole('fraud-officer')")
public ResponseEntity<DataSet> getDataSet(String setId) {
String userName = userInfoService.getUserName();
log.info("getDataSet initiator: {} id: {}", userName, setId);
var dataSet = paymentsDataSetService.getDataSet(setId);
log.info("getDataSet succeeded dataSet: {}", dataSet);
return ResponseEntity.ok(dataSetModelToDataSetApiConverter.convert(dataSet));
}
@Override
@PreAuthorize("hasAnyRole('fraud-officer')")
public ResponseEntity<String> insertDataSet(@Valid DataSet dataSet) {
String userName = userInfoService.getUserName();
log.info("insertDataSet initiator: {} dataSet: {}", userName, dataSet);
DataSetModel dataSetModel = dataSetToTestDataSetModelConverter.convert(dataSet);
dataSetModel.setLastModificationInitiator(userName);
Long id = paymentsDataSetService.insertDataSet(dataSetModel);
log.info("insertDataSet succeeded dataSet: {}", dataSet);
return ResponseEntity.ok(String.valueOf(id));
}
@Override
@PreAuthorize("hasAnyRole('fraud-officer')")
public ResponseEntity<String> removeDataSet(String id) {
String userName = userInfoService.getUserName();
log.info("removeDataSet initiator: {} id: {}", userName, id);
paymentsDataSetService.removeDataSet(id, userName);
log.info("removeDataSet succeeded id: {}", id);
return ResponseEntity.ok(id);
}
private CheckedDataSetModel createCheckedDataSet(ApplyRuleOnHistoricalDataSetRequest request,
String userName,
HistoricalDataSetCheckResult historicalDataSetCheckResult) {
CheckedDataSetModel dataSetModel =
dataSetCheckResultToDaoModelConverter.convert(historicalDataSetCheckResult);
dataSetModel.setInitiator(userName);
PaymentReference reference = request.getReference();
if (reference != null) {
dataSetModel.setPartyId(reference.getPartyId());
dataSetModel.setShopId(reference.getShopId());
}
dataSetModel.setCheckingTimestamp(request.getRuleSetTimestamp());
dataSetModel.setTestDataSetId(request.getDataSetId());
dataSetModel.setTemplate(request.getTemplate());
return dataSetModel;
}
private String buildContinuationId(Integer filterSize, List<DataSetModel> dataSetModels) {
if (dataSetModels.size() == filterSize) {
var lastDataSet = dataSetModels.get(dataSetModels.size() - 1);
return lastDataSet.getId();
}
return null;
}
}

View File

@ -5,9 +5,9 @@ import com.rbkmoney.damsel.fraudbusters.TemplateValidateError;
import com.rbkmoney.fraudbusters.management.converter.payment.TemplateValidateErrorsToValidateTemplateResponseConverter;
import com.rbkmoney.fraudbusters.management.dao.TemplateDao;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsTemplatesService;
import com.rbkmoney.fraudbusters.management.service.TemplateCommandService;
import com.rbkmoney.fraudbusters.management.service.iface.ValidationTemplateService;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsTemplatesService;
import com.rbkmoney.fraudbusters.management.utils.CommandMapper;
import com.rbkmoney.fraudbusters.management.utils.PagingDataUtils;
import com.rbkmoney.fraudbusters.management.utils.UserInfoService;

View File

@ -5,7 +5,6 @@ import com.rbkmoney.fraudbusters.management.converter.p2p.TemplateModelToCommand
import com.rbkmoney.fraudbusters.management.domain.TemplateModel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@RequiredArgsConstructor

View File

@ -2,7 +2,6 @@ package com.rbkmoney.fraudbusters.management.service.payment;
import com.rbkmoney.damsel.fraudbusters.FraudPayment;
import com.rbkmoney.damsel.fraudbusters.PaymentServiceSrv;
import com.rbkmoney.fraudbusters.management.utils.UserInfoService;
import com.rbkmoney.fraudbusters.management.utils.parser.CsvFraudPaymentParser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

View File

@ -0,0 +1,83 @@
package com.rbkmoney.fraudbusters.management.service.payment;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetCheckingResultDao;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetDao;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.PaymentDao;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import com.rbkmoney.fraudbusters.management.utils.FilterRequestUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class PaymentsDataSetService {
private final DataSetDao dataSetDao;
private final DataSetCheckingResultDao dataSetCheckingResultDao;
private final PaymentDao paymentDao;
public List<DataSetModel> filterDataSets(String from, String to, FilterRequest filterRequest) {
var fromDate = DateTimeUtils.parse(from);
var toDate = DateTimeUtils.parse(to);
filterRequest.setSearchValue(FilterRequestUtils.prepareSearchValue(filterRequest.getSearchValue()));
return dataSetDao.filter(fromDate, toDate, filterRequest);
}
@Transactional
public void removeDataSet(String id, String initiator) {
var idDataSet = Long.valueOf(id);
paymentDao.removeByDataSetId(idDataSet);
dataSetDao.remove(idDataSet);
}
public DataSetModel getDataSet(String id) {
var idDataSet = Long.valueOf(id);
var testDataSetModel = dataSetDao.getById(idDataSet);
List<PaymentModel> byDataSetId = paymentDao.getByDataSetId(idDataSet);
testDataSetModel.setPaymentModelList(byDataSetId);
return testDataSetModel;
}
public CheckedDataSetModel getCheckedDataSet(String id) {
var idDataSet = Long.valueOf(id);
return dataSetCheckingResultDao.getById(idDataSet);
}
@Transactional
public Long insertDataSet(DataSetModel dataSetModel) {
Optional<Long> id = dataSetDao.insert(dataSetModel);
if (id.isPresent() && !CollectionUtils.isEmpty(dataSetModel.getPaymentModelList())) {
List<PaymentModel> paymentModelList = dataSetModel.getPaymentModelList();
paymentDao.insertBatch(paymentModelList.stream()
.map(testPaymentModel -> updateModel(dataSetModel.getLastModificationInitiator(), id.get(),
testPaymentModel))
.collect(Collectors.toList()));
}
return id.orElse(null);
}
public Long insertCheckedDataSet(CheckedDataSetModel dataSetModel, String initiator) {
dataSetModel.setInitiator(initiator);
Optional<Long> id = dataSetCheckingResultDao.insert(dataSetModel);
return id.orElse(null);
}
private PaymentModel updateModel(String initiator, Long id,
PaymentModel paymentModel) {
paymentModel.setTestDataSetId(id);
paymentModel.setLastModificationInitiator(initiator);
paymentModel.setLastModificationDate(null);
return paymentModel;
}
}

View File

@ -5,14 +5,11 @@ import com.rbkmoney.fraudbusters.management.converter.payment.PaymentReferenceMo
import com.rbkmoney.fraudbusters.management.converter.payment.ReferenceToCommandConverter;
import com.rbkmoney.fraudbusters.management.dao.payment.reference.PaymentReferenceDao;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentReferenceModel;
import com.rbkmoney.fraudbusters.management.filter.UnknownPaymentTemplateInReferenceFilter;
import com.rbkmoney.fraudbusters.management.utils.CommandMapper;
import com.rbkmoney.fraudbusters.management.utils.PaymentUnknownTemplateFinder;
import com.rbkmoney.swag.fraudbusters.management.model.PaymentReference;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;

View File

@ -10,7 +10,6 @@ import org.springframework.stereotype.Service;
import java.io.IOException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
@Service
@RequiredArgsConstructor

View File

@ -18,4 +18,8 @@ public class DateTimeUtils {
: null;
}
public static LocalDateTime parse(@RequestParam @Validated String date) {
return LocalDateTime.parse(date, DateTimeUtils.DATE_TIME_FORMATTER);
}
}

View File

@ -0,0 +1,56 @@
CREATE TABLE af.test_data_set
(
id BIGSERIAL NOT NULL,
name CHARACTER VARYING NOT NULL,
last_modification_initiator CHARACTER VARYING NOT NULL,
last_modification_time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (now() at time zone 'utc'),
CONSTRAINT testing_data_set_pkey PRIMARY KEY (id),
UNIQUE (name)
);
CREATE TABLE af.test_payment
(
id BIGSERIAL NOT NULL,
test_data_set_id BIGINT NOT NULL,
last_modification_initiator CHARACTER VARYING NOT NULL,
last_modification_time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (now() at time zone 'utc'),
payment_id CHARACTER VARYING NOT NULL,
event_time TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (now() at time zone 'utc'),
amount INT NOT NULL,
currency CHARACTER VARYING NOT NULL,
card_token CHARACTER VARYING NOT NULL,
status CHARACTER VARYING NOT NULL,
payer_type CHARACTER VARYING,
payment_system CHARACTER VARYING,
payment_country CHARACTER VARYING,
payment_tool CHARACTER VARYING,
mobile boolean,
recurrent boolean,
party_id CHARACTER VARYING NOT NULL,
shop_id CHARACTER VARYING NOT NULL,
ip CHARACTER VARYING,
fingerprint CHARACTER VARYING,
email CHARACTER VARYING,
error_code CHARACTER VARYING,
error_reason CHARACTER VARYING,
provider_id CHARACTER VARYING,
terminal_id CHARACTER VARYING,
country CHARACTER VARYING,
bin CHARACTER VARYING,
last_digits CHARACTER VARYING,
CONSTRAINT data_set_payment_pkey PRIMARY KEY (id),
CONSTRAINT fk_test_data_set FOREIGN KEY (test_data_set_id) REFERENCES af.test_data_set (id)
);

View File

@ -0,0 +1,29 @@
CREATE TABLE af.test_data_set_checking_result
(
id BIGSERIAL NOT NULL,
test_data_set_id BIGINT NOT NULL,
initiator CHARACTER VARYING NOT NULL,
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT (now() at time zone 'utc'),
template TEXT NOT NULL,
party_id CHARACTER VARYING,
shop_id CHARACTER VARYING,
checking_timestamp TIMESTAMP WITHOUT TIME ZONE,
CONSTRAINT test_data_set_checking_result_pkey PRIMARY KEY (id)
);
CREATE TABLE af.test_payment_checking_result
(
id BIGSERIAL NOT NULL,
test_data_set_checking_result_id BIGINT NOT NULL,
test_payment_id BIGINT NOT NULL,
checked_template CHARACTER VARYING,
result_status CHARACTER VARYING,
rule_checked CHARACTER VARYING,
notifications_rule TEXT[],
CONSTRAINT test_payment_checking_result_pkey PRIMARY KEY (id),
CONSTRAINT fk_test_data_set_checking_result FOREIGN KEY (test_data_set_checking_result_id) REFERENCES af.test_data_set_checking_result (id)
);

View File

@ -17,8 +17,8 @@ import com.rbkmoney.fraudbusters.management.domain.payment.DefaultPaymentReferen
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentReferenceModel;
import com.rbkmoney.fraudbusters.management.filter.UnknownPaymentTemplateInReferenceFilter;
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentGroupsResource;
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsTemplatesResource;
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsReferenceResource;
import com.rbkmoney.fraudbusters.management.resource.payment.PaymentsTemplatesResource;
import com.rbkmoney.fraudbusters.management.service.iface.AuditService;
import com.rbkmoney.swag.fraudbusters.management.model.*;
import lombok.extern.slf4j.Slf4j;

View File

@ -0,0 +1,49 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import java.time.LocalDateTime;
import java.util.List;
import static org.junit.Assert.*;
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = {CheckedDataSetModelToCheckedDataSetApiConverter.class,
CheckedPaymentModelToCheckedDataSetRowConverter.class,
PaymentModelToPaymentApiConverter.class})
public class TestCheckedDataSetModelToCheckedDataSetApiConverterTest {
public static final String TEST = "TEST";
public static final String TEST_TEMPLATE = "test_template";
public static final String TEST_DATA_SET_ID = "1";
@Autowired
CheckedDataSetModelToCheckedDataSetApiConverter checkedDataSetModelToCheckedDataSetApiConverter;
@Test
public void testConvert() {
CheckedDataSetModel testDataSetModel = CheckedDataSetModel.builder()
.initiator(TEST)
.testDataSetId(1L)
.shopId(TEST)
.partyId(TEST)
.id(2L)
.createdAt(LocalDateTime.now())
.template(TEST_TEMPLATE)
.checkedPaymentModels(List.of())
.build();
var checkedDataSet = checkedDataSetModelToCheckedDataSetApiConverter.convert(testDataSetModel);
assertNotNull(checkedDataSet);
assertEquals(TEST_DATA_SET_ID, checkedDataSet.getTestDataSetId());
assertEquals(TEST, checkedDataSet.getInitiator());
assertEquals(TEST_TEMPLATE, checkedDataSet.getTemplate());
assertTrue(checkedDataSet.getRows().isEmpty());
}
}

View File

@ -0,0 +1,29 @@
package com.rbkmoney.fraudbusters.management.converter.payment;
import com.rbkmoney.damsel.fraudbusters.*;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.utils.DataSourceBeanUtils;
import org.junit.jupiter.api.Test;
import java.util.Set;
import static org.junit.Assert.assertEquals;
class TestHistoricalDataSetCheckResultToTestCheckedDataSetModelConverter {
HistoricalDataSetCheckResultToTestCheckedDataSetModelConverter converter =
new HistoricalDataSetCheckResultToTestCheckedDataSetModelConverter(
new PaymentToTestPaymentModelConverter());
@Test
void convert() {
CheckedDataSetModel model = converter.convert(new HistoricalDataSetCheckResult()
.setHistoricalTransactionCheck(Set.of(new HistoricalTransactionCheck()
.setTransaction(DataSourceBeanUtils.createDamselPayment())
.setCheckResult(new CheckResult().setConcreteCheckResult(new ConcreteCheckResult()
.setResultStatus(ResultStatus.accept(new Accept())))))));
assertEquals("accept", model.getCheckedPaymentModels().get(0).getResultStatus());
}
}

View File

@ -0,0 +1,91 @@
package com.rbkmoney.fraudbusters.management.dao.payment.dataset;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedPaymentModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import static org.junit.Assert.*;
@ContextConfiguration(classes = {DataSetCheckingResultDaoImpl.class, DataSetDaoImpl.class,
PaymentDaoImpl.class})
public class TestDataSetCheckingResultDaoImpl extends AbstractPostgresIntegrationTest {
public static final String TEST = "test";
@Autowired
private DataSetCheckingResultDaoImpl dataSetCheckingResultDaoById;
@Autowired
private DataSetDaoImpl dataSetDao;
@Autowired
private PaymentDaoImpl paymentDao;
@Test
public void testDataSetCheckingResult() {
PaymentModel paymentModel = createTestPaymentModel();
Optional<Long> dataSetId = dataSetDao.insert(createDataSet(paymentModel));
Long testDataSetId = dataSetId.get();
paymentModel.setTestDataSetId(testDataSetId);
paymentDao.insert(paymentModel);
CheckedDataSetModel byId = dataSetCheckingResultDaoById.getById(testDataSetId);
assertEquals(testDataSetId, byId.getTestDataSetId());
assertEquals(Long.valueOf(1L), byId.getCheckedPaymentModels().get(0).getPaymentModel().getId());
Optional<Long> insert = dataSetCheckingResultDaoById.insert(createCheckedDataSet(testDataSetId, 1L));
assertTrue(insert.isPresent());
byId = dataSetCheckingResultDaoById.getById(testDataSetId);
assertEquals(TEST, byId.getTemplate());
assertFalse(byId.getCheckedPaymentModels().isEmpty());
assertEquals(Long.valueOf(1L), byId.getCheckedPaymentModels().get(0).getTestPaymentId());
assertEquals(TEST, byId.getCheckedPaymentModels().get(0).getResultStatus());
assertEquals(TEST, byId.getCheckedPaymentModels().get(0).getRuleChecked());
}
private CheckedDataSetModel createCheckedDataSet(Long testDataSetId, Long paymentId) {
return CheckedDataSetModel.builder()
.testDataSetId(testDataSetId)
.checkedPaymentModels(List.of(CheckedPaymentModel.builder()
.testPaymentId(paymentId)
.resultStatus(TEST)
.ruleChecked(TEST)
.build()))
.initiator(TEST)
.template(TEST)
.build();
}
private DataSetModel createDataSet(PaymentModel paymentModel) {
return DataSetModel.builder()
.name(TEST)
.lastModificationInitiator(TEST)
.template("sadasdsa")
.paymentModelList(List.of(paymentModel))
.build();
}
private PaymentModel createTestPaymentModel() {
return PaymentModel.builder()
.cardToken("cardToken")
.amount(123L)
.paymentId(TEST)
.partyId(TEST)
.shopId(TEST)
.status(TEST)
.lastModificationInitiator(TEST)
.eventTime(LocalDateTime.now())
.currency("RUB")
.build();
}
}

View File

@ -0,0 +1,127 @@
package com.rbkmoney.fraudbusters.management.resource.payment;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rbkmoney.damsel.fraudbusters.HistoricalDataServiceSrv;
import com.rbkmoney.fraudbusters.management.domain.payment.CheckedDataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsDataSetService;
import com.rbkmoney.fraudbusters.management.utils.DataSourceBeanUtils;
import com.rbkmoney.swag.fraudbusters.management.model.DataSet;
import com.rbkmoney.swag.fraudbusters.management.model.Payment;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import java.util.List;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Slf4j
@SpringBootTest
@AutoConfigureMockMvc
@EnableAutoConfiguration(exclude = {FlywayAutoConfiguration.class, JooqAutoConfiguration.class})
class PaymentDataSetsResourceTest {
@Autowired
private MockMvc mockMvc;
@MockBean
PaymentsDataSetService paymentsDataSetService;
@MockBean
HistoricalDataServiceSrv.Iface historicalDataServiceSrv;
ObjectMapper objectMapper = new ObjectMapper();
@Test
void getCheckedDataSet() throws Exception {
when(paymentsDataSetService.getCheckedDataSet(any())).thenReturn(new CheckedDataSetModel());
String id = "id";
this.mockMvc.perform(get(String.format("/payments-data-set/checked-data-sets/%s", id)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content()
.json("{\"id\":\"null\",\"testDataSetId\":\"null\",\"template\":null," +
"\"rows\":[],\"createdAt\":null,\"checkingTimestamp\":null," +
"\"initiator\":null,\"merchantInfo\":{\"partyId\":null,\"shopId\":null}}"));
verify(paymentsDataSetService, times(1)).getCheckedDataSet(id);
}
@Test
void filterDataSets() throws Exception {
when(paymentsDataSetService.filterDataSets(any(), any(), any())).thenReturn(List.of(new DataSetModel()));
this.mockMvc.perform(get("/payments-data-set/data-sets/filter")
.queryParams(DataSourceBeanUtils.createParams()))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content()
.json("{\"continuationId\":null,\"result\":" +
"[{\"id\":null,\"name\":null,\"rows\":[]," +
"\"lastModificationAt\":null,\"lastModificationInitiator\":null}]}"));
verify(paymentsDataSetService, times(1)).filterDataSets(any(), any(), any());
}
@Test
void getDataSet() throws Exception {
when(paymentsDataSetService.getDataSet(any())).thenReturn(new DataSetModel());
String id = "id";
this.mockMvc.perform(get(String.format("/payments-data-set/data-sets/%s", id)))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content()
.json("{\"id\":null,\"name\":null,\"rows\":[]," +
"\"lastModificationAt\":null,\"lastModificationInitiator\":null}"));
verify(paymentsDataSetService, times(1)).getDataSet(id);
}
@Test
void insertDataSet() throws Exception {
when(paymentsDataSetService.insertDataSet(any())).thenReturn(1L);
this.mockMvc.perform(post("/payments-data-set/data-sets")
.content(objectMapper.writeValueAsString(new DataSet()))
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content()
.string("1"));
}
@Test
void applyRuleOnHistoricalDataSet() throws Exception {
Payment payment = DataSourceBeanUtils.createPayment();
when(historicalDataServiceSrv.applyRuleOnHistoricalDataSet(any()))
.thenReturn(DataSourceBeanUtils.createHistoricalResponse());
this.mockMvc.perform(post("/payments-data-set/data-sets/applyRuleOnHistoricalDataSet")
.content(objectMapper.writeValueAsString(DataSourceBeanUtils.createApplyRequst(payment)))
.contentType(MediaType.APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().string("0"));
}
@Test
void removeDataSet() throws Exception {
doNothing().when(paymentsDataSetService).removeDataSet(any(), any());
this.mockMvc.perform(delete(String.format("/payments-data-set/data-sets/%s", "id")))
.andDo(print())
.andExpect(status().isOk())
.andExpect(content()
.string("id"));
}
}

View File

@ -4,8 +4,8 @@ import com.rbkmoney.damsel.wb_list.ListType;
import com.rbkmoney.fraudbusters.management.converter.payment.WbListRecordToRowConverter;
import com.rbkmoney.fraudbusters.management.converter.payment.WbListRecordsModelToWbListRecordConverter;
import com.rbkmoney.fraudbusters.management.dao.payment.wblist.WbListDao;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsListsService;
import com.rbkmoney.fraudbusters.management.service.WbListCommandService;
import com.rbkmoney.fraudbusters.management.service.payment.PaymentsListsService;
import com.rbkmoney.fraudbusters.management.utils.ParametersService;
import com.rbkmoney.fraudbusters.management.utils.PaymentCountInfoGenerator;
import com.rbkmoney.fraudbusters.management.utils.UserInfoService;

View File

@ -0,0 +1,43 @@
package com.rbkmoney.fraudbusters.management.service.payment;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.payment.PaymentModel;
import com.rbkmoney.swag.fraudbusters.management.model.Payment;
import java.time.LocalDateTime;
import java.util.List;
public class DataSetModelUtils {
public static final String TEST_INITIATOR = "test_initiator";
public static final String TEST = "test";
public static final String PAYMENT_ID = "id";
public static final String PAYMENT_COUNTRY = "RUS";
public static final String PARTY_ID = "partyId";
public static final String SHOP_ID = "shopId";
public static DataSetModel initTestDataSetModel(LocalDateTime lastModificationDate) {
return DataSetModel.builder()
.lastModificationInitiator(TEST_INITIATOR)
.lastModificationTime(lastModificationDate)
.name(TEST)
.paymentModelList(List.of(initTestPaymentModel(lastModificationDate)))
.build();
}
public static PaymentModel initTestPaymentModel(LocalDateTime lastModificationDate) {
return PaymentModel.builder()
.lastModificationDate(lastModificationDate)
.status(Payment.StatusEnum.CAPTURED.name())
.amount(123L)
.currency("RUB")
.cardToken("cardToken")
.paymentId(PAYMENT_ID)
.paymentCountry(PAYMENT_COUNTRY)
.terminalId("123")
.eventTime(lastModificationDate)
.partyId(PARTY_ID)
.shopId(SHOP_ID)
.build();
}
}

View File

@ -0,0 +1,93 @@
package com.rbkmoney.fraudbusters.management.service.payment;
import com.rbkmoney.fraudbusters.management.dao.AbstractPostgresIntegrationTest;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetCheckingResultDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.DataSetDaoImpl;
import com.rbkmoney.fraudbusters.management.dao.payment.dataset.PaymentDaoImpl;
import com.rbkmoney.fraudbusters.management.domain.payment.DataSetModel;
import com.rbkmoney.fraudbusters.management.domain.request.FilterRequest;
import com.rbkmoney.fraudbusters.management.utils.DateTimeUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import java.time.LocalDateTime;
import java.util.List;
import static com.rbkmoney.fraudbusters.management.service.payment.DataSetModelUtils.TEST_INITIATOR;
import static org.junit.Assert.assertEquals;
@ContextConfiguration(classes = {DataSetCheckingResultDaoImpl.class, PaymentsDataSetService.class,
DataSetDaoImpl.class, PaymentDaoImpl.class})
public class PaymentsDataSetServiceTest extends AbstractPostgresIntegrationTest {
@Autowired
PaymentsDataSetService paymentsDataSetService;
@Test
@SuppressWarnings("VariableDeclarationUsageDistance")
public void filterDataSets() {
LocalDateTime lastModificationDate = LocalDateTime.now();
DataSetModel dataSetModel = DataSetModelUtils.initTestDataSetModel(lastModificationDate);
dataSetModel.setLastModificationInitiator(TEST_INITIATOR);
Long idFirst = paymentsDataSetService.insertDataSet(dataSetModel);
dataSetModel.setName(DataSetModelUtils.TEST + "2");
dataSetModel.getPaymentModelList().get(0).setPaymentId(DataSetModelUtils.TEST + "2");
Long idSecond = paymentsDataSetService.insertDataSet(dataSetModel);
String from = lastModificationDate.minusDays(1L).format(DateTimeUtils.DATE_TIME_FORMATTER);
String to = lastModificationDate.format(DateTimeUtils.DATE_TIME_FORMATTER);
List<DataSetModel> dataSetModels = paymentsDataSetService.filterDataSets(
from,
to,
FilterRequest.builder()
.size(10)
.build());
assertEquals(2, dataSetModels.size());
paymentsDataSetService.removeDataSet(String.valueOf(idFirst), TEST_INITIATOR);
dataSetModels = paymentsDataSetService.filterDataSets(
from,
to,
FilterRequest.builder()
.size(10)
.build());
assertEquals(1, dataSetModels.size());
paymentsDataSetService.removeDataSet(String.valueOf(idSecond), TEST_INITIATOR);
dataSetModels = paymentsDataSetService.filterDataSets(
from,
to,
FilterRequest.builder()
.size(10)
.build());
assertEquals(0, dataSetModels.size());
}
@Test
public void insertDataSet() {
LocalDateTime lastModificationDate = LocalDateTime.now();
Long id = paymentsDataSetService.insertDataSet(DataSetModelUtils.initTestDataSetModel(lastModificationDate));
DataSetModel dataSet = paymentsDataSetService.getDataSet(String.valueOf(id));
assertEquals(DataSetModelUtils.TEST, dataSet.getName());
assertEquals(TEST_INITIATOR, dataSet.getLastModificationInitiator());
dataSet.getPaymentModelList()
.forEach(testPaymentModel -> {
assertEquals(DataSetModelUtils.PAYMENT_ID, testPaymentModel.getPaymentId());
assertEquals(DataSetModelUtils.PAYMENT_COUNTRY, testPaymentModel.getPaymentCountry());
assertEquals(DataSetModelUtils.PARTY_ID, testPaymentModel.getPartyId());
assertEquals(DataSetModelUtils.SHOP_ID, testPaymentModel.getShopId());
});
paymentsDataSetService.removeDataSet(String.valueOf(id), TEST_INITIATOR);
}
}

View File

@ -13,7 +13,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.time.LocalDateTime;
import java.util.List;
public class CsvFraudPaymentParserTest {

View File

@ -0,0 +1,75 @@
package com.rbkmoney.fraudbusters.management.utils;
import com.rbkmoney.damsel.domain.BankCard;
import com.rbkmoney.damsel.domain.Cash;
import com.rbkmoney.damsel.domain.CurrencyRef;
import com.rbkmoney.damsel.domain.PaymentTool;
import com.rbkmoney.damsel.fraudbusters.*;
import com.rbkmoney.swag.fraudbusters.management.model.ApplyRuleOnHistoricalDataSetRequest;
import com.rbkmoney.swag.fraudbusters.management.model.PaymentReference;
import org.springframework.util.LinkedMultiValueMap;
import java.util.List;
import java.util.Set;
public class DataSourceBeanUtils {
public static final String PARTY_ID = "partyId";
public static final String SHOP_ID = "shopId";
public static HistoricalDataSetCheckResult createHistoricalResponse() {
return new HistoricalDataSetCheckResult()
.setHistoricalTransactionCheck(Set.of(new HistoricalTransactionCheck()
.setCheckResult(new CheckResult()
.setConcreteCheckResult(new ConcreteCheckResult()
.setResultStatus(ResultStatus.accept(new Accept()))
.setRuleChecked("test"))
.setCheckedTemplate("test"))
.setTransaction(createDamselPayment())));
}
public static com.rbkmoney.swag.fraudbusters.management.model.Payment createPayment() {
return new com.rbkmoney.swag.fraudbusters.management.model.Payment()
.amount(100L)
.currency("RUB")
.id("1")
.mobile(false)
.recurrent(false)
.status(com.rbkmoney.swag.fraudbusters.management.model.Payment.StatusEnum.CAPTURED)
.merchantInfo(new com.rbkmoney.swag.fraudbusters.management.model.MerchantInfo()
.partyId(PARTY_ID)
.shopId(SHOP_ID));
}
public static Payment createDamselPayment() {
return new Payment()
.setId("1")
.setPaymentTool(PaymentTool.bank_card(new BankCard()))
.setCost(new Cash()
.setAmount(12L)
.setCurrency(new CurrencyRef()
.setSymbolicCode("RUB")))
.setStatus(PaymentStatus.captured)
.setPayerType(PayerType.payment_resource);
}
public static ApplyRuleOnHistoricalDataSetRequest createApplyRequst(
com.rbkmoney.swag.fraudbusters.management.model.Payment payment) {
return new ApplyRuleOnHistoricalDataSetRequest()
.dataSetId(1L)
.reference(new PaymentReference()
.partyId(PARTY_ID)
.shopId(SHOP_ID))
.template("test")
.records(List.of(payment));
}
public static LinkedMultiValueMap<String, String> createParams() {
LinkedMultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("paymentId", "test");
params.add("size", "100");
params.add("from", "2021-07-27 00:00:00");
params.add("to", "2021-07-27 13:28:54");
return params;
}
}