Skip to content

Instantly share code, notes, and snippets.

import com.liferay.portal.kernel.util.GetterUtil
import com.liferay.portal.kernel.util.Validator
import com.liferay.portal.kernel.xml.Document
import com.liferay.portal.kernel.xml.Element
import com.liferay.portal.kernel.xml.SAXReaderUtil
import com.liferay.portal.model.LayoutSet
import com.liferay.portal.model.Portlet
import com.liferay.portal.model.PortletPreferences
import com.liferay.portal.service.GroupLocalServiceUtil
import com.liferay.portal.service.LayoutSetLocalServiceUtil
@nshaw
nshaw / show_publish_dates_v61.groovy
Last active June 1, 2016 21:09
show_publish_dates.groovy
import com.liferay.portal.kernel.util.DateUtil
import com.liferay.portal.kernel.util.GetterUtil
import com.liferay.portal.kernel.util.StringPool
import com.liferay.portal.kernel.util.Validator
import com.liferay.portal.kernel.xml.Document
import com.liferay.portal.kernel.xml.Element
import com.liferay.portal.kernel.xml.SAXReaderUtil
import com.liferay.portal.model.Layout
import com.liferay.portal.model.LayoutSet
import com.liferay.portal.model.Portlet
@nshaw
nshaw / show_class_location.groovy
Created June 25, 2014 15:52
Show the location of a class as loaded by the JVM
import java.security.CodeSource
import com.liferay.portlet.dynamicdatamapping.storage.BaseStorageAdapter;
try {
// Change this to whatever class you want to inspect
Class clazz = BaseStorageAdapter.class;
CodeSource src = BaseStorageAdapter.class.getProtectionDomain().getCodeSource();
if (src != null) {
println clazz.getSimpleName() + " is sourced here: "+ src
}
#set ($defaultSiteName = "ABC")
#set ($group = $groupLocalService.getGroup($company_id, $defaultSiteName))
#set ($isSiteAdmin = ($userGroupRoleLocalService.hasUserGroupRole($user_id, $group.getGroupId(),"Site Administrator", true)))
#set ($isAbcSupport = ($roleLocalService.hasUserRole($user_id, $company_id, "ABC Support", true)))
#set($isAbcAdmin = ($roleLocalService.hasUserRole($user_id, $company_id, "ABC Admin", true)))
@nshaw
nshaw / list_dl_indexers.groovy
Created April 19, 2013 15:43
List the indexers defined for the Document Library Portlet
import com.liferay.portal.kernel.search.Indexer
import com.liferay.portal.kernel.search.IndexerPostProcessor
import com.liferay.portal.model.Portlet
import com.liferay.portal.service.CompanyLocalServiceUtil
import com.liferay.portal.service.PortletLocalServiceUtil
try {
String portletId = "20"; //Document Library
long companyId = CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId();
Portlet portlet = PortletLocalServiceUtil.getPortletById(
@nshaw
nshaw / display_cluster_details.groovy
Last active August 26, 2022 07:47
v3. Sorted nodes visible to ClusterExecutor, added default heartbeat value to support LR 6.0 v2. Added more logging to improve readability, removed some logic which was examining packet content, changed duration to be based on configured heartbeat interval v1. First revision
import com.liferay.portal.kernel.cluster.ClusterExecutorUtil
import com.liferay.portal.kernel.cluster.ClusterNode
import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayInputStream
import com.liferay.portal.kernel.io.unsync.UnsyncByteArrayOutputStream
import com.liferay.portal.kernel.util.DateUtil
import com.liferay.portal.kernel.util.GetterUtil
import com.liferay.portal.kernel.util.PropsUtil
import com.liferay.portal.kernel.util.StringBundler
import com.liferay.util.transport.DatagramHandler
import com.liferay.util.transport.MulticastDatagramHandler
@nshaw
nshaw / set_mdr_permissions.groovy
Created February 20, 2013 17:38
Add MDR permissions to users with the role Content Editor.
import com.liferay.portal.service.RoleLocalServiceUtil
import com.liferay.portal.service.ResourcePermissionLocalServiceUtil
import com.liferay.portal.service.ResourceActionLocalServiceUtil
import com.liferay.portal.security.permission.ActionKeys
import com.liferay.portal.model.ResourceAction
import com.liferay.portal.util.PortletKeys
Map<String, String[]> portletSets = new TreeMap<String, String[]>();
// Mobile Device Rules
import com.liferay.portal.model.Organization
import com.liferay.portal.model.Role
import com.liferay.portal.model.User
import com.liferay.portal.security.permission.PermissionChecker
import com.liferay.portal.security.permission.PermissionCheckerBag
import com.liferay.portal.security.permission.PermissionCheckerFactoryUtil
import com.liferay.portal.service.OrganizationLocalServiceUtil
import com.liferay.portal.service.RoleLocalServiceUtil
import com.liferay.portal.service.UserLocalServiceUtil
import com.liferay.portal.service.permission.PortletPermissionUtil
@nshaw
nshaw / upgrade_lr5.1_lr6.1_fix_journalarticle_index.sql
Created February 7, 2013 13:43
In 5.1.7, this index is unique (create unique index IX_3463D95B on JournalArticle (uuid_, groupId)) but in the client's database, it's showing as a non-unique index. So that explains why the duplicate entries are allowed in the database. This script will remove all old versions of JournalArticles and only retain the newest therefore satisfying t…
drop index IX_3463D95B on JournalArticle;
create temporary table temp_ja
select * from (
select groupId, articleId, uuid_, type_, max(version) as 'maxVersionId', count(id_) as 'countId' from JournalArticle ja
group by groupId, uuid_
) temp
where temp.countId > 1;
delete ja from JournalArticle ja
@nshaw
nshaw / display_session_count.groovy
Created January 30, 2013 20:25
Groovy script to display the current number of active Tomcat sessions. Useful if you don't have a Tomcat monitoring solution in place.
import java.lang.management.ManagementFactory
import javax.management.MBeanServer
import javax.management.ObjectName
import com.liferay.portal.kernel.util.StringUtil
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("Catalina:type=Manager,context=/,host=localhost")
Object mbean = mbs.getMBeanInfo(objectName);
println "Found manager bean"
//println mbean.toString()