-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Igor Urisman
authored and
Igor Urisman
committed
Jun 19, 2023
1 parent
4a4c2d7
commit cd0ec4c
Showing
12 changed files
with
166 additions
and
213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.idea/ | ||
/target/ |
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
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/variant/extapi/std/demo/UserTargetingHook.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,54 @@ | ||
package com.variant.extapi.std.demo; | ||
|
||
import com.variant.server.api.Session; | ||
import com.variant.server.api.lifecycle.LifecycleHook; | ||
import com.variant.server.api.lifecycle.VariationQualificationLifecycleEvent; | ||
import com.variant.server.api.lifecycle.VariationTargetingLifecycleEvent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
|
||
/** | ||
* Life-cycle hook to disqualify blacklisted users. | ||
* The black list of users is given in the hook's initializer object, e.g. as following: | ||
* <code> | ||
* 'init': {'blackList':['Nikita Krushchev']} | ||
* </code> | ||
* | ||
*/ | ||
public class UserTargetingHook implements LifecycleHook<VariationTargetingLifecycleEvent> { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(UserTargetingHook.class); | ||
|
||
private final String[] blackList; | ||
|
||
public UserTargetingHook(String init) { | ||
blackList = new String[0]; | ||
//blackList = config.getList("blackList").stream().map(e -> e.unwrapped()).toArray(String[]::new); | ||
} | ||
|
||
@Override | ||
public Class<VariationTargetingLifecycleEvent> getLifecycleEventClass() { | ||
return VariationTargetingLifecycleEvent.class; | ||
} | ||
|
||
@Override | ||
public Optional<VariationTargetingLifecycleEvent.PostResult> post(VariationTargetingLifecycleEvent event) { | ||
|
||
Session ssn = event.getSession(); | ||
String user = ssn.getAttributes().get("user"); | ||
|
||
boolean blacklisted = Arrays.stream(blackList).filter(d -> user.equals(d)).findFirst().isPresent(); | ||
|
||
if (blacklisted) | ||
LOG.info("Disqualified blacklisted user [" + user + "] from variation " + event.getVariation().getName() + "]"); | ||
|
||
VariationTargetingLifecycleEvent.PostResult result = event.mkPostResult(); | ||
// result.setQualified(!blacklisted); | ||
return Optional.of(result); | ||
} | ||
|
||
} |
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
5 changes: 2 additions & 3 deletions
5
src/main/java/com/variant/extapi/std/flush/TraceEventFlusherNull.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
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
Oops, something went wrong.