Skip to content

Instantly share code, notes, and snippets.

@nshaw
nshaw / find_user_by_email.groovy
Created October 5, 2012 16:42
Find User By Email
import com.liferay.portal.service.UserLocalServiceUtil
import com.liferay.portal.util.PortalUtil
import com.liferay.portal.model.User
try {
long companyId = PortalUtil.getDefaultCompanyId()
String email = "[email protected]"
User user = UserLocalServiceUtil.getUserByEmailAddress(companyId, email)
println user
@nshaw
nshaw / log_live_template
Created October 30, 2012 15:22
IntelliJ Live Template
private static Log _log =
LogFactoryUtil.getLog($NAME$.class);
@nshaw
nshaw / set_commpany_virtual_host.groovy
Created October 31, 2012 16:22
set company virtual host
setCompanyVirtualHost("uat.company.org");
def setCompanyVirtualHost(newVirtualHost) {
long companyId = PortalUtil.getDefaultCompanyId()
Company c = CompanyLocalServiceUtil.getCompany(companyId)
println "Current company virtual host: " + c.virtualHostname
c = CompanyServiceUtil.updateCompany(companyId, newVirtualHost, c.mx, c.maxUsers, c.active);
@nshaw
nshaw / aui_ready_liferay_service.js
Created November 15, 2012 16:03
AUI ready example - two calls to Liferay.Service, second fails
var videoListItem;
var videoListItems;
AUI().ready('aui-io',
function() {
var params = {
groupId:"$groupId",
uuid:"$uuid.data"
}
Liferay.Service.SS.DMContent.getDMVideoList(params,
function (msg) {
/**
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
@nshaw
nshaw / cluster_details.groovy
Created January 28, 2013 15:47
Display the details of nodes visible to a cluster.
import com.liferay.portal.kernel.cluster.ClusterExecutorUtil
import com.liferay.portal.kernel.cluster.ClusterNode
try {
println "Clustering enabled: " + ClusterExecutorUtil.isEnabled()
List<ClusterNode> nodes = ClusterExecutorUtil.getClusterNodes()
println "Number of nodes: " + nodes.size()
@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()
@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
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 / 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