Skip to content

Commit

Permalink
fix: Fix Setting Permanent Link Id when set twice in two different th…
Browse files Browse the repository at this point in the history
…reads - Meeds-io/MIPs#134 (#938)

Prior to this change, when setting twice the same value for a permanent
link id in two different threads, then one of them will through an
exception. This change ensures to not throw exception when the permanent
link is already set.
  • Loading branch information
boubaker authored Jul 24, 2024
1 parent 2af0c42 commit f69df08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.container.PortalContainer;
import org.exoplatform.container.RootContainer.PortalContainerPostCreateTask;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.security.Identity;

import io.meeds.portal.permlink.model.PermanentLinkObject;
Expand All @@ -53,6 +55,9 @@

public class PermanentLinkServiceImpl implements PermanentLinkService, Startable {

private static final Log LOG =
ExoLogger.getLogger(PermanentLinkServiceImpl.class);

public static final Context PERMANEN_LINK_CONTEXT = Context.GLOBAL.id("PermanentLink");

public static final Scope PERMANENT_LINK_SCOPE = Scope.GLOBAL.id("PermanentLinkIds");
Expand Down Expand Up @@ -207,10 +212,21 @@ private String getById(String permanentLinkId) {

private String getAndSetId(String permanentLink) {
String permanentLinkId = generateHash(permanentLink);
settingService.set(PERMANEN_LINK_CONTEXT,
PERMANENT_LINK_IDS_SCOPE,
permanentLinkId,
SettingValue.create(permanentLink));
try {
settingService.set(PERMANEN_LINK_CONTEXT,
PERMANENT_LINK_IDS_SCOPE,
permanentLinkId,
SettingValue.create(permanentLink));
} catch (RuntimeException e) {
if (settingService.get(PERMANEN_LINK_CONTEXT,
PERMANENT_LINK_IDS_SCOPE,
permanentLinkId)
== null) {
throw e;
} else {
LOG.debug("Duplicated Permanent Link Id {} set. This may be due to parallel saving", permanentLinkId);
}
}
return permanentLinkId;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ private List<UIPortlet> getCurrentPortlets() {
// Determine portlets visible on the page
uiPortlets = new ArrayList<>();
UISharedLayout sharedLayout = uiWorkingWorkspace.findFirstComponentOfType(UISharedLayout.class);
if (sharedLayout.isShowSharedLayout(requestContext)) {
if (sharedLayout == null || sharedLayout.isShowSharedLayout(requestContext)) {
uiWorkingWorkspace.findComponentOfType(uiPortlets, UIPortlet.class);
} else {
UIPage currentPage = getCurrentPage();
Expand Down

0 comments on commit f69df08

Please sign in to comment.