Example usage for com.liferay.portal.kernel.repository RepositoryProviderUtil getFileEntryLocalRepository

List of usage examples for com.liferay.portal.kernel.repository RepositoryProviderUtil getFileEntryLocalRepository

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository RepositoryProviderUtil getFileEntryLocalRepository.

Prototype

public static LocalRepository getFileEntryLocalRepository(long fileEntryId) throws PortalException 

Source Link

Usage

From source file:com.liferay.document.library.internal.trash.DLFileEntryTrashHandler.java

License:Open Source License

@Override
protected DocumentRepository getDocumentRepository(long classPK) throws PortalException {

    LocalRepository localRepository = RepositoryProviderUtil.getFileEntryLocalRepository(classPK);

    if (!localRepository.isCapabilityProvided(TrashCapability.class)) {
        throw new UnsupportedCapabilityException(TrashCapability.class,
                "Repository " + localRepository.getRepositoryId());
    }/*ww w.  j  a  v  a 2  s.  c om*/

    return localRepository;
}

From source file:com.liferay.document.library.service.test.DLFileEntryLocalServiceTest.java

License:Open Source License

@Test
public void testDeleteFileEntries() 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);

    for (int i = 0; i < 20; i++) {
        FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(),
                _group.getGroupId(), folder.getFolderId(), RandomTestUtil.randomString(),
                ContentTypes.TEXT_PLAIN, RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE),
                serviceContext);/*  w  ww  .  j ava 2  s .  c  o m*/

        LocalRepository localRepository = RepositoryProviderUtil
                .getFileEntryLocalRepository(fileEntry.getFileEntryId());

        DLTrashLocalServiceUtil.moveFileEntryToTrash(TestPropsValues.getUserId(),
                localRepository.getRepositoryId(), fileEntry.getFileEntryId());
    }

    for (int i = 0; i < IntervalActionProcessor.INTERVAL_DEFAULT; i++) {
        DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), _group.getGroupId(),
                folder.getFolderId(), RandomTestUtil.randomString(), ContentTypes.TEXT_PLAIN,
                RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext);
    }

    DLFileEntryLocalServiceUtil.deleteFileEntries(_group.getGroupId(), folder.getFolderId(), false);

    int fileEntriesCount = DLFileEntryLocalServiceUtil.getFileEntriesCount(_group.getGroupId(),
            folder.getFolderId());

    Assert.assertEquals(20, fileEntriesCount);
}