From 3f445357986332bfe56d0848d48471a5f8898561 Mon Sep 17 00:00:00 2001 From: Boubaker Khanfir Date: Fri, 15 Nov 2024 19:52:43 +0100 Subject: [PATCH] fix: Fix Display Last Accessed Space - Meeds-io/MIPs#160 Prior to this change, the last accessed space wasn't displayed for the space template masters. This change will fix the Space LAst Access Listing. --- .../space/service/SpaceServiceImpl.java | 1 - .../core/jpa/storage/dao/jpa/SpaceDAO.java | 22 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/component/core/src/main/java/io/meeds/social/space/service/SpaceServiceImpl.java b/component/core/src/main/java/io/meeds/social/space/service/SpaceServiceImpl.java index 22ed6490e0a..633d4b30f2d 100644 --- a/component/core/src/main/java/io/meeds/social/space/service/SpaceServiceImpl.java +++ b/component/core/src/main/java/io/meeds/social/space/service/SpaceServiceImpl.java @@ -326,7 +326,6 @@ public ListAccess getLastAccessedSpace(String username) { } return new SpaceListAccess(spaceStorage, spaceSearchConnector, - getSpaceTemplateService(), username, SpaceListAccessType.LASTEST_ACCESSED); } diff --git a/component/core/src/main/java/org/exoplatform/social/core/jpa/storage/dao/jpa/SpaceDAO.java b/component/core/src/main/java/org/exoplatform/social/core/jpa/storage/dao/jpa/SpaceDAO.java index 3ba45715d94..475e513a588 100644 --- a/component/core/src/main/java/org/exoplatform/social/core/jpa/storage/dao/jpa/SpaceDAO.java +++ b/component/core/src/main/java/org/exoplatform/social/core/jpa/storage/dao/jpa/SpaceDAO.java @@ -34,7 +34,6 @@ import org.exoplatform.social.core.jpa.storage.entity.SpaceEntity; import org.exoplatform.social.core.search.Sorting; import org.exoplatform.social.core.search.Sorting.SortBy; -import org.exoplatform.social.core.space.SpaceFilter; import org.exoplatform.social.core.space.model.Space; import io.meeds.social.space.constant.SpaceMembershipStatus; @@ -279,13 +278,13 @@ private String getQueryFilterName(List suffixes, boolean count) { return queryName; } - private String getQueryFilterContent(SpaceFilter spaceFilter, + private String getQueryFilterContent(XSpaceFilter spaceFilter, List predicates, List parameterNames, boolean count) { String querySelect = count ? "SELECT COUNT(DISTINCT s.id) FROM SocSpaceEntity s " : - "SELECT DISTINCT(s.id, " + getSortField(spaceFilter.getSorting()) + ") FROM SocSpaceEntity s "; - if (parameterNames.contains(PARAM_USER_ID)) { + "SELECT DISTINCT(s.id, " + getSortField(spaceFilter) + ") FROM SocSpaceEntity s "; + if (parameterNames.contains(PARAM_USER_ID) || spaceFilter.isLastAccess()) { querySelect += " INNER JOIN s.members sm "; } @@ -296,8 +295,8 @@ private String getQueryFilterContent(SpaceFilter spaceFilter, queryContent = querySelect + " WHERE " + StringUtils.join(predicates, " AND "); } if (!count) { - queryContent += " ORDER BY " + getSortField(spaceFilter.getSorting()) + - (spaceFilter.getSorting().orderBy.equals(Sorting.OrderBy.DESC) ? " DESC " : " ASC "); + queryContent += " ORDER BY " + getSortField(spaceFilter) + + (spaceFilter.isLastAccess() || spaceFilter.getSorting().orderBy.equals(Sorting.OrderBy.DESC) ? " DESC " : " ASC "); } return queryContent; } @@ -414,9 +413,9 @@ private void buildPermissionPredicates(XSpaceFilter spaceFilter, // NOSONAR private void buildSortSuffixes(XSpaceFilter spaceFilter, List suffixes) { Sorting sorting = spaceFilter.getSorting(); - String sortField = getSortField(spaceFilter.getSorting()); + String sortField = getSortField(spaceFilter); suffixes.add("OrderBy"); - suffixes.add(StringUtils.capitalize(sortField.replace("s.", ""))); + suffixes.add(StringUtils.capitalize(sortField.replace("s.", "").replace("sm.", ""))); if (sorting.orderBy.equals(Sorting.OrderBy.DESC)) { suffixes.add("DESC"); } else { @@ -424,8 +423,11 @@ private void buildSortSuffixes(XSpaceFilter spaceFilter, List suffixes) } } - private String getSortField(Sorting sorting) { - if (sorting.sortBy.equals(SortBy.DATE)) { + private String getSortField(XSpaceFilter spaceFilter) { + Sorting sorting = spaceFilter.getSorting(); + if (spaceFilter.isLastAccess()) { + return "sm.lastAccess"; + } else if (sorting.sortBy.equals(SortBy.DATE)) { return "s.createdDate"; } else { return "s.displayName";