|
32 | 32 | import com.optimizely.ab.config.parser.DefaultConfigParser;
|
33 | 33 | import com.optimizely.ab.error.ErrorHandler;
|
34 | 34 | import com.optimizely.ab.error.NoOpErrorHandler;
|
35 |
| -import com.optimizely.ab.error.RaiseExceptionErrorHandler; |
36 | 35 | import com.optimizely.ab.event.EventHandler;
|
37 | 36 | import com.optimizely.ab.event.LogEvent;
|
38 | 37 | import com.optimizely.ab.event.internal.BuildVersionInfo;
|
|
42 | 41 | import org.slf4j.Logger;
|
43 | 42 | import org.slf4j.LoggerFactory;
|
44 | 43 |
|
45 |
| -import javax.annotation.CheckForNull; |
46 | 44 | import javax.annotation.Nonnull;
|
47 | 45 | import javax.annotation.Nullable;
|
48 | 46 | import javax.annotation.concurrent.ThreadSafe;
|
@@ -131,7 +129,7 @@ Variation activate(@Nonnull String experimentKey,
|
131 | 129 |
|
132 | 130 | ProjectConfig currentConfig = getProjectConfig();
|
133 | 131 |
|
134 |
| - Experiment experiment = getExperimentOrThrow(currentConfig, experimentKey); |
| 132 | + Experiment experiment = currentConfig.getExperimentForKey(experimentKey, errorHandler); |
135 | 133 | if (experiment == null) {
|
136 | 134 | // if we're unable to retrieve the associated experiment, return null
|
137 | 135 | logger.info("Not activating user \"{}\" for experiment \"{}\".", userId, experimentKey);
|
@@ -228,7 +226,7 @@ public void track(@Nonnull String eventName,
|
228 | 226 |
|
229 | 227 | ProjectConfig currentConfig = getProjectConfig();
|
230 | 228 |
|
231 |
| - EventType eventType = getEventTypeOrThrow(currentConfig, eventName); |
| 229 | + EventType eventType = currentConfig.getEventTypeForName(eventName, errorHandler); |
232 | 230 | if (eventType == null) {
|
233 | 231 | // if no matching event type could be found, do not dispatch an event
|
234 | 232 | logger.info("Not tracking event \"{}\" for user \"{}\".", eventName, userId);
|
@@ -638,7 +636,7 @@ Variation getVariation(@Nonnull String experimentKey,
|
638 | 636 |
|
639 | 637 | ProjectConfig currentConfig = getProjectConfig();
|
640 | 638 |
|
641 |
| - Experiment experiment = getExperimentOrThrow(currentConfig, experimentKey); |
| 639 | + Experiment experiment = currentConfig.getExperimentForKey(experimentKey, errorHandler); |
642 | 640 | if (experiment == null) {
|
643 | 641 | // if we're unable to retrieve the associated experiment, return null
|
644 | 642 | return null;
|
@@ -720,64 +718,6 @@ public UserProfileService getUserProfileService() {
|
720 | 718 |
|
721 | 719 | //======== Helper methods ========//
|
722 | 720 |
|
723 |
| - /** |
724 |
| - * Helper method to retrieve the {@link Experiment} for the given experiment key. |
725 |
| - * If {@link RaiseExceptionErrorHandler} is provided, either an experiment is returned, or an exception is thrown. |
726 |
| - * If {@link NoOpErrorHandler} is used, either an experiment or {@code null} is returned. |
727 |
| - * |
728 |
| - * @param projectConfig the current project config |
729 |
| - * @param experimentKey the experiment to retrieve from the current project config |
730 |
| - * @return the experiment for given experiment key |
731 |
| - * |
732 |
| - * @throws UnknownExperimentException if there are no experiments in the current project config with the given |
733 |
| - * experiment key |
734 |
| - */ |
735 |
| - private @CheckForNull Experiment getExperimentOrThrow(@Nonnull ProjectConfig projectConfig, |
736 |
| - @Nonnull String experimentKey) |
737 |
| - throws UnknownExperimentException { |
738 |
| - |
739 |
| - Experiment experiment = projectConfig |
740 |
| - .getExperimentKeyMapping() |
741 |
| - .get(experimentKey); |
742 |
| - |
743 |
| - // if the given experiment key isn't present in the config, log and potentially throw an exception |
744 |
| - if (experiment == null) { |
745 |
| - String unknownExperimentError = String.format("Experiment \"%s\" is not in the datafile.", experimentKey); |
746 |
| - logger.error(unknownExperimentError); |
747 |
| - errorHandler.handleError(new UnknownExperimentException(unknownExperimentError)); |
748 |
| - } |
749 |
| - |
750 |
| - return experiment; |
751 |
| - } |
752 |
| - |
753 |
| - /** |
754 |
| - * Helper method to retrieve the {@link EventType} for the given event name. |
755 |
| - * If {@link RaiseExceptionErrorHandler} is provided, either an event type is returned, or an exception is thrown. |
756 |
| - * If {@link NoOpErrorHandler} is used, either an event type or {@code null} is returned. |
757 |
| - * |
758 |
| - * @param projectConfig the current project config |
759 |
| - * @param eventName the event type to retrieve from the current project config |
760 |
| - * @return the event type for the given event name |
761 |
| - * |
762 |
| - * @throws UnknownEventTypeException if there are no event types in the current project config with the given name |
763 |
| - */ |
764 |
| - private EventType getEventTypeOrThrow(ProjectConfig projectConfig, String eventName) |
765 |
| - throws UnknownEventTypeException { |
766 |
| - |
767 |
| - EventType eventType = projectConfig |
768 |
| - .getEventNameMapping() |
769 |
| - .get(eventName); |
770 |
| - |
771 |
| - // if the given event name isn't present in the config, log and potentially throw an exception |
772 |
| - if (eventType == null) { |
773 |
| - String unknownEventTypeError = String.format("Event \"%s\" is not in the datafile.", eventName); |
774 |
| - logger.error(unknownEventTypeError); |
775 |
| - errorHandler.handleError(new UnknownEventTypeException(unknownEventTypeError)); |
776 |
| - } |
777 |
| - |
778 |
| - return eventType; |
779 |
| - } |
780 |
| - |
781 | 721 | /**
|
782 | 722 | * Helper method to verify that the given attributes map contains only keys that are present in the
|
783 | 723 | * {@link ProjectConfig}.
|
|
0 commit comments