-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Generalize interfaces * Add tests for p2p * Add currency function * Added naming lists * Change logic exception
- Loading branch information
Showing
51 changed files
with
953 additions
and
478 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 4 additions & 15 deletions
19
src/main/java/com/rbkmoney/fraudo/aggregator/CountAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
package com.rbkmoney.fraudo.aggregator; | ||
|
||
import com.rbkmoney.fraudo.constant.CheckedField; | ||
import com.rbkmoney.fraudo.model.FraudModel; | ||
import com.rbkmoney.fraudo.model.TimeWindow; | ||
|
||
import java.util.List; | ||
|
||
public interface CountAggregator { | ||
public interface CountAggregator<T, U> { | ||
|
||
@Deprecated | ||
Integer count(CheckedField checkedField, FraudModel model, Long timeInMinutes); | ||
Integer count(U checkedField, T model, TimeWindow timeWindow, List<U> fields); | ||
|
||
Integer count(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, List<CheckedField> fields); | ||
Integer countSuccess(U checkedField, T model, TimeWindow timeWindow, List<U> fields); | ||
|
||
@Deprecated | ||
Integer countSuccess(CheckedField checkedField, FraudModel model, Long timeInMinutes); | ||
|
||
Integer countSuccess(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, List<CheckedField> fields); | ||
|
||
@Deprecated | ||
Integer countError(CheckedField checkedField, FraudModel model, Long timeInMinutes, String errorCode); | ||
|
||
Integer countError(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, String errorCode, List<CheckedField> fields); | ||
Integer countError(U checkedField, T model, TimeWindow timeWindow, String errorCode, List<U> fields); | ||
|
||
} |
19 changes: 4 additions & 15 deletions
19
src/main/java/com/rbkmoney/fraudo/aggregator/SumAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,15 @@ | ||
package com.rbkmoney.fraudo.aggregator; | ||
|
||
import com.rbkmoney.fraudo.constant.CheckedField; | ||
import com.rbkmoney.fraudo.model.FraudModel; | ||
import com.rbkmoney.fraudo.model.TimeWindow; | ||
|
||
import java.util.List; | ||
|
||
public interface SumAggregator { | ||
public interface SumAggregator<T, U> { | ||
|
||
@Deprecated | ||
Double sum(CheckedField checkedField, FraudModel model, Long timeInMinutes); | ||
Double sum(U checkedField, T model, TimeWindow timeWindow, List<U> fields); | ||
|
||
Double sum(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, List<CheckedField> fields); | ||
Double sumSuccess(U checkedField, T model, TimeWindow timeWindow, List<U> fields); | ||
|
||
@Deprecated | ||
Double sumSuccess(CheckedField checkedField, FraudModel model, Long timeInMinutes); | ||
|
||
Double sumSuccess(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, List<CheckedField> fields); | ||
|
||
@Deprecated | ||
Double sumError(CheckedField checkedField, FraudModel model, Long timeInMinutes, String errorCode); | ||
|
||
Double sumError(CheckedField checkedField, FraudModel model, TimeWindow timeWindow, String errorCode, List<CheckedField> fields); | ||
Double sumError(U checkedField, T model, TimeWindow timeWindow, String errorCode, List<U> fields); | ||
|
||
} |
9 changes: 2 additions & 7 deletions
9
src/main/java/com/rbkmoney/fraudo/aggregator/UniqueValueAggregator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
package com.rbkmoney.fraudo.aggregator; | ||
|
||
import com.rbkmoney.fraudo.constant.CheckedField; | ||
import com.rbkmoney.fraudo.model.FraudModel; | ||
import com.rbkmoney.fraudo.model.TimeWindow; | ||
|
||
import java.util.List; | ||
|
||
public interface UniqueValueAggregator { | ||
public interface UniqueValueAggregator<T, U> { | ||
|
||
@Deprecated | ||
Integer countUniqueValue(CheckedField countField, FraudModel fraudModel, CheckedField onField, Long time); | ||
|
||
Integer countUniqueValue(CheckedField countField, FraudModel fraudModel, CheckedField onField, TimeWindow timeWindow, List<CheckedField> fields); | ||
Integer countUniqueValue(U countField, T payoutModel, U onField, TimeWindow timeWindow, List<U> fields); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/rbkmoney/fraudo/constant/P2PCheckedField.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.rbkmoney.fraudo.constant; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public enum P2PCheckedField { | ||
|
||
EMAIL("email"), | ||
IP("ip"), | ||
FINGERPRINT("fingerprint"), | ||
COUNTRY_BANK("country_bank"), | ||
BIN("bin"), | ||
PAN("pan"), | ||
CURRENCY("currency"), | ||
IDENTITY_ID("identity_id"), | ||
CARD_TOKEN_FROM("card_token_from"), | ||
CARD_TOKEN_TO("card_token_to"); | ||
|
||
private String value; | ||
private static Map<String, P2PCheckedField> valueMap = new HashMap<>(); | ||
|
||
static { | ||
for (P2PCheckedField value : P2PCheckedField.values()) { | ||
valueMap.put(value.value, value); | ||
} | ||
} | ||
|
||
P2PCheckedField(String value) { | ||
this.value = value; | ||
} | ||
|
||
public static P2PCheckedField getByValue(String value) { | ||
return valueMap.get(value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/com/rbkmoney/fraudo/exception/NotValidContextException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.rbkmoney.fraudo.exception; | ||
|
||
public class NotValidContextException extends RuntimeException { | ||
|
||
private static final String ERROR_MESSAGE = "Context is not valid!"; | ||
|
||
public NotValidContextException() { | ||
super(ERROR_MESSAGE); | ||
} | ||
} |
44 changes: 27 additions & 17 deletions
44
src/main/java/com/rbkmoney/fraudo/factory/FastFraudVisitorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
package com.rbkmoney.fraudo.factory; | ||
|
||
import com.rbkmoney.fraudo.FraudoVisitor; | ||
import com.rbkmoney.fraudo.aggregator.CountAggregator; | ||
import com.rbkmoney.fraudo.aggregator.SumAggregator; | ||
import com.rbkmoney.fraudo.aggregator.UniqueValueAggregator; | ||
import com.rbkmoney.fraudo.finder.InListFinder; | ||
import com.rbkmoney.fraudo.model.FraudModel; | ||
import com.rbkmoney.fraudo.model.BaseModel; | ||
import com.rbkmoney.fraudo.resolver.CountryResolver; | ||
import com.rbkmoney.fraudo.visitor.*; | ||
import com.rbkmoney.fraudo.resolver.FieldResolver; | ||
import com.rbkmoney.fraudo.resolver.GroupByModelResolver; | ||
import com.rbkmoney.fraudo.visitor.CountVisitor; | ||
import com.rbkmoney.fraudo.visitor.CustomFuncVisitor; | ||
import com.rbkmoney.fraudo.visitor.ListVisitor; | ||
import com.rbkmoney.fraudo.visitor.SumVisitor; | ||
import com.rbkmoney.fraudo.visitor.impl.*; | ||
|
||
public class FastFraudVisitorFactory implements FraudVisitorFactory { | ||
public class FastFraudVisitorFactory<T extends BaseModel, U> implements FraudVisitorFactory<T, U> { | ||
|
||
@Override | ||
public FraudoVisitor<Object> createVisitor(FraudModel model, | ||
CountAggregator countAggregator, | ||
SumAggregator sumAggregator, | ||
UniqueValueAggregator uniqueValueAggregator, | ||
CountryResolver countryResolver, | ||
InListFinder blackListFinder, | ||
InListFinder whiteListFinder, | ||
InListFinder greyListFinder) { | ||
CountVisitorImpl countVisitor = new CountVisitorImpl(model, countAggregator); | ||
SumVisitorImpl sumVisitor = new SumVisitorImpl(model, sumAggregator); | ||
ListVisitorImpl listVisitor = new ListVisitorImpl(model, blackListFinder, whiteListFinder, greyListFinder); | ||
CustomFuncVisitorImpl customFuncVisitor = new CustomFuncVisitorImpl(model, uniqueValueAggregator, countryResolver); | ||
return new FastFraudVisitorImpl(countVisitor, sumVisitor, listVisitor, customFuncVisitor); | ||
public FastFraudVisitorImpl<T> createVisitor( | ||
CountAggregator<T, U> countAggregator, | ||
SumAggregator<T, U> sumAggregator, | ||
UniqueValueAggregator<T, U> uniqueValueAggregator, | ||
CountryResolver<U> countryResolver, | ||
InListFinder<T, U> listFinder, | ||
FieldResolver<T, U> fieldResolver, | ||
GroupByModelResolver<T, U> groupByModelResolver) { | ||
CountVisitor<T> countVisitor = new CountVisitorImpl<>(countAggregator, fieldResolver, groupByModelResolver); | ||
SumVisitor<T> sumVisitor = new SumVisitorImpl<>(sumAggregator, fieldResolver, groupByModelResolver); | ||
ListVisitor<T> listVisitor = new ListVisitorImpl<>(listFinder, fieldResolver); | ||
CustomFuncVisitor<T> customFuncVisitor = new CustomFuncVisitorImpl<>( | ||
uniqueValueAggregator, | ||
countryResolver, | ||
fieldResolver, | ||
groupByModelResolver); | ||
return new FastFraudVisitorImpl<>(countVisitor, sumVisitor, listVisitor, customFuncVisitor); | ||
} | ||
|
||
} |
22 changes: 11 additions & 11 deletions
22
src/main/java/com/rbkmoney/fraudo/factory/FraudVisitorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
package com.rbkmoney.fraudo.factory; | ||
|
||
import com.rbkmoney.fraudo.FraudoVisitor; | ||
import com.rbkmoney.fraudo.aggregator.CountAggregator; | ||
import com.rbkmoney.fraudo.aggregator.SumAggregator; | ||
import com.rbkmoney.fraudo.aggregator.UniqueValueAggregator; | ||
import com.rbkmoney.fraudo.finder.InListFinder; | ||
import com.rbkmoney.fraudo.model.FraudModel; | ||
import com.rbkmoney.fraudo.resolver.CountryResolver; | ||
import com.rbkmoney.fraudo.resolver.FieldResolver; | ||
import com.rbkmoney.fraudo.resolver.GroupByModelResolver; | ||
import com.rbkmoney.fraudo.visitor.impl.FastFraudVisitorImpl; | ||
|
||
public interface FraudVisitorFactory { | ||
public interface FraudVisitorFactory<T, U> { | ||
|
||
FraudoVisitor<Object> createVisitor(FraudModel model, | ||
CountAggregator countAggregator, | ||
SumAggregator sumAggregator, | ||
UniqueValueAggregator uniqueValueAggregator, | ||
CountryResolver countryResolver, | ||
InListFinder blackListFinder, | ||
InListFinder whiteListFinder, | ||
InListFinder greyListFinder); | ||
FastFraudVisitorImpl createVisitor(CountAggregator<T, U> countAggregator, | ||
SumAggregator<T, U> sumAggregator, | ||
UniqueValueAggregator<T, U> uniqueValueAggregator, | ||
CountryResolver<U> countryResolver, | ||
InListFinder<T, U> listFinder, | ||
FieldResolver<T, U> fieldPairResolver, | ||
GroupByModelResolver<T, U> groupByModelResolver); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package com.rbkmoney.fraudo.finder; | ||
|
||
import com.rbkmoney.fraudo.constant.CheckedField; | ||
|
||
import com.rbkmoney.fraudo.model.Pair; | ||
|
||
import java.util.List; | ||
|
||
public interface InListFinder { | ||
public interface InListFinder<T, U> { | ||
|
||
Boolean findInBlackList(List<Pair<U, String>> fields, T model); | ||
|
||
Boolean findInWhiteList(List<Pair<U, String>> fields, T model); | ||
|
||
Boolean findInList(String partyId, String shopId, CheckedField field, String value); | ||
Boolean findInGreyList(List<Pair<U, String>> fields, T model); | ||
|
||
Boolean findInList(String partyId, String shopId, List<CheckedField> fields, List<String> value); | ||
Boolean findInList(String name, List<Pair<U, String>> fields, T model); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.rbkmoney.fraudo.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class BaseModel { | ||
|
||
private String ip; | ||
private String email; | ||
private String fingerprint; | ||
private Long amount; | ||
private String currency; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.rbkmoney.fraudo.model; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class P2PModel extends BaseModel { | ||
|
||
private String bin; | ||
private String pan; | ||
private String country; | ||
private String cardTokenFrom; | ||
private String cardTokenTo; | ||
private String identityId; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.rbkmoney.fraudo.model; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class Pair<T, U> { | ||
|
||
private T first; | ||
private U second; | ||
|
||
} |
Oops, something went wrong.