diff --git a/dotCMS/src/integration-test/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculatorIntegrationTest.java b/dotCMS/src/integration-test/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculatorIntegrationTest.java index 156b14c291c7..0118b48145e9 100644 --- a/dotCMS/src/integration-test/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculatorIntegrationTest.java +++ b/dotCMS/src/integration-test/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculatorIntegrationTest.java @@ -1,18 +1,19 @@ package com.dotcms.experiments.business; import com.dotcms.analytics.metrics.*; -import com.dotcms.datagen.ExperimentDataGen; -import com.dotcms.datagen.HTMLPageDataGen; -import com.dotcms.datagen.SiteDataGen; -import com.dotcms.datagen.TemplateDataGen; +import com.dotcms.datagen.*; import com.dotcms.experiments.model.Experiment; import com.dotcms.experiments.model.GoalFactory; import com.dotcms.experiments.model.Goals; import com.dotcms.util.IntegrationTestInitService; +import com.dotcms.vanityurl.model.VanityUrl; import com.dotmarketing.beans.Host; +import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; import com.dotmarketing.portlets.templates.model.Template; import com.liferay.util.StringPool; +import jdk.jshell.spi.ExecutionControl; import org.junit.BeforeClass; import org.junit.Test; @@ -254,4 +255,195 @@ public void urlParameterGoalAndExistsOperator(){ assertFalse("http://localhost:8080/testing?DifferentTestParameter=testValue".matches(targetRegularExpression)); assertTrue("http://localhost:8080/testing?testParameter=anyValue".matches(targetRegularExpression)); } + + /** + * Method to test: {@link ExperimentUrlPatternCalculator#calculatePageUrlRegexPattern(Experiment)} + * When: Exists a Published Vanity Url with the forwardTo equals to the URI og the Experiment's Page + * Should: The regex returned by the method should match the VanityUrl's URI + * + * @throws DotDataException + */ + @Test + public void experimentWithVanityUrl() throws DotDataException { + + final Host host = new SiteDataGen().nextPersisted(); + final Template template = new TemplateDataGen().host(host).nextPersisted(); + + final HTMLPageAsset experimentPage = new HTMLPageDataGen(host, template).nextPersisted(); + + final Condition condition = Condition.builder() + .parameter("url") + .value("testing") + .operator(AbstractCondition.Operator.CONTAINS) + .build(); + + final Metric metric = Metric.builder() + .name("Testing Metric") + .type(MetricType.REACH_PAGE) + .addConditions(condition).build(); + + final Goals goal = Goals.builder().primary(GoalFactory.create(metric)).build(); + final Experiment experiment = new ExperimentDataGen() + .page(experimentPage) + .addGoal(goal) + .nextPersisted(); + + final Contentlet vanityUrl = new VanityUrlDataGen() + .uri("/testing") + .forwardTo(experimentPage.getURI()) + .action(200) + .host(host) + .languageId(experimentPage.getLanguageId()) + .nextPersistedAndPublish(); + + final String regex = ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(experiment); + + assertTrue(("http://localhost:8080/" + experimentPage.getPageUrl()).matches(regex)); + assertTrue(("http://localhost:8080/testing").matches(regex)); + + } + + /** + * Method to test: {@link ExperimentUrlPatternCalculator#calculatePageUrlRegexPattern(Experiment)} + * When: Exists a Published Vanity Url with the forwardTo equals to the URI og the Experiment's Page but with not 200 action + * Should: The regex returned by the method should NOT match the VanityUrl's URI + * + * @throws DotDataException + */ + @Test + public void experimentWithVanityUrlWithNot200Action() throws DotDataException { + final Host host = new SiteDataGen().nextPersisted(); + final Template template = new TemplateDataGen().host(host).nextPersisted(); + + final HTMLPageAsset experimentPage = new HTMLPageDataGen(host, template).nextPersisted(); + + final Condition condition = Condition.builder() + .parameter("url") + .value("testing") + .operator(AbstractCondition.Operator.CONTAINS) + .build(); + + final Metric metric = Metric.builder() + .name("Testing Metric") + .type(MetricType.REACH_PAGE) + .addConditions(condition).build(); + + final Goals goal = Goals.builder().primary(GoalFactory.create(metric)).build(); + final Experiment experiment = new ExperimentDataGen() + .page(experimentPage) + .addGoal(goal) + .nextPersisted(); + + final Contentlet vanityUrl = new VanityUrlDataGen() + .uri("/testing") + .forwardTo(experimentPage.getURI()) + .action(301) + .host(host) + .languageId(experimentPage.getLanguageId()) + .nextPersistedAndPublish(); + + final String regex = ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(experiment); + + assertTrue(("http://localhost:8080/" + experimentPage.getPageUrl()).matches(regex)); + assertFalse(("http://localhost:8080/testing").matches(regex)); + } + + /** + * Method to test: {@link ExperimentUrlPatternCalculator#calculatePageUrlRegexPattern(Experiment)} + * When: Exists a UnPublished Vanity Url with the forwardTo equals to the URI og the Experiment's Page + * Should: The regex returned by the method should NOT match the VanityUrl's URI + * + * @throws DotDataException + */ + @Test + public void experimentWithUnPublishedVanity() throws DotDataException { + final Host host = new SiteDataGen().nextPersisted(); + final Template template = new TemplateDataGen().host(host).nextPersisted(); + + final HTMLPageAsset experimentPage = new HTMLPageDataGen(host, template).nextPersisted(); + + final Condition condition = Condition.builder() + .parameter("url") + .value("testing") + .operator(AbstractCondition.Operator.CONTAINS) + .build(); + + final Metric metric = Metric.builder() + .name("Testing Metric") + .type(MetricType.REACH_PAGE) + .addConditions(condition).build(); + + final Goals goal = Goals.builder().primary(GoalFactory.create(metric)).build(); + final Experiment experiment = new ExperimentDataGen() + .page(experimentPage) + .addGoal(goal) + .nextPersisted(); + + final Contentlet vanityUrl = new VanityUrlDataGen() + .uri("/testing") + .forwardTo(experimentPage.getURI()) + .action(301) + .host(host) + .languageId(experimentPage.getLanguageId()) + .nextPersisted(); + + final String regex = ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(experiment); + + assertTrue(("http://localhost:8080/" + experimentPage.getPageUrl()).matches(regex)); + assertFalse(("http://localhost:8080/testing").matches(regex)); + } + + /** + * Method to test: {@link ExperimentUrlPatternCalculator#calculatePageUrlRegexPattern(Experiment)} + * When: Exists 2 Published Vanity Url with the forwardTo equals to the URI og the Experiment's Page and action equals to 200 + * Should: The regex returned by the method should match both the VanityUrl's URI + * + * @throws DotDataException + */ + @Test + public void experimentWithTwoPublishedVanity() throws DotDataException { + final Host host = new SiteDataGen().nextPersisted(); + final Template template = new TemplateDataGen().host(host).nextPersisted(); + + final HTMLPageAsset experimentPage = new HTMLPageDataGen(host, template).nextPersisted(); + + final Condition condition = Condition.builder() + .parameter("url") + .value("testing") + .operator(AbstractCondition.Operator.CONTAINS) + .build(); + + final Metric metric = Metric.builder() + .name("Testing Metric") + .type(MetricType.REACH_PAGE) + .addConditions(condition).build(); + + final Goals goal = Goals.builder().primary(GoalFactory.create(metric)).build(); + final Experiment experiment = new ExperimentDataGen() + .page(experimentPage) + .addGoal(goal) + .nextPersisted(); + + final Contentlet vanityUrl_1 = new VanityUrlDataGen() + .uri("/testing") + .forwardTo(experimentPage.getURI()) + .action(200) + .host(host) + .languageId(experimentPage.getLanguageId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_2 = new VanityUrlDataGen() + .uri("/another_testing") + .forwardTo(experimentPage.getURI()) + .action(200) + .host(host) + .languageId(experimentPage.getLanguageId()) + .nextPersistedAndPublish(); + + final String regex = ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(experiment); + + assertTrue(("http://localhost:8080/" + experimentPage.getPageUrl()).matches(regex)); + assertTrue(("http://localhost:8080/testing").matches(regex)); + assertTrue(("http://localhost:8080/another_testing").matches(regex)); + } } diff --git a/dotCMS/src/integration-test/java/com/dotcms/vanityurl/business/VanityUrlAPITest.java b/dotCMS/src/integration-test/java/com/dotcms/vanityurl/business/VanityUrlAPITest.java index 30b2d1b2c6f2..28138299dd12 100644 --- a/dotCMS/src/integration-test/java/com/dotcms/vanityurl/business/VanityUrlAPITest.java +++ b/dotCMS/src/integration-test/java/com/dotcms/vanityurl/business/VanityUrlAPITest.java @@ -1035,4 +1035,255 @@ private Contentlet createVanity(final Host site, final Language lang) throws Dot return ContentletDataGen.publish(vanityURL); } + /** + * Method to test: {@link VanityUrlAPIImpl#findByForward(Host, Language, String)} + * When: Have Vanity Urls with the follow fowardTo values (the firsts 7 with the same Lang and Host): + * 1) /Testing + * 2) /folder/Testing + * 3) /folder/sub_folder/Testing + * 4) /whatever/Testing + * 5) /folder/whatever + * 6) /Testing but with different action + * 7) /Testing but with different uri + * 8) /Testing but in another host + * 9) /folder/Testing but in another lang + * 10 and 11 /folder/Testing but with different action + * + * and we call the method with the Host and Language of the first 5 Vanity Urls and with the Regex equals to: "/Testing" + * + * Should: returns (1) and (7) + */ + @Test + public void findByForward(){ + final Host host = new SiteDataGen().nextPersisted(); + final Language language = new LanguageDataGen().nextPersisted(); + + final Contentlet vanityUrl_1 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_2 = new VanityUrlDataGen() + .forwardTo("/folder/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_3 = new VanityUrlDataGen() + .forwardTo("/folder/sub_folder/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_4 = new VanityUrlDataGen() + .forwardTo("/whatever/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_5 = new VanityUrlDataGen() + .forwardTo("/folder/whatever") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_6 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(301) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_7 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever_2") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Host host_2 = new SiteDataGen().nextPersisted(); + + final Contentlet vanityUrl_8 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host_2) + .nextPersistedAndPublish(); + + final Language language_2 = new LanguageDataGen().nextPersisted(); + + final Contentlet vanityUrl_9 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/folder/Testing") + .action(200) + .host(host) + .languageId(language_2.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_10 = new VanityUrlDataGen() + .forwardTo("/folder/Testing") + .uri("/whatever") + .action(301) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_11 = new VanityUrlDataGen() + .forwardTo("/folder/Testing") + .uri("/whatever") + .action(302) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final List byForward = APILocator.getVanityUrlAPI().findByForward(host, language, + "/Testing", 200); + + assertEquals(2, byForward.size()); + + final List ids = byForward.stream().map(cachedVanityUrl -> cachedVanityUrl.vanityUrlId) + .collect(Collectors.toList()); + + assertTrue(ids.contains(vanityUrl_1.getIdentifier())); + assertTrue(ids.contains(vanityUrl_7.getIdentifier())); + } + + /** + * Method to test: {@link VanityUrlAPIImpl#findByForward(Host, Language, String)} + * When: Have Vanity Urls with the follow fowardTo values ( the first 2 have the same Lang and Host): + * 1) /Testing (Publish) + * 2) /Testing (Not Publish) + * 3) /Testing (Publish) with different host + * 4) /Testing (Publish) with different action + * + * and we call the method with the Host and Language of the first 5 Vanity Urls and with the Regex equals to: "/Testing" + * + * Should: returns just (1) + */ + @Test + public void findByForwardNotReturnUnPublish() { + final Host host = new SiteDataGen().nextPersisted(); + final Language language = new LanguageDataGen().nextPersisted(); + + final Contentlet vanityUrl_1 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_2 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersisted(); + + final Contentlet vanityUrl_3 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(301) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Host host_2 = new SiteDataGen().nextPersisted(); + + final Contentlet vanityUrl_4 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host_2) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final List byForward = APILocator.getVanityUrlAPI().findByForward(host, language, + "/Testing", 200); + + assertEquals(1, byForward.size()); + + final List ids = byForward.stream().map(cachedVanityUrl -> cachedVanityUrl.vanityUrlId) + .collect(Collectors.toList()); + + assertTrue(ids.contains(vanityUrl_1.getIdentifier())); + } + + /** + * Method to test: {@link VanityUrlAPIImpl#findByForward(Host, Language, String)} + * When: Have Vanity Urls with the follow fowardTo values (all of them with the same Lang and Host): + * 1) /Testing Not Publish + * 2) /folder/Testing + * 3) /folder/sub_folder/Testing + * 4) /whatever/Testing + * 5) /folder/whatever + * + * and we call the method with Regex equals to: "\/folder_2\/.*" + * + * Should: return an empty list + */ + @Test + public void findByForwardReturnedEmptyList(){ + final Host host = new SiteDataGen().nextPersisted(); + final Language language = new LanguageDataGen().nextPersisted(); + + final Contentlet vanityUrl_1 = new VanityUrlDataGen() + .forwardTo("/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersisted(); + + final Contentlet vanityUrl_2 = new VanityUrlDataGen() + .forwardTo("/folder/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_3 = new VanityUrlDataGen() + .forwardTo("/folder/sub_folder/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_4 = new VanityUrlDataGen() + .forwardTo("/whatever/Testing") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final Contentlet vanityUrl_5 = new VanityUrlDataGen() + .forwardTo("/folder/whatever") + .uri("/whatever") + .action(200) + .host(host) + .languageId(language.getId()) + .nextPersistedAndPublish(); + + final List byForward = APILocator.getVanityUrlAPI().findByForward(host, language, + "/Testing", 200); + + assertTrue(byForward.isEmpty()); + } } \ No newline at end of file diff --git a/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculator.java b/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculator.java index f9c358c655c8..8c4c7e12da4e 100644 --- a/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculator.java +++ b/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentUrlPatternCalculator.java @@ -1,15 +1,26 @@ package com.dotcms.experiments.business; +import static com.dotcms.experiments.business.RegexUrlPatterStrategy.*; import static com.dotcms.util.CollectionsUtils.list; import com.dotcms.analytics.metrics.*; +import com.dotcms.experiments.model.Experiment; +import com.dotcms.vanityurl.model.CachedVanityUrl; +import com.dotmarketing.beans.Host; +import com.dotmarketing.business.APILocator; import com.dotmarketing.exception.DotDataException; +import com.dotmarketing.exception.DotRuntimeException; +import com.dotmarketing.exception.DotSecurityException; +import com.dotmarketing.portlets.contentlet.model.Contentlet; import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset; +import com.dotmarketing.portlets.languagesmanager.model.Language; +import com.liferay.util.StringPool; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; /** * Util class to calculate the regex pattern for a given {@link HTMLPageAsset} @@ -25,8 +36,8 @@ public enum ExperimentUrlPatternCalculator { ); /** - * Calculate the URL regex pattern for the given {@link HTMLPageAsset}, - * This pattern is used to match the Event's url page with the {@link HTMLPageAsset} url. + * Calculate the URL regex pattern for the given {@link Experiment}, + * This pattern is used to match the Event's url page with the {@link Experiment}'s {@link HTMLPageAsset} url. * * For example if you create a Experiment using the "/blog/index" page, any of * the following urls will be matched: @@ -40,23 +51,56 @@ public enum ExperimentUrlPatternCalculator { * If the page use inside the Experiment isuse as Detail Page on any Content Type then is even * more complicated. * - * @param htmlPageAsset + * @param experiment * @return */ - public String calculatePageUrlRegexPattern(final HTMLPageAsset htmlPageAsset) { + public String calculatePageUrlRegexPattern(final Experiment experiment) { + final HTMLPageAsset htmlPageAsset = getHtmlPageAsset(experiment); + try { - return URL_REGEX_PATTERN_STRATEGIES.stream() - .filter(strategy -> strategy.isMatch(htmlPageAsset)) - .findFirst() - .orElseGet(()-> DEFAULT_REGEX_URL_PATTERN_STRATEGY) + final Host host = APILocator.getHostAPI().find(htmlPageAsset.getHost(), APILocator.systemUser(), false); + final Language language = APILocator.getLanguageAPI().getLanguage(htmlPageAsset.getLanguageId()); + + final String vanityUrlRegex = getVanityUrlsRegex(host, language, htmlPageAsset); + + final String experimentPageRegex = URL_REGEX_PATTERN_STRATEGIES.stream() + .filter(strategy -> strategy.isMatch(htmlPageAsset)) + .findFirst() + .orElseGet(() -> DEFAULT_REGEX_URL_PATTERN_STRATEGY) .getRegexPattern(htmlPageAsset).toLowerCase(); - } catch (final RegexUrlPatterStrategyException e) { + return vanityUrlRegex.isEmpty() ? experimentPageRegex : + String.format("(%s|%s)", experimentPageRegex , vanityUrlRegex); + } catch (final RegexUrlPatterStrategyException | DotDataException | DotSecurityException e) { throw new RuntimeException(String.format("It is not possible to get the URI for %s", htmlPageAsset.getInode()), e); } } + private static String getVanityUrlsRegex(final Host host, final Language language, + final HTMLPageAsset htmlPageAsset) throws DotDataException { + + final String vanityUrlRegex = APILocator.getVanityUrlAPI() + .findByForward(host, language, htmlPageAsset.getURI(), 200) + .stream() + .map(vanitysUrls -> String.format(DEFAULT_URL_REGEX_TEMPLATE, vanitysUrls.pattern)) + .collect(Collectors.joining(StringPool.PIPE)); + return vanityUrlRegex.isEmpty() ? StringPool.BLANK : String.format("^%s$", vanityUrlRegex); + } + + private HTMLPageAsset getHtmlPageAsset(final Experiment experiment) { + + try { + final Contentlet contentlet = APILocator.getContentletAPI() + .findContentletByIdentifierAnyLanguage(experiment.pageId(), false); + final HTMLPageAsset htmlPageAsset = APILocator.getHTMLPageAssetAPI() + .fromContentlet(contentlet); + return htmlPageAsset; + } catch (DotDataException e) { + throw new DotRuntimeException(e); + } + } + public Optional calculateTargetPageUrlPattern(final HTMLPageAsset htmlPageAsset, final Metric metric) { final MetricType type = metric.type(); Optional regexParameterName = type.getRegexParameterName(); diff --git a/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentsAPIImpl.java b/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentsAPIImpl.java index 1776ccb0629f..34e692e3aba8 100644 --- a/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentsAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/experiments/business/ExperimentsAPIImpl.java @@ -237,63 +237,6 @@ private static boolean isExistingSchedulingChanging(Experiment experimentToSave, equals(experimentToSave.scheduling()); } - private static boolean isUrlParameterOrReachPage(Goals goals) { - final MetricType metricType = goals.primary().getMetric().type(); - return metricType == MetricType.URL_PARAMETER || metricType == MetricType.REACH_PAGE; - } - - private static boolean isExitOrBounceRate(Goals goals) { - final MetricType metricType = goals.primary().getMetric().type(); - return metricType == MetricType.EXIT_RATE || metricType == MetricType.BOUNCE_RATE; - } - - private void addVisitBeforeCondition(final HTMLPageAsset page, final Builder builder, final Goals goals) { - - final com.dotcms.analytics.metrics.Condition visitBefore = com.dotcms.analytics.metrics.Condition.builder() - .parameter("visitBefore") - //.operator(Operator.REGEX) - .value(ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(page)) - .build(); - - final Goals newGoal = createNewGoals(goals, visitBefore); - builder.goals(newGoal); - } - - private void addUrlCondition(final HTMLPageAsset page, final Builder builder, final Goals goals) { - - final com.dotcms.analytics.metrics.Condition refererCondition = createConditionWithUrlValue( - page, "url"); - - final Goals newGoal = createNewGoals(goals, refererCondition); - builder.goals(newGoal); - } - - @NotNull - private static Goals createNewGoals(final Goals oldGoals, - final com.dotcms.analytics.metrics.Condition newConditionToAdd) { - final Metric newMetric = Metric.builder().from(oldGoals.primary().getMetric()) - .addConditions(newConditionToAdd).build(); - final Goal newGoal = GoalFactory.create(newMetric); - return Goals.builder().from(oldGoals).primary(newGoal).build(); - } - - private boolean hasCondition(final Goals goals, final String conditionName){ - return goals.primary().getMetric().conditions() - .stream() - .anyMatch(condition ->conditionName .equals(condition.parameter())); - } - private com.dotcms.analytics.metrics.Condition createConditionWithUrlValue( - final HTMLPageAsset page, - final String conditionName) { - - return com.dotcms.analytics.metrics.Condition.builder() - .parameter(conditionName) - //.operator(Operator.REGEX) - .value(ExperimentUrlPatternCalculator.INSTANCE.calculatePageUrlRegexPattern(page)) - .build(); - - } - private void saveTargetingConditions(final Experiment experiment, final User user) throws DotDataException, DotSecurityException { if(experiment.targetingConditions().isEmpty()) { diff --git a/dotCMS/src/main/java/com/dotcms/experiments/business/web/ExperimentWebAPIImpl.java b/dotCMS/src/main/java/com/dotcms/experiments/business/web/ExperimentWebAPIImpl.java index 55978bfbbbf7..6b675cf3e273 100644 --- a/dotCMS/src/main/java/com/dotcms/experiments/business/web/ExperimentWebAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/experiments/business/web/ExperimentWebAPIImpl.java @@ -131,7 +131,7 @@ private SelectedExperiment getExperimentSelected(final Experiment experiment, .expireTime(experiment.lookBackWindowExpireTime()) .runningId(currentRunningId) .experimentPagePattern(ExperimentUrlPatternCalculator.INSTANCE - .calculatePageUrlRegexPattern(htmlPageAsset)); + .calculatePageUrlRegexPattern(experiment)); final Optional targetPageUrlPattern = ExperimentUrlPatternCalculator.INSTANCE .calculateTargetPageUrlPattern(htmlPageAsset, metric); diff --git a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPI.java b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPI.java index 0742faadcf41..f07babdecda1 100644 --- a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPI.java +++ b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPI.java @@ -108,4 +108,15 @@ boolean handleVanityURLRedirects(VanityUrlRequestWrapper request, HttpServletRes VanityUrlResult vanityUrlResult); + /** + * Look all the {@link VanityUrl} that are equals to forward + * + * @param host {@link VanityUrl}'s Host + * @param language {@link VanityUrl}'s Language + * @param forward forward to look for + * @param language action to look for + * @return + */ + List findByForward(Host host, Language language, String forward, int action); + } diff --git a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java index a24341671d19..f82eff08eb56 100644 --- a/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/vanityurl/business/VanityUrlAPIImpl.java @@ -388,5 +388,16 @@ public boolean handleVanityURLRedirects(final VanityUrlRequestWrapper request, f return false; } + @Override + @CloseDBIfOpened + public List findByForward(final Host host, final Language language, final String forward, + int action) { + return load(host, language) + .stream() + .filter(cachedVanityUrl -> cachedVanityUrl.response == action) + .filter(cachedVanityUrl -> cachedVanityUrl.forwardTo.equals(forward)) + .collect(Collectors.toList()); + } + }