Commit 6ad2af59 authored by Elias Englmeier's avatar Elias Englmeier
Browse files

added resource permission to video files

parent 94b29f1f
......@@ -13,6 +13,7 @@ import java.util.UUID;
import org.osgi.service.component.annotations.Component;
import com.liferay.counter.kernel.service.CounterLocalServiceUtil;
import com.liferay.document.library.kernel.model.DLFileEntry;
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil;
......@@ -23,9 +24,19 @@ import com.liferay.portal.kernel.backgroundtask.BackgroundTaskResult;
import com.liferay.portal.kernel.backgroundtask.BaseBackgroundTaskExecutor;
import com.liferay.portal.kernel.backgroundtask.display.BackgroundTaskDisplay;
import com.liferay.portal.kernel.backgroundtask.display.BackgroundTaskDisplayFactoryUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.model.ResourceAction;
import com.liferay.portal.kernel.model.ResourceConstants;
import com.liferay.portal.kernel.model.ResourcePermission;
import com.liferay.portal.kernel.model.Role;
import com.liferay.portal.kernel.model.RoleConstants;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.security.permission.ActionKeys;
import com.liferay.portal.kernel.service.ResourceActionLocalServiceUtil;
import com.liferay.portal.kernel.service.ResourcePermissionLocalServiceUtil;
import com.liferay.portal.kernel.service.RoleLocalServiceUtil;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.util.MimeTypesUtil;
......@@ -100,7 +111,7 @@ public class VideoConverter extends BaseBackgroundTaskExecutor {
Ideas i = IdeasUtil.findByPrimaryKey(ideasId);
String title = i.getUserName() + "IDEAS_VIDEO" + UUID.randomUUID () + "." + convertTo;
FileEntry createdEntry = DLAppLocalServiceUtil.addFileEntry(i.getUserId(), i.getGroupId(),
FileEntry createdEntry = DLAppLocalServiceUtil.addFileEntry(i.getUserId(), gId,
dlEntry.getFolderId(), tmpOutputFile.getName(),
MimeTypesUtil.getContentType(tmpOutputFile), title,
"converted video file", "none", tmpOutputFile, new ServiceContext());
......@@ -121,11 +132,32 @@ public class VideoConverter extends BaseBackgroundTaskExecutor {
tmpSourceFile.delete();
tmpOutputFile.delete();
logger.info("-------------------------------- Updating File Permission -----------------------------------");
updateResourcePermission(createdEntry);
logger.info("--------------------- Execution of background task finished ---------------------");
return BackgroundTaskResult.SUCCESS;
}
@Override
private synchronized void updateResourcePermission(FileEntry createdEntry) throws PortalException {
Role siteMemberRole = RoleLocalServiceUtil.getRole(createdEntry.getCompanyId(), RoleConstants.GUEST);
ResourceAction resourceAction = ResourceActionLocalServiceUtil.getResourceAction(DLFileEntry.class.getName(), ActionKeys.VIEW);
ResourcePermission resourcePermission = ResourcePermissionLocalServiceUtil
.createResourcePermission(CounterLocalServiceUtil.increment());
resourcePermission.setCompanyId(createdEntry.getCompanyId());
resourcePermission.setName(DLFileEntry.class.getName());
resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
resourcePermission.setPrimKey(String.valueOf(createdEntry.getPrimaryKey()));
resourcePermission.setRoleId(siteMemberRole.getRoleId());
resourcePermission.setActionIds(resourceAction.getBitwiseValue());
ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);
}
@Override
public BackgroundTaskDisplay getBackgroundTaskDisplay(BackgroundTask backgroundTask) {
return BackgroundTaskDisplayFactoryUtil.getBackgroundTaskDisplay(backgroundTask);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment