Example usage for com.liferay.portal.kernel.repository.model Folder getFolderId

List of usage examples for com.liferay.portal.kernel.repository.model Folder getFolderId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model Folder getFolderId.

Prototype

public long getFolderId();

Source Link

Usage

From source file:com.liferay.blogs.web.internal.portlet.action.EditImageMVCActionCommand.java

License:Open Source License

protected void deleteImages(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] deleteFileEntryIds = null;

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    if (fileEntryId > 0) {
        deleteFileEntryIds = new long[] { fileEntryId };
    } else {//from ww w. j ava  2  s . co m
        deleteFileEntryIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteFileEntryIds"), 0L);
    }

    Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(),
            themeDisplay.getScopeGroupId());

    for (long deleteFileEntryId : deleteFileEntryIds) {
        FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(deleteFileEntryId);

        if (fileEntry.getFolderId() != folder.getFolderId()) {
            continue;
        }

        if ((fileEntry.getUserId() == themeDisplay.getUserId()) || BlogsPermission.contains(
                themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.UPDATE)) {

            PortletFileRepositoryUtil.deletePortletFileEntry(deleteFileEntryId);
        }
    }
}

From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadFileEntryHandler.java

License:Open Source License

protected FileEntry addFileEntry(String fileName, String contentType, InputStream inputStream,
        ThemeDisplay themeDisplay) throws PortalException {

    Folder folder = blogsLocalService.addAttachmentsFolder(themeDisplay.getUserId(),
            themeDisplay.getScopeGroupId());

    String uniqueFileName = PortletFileRepositoryUtil.getUniqueFileName(themeDisplay.getScopeGroupId(),
            folder.getFolderId(), fileName);

    return PortletFileRepositoryUtil.addPortletFileEntry(themeDisplay.getScopeGroupId(),
            themeDisplay.getUserId(), BlogsEntry.class.getName(), 0, BlogsConstants.SERVICE_NAME,
            folder.getFolderId(), inputStream, uniqueFileName, contentType, true);
}

From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadHandler.java

License:Open Source License

@Override
protected FileEntry addFileEntry(long userId, long groupId, long folderId, String fileName, String contentType,
        InputStream inputStream, long size, ServiceContext serviceContext) throws PortalException {

    Folder folder = BlogsEntryLocalServiceUtil.addAttachmentsFolder(userId, groupId);

    return PortletFileRepositoryUtil.addPortletFileEntry(groupId, userId, BlogsEntry.class.getName(), 0,
            BlogsConstants.SERVICE_NAME, folder.getFolderId(), inputStream, fileName, contentType, true);
}

From source file:com.liferay.blogs.web.internal.upload.ImageBlogsUploadHandler.java

License:Open Source License

@Override
protected FileEntry fetchFileEntry(long userId, long groupId, long folderId, String fileName)
        throws PortalException {

    Folder folder = BlogsEntryLocalServiceUtil.addAttachmentsFolder(userId, groupId);

    try {/*from   w  w  w.j  av  a  2 s .  c  o m*/
        return PortletFileRepositoryUtil.getPortletFileEntry(groupId, folder.getFolderId(), fileName);
    } catch (PortalException pe) {
        if (_log.isDebugEnabled()) {
            _log.debug(pe, pe);
        }

        return null;
    }
}

From source file:com.liferay.bookmarks.uad.exporter.BookmarksEntryUADEntityExporter.java

License:Open Source License

@Override
public void export(UADEntity uadEntity) throws PortalException {
    BookmarksEntry bookmarksEntry = _getBookmarksEntry(uadEntity);

    String json = getJSON(bookmarksEntry);

    Folder folder = getFolder(bookmarksEntry.getCompanyId(), BookmarksPortletKeys.BOOKMARKS, _FOLDER_NAME);

    try {//w  ww .ja v  a2  s. c om
        InputStream is = new UnsyncByteArrayInputStream(json.getBytes(StringPool.UTF8));

        PortletFileRepositoryUtil.addPortletFileEntry(folder.getGroupId(), bookmarksEntry.getUserId(),
                Group.class.getName(), folder.getGroupId(), BookmarksPortletKeys.BOOKMARKS,
                folder.getFolderId(), is, uadEntity.getUADEntityId() + ".json", ContentTypes.APPLICATION_JSON,
                false);
    } catch (UnsupportedEncodingException uee) {
        throw new UADEntityExporterException(uee);
    }
}

From source file:com.liferay.bookmarks.uad.exporter.test.BookmarksEntryUADEntityExporterTest.java

License:Open Source License

private FileEntry _getFileEntry(long companyId, String uadEntityId) throws Exception {

    Group guestGroup = _groupLocalService.getGroup(companyId, GroupConstants.GUEST);

    Repository repository = PortletFileRepositoryUtil.getPortletRepository(guestGroup.getGroupId(),
            BookmarksPortletKeys.BOOKMARKS);

    Folder folder = PortletFileRepositoryUtil.getPortletFolder(repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "UADExport");

    return PortletFileRepositoryUtil.getPortletFileEntry(guestGroup.getGroupId(), folder.getFolderId(),
            uadEntityId + ".json");
}

From source file:com.liferay.compat.hook.webdav.CompatDLWebDAVStorageImpl.java

License:Open Source License

