Skip to content

Instantly share code, notes, and snippets.

@kimakunc
kimakunc / Multipart Upload to DL
Created July 26, 2016 19:46
Liferay 6.2 add multipart File to DL
private FileEntry addFileEntry(CommonsMultipartFile multipartFile, long userId, long repositoryId,
ServiceContext serviceContext, long folderId, String sourceFileName, String mimeType, String title,
String changeLog, String description) throws PortalException, SystemException {
FileEntry fileEntry = null;
try {
fileEntry = DLAppLocalServiceUtil.addFileEntry(userId, repositoryId, folderId, sourceFileName, mimeType,
title, description, changeLog, multipartFile.getBytes(), serviceContext);
@kimakunc
kimakunc / LiferayDLFolder.txt
Last active July 26, 2016 19:44
Liferay 6.2 DL Folder
private Folder getDLFolder(ThemeDisplay themeDisplay, String folderName) throws PortalException, SystemException {
long scopeGroupId = themeDisplay.getScopeGroupId();
Folder folder = DLAppLocalServiceUtil.getFolder(scopeGroupId, 0, folderName);
if (folder != null) {
return folder;
} else {
throw new NoSuchFolderException();
}
}
@kimakunc
kimakunc / Regular Role
Created May 28, 2013 09:36
Liferay 6.1 create a regular role
public static void createRegularRole(String roleName, Map<Locale, String> title, Map<Locale, String> description) {
long companyId = PortalUtil.getDefaultCompanyId();
int type = RoleConstants.TYPE_REGULAR;
try {
Role newRole = RoleLocalServiceUtil.addRole(LiferayUtil.getDefaultUserId(companyId), companyId, roleName,
title, description, type);
LOGGER.info("Added new role with id [" + newRole.getRoleId() + "] and name [" + newRole.getName() + "].");
} catch (Exception e) {
if (e instanceof DuplicateRoleException) {
LOGGER.debug("Role [" + roleName + "] already exists.");
@kimakunc
kimakunc / Liferay 6.1 permissions
Created May 28, 2013 09:34
Set "view" and "update" permissions on Expando Column for the "Guest" role using Liferay API.
private static void setExpandoPermissions(long companyId, ExpandoColumn column) {
try {
Role guestUserRole = RoleLocalServiceUtil.getRole(companyId, RoleConstants.GUEST);
if (guestUserRole != null) {
// define actions
String[] actionIds = new String[] { ActionKeys.VIEW, ActionKeys.UPDATE };
// set the permission
@kimakunc
kimakunc / Liferay global and guest group
Last active July 29, 2022 16:26
Retrieve "Global" or "Guest" scope groups from Liferay API
// get the global group
Group globalGroup = GroupLocalServiceUtil.getCompanyGroup(companyId);
//get the guest group
Group guestGroup = GroupLocalServiceUtil.getGroup(companyId, GroupConstants.GUEST);