Skip to content

Commit

Permalink
#31402 fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Feb 25, 2025
2 parents bf7963f + 9d69c74 commit e5a2ad1
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public AnalyticsAPIImpl() {

@Override
public void notify(final SystemTableUpdatedKeyEvent event) {
Logger.info(this, String.format("Received event with key [%s]", event.getKey()));
if (event.getKey().contains(ANALYTICS_IDP_URL_KEY)) {
analyticsIdpUrl.set(resolveAnalyticsIdpUrl());
} else if (event.getKey().contains(ANALYTICS_ACCESS_TOKEN_RENEW_TIMEOUT_KEY)) {
Expand Down Expand Up @@ -436,5 +437,4 @@ private CircuitBreakerUrl.Response<AnalyticsKey> requestAnalyticsKey(final Analy
private Map<String, String> analyticsKeyHeaders(final AccessToken accessToken) throws AnalyticsException {
return CircuitBreakerUrl.authHeaders(AnalyticsHelper.get().formatBearer(accessToken));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.dotmarketing.portlets.contentlet.business.ContentletAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.fileassets.business.FileAssetAPI;
import com.dotmarketing.util.PageMode;
import com.liferay.util.StringPool;
import io.vavr.control.Try;

Expand Down Expand Up @@ -85,9 +86,8 @@ protected Optional<Contentlet> getFileAsset(String uri, Host host, Long language
final String actualUri = uri.substring(0, uri.lastIndexOf('.')) + ".scss";
return Optional.ofNullable(this.fileAssetAPI.getFileByPath(actualUri, host, languageId, true));
} else if (uri.startsWith("/dA") || uri.startsWith("/contentAsset") || uri.startsWith("/dotAsset")) {
final String[] split = uri.split(StringPool.FORWARD_SLASH);
final String id = uri.startsWith("/contentAsset") ? split[3] : split[2];
return getFileAsset(languageId, id);
final FieldNameIdentifier fieldNameIdentifier = getIdentifierAndFieldName(uri);
return getFileAsset(languageId, fieldNameIdentifier);
} else {
return Optional.ofNullable(this.fileAssetAPI.getFileByPath(uri, host, languageId, true));
}
Expand All @@ -96,15 +96,47 @@ protected Optional<Contentlet> getFileAsset(String uri, Host host, Long language
}
}

private Optional<Contentlet> getFileAsset(final Long languageId, final String id) throws DotDataException, DotSecurityException {
private static FieldNameIdentifier getIdentifierAndFieldName(String uri) {
final String[] split = uri.split(StringPool.FORWARD_SLASH);

return Optional.ofNullable(contentletAPI.findContentletByIdentifier(id, true, languageId,
APILocator.systemUser(), false));
final int idIndex = uri.startsWith("/contentAsset") ? 3 : 2;
final int fieldNameIndex = uri.startsWith("/contentAsset") ? 4 : 3;

return new FieldNameIdentifier(split[idIndex],
fieldNameIndex < split.length || !uri.startsWith("/dotAsset")? split[fieldNameIndex] : null);
}

private Optional<Contentlet> getFileAsset(final Long languageId, final FieldNameIdentifier fieldNameIdentifier)
throws DotDataException, DotSecurityException {

final Contentlet contentletByIdentifier = contentletAPI.findContentletByIdentifier(fieldNameIdentifier.identifier,
PageMode.get().showLive, languageId,
APILocator.systemUser(), false);

if (Objects.nonNull(fieldNameIdentifier.fieldName)) {
final String binaryFileId = contentletByIdentifier.getStringProperty(fieldNameIdentifier.fieldName);

return Optional.ofNullable(contentletAPI.findContentletByIdentifier(binaryFileId,
PageMode.get().showLive, languageId,
APILocator.systemUser(), false));
} else {
return Optional.ofNullable(contentletByIdentifier);
}
}

@Override
public boolean isAsync() {
return true;
}

private static class FieldNameIdentifier {
final String fieldName;
final String identifier;

FieldNameIdentifier(final String identifier, final String fieldName) {
this.fieldName = fieldName;
this.identifier = identifier;
}
}

}
27 changes: 8 additions & 19 deletions dotCMS/src/main/java/com/dotcms/rest/api/v1/page/PageResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.dotcms.util.ConversionUtils;
import com.dotcms.util.HttpRequestDataUtil;
import com.dotcms.util.PaginationUtil;
import com.dotcms.util.TimeMachineUtil;
import com.dotcms.util.pagination.ContentTypesPaginator;
import com.dotcms.util.pagination.OrderDirection;
import com.dotcms.vanityurl.business.VanityUrlAPI;
Expand Down Expand Up @@ -61,12 +62,7 @@
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.portlets.templates.model.Template;
import com.dotmarketing.portlets.workflows.model.WorkflowAction;
import com.dotmarketing.util.DateUtil;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.StringUtils;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.util.WebKeys;
import com.dotmarketing.util.*;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -356,19 +352,12 @@ private PageRenderParams optionalRenderParams(final String modeParam,
if (null != deviceInode){
builder.deviceInode(deviceInode);
}
if (null != timeMachineDateAsISO8601) {
final Date date;
try {
date = Try.of(() -> DateUtil.convertDate(timeMachineDateAsISO8601)).getOrElseThrow(
e -> new IllegalArgumentException(
String.format("Error Parsing date: %s", timeMachineDateAsISO8601),
e));
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
}
final Instant instant = date.toInstant();
builder.timeMachineDate(instant);
}
TimeMachineUtil.parseTimeMachineDate(timeMachineDateAsISO8601).ifPresentOrElse(
builder::timeMachineDate,
() -> Logger.debug(this, () -> String.format(
"Date %s is not older than the grace window. Skipping Time Machine setup.",
timeMachineDateAsISO8601))
);
return builder.build();
}

Expand Down
46 changes: 45 additions & 1 deletion dotCMS/src/main/java/com/dotcms/util/TimeMachineUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

import com.dotcms.api.web.HttpServletRequestThreadLocal;
import com.dotcms.rest.api.v1.page.PageResource;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.DateUtil;
import io.vavr.Lazy;
import io.vavr.control.Try;
import java.time.Duration;
import java.time.Instant;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public final class TimeMachineUtil {

private TimeMachineUtil(){}

private static final Lazy<Integer> FTM_GRACE_WINDOW_LIMIT =
Lazy.of(() -> Config.getIntProperty("FTM_GRACE_WINDOW_LIMIT", 5));
/**
* If Time Machine is running return the timestamp of the Time Machine date
* Running Time Machine is determined by the presence of the attribute PageResource.TM_DATE in the request or session
Expand Down Expand Up @@ -59,4 +67,40 @@ public static boolean isRunning(){
public static boolean isNotRunning(){
return !isRunning();
}

/**
* Parses and validates the given date string in ISO 8601 format.
*
* @param dateAsISO8601 The date string in ISO 8601 format. If null, an empty {@link Optional} is returned.
* @return An {@link Optional} containing a valid {@link Instant} if parsing is successful and the date meets the validation criteria.
* Returns an empty {@link Optional} if the date is invalid or does not meet the validation criteria.
* @throws IllegalArgumentException If the date string cannot be parsed.
*/
public static Optional<Instant> parseTimeMachineDate(final String dateAsISO8601) {
if (Objects.isNull(dateAsISO8601)) {
return Optional.empty();
}
Instant instant = Try.of(() -> DateUtil.convertDate(dateAsISO8601))
.map(Date::toInstant)
.getOrElseThrow(e ->
new IllegalArgumentException(
String.format("Error Parsing date: %s", dateAsISO8601), e)
);
return isOlderThanGraceWindow(instant) ? Optional.of(instant) : Optional.empty();
}


/**
* Determines if the FTM logic should be applied based on the given timeMachineDate.
* It checks if the date is older than the grace window (not too recent),
* using a configurable time limit.
*
* @param timeMachineDate The Time Machine date from the request.
* @return true if the timeMachineDate is older than the grace window, meaning FTM logic should be applied,
* false otherwise (if within the grace window).
*/
public static boolean isOlderThanGraceWindow(final Instant timeMachineDate) {
final Instant graceWindowTime = Instant.now().plus(Duration.ofMinutes(FTM_GRACE_WINDOW_LIMIT.get()));
return timeMachineDate.isAfter(graceWindowTime);
}
}
20 changes: 19 additions & 1 deletion dotcms-integration/src/test/java/com/dotcms/MainSuite1a.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,25 @@
Task240306MigrateLegacyLanguageVariablesTest.class,
EmailActionletTest.class,
OpenAIGenerateImageActionletTest.class,
RequestMatcherTest.class
RequestMatcherTest.class,
com.dotmarketing.portlets.rules.conditionlet.ConditionletOSGIFTest.class,
com.dotmarketing.portlets.rules.conditionlet.CurrentSessionLanguageConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.NumberOfTimesPreviouslyVisitedConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.UsersBrowserLanguageConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.UsersSiteVisitsConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.VisitorOperatingSystemConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.VisitedUrlConditionletTest.class,
com.dotmarketing.portlets.rules.business.RulesCacheFTest.class,
com.dotmarketing.portlets.templates.business.TemplateAPITest.class,
com.dotmarketing.portlets.containers.business.ContainerAPIImplTest.class,
com.dotmarketing.portlets.folders.business.FolderAPITest.class,
com.dotmarketing.portlets.containers.business.ContainerAPITest.class,
com.dotmarketing.portlets.containers.business.FileAssetContainerUtilTest.class,
com.dotmarketing.portlets.htmlpages.business.HTMLPageAPITest.class,
com.dotmarketing.portlets.structure.factories.StructureFactoryTest.class,
com.dotmarketing.portlets.structure.factories.FieldFactoryTest.class,
com.dotmarketing.portlets.structure.model.ContentletRelationshipsTest.class,
com.dotmarketing.portlets.structure.transform.ContentletRelationshipsTransformerTest.class,
})

public class MainSuite1a {
Expand Down
85 changes: 14 additions & 71 deletions dotcms-integration/src/test/java/com/dotcms/MainSuite2a.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package com.dotcms;

import com.dotcms.ai.workflow.OpenAIAutoTagActionletTest;
import com.dotcms.content.elasticsearch.util.ESMappingUtilHelperTest;
import com.dotcms.contenttype.business.DotAssetBaseTypeToContentTypeStrategyImplTest;
import com.dotcms.contenttype.test.DotAssetAPITest;
import com.dotcms.dotpubsub.PostgresPubSubImplTest;
import com.dotcms.ema.EMAWebInterceptorTest;
import com.dotcms.enterprise.cluster.ClusterFactoryTest;
import com.dotcms.junit.MainBaseSuite;
import com.dotcms.mock.request.CachedParameterDecoratorTest;
import com.dotcms.publisher.bundle.business.BundleFactoryTest;
import com.dotcms.publisher.business.PublishAuditAPITest;
import com.dotcms.publisher.util.PushedAssetUtilTest;
import com.dotcms.publishing.PublisherFilterImplTest;
import com.dotcms.publishing.PushPublishFiltersInitializerTest;
import com.dotcms.rendering.velocity.directive.DotParseTest;
import com.dotcms.rendering.velocity.servlet.VelocityServletIntegrationTest;
import com.dotcms.rest.BundleResourceTest;
import com.dotcms.rest.api.v1.apps.AppsResourceTest;
import com.dotcms.rest.api.v1.folder.FolderResourceTest;
import com.dotcms.rest.api.v1.pushpublish.PushPublishFilterResourceTest;
import com.dotcms.rest.api.v1.user.UserResourceIntegrationTest;
import com.dotcms.saml.IdentityProviderConfigurationFactoryTest;
import com.dotcms.saml.SamlConfigurationServiceTest;
import com.dotcms.security.apps.AppsAPIImplTest;
import com.dotcms.security.apps.AppsCacheImplTest;
import com.dotcms.translate.GoogleTranslationServiceIntegrationTest;
import com.dotmarketing.image.focalpoint.FocalPointAPITest;
import com.dotmarketing.portlets.cmsmaintenance.factories.CMSMaintenanceFactoryTest;
import com.dotmarketing.portlets.containers.business.ContainerFactoryImplTest;
Expand All @@ -26,12 +36,12 @@
import com.dotmarketing.portlets.folders.model.FolderTest;
import com.dotmarketing.portlets.templates.business.TemplateFactoryImplTest;
import com.dotmarketing.portlets.workflows.actionlet.PushNowActionletTest;
import com.dotmarketing.portlets.workflows.model.TestWorkflowAction;
import com.dotmarketing.quartz.job.CleanUpFieldReferencesJobTest;
import com.dotmarketing.startup.runonce.Task05195CreatesDestroyActionAndAssignDestroyDefaultActionsToTheSystemWorkflowTest;
import com.dotmarketing.startup.runonce.Task05210CreateDefaultDotAssetTest;
import com.dotmarketing.startup.runonce.Task05225RemoveLoadRecordsToIndexTest;
import com.dotmarketing.startup.runonce.Task05305AddPushPublishFilterColumnTest;
import com.dotmarketing.startup.runonce.Task05350AddDotSaltClusterColumnTest;
import com.dotmarketing.startup.runonce.Task240131UpdateLanguageVariableContentTypeTest;
import com.dotmarketing.util.HashBuilderTest;
import com.dotmarketing.util.TestConfig;
import com.liferay.portal.language.LanguageUtilTest;
Expand Down Expand Up @@ -90,76 +100,9 @@
com.dotmarketing.portlets.personas.business.DeleteMultiTreeUsedPersonaTagJobTest.class,
com.dotmarketing.portlets.links.business.MenuLinkAPITest.class,
com.dotmarketing.portlets.links.factories.LinkFactoryTest.class,
com.dotmarketing.portlets.rules.conditionlet.ConditionletOSGIFTest.class,
com.dotmarketing.portlets.rules.conditionlet.CurrentSessionLanguageConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.NumberOfTimesPreviouslyVisitedConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.UsersBrowserLanguageConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.UsersSiteVisitsConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.VisitorOperatingSystemConditionletTest.class,
com.dotmarketing.portlets.rules.conditionlet.VisitedUrlConditionletTest.class,
com.dotmarketing.portlets.rules.business.RulesCacheFTest.class,
com.dotmarketing.portlets.templates.business.TemplateAPITest.class,
com.dotmarketing.portlets.containers.business.ContainerAPIImplTest.class,
com.dotmarketing.portlets.folders.business.FolderAPITest.class,
com.dotmarketing.portlets.containers.business.ContainerAPITest.class,
com.dotmarketing.portlets.containers.business.FileAssetContainerUtilTest.class,
com.dotmarketing.portlets.htmlpages.business.HTMLPageAPITest.class,
com.dotmarketing.portlets.structure.factories.StructureFactoryTest.class,
com.dotmarketing.portlets.structure.factories.FieldFactoryTest.class,
com.dotmarketing.portlets.structure.model.ContentletRelationshipsTest.class,
com.dotmarketing.portlets.structure.transform.ContentletRelationshipsTransformerTest.class,
com.dotmarketing.portlets.categories.business.CategoryAPITest.class,
com.dotmarketing.filters.FiltersTest.class,
com.dotmarketing.business.VersionableAPITest.class,
com.dotmarketing.business.UserAPITest.class,
com.dotmarketing.business.portal.PortletAPIImplTest.class,
com.dotmarketing.business.web.LanguageWebApiTest.class,
com.dotmarketing.business.IdentifierFactoryTest.class,
com.dotmarketing.business.IdentifierAPITest.class,
com.dotmarketing.business.CommitListenerCacheWrapperTest.class,
com.dotmarketing.business.RoleAPITest.class,
com.dotmarketing.business.IdentifierConsistencyIntegrationTest.class,
com.dotmarketing.business.LayoutAPITest.class,
com.dotmarketing.business.PermissionAPIIntegrationTest.class,
com.dotmarketing.business.PermissionAPITest.class,
com.dotmarketing.servlets.BinaryExporterServletTest.class,
com.dotmarketing.servlets.ShortyServletAndTitleImageTest.class,
com.dotmarketing.servlets.ajax.AjaxDirectorServletIntegrationTest.class,
com.dotmarketing.factories.MultiTreeAPITest.class,
FocalPointAPITest.class,
com.dotmarketing.tag.business.TagAPITest.class,
OSGIUtilTest.class,
CleanUpFieldReferencesJobTest.class,
CachedParameterDecoratorTest.class,
ContainerFactoryImplTest.class,
TemplateFactoryImplTest.class,
TestConfig.class,
FolderTest.class,
PublishAuditAPITest.class,
BundleFactoryTest.class,
com.dotcms.security.apps.SecretsStoreKeyStoreImplTest.class,
AppsAPIImplTest.class,
AppsResourceTest.class,
AppsCacheImplTest.class,
VelocityServletIntegrationTest.class,
DotAssetAPITest.class,
DotAssetBaseTypeToContentTypeStrategyImplTest.class,
FileAssetAPIImplIntegrationTest.class,
FileAssetFactoryIntegrationTest.class,
UserResourceIntegrationTest.class,
IntegrationResourceLinkTest.class,
HashBuilderTest.class,
LanguageUtilTest.class,
FolderResourceTest.class,
Task05225RemoveLoadRecordsToIndexTest.class,
PublisherFilterImplTest.class,
PushPublishFiltersInitializerTest.class,
PushPublishFilterResourceTest.class,
PushNowActionletTest.class,
Task05305AddPushPublishFilterColumnTest.class,
CMSMaintenanceFactoryTest.class,
Task05350AddDotSaltClusterColumnTest.class,
PostgresPubSubImplTest.class
com.dotmarketing.portlets.categories.business.CategoryAPITest.class,
com.dotmarketing.filters.FiltersTest.class
})
public class MainSuite2a {

Expand Down
Loading

0 comments on commit e5a2ad1

Please sign in to comment.