public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException {

    Resource resource = getResource(webDAVRequest);

    Lock lock = null;/*from w  w w  . j a v  a  2  s  .  com*/
    int status = HttpServletResponse.SC_OK;

    try {
        if (resource == null) {
            status = HttpServletResponse.SC_CREATED;

            HttpServletRequest request = webDAVRequest.getHttpServletRequest();

            String[] pathArray = webDAVRequest.getPathArray();

            long companyId = webDAVRequest.getCompanyId();
            long groupId = webDAVRequest.getGroupId();
            long parentFolderId = getParentFolderId(companyId, pathArray);
            String title = WebDAVUtil.getResourceName(pathArray);

            String contentType = GetterUtil.get(request.getHeader(HttpHeaders.CONTENT_TYPE),
                    ContentTypes.APPLICATION_OCTET_STREAM);

            if (contentType.equals(ContentTypes.APPLICATION_OCTET_STREAM)) {
                contentType = MimeTypesUtil.getContentType(request.getInputStream(), title);
            }

            String description = StringPool.BLANK;
            String changeLog = StringPool.BLANK;

            File file = FileUtil.createTempFile(FileUtil.getExtension(title));

            file.createNewFile();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId));
            serviceContext.setAddGuestPermissions(true);

            FileEntry fileEntry = DLAppServiceUtil.addFileEntry(groupId, parentFolderId, title, contentType,
                    title, description, changeLog, file, serviceContext);

            resource = toResource(webDAVRequest, fileEntry, false);
        }

        if (isInstanceOfDLFileEntryResourceImpl(super.getResource(webDAVRequest))) {

            FileEntry fileEntry = (FileEntry) resource.getModel();

            ServiceContext serviceContext = new ServiceContext();

            serviceContext.setAttribute(DLUtil.MANUAL_CHECK_IN_REQUIRED,
                    CompatWebDAVThreadLocal.isManualCheckInRequired());

            DLAppServiceUtil.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext);

            lock = fileEntry.getLock();
        } else {
            boolean inheritable = false;

            long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest());

            if (depth != 0) {
                inheritable = true;
            }

            Folder folder = (Folder) resource.getModel();

            lock = DLAppServiceUtil.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner,
                    inheritable, timeout);
        }
    } catch (Exception e) {

        // DuplicateLock is 423 not 501

        if (!(e instanceof DuplicateLockException)) {
            throw new WebDAVException(e);
        }

        status = WebDAVUtil.SC_LOCKED;
    }

    return new Status(lock, status);
}

From source file:com.liferay.document.library.convert.test.DocumentLibraryConvertProcessTest.java

License:Open Source License

@Test
public void testMigrateDLWhenFileEntryInFolder() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    Folder folder = DLAppServiceUtil.addFolder(_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    testMigrateDL(folder.getFolderId());
}

From source file:com.liferay.document.library.convert.test.DocumentLibraryConvertProcessTest.java

License:Open Source License

protected void testMigrateAndCheckOldRepositoryFiles(Boolean delete) throws Exception {

    _convertProcess.setParameterValues(new String[] { _CLASS_NAME_DB_STORE, delete.toString() });

    FileEntry rootFileEntry = addFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString() + ".txt", ContentTypes.TEXT_PLAIN,
            RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE));

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    Folder folder = DLAppServiceUtil.addFolder(_group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    FileEntry folderFileEntry = addFileEntry(folder.getFolderId(), "liferay.jpg", ContentTypes.IMAGE_JPEG,
            FileUtil.getBytes(getClass(), "dependencies/liferay.jpg"));

    ImageProcessorUtil.generateImages(null, folderFileEntry.getFileVersion());

    _convertProcess.convert();/*from   ww w  .ja v  a  2  s  . c  o  m*/

    DLFileEntry rootDLFileEntry = (DLFileEntry) rootFileEntry.getModel();

    Assert.assertNotEquals(delete, _sourceStore.hasFile(rootDLFileEntry.getCompanyId(),
            rootDLFileEntry.getDataRepositoryId(), rootDLFileEntry.getName()));

    DLFileEntry folderDLFileEntry = (DLFileEntry) folderFileEntry.getModel();

    DLProcessor imageProcessor = DLProcessorRegistryUtil.getDLProcessor(DLProcessorConstants.IMAGE_PROCESSOR);

    if (imageProcessor instanceof ImageProcessorImpl) {
        Assert.assertNotEquals(delete, _sourceStore.hasDirectory(folderDLFileEntry.getCompanyId(),
                DLPreviewableProcessor.REPOSITORY_ID, DLPreviewableProcessor.THUMBNAIL_PATH));
    }

    Assert.assertNotEquals(delete, _sourceStore.hasFile(folderDLFileEntry.getCompanyId(),
            folderDLFileEntry.getDataRepositoryId(), folderDLFileEntry.getName()));

    DLContentLocalServiceUtil.getContent(
            folderDLFileEntry.getCompanyId(), DLFolderConstants
                    .getDataRepositoryId(folderDLFileEntry.getRepositoryId(), folderDLFileEntry.getFolderId()),
            folderDLFileEntry.getName());

    DLContentLocalServiceUtil.getContent(
            rootDLFileEntry.getCompanyId(), DLFolderConstants
                    .getDataRepositoryId(rootDLFileEntry.getRepositoryId(), rootDLFileEntry.getFolderId()),
            rootDLFileEntry.getName());
}

From source file:com.liferay.document.library.demo.data.creator.internal.BaseFolderDemoDataCreatorImpl.java

License:Open Source License

protected Folder createFolder(long userId, long groupId, long folderId, String name) throws PortalException {

    Folder folder = null;

    try {//from   w w w  .  ja v a2s  .  c o  m
        folder = dlAppLocalService.getFolder(groupId, folderId, name);
    } catch (NoSuchFolderException nsfe) {
        if (_log.isWarnEnabled()) {
            _log.warn(nsfe, nsfe);
        }

        folder = dlAppLocalService.addFolder(userId, groupId, folderId, name, StringPool.BLANK,
                new ServiceContext());
    }

    _folderIds.add(folder.getFolderId());

    return folder;
}