Skip to content

Commit

Permalink
Fixed: example/control/ManagePortalPages?parentPortalPageId=EXAMPLE w…
Browse files Browse the repository at this point in the history
…orks 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
  • Loading branch information
nmalin committed Oct 23, 2024
1 parent ad9035e commit 62e7aa2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

/**
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion framework/common/webcommon/WEB-INF/portal-controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down

0 comments on commit 62e7aa2

Please sign in to comment.