Example usage for com.liferay.portal.kernel.repository LocalRepository getRepositoryId

List of usage examples for com.liferay.portal.kernel.repository LocalRepository getRepositoryId

Introduction

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

Prototype

public long getRepositoryId();

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());
    }/*from   w w w.  j a  v a2  s.  c  om*/

    return localRepository;
}

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

License:Open Source License

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

    LocalRepository localRepository = RepositoryProviderUtil.getFileShortcutLocalRepository(classPK);

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

    return localRepository;
}

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

License:Open Source License

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

    LocalRepository localRepository = RepositoryProviderUtil.getFolderLocalRepository(classPK);

    if (!localRepository.isCapabilityProvided(TrashCapability.class)) {
        throw new UnsupportedCapabilityException(TrashCapability.class,
                "Repository " + localRepository.getRepositoryId());
    }//w  ww. jav a2s .c o  m

    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);//from w  ww .  j  a  v a2  s .  c  om

        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);
}

From source file:com.liferay.portlet.documentlibrary.service.impl.DLAppLocalServiceImpl.java

License:Open Source License

/**
 * Moves the file entry to the new folder.
 *
 * @param  userId the primary key of the user
 * @param  fileEntryId the primary key of the file entry
 * @param  newFolderId the primary key of the new folder
 * @param  serviceContext the service context to be applied
 * @return the file entry/* w w  w.  j a  v a  2 s.c o m*/
 * @throws PortalException if the file entry or the new folder could not be
 *         found
 * @throws SystemException if a system exception occurred
 */
public FileEntry moveFileEntry(long userId, long fileEntryId, long newFolderId, ServiceContext serviceContext)
        throws PortalException, SystemException {

    LocalRepository fromLocalRepository = getLocalRepository(0, fileEntryId, 0);
    LocalRepository toLocalRepository = getLocalRepository(newFolderId, serviceContext);

    if (fromLocalRepository.getRepositoryId() == toLocalRepository.getRepositoryId()) {

        // Move file entries within repository

        FileEntry fileEntry = fromLocalRepository.moveFileEntry(userId, fileEntryId, newFolderId,
                serviceContext);

        return fileEntry;
    }

    // Move file entries between repositories

    return moveFileEntries(userId, fileEntryId, newFolderId, fromLocalRepository, toLocalRepository,
            serviceContext);
}