This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new 727f3cec1e Fixed: example/control/ManagePortalPages?parentPortalPageId=EXAMPLE works but reports an error (OFBIZ-13150) 727f3cec1e is described below commit 727f3cec1e2739a01420888306f66d1b5cc49eae Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Thu Oct 24 00:30:16 2024 +0200 Fixed: example/control/ManagePortalPages?parentPortalPageId=EXAMPLE works but reports an error (OFBIZ-13150) Error due to call the method as copyIfRequiredSystemPage groovy event where the function has been move on private helper function for PortalPageServices. To fix, we restore it on PortalPageMethods and call it from PortalPageServices through script invoker (to escape code duplication). Thanks to Jacques Le Roux for the issue --- .../apache/ofbiz/common/PortalPageMethods.groovy | 22 ++++++++++++ .../apache/ofbiz/common/PortalPageServices.groovy | 39 +++++++++------------- .../common/webcommon/WEB-INF/portal-controller.xml | 2 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy index 8a57d83f11..34d401b1fe 100644 --- a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy +++ b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy @@ -63,3 +63,25 @@ String setPortalPortletAttributes() { } return success() } + +/** + * Check if the page is a system page, then copy before allowing + */ +String copyIfRequiredSystemPage() { + GenericValue portalPage = from('PortalPage').where(parameters).cache().queryOne() + ?: from('PortalPage').where(portalPageId: parameters.parentPortalPageId).cache().queryOne() + Map serviceResult = [:] + if (portalPage && portalPage.ownerUserLoginId == '_NA_' && from('PortalPage') + .where(originalPortalPageId: portalPage.portalPageId, + ownerUserLoginId: userLogin.userLoginId) + .queryCount() == 0 ) { + // copy the portal page + serviceResult = run service: 'createPortalPage', with: [*: portalPage.getAllFields(), + portalPageId: null, + originalPortalPageId: portalPage.portalPageId, + ownerUserLoginId: userLogin.userLoginId] + run service: 'duplicatePortalPageDetails', with: [fromPortalPageId: portalPage.portalPageId, + toPortalPageId: serviceResult.portalPageId] + } + return serviceResult ? serviceResult.portalPageId : portalPage?.portalPageId +} diff --git a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy index 6026ee3b52..972aa253bd 100644 --- a/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy +++ b/framework/common/src/main/groovy/org/apache/ofbiz/common/PortalPageServices.groovy @@ -18,10 +18,12 @@ */ package org.apache.ofbiz.common +import org.apache.ofbiz.base.util.GroovyUtil import org.apache.ofbiz.entity.GenericValue import org.apache.ofbiz.entity.condition.EntityCondition import org.apache.ofbiz.entity.condition.EntityConditionBuilder import org.apache.ofbiz.service.ServiceUtil +import org.codehaus.groovy.runtime.InvokerHelper /** * Moves a PortalPortlet from the actual portalPage to a different one @@ -33,12 +35,16 @@ Map movePortletToPortalPage() { return checkIsOwner } GenericValue sourcePortalPagePortlet = from('PortalPagePortlet').where(parameters).cache().queryOne() - GenericValue targetPortalPortlet = makeValue('PortalPagePortlet', [*: parameters, - portalPageId: copyIfRequiredSystemPage(), - columnNum: 1]) - delegator.setNextSubSeqId(targetPortalPortlet, 'portletSeqId', 5, 1) - targetPortalPortlet.create() - sourcePortalPagePortlet.remove() + String idOfcopyIfRequiredSystemPage = copyIfRequiredSystemPage() + if (idOfcopyIfRequiredSystemPage) { + GenericValue targetPortalPortlet = makeValue('PortalPagePortlet', [*: parameters, + portalPageId: idOfcopyIfRequiredSystemPage, + columnNum: 1]) + delegator.setNextSubSeqId(targetPortalPortlet, 'portletSeqId', 5, 1) + targetPortalPortlet.create() + sourcePortalPagePortlet.remove() + } + return success(sourcePortalPagePortlet) } /** @@ -348,23 +354,8 @@ private Map checkOwnerShip() { return success() } -/** - * Check if the page is a system page, then copy before allowing - */ private String copyIfRequiredSystemPage() { - GenericValue portalPage = from('PortalPage').where(parameters).cache().queryOne() - Map serviceResult = [:] - if (portalPage && portalPage.ownerUserLoginId == '_NA_' && from('PortalPage') - .where(originalPortalPageId: parameters.portalPageId, - ownerUserLoginId: userLogin.userLoginId) - .queryCount() == 0 ) { - // copy the portal page - serviceResult = run service: 'createPortalPage', with: [*: portalPage.getAllFields(), - portalPageId: null, - originalPortalPageId: portalPage.portalPageId, - ownerUserLoginId: userLogin.userLoginId] - run service: 'duplicatePortalPageDetails', with: [fromPortalPageId: parameters.portalPageId, - toPortalPageId: serviceResult.portalPageId] - } - return serviceResult ? serviceResult.portalPageId : portalPage?.portalPageId + Script script = InvokerHelper.createScript( + GroovyUtil.getScriptClassFromLocation('component://common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy'), binding) + return script.invokeMethod('copyIfRequiredSystemPage', null) as String } diff --git a/framework/common/webcommon/WEB-INF/portal-controller.xml b/framework/common/webcommon/WEB-INF/portal-controller.xml index 6ccf335501..142516ca52 100644 --- a/framework/common/webcommon/WEB-INF/portal-controller.xml +++ b/framework/common/webcommon/WEB-INF/portal-controller.xml @@ -58,7 +58,7 @@ under the License. <!-- Portal page update requests --> <request-map uri="ManagePortalPages"> <security https="true" auth="true"/> - <event type="groovy" invoke="copyIfRequiredSystemPage" path="component://common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy"/> + <event type="groovy" invoke="copyIfRequiredSystemPage" path="component://common/src/main/groovy/org/apache/ofbiz/common/PortalPageMethods.groovy"/> <response name="success" type="view" value="ManagePortalPages"/> </request-map> <request-map uri="NewPortalPage">