Skip to content

Instantly share code, notes, and snippets.

View marcosblandim's full-sized avatar

marcosblandim

View GitHub Profile
@marcosblandim
marcosblandim / get-display-page-asset.ftl
Last active March 21, 2022 21:53
LIFERAY: Get the Display Page's Asset inside a Freemarker
<#assign assetEntryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetEntryLocalService")/>
<#if Request.INFO_ITEM_DETAILS??>
<#assign
info_item_reference = Request.INFO_ITEM_DETAILS.getInfoItemReference()
className = info_item_reference.getClassName()
classPK = info_item_reference.getClassPK()
asset = assetEntryLocalService.getEntry(className, classPK)
@marcosblandim
marcosblandim / get-asset-friendly-url.ftl
Last active March 21, 2022 21:53
LIFERAY: Get the Friendly URL of Asset's Display Page inside a Freemarker
<#assign
assetDisplayPageFriendlyURLProvider = serviceLocator.findService("com.liferay.asset.display.page.portlet.AssetDisplayPageFriendlyURLProvider")
friendlyURL = assetDisplayPageFriendlyURLProvider.getFriendlyURL(assetEntry.getClassName(), assetEntry.getClassPK(), themeDisplay)
/>
${friendlyURL}
* Make sure to remove `serviceLocator` from `Restricted Classes` in `System Settings > Template Engines > FreeMarker Engine`.
* Your Freemarker can be a Fragment, Widget Template, Web Content Template, etc; just make sure to use Freemarker's alternative square bracket syntax when inside a Fragment.
@marcosblandim
marcosblandim / get-wc-template-asset.ftl
Last active May 12, 2022 12:32
LIFERAY: Get the AssetEntry of a Web Content (Journal Article naming in the database) Template Freemarker
<#assign
JournalArticleService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")
AssetEntryLocalService = serviceLocator.findService("com.liferay.asset.kernel.service.AssetEntryLocalService")
journalArticle = JournalArticleService.getArticle(themeDisplay.getSiteGroupId(),.data_model["reserved-article-id"].data)
assetEntry = AssetEntryLocalService.getEntry(journalArticle.getModelClassName(), journalArticle.getResourcePrimKey())
/>
${assetEntry}
@marcosblandim
marcosblandim / liferay-user-rest-api.java
Last active July 7, 2022 21:53
Exemplo de API Rest no Liferay
package br.com.simplify.liferay.rest.application;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@marcosblandim
marcosblandim / Language.properties
Created October 26, 2022 19:38
LIFERAY: make User's "last name" field optional
lang.user.name.required.field.names=
@marcosblandim
marcosblandim / resourceLocatorUsage.groovy
Last active October 26, 2022 20:04
LIFERAY: Use ResourceLocator with Groovy
import com.liferay.headless.admin.user.resource.v1_0.RoleResource
import com.liferay.portal.kernel.model.User
import com.liferay.portal.kernel.model.role.RoleConstants
import com.liferay.portal.kernel.security.auth.GuestOrUserUtil
import com.liferay.portal.kernel.service.ServiceContext
import com.liferay.portal.kernel.service.ServiceContextThreadLocal
import com.liferay.portal.vulcan.pagination.Pagination
import com.liferay.portal.vulcan.resource.locator.ResourceLocator
import com.liferay.portal.vulcan.resource.locator.ResourceLocatorFactory
import org.osgi.framework.Bundle
@marcosblandim
marcosblandim / UseOSGIServicesGroovy.groovy
Last active April 6, 2023 14:39
How to use Liferay OSGI Services inside Server Administration Groovy
import com.liferay.journal.service.JournalArticleLocalService
import com.liferay.portal.template.ServiceLocator
serviceLocator = ServiceLocator.newInstance()
journalArticleLocalService = serviceLocator.findService(JournalArticleLocalService.class.getName())
println journalArticleLocalService.getJournalArticles(1,3)
@marcosblandim
marcosblandim / fragment-number-configuration.json
Created January 30, 2023 16:32
Liferay: Fragment configuration of an integer number with boundaries
{
"fieldSets": [
{
"fields": [
{
"name": "number",
"label": "Number",
"type": "text",
"dataType": "int",
"defaultValue": "5",
@marcosblandim
marcosblandim / getOSGiService.groovy
Last active September 6, 2023 14:41
Liferay: Get OSGi Service in Groovy
import com.liferay.registry.Registry
import com.liferay.registry.RegistryUtil
import com.liferay.registry.ServiceReference
def getService(Class clazz) {
Registry registry = RegistryUtil.getRegistry();
ServiceReference serviceReference = registry.getServiceReference(clazz);
return registry.getService(serviceReference);
private SchedulerEngine getSchedulerEngine() {
SchedulerEngine schedulerEngine = (SchedulerEngine) IdentifiableOSGiServiceUtil.getIdentifiableOSGiService(OSGI_SERVICE_IDENTIFIER);
}
private final String OSGI_SERVICE_IDENTIFIER = "com.liferay.portal.scheduler.multiple.internal.ClusterSchedulerEngine";
SchedulerEngine schedulerEngine = getSchedulerEngine();