Created
July 4, 2017 21:32
-
-
Save evaldeslacasa/3bfb5851dae8fcd861ea37a242621a1b to your computer and use it in GitHub Desktop.
Liferay Groovy Script to get all site ids nested within a site when passing this site id as parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.liferay.portal.util.*; | |
import com.liferay.portal.model.*; | |
import com.liferay.portal.service.*; | |
import com.liferay.portlet.journal.*; | |
try { | |
company = PortalUtil.getCompany(actionRequest) | |
companyId = company.getCompanyId() | |
global = GroupLocalServiceUtil.getGroup(companyId, companyId.toString()); | |
globalGroupId = global.getGroupId(); | |
parentGroup = GroupLocalServiceUtil.getFriendlyURLGroup(companyId, "/site-friendly-url"); | |
siteGroupIds = getSiteGroupIds(parentGroup.getGroupId()); | |
out.println(siteGroupIds); | |
} catch(e) { | |
out.println("""<div class="portlet-msg-error">${e}</div>""") | |
e.printStackTrace(out) | |
} | |
def getSiteGroupIds(parentGroupId) { | |
def siteGroupIds = []; | |
siteGroupIds << parentGroupId; | |
list = []; | |
q = list as Queue; | |
q << avisonYoungGroupId; | |
while(q.size > 0) { | |
currentGroupId = q.get(0); | |
currentGroup = GroupLocalServiceUtil.getGroup(currentGroupId); | |
childrenGroups = currentGroup.getChildren(true); | |
out.println(childrenGroups); | |
for (Group childrenGroup : childrenGroups) { | |
childrenGroupId = childrenGroup.getGroupId(); | |
q << childrenGroupId; | |
siteGroupIds << childrenGroupId; | |
} | |
q.poll(); | |
} | |
return siteGroupIds; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment