Guest User

Untitled

a guest
Aug 16th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import com.liferay.portal.service.PortletLocalServiceUtil
  2. import com.liferay.portal.service.ResourceLocalServiceUtil
  3. import com.liferay.portal.service.ReleaseLocalServiceUtil
  4.  
  5. import com.liferay.portal.model.Portlet
  6. import com.liferay.portal.model.Layout
  7. import com.liferay.portal.service.LayoutLocalServiceUtil
  8. import com.liferay.portal.model.LayoutTypePortlet
  9. import com.liferay.portal.model.LayoutType
  10.  
  11. // Param1: User ID
  12. // Param2: Group ID
  13. // Param2: isPrivateLayout
  14. cleanGroupLayouts(10434, 10181, false)
  15.  
  16. def cleanGroupLayouts(userId, groupId, privateLayout){
  17. Set<Portlet> undeployedPortlets = new HashSet<Portlet>();
  18. long companyId = 0
  19. List<Layout> layouts= LayoutLocalServiceUtil.getLayouts(groupId, privateLayout)
  20. for(Layout layout: layouts){
  21. companyId = layout.getCompanyId();
  22. undeployedPortlets.addAll(deleteUndeployedPortlets(userId, layout))
  23. }
  24. }
  25.  
  26. def Set<Portlet> deleteUndeployedPortlets(userId, layout) {
  27. LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType()
  28. List<Portlet> allPortlets = layoutTypePortlet.getPortlets()
  29.  
  30. Set<Portlet> undeployedPortlets = new HashSet<Portlet>();
  31.  
  32. for(Portlet pagePortlet: allPortlets){
  33. if(pagePortlet.isUndeployedPortlet()){
  34. out.println pagePortlet.getPortletId()
  35. layoutTypePortlet.removePortletId(userId, pagePortlet.getPortletId())
  36. undeployedPortlets.add(pagePortlet)
  37. }
  38. }
  39. LayoutLocalServiceUtil.updateLayout(layout.getGroupId(), layout.isPrivateLayout(),layout.getLayoutId(), layout.getTypeSettings())
  40.  
  41. return undeployedPortlets
  42. }
Add Comment
Please, Sign In to add comment