mirror of
https://github.com/valitydev/fraudo.git
synced 2024-11-06 01:45:16 +00:00
Add type flags (#37)
This commit is contained in:
parent
992b0a8586
commit
3952c3ea07
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>fraudo</artifactId>
|
||||
<version>0.0.19</version>
|
||||
<version>0.0.20</version>
|
||||
|
||||
<name>Fraudo</name>
|
||||
<description>Language for describing antifraud patterns</description>
|
||||
|
@ -36,6 +36,8 @@ relationalExpression
|
||||
| in_grey_list
|
||||
| in_list
|
||||
| like
|
||||
| is_mobile
|
||||
| is_recurrent
|
||||
;
|
||||
|
||||
unaryExpression
|
||||
@ -98,3 +100,11 @@ sum_refund
|
||||
in
|
||||
: 'in' LPAREN (stringExpression) DELIMETER string_list RPAREN
|
||||
;
|
||||
|
||||
is_mobile
|
||||
: 'isMobile' LPAREN RPAREN
|
||||
;
|
||||
|
||||
is_recurrent
|
||||
: 'isRecurrent' LPAREN RPAREN
|
||||
;
|
@ -32,6 +32,14 @@ currency
|
||||
: 'currency' LPAREN RPAREN
|
||||
;
|
||||
|
||||
payer_type
|
||||
: 'payerType' LPAREN RPAREN
|
||||
;
|
||||
|
||||
token_provider
|
||||
: 'tokenProvider' LPAREN RPAREN
|
||||
;
|
||||
|
||||
count
|
||||
: 'count' LPAREN STRING time_window (group_by)? RPAREN
|
||||
;
|
||||
|
@ -7,6 +7,7 @@ import com.rbkmoney.fraudo.payment.aggregator.CountPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.aggregator.SumPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTypeResolver;
|
||||
import com.rbkmoney.fraudo.payment.visitor.impl.FirstFindVisitorImpl;
|
||||
import com.rbkmoney.fraudo.resolver.CountryResolver;
|
||||
import com.rbkmoney.fraudo.resolver.FieldResolver;
|
||||
@ -20,6 +21,7 @@ public interface FraudVisitorFactory {
|
||||
InListFinder<T, U> listFinder,
|
||||
FieldResolver<T, U> fieldPairResolver,
|
||||
PaymentGroupResolver<T, U> paymentGroupResolver,
|
||||
PaymentTimeWindowResolver timeWindowResolver);
|
||||
PaymentTimeWindowResolver timeWindowResolver,
|
||||
PaymentTypeResolver<T> paymentTypeResolver);
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.rbkmoney.fraudo.payment.aggregator.CountPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.aggregator.SumPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTypeResolver;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.ListVisitor;
|
||||
@ -26,12 +27,18 @@ public class FraudVisitorFactoryImpl implements FraudVisitorFactory {
|
||||
InListFinder<T, U> listFinder,
|
||||
FieldResolver<T, U> fieldResolver,
|
||||
PaymentGroupResolver<T, U> paymentGroupResolver,
|
||||
PaymentTimeWindowResolver timeWindowResolver) {
|
||||
PaymentTimeWindowResolver timeWindowResolver,
|
||||
PaymentTypeResolver<T> paymentTypeResolver) {
|
||||
CountVisitor<T> countVisitor = new CountVisitorImpl<>(countPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
SumVisitor<T> sumVisitor = new SumVisitorImpl<>(sumPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
ListVisitor<T> listVisitor = new ListVisitorImpl<>(listFinder, fieldResolver);
|
||||
CustomFuncVisitor<T> customFuncVisitor = new CustomFuncVisitorImpl<>(
|
||||
uniqueValueAggregator, countryResolver, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
uniqueValueAggregator,
|
||||
countryResolver,
|
||||
fieldResolver,
|
||||
paymentGroupResolver,
|
||||
timeWindowResolver,
|
||||
paymentTypeResolver);
|
||||
return new FirstFindVisitorImpl<>(countVisitor, sumVisitor, listVisitor, customFuncVisitor, fieldResolver);
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import com.rbkmoney.fraudo.payment.aggregator.CountPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.aggregator.SumPaymentAggregator;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTypeResolver;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CountVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
|
||||
import com.rbkmoney.fraudo.payment.visitor.ListVisitor;
|
||||
@ -26,12 +27,18 @@ public class FullVisitorFactoryImpl implements FraudVisitorFactory {
|
||||
InListFinder<T, U> listFinder,
|
||||
FieldResolver<T, U> fieldResolver,
|
||||
PaymentGroupResolver<T, U> paymentGroupResolver,
|
||||
PaymentTimeWindowResolver timeWindowResolver) {
|
||||
PaymentTimeWindowResolver timeWindowResolver,
|
||||
PaymentTypeResolver<T> paymentTypeResolver) {
|
||||
CountVisitor<T> countVisitor = new CountVisitorImpl<>(countPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
SumVisitor<T> sumVisitor = new SumVisitorImpl<>(sumPaymentAggregator, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
ListVisitor<T> listVisitor = new ListVisitorImpl<>(listFinder, fieldResolver);
|
||||
CustomFuncVisitor<T> customFuncVisitor = new CustomFuncVisitorImpl<>(
|
||||
uniqueValueAggregator, countryResolver, fieldResolver, paymentGroupResolver, timeWindowResolver);
|
||||
uniqueValueAggregator,
|
||||
countryResolver,
|
||||
fieldResolver,
|
||||
paymentGroupResolver,
|
||||
timeWindowResolver,
|
||||
paymentTypeResolver);
|
||||
return new FullVisitorImpl<>(countVisitor, sumVisitor, listVisitor, customFuncVisitor, fieldResolver);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.rbkmoney.fraudo.payment.resolver;
|
||||
|
||||
public interface PaymentTypeResolver<T> {
|
||||
|
||||
Boolean isMobile(T model);
|
||||
|
||||
Boolean isRecurrent(T model);
|
||||
|
||||
}
|
@ -10,4 +10,8 @@ public interface CustomFuncVisitor<T> {
|
||||
|
||||
Integer visitUnique(UniqueContext ctx, T model);
|
||||
|
||||
boolean visitCheckMobile(Is_mobileContext ctx, T model);
|
||||
|
||||
boolean visitCheckRecurrent(Is_recurrentContext ctx, T model);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.rbkmoney.fraudo.aggregator.UniqueValueAggregator;
|
||||
import com.rbkmoney.fraudo.model.Pair;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTypeResolver;
|
||||
import com.rbkmoney.fraudo.payment.visitor.CustomFuncVisitor;
|
||||
import com.rbkmoney.fraudo.resolver.CountryResolver;
|
||||
import com.rbkmoney.fraudo.resolver.FieldResolver;
|
||||
@ -20,6 +21,7 @@ public class CustomFuncVisitorImpl<T, U> implements CustomFuncVisitor<T> {
|
||||
private final FieldResolver<T, U> fieldResolver;
|
||||
private final PaymentGroupResolver<T, U> groupResolver;
|
||||
private final PaymentTimeWindowResolver timeWindowResolver;
|
||||
private final PaymentTypeResolver<T> paymentTypeResolver;
|
||||
|
||||
@Override
|
||||
public String visitCountryBy(Country_byContext ctx, T model) {
|
||||
@ -49,4 +51,14 @@ public class CustomFuncVisitorImpl<T, U> implements CustomFuncVisitor<T> {
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitCheckMobile(Is_mobileContext ctx, T model) {
|
||||
return paymentTypeResolver.isMobile(model);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean visitCheckRecurrent(Is_recurrentContext ctx, T model) {
|
||||
return paymentTypeResolver.isRecurrent(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -365,4 +365,13 @@ public class FirstFindVisitorImpl<T extends BaseModel, U> extends FraudoPaymentB
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitIs_mobile(Is_mobileContext ctx) {
|
||||
return customFuncVisitor.visitCheckMobile(ctx, threadLocalModel.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean visitIs_recurrent(Is_recurrentContext ctx) {
|
||||
return customFuncVisitor.visitCheckRecurrent(ctx, threadLocalModel.get());
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import com.rbkmoney.fraudo.payment.factory.FraudVisitorFactoryImpl;
|
||||
import com.rbkmoney.fraudo.payment.factory.FullVisitorFactoryImpl;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentGroupResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTimeWindowResolver;
|
||||
import com.rbkmoney.fraudo.payment.resolver.PaymentTypeResolver;
|
||||
import com.rbkmoney.fraudo.resolver.CountryResolver;
|
||||
import com.rbkmoney.fraudo.resolver.FieldResolver;
|
||||
import com.rbkmoney.fraudo.test.constant.PaymentCheckedField;
|
||||
@ -36,6 +37,8 @@ public class AbstractPaymentTest {
|
||||
InListFinder<PaymentModel, PaymentCheckedField> inListFinder;
|
||||
@Mock
|
||||
PaymentTimeWindowResolver timeWindowResolver;
|
||||
@Mock
|
||||
PaymentTypeResolver<PaymentModel> paymentModelPaymentTypeResolver;
|
||||
|
||||
private FieldResolver<PaymentModel, PaymentCheckedField> fieldResolver = new PaymentModelFieldResolver();
|
||||
private PaymentGroupResolver<PaymentModel, PaymentCheckedField> paymentGroupResolver = new PaymentGroupResolver<>(fieldResolver);
|
||||
@ -60,7 +63,8 @@ public class AbstractPaymentTest {
|
||||
inListFinder,
|
||||
fieldResolver,
|
||||
paymentGroupResolver,
|
||||
timeWindowResolver)
|
||||
timeWindowResolver,
|
||||
paymentModelPaymentTypeResolver)
|
||||
.visit(parse, model);
|
||||
}
|
||||
|
||||
@ -74,7 +78,8 @@ public class AbstractPaymentTest {
|
||||
inListFinder,
|
||||
fieldResolver,
|
||||
paymentGroupResolver,
|
||||
timeWindowResolver)
|
||||
timeWindowResolver,
|
||||
paymentModelPaymentTypeResolver)
|
||||
.visit(parse, model);
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,28 @@ public class CustomTest extends AbstractPaymentTest {
|
||||
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tokenProviderTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/is_mobile.frd");
|
||||
when(paymentModelPaymentTypeResolver.isMobile(any())).thenReturn(true);
|
||||
|
||||
ParseContext parseContext = getParseContext(resourceAsStream);
|
||||
PaymentModel model = new PaymentModel();
|
||||
ResultModel result = invoke(parseContext, model);
|
||||
assertEquals(ResultStatus.ACCEPT, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void payerTypeTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/is_recurrent.frd");
|
||||
when(paymentModelPaymentTypeResolver.isRecurrent(any())).thenReturn(true);
|
||||
|
||||
ParseContext parseContext = getParseContext(resourceAsStream);
|
||||
PaymentModel model = new PaymentModel();
|
||||
ResultModel result = invoke(parseContext, model);
|
||||
assertEquals(ResultStatus.DECLINE, ResultUtils.findFirstNotNotifyStatus(result).get().getResultStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void amountTest() throws Exception {
|
||||
InputStream resourceAsStream = CustomTest.class.getResourceAsStream("/rules/amount.frd");
|
||||
|
1
src/test/resources/rules/is_mobile.frd
Normal file
1
src/test/resources/rules/is_mobile.frd
Normal file
@ -0,0 +1 @@
|
||||
rule: isMobile() -> accept;
|
1
src/test/resources/rules/is_recurrent.frd
Normal file
1
src/test/resources/rules/is_recurrent.frd
Normal file
@ -0,0 +1 @@
|
||||
rule: isRecurrent() -> decline;
|
Loading…
Reference in New Issue
Block a user