Skip to content

Instantly share code, notes, and snippets.

@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()
/**
* 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 / 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) {
@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 / log_live_template
Created October 30, 2012 15:22
IntelliJ Live Template
private static Log _log =
LogFactoryUtil.getLog($NAME$.class);
@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 / CustomServiceComponentLocalServiceImpl.java
Created September 11, 2012 12:54
Fix ServiceComponentLocalServiceImpl handling of indexes
public class CustomServiceComponentLocalServiceImpl extends
ServiceComponentLocalServiceImpl {
@Override
public void upgradeDB(
ClassLoader classLoader, String buildNamespace, long buildNumber,
boolean buildAutoUpgrade, ServiceComponent previousServiceComponent,
String tablesSQL, String sequencesSQL, String indexesSQL)
throws Exception {
@nshaw
nshaw / CustomJSONServiceAction.java
Created September 11, 2012 12:43
Make HTTP request available to JSON services
public String getJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String className = ParamUtil.getString(request, "serviceClassName");
boolean useThreadLocal = (className.indexOf("UmpServiceUtil") > 0) || (className.indexOf("MyStreetServiceUtil") > 0);
try {
if (useThreadLocal) {
JSONRequestThreadLocal.setRequest(request);
}
return super.getJSON(mapping, form, request, response);
}
@nshaw
nshaw / gist:3693859
Created September 10, 2012 21:05
patch for PortletExporter.java:exportAssetTags(PortletDataContext) to improve page publishing performance
for (AssetTag assetTag : assetTags) {
// CUSTOM START
// By only exporting tags that are more recent than the export start
// date of the Layout, we assume that at some point in time the
// exporting Site and the importing Site had exactly the same Tags,
// and that every Layout export will harvest any tags not found in
// the importing Site
if(portletDataContext.hasDateRange()) {
int diff = DateUtil.compareTo(portletDataContext.getStartDate(),
assetTag.getModifiedDate());
@nshaw
nshaw / gist:3638497
Created September 5, 2012 15:31
Patch tool - detect code conflicts
import java.util.zip.ZipFile
/*
* detect-patch-conflicts.groovy
* Input - patches.dir property to indicate the location of the patches zip files
* Output - detected.patch.conflict property - set to true if conflicts were found
*/
def conflict = false
// CUSTOM START - this configuraton should be paramaterized to generalize this script