Example usage for com.liferay.portal.kernel.repository.model FileShortcut getFileShortcutId

List of usage examples for com.liferay.portal.kernel.repository.model FileShortcut getFileShortcutId

Introduction

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

Prototype

public long getFileShortcutId();

Source Link

Usage

From source file:com.liferay.document.library.internal.exportimport.data.handler.FileShortcutStagedModelDataHandler.java

License:Open Source License

@Override
public void deleteStagedModel(FileShortcut fileShortcut) throws PortalException {

    _dlFileShortcutLocalService.deleteFileShortcut(fileShortcut.getFileShortcutId());
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FileShortcutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, FileShortcut fileShortcut)
        throws Exception {

    long userId = portletDataContext.getUserId(fileShortcut.getUserUuid());

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.class);

    long folderId = MapUtil.getLong(folderIds, fileShortcut.getFolderId(), fileShortcut.getFolderId());

    long groupId = portletDataContext.getScopeGroupId();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        Folder folder = FolderUtil.findByPrimaryKey(folderId);

        groupId = folder.getRepositoryId();
    }/*from  w  ww .  j a  va2  s  . co  m*/

    Map<Long, Long> fileEntryIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(FileEntry.class);

    long fileEntryId = MapUtil.getLong(fileEntryIds, fileShortcut.getToFileEntryId(),
            fileShortcut.getToFileEntryId());

    FileEntry importedFileEntry = null;

    try {
        importedFileEntry = _dlAppLocalService.getFileEntry(fileEntryId);
    } catch (PortalException pe) {
        if (_log.isWarnEnabled()) {
            _log.warn("Unable to fetch file entry " + fileEntryId, pe);
        }

        return;
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(fileShortcut);

    FileShortcut importedFileShortcut = null;

    if (portletDataContext.isDataStrategyMirror()) {
        FileShortcut existingFileShortcut = fetchStagedModelByUuidAndGroupId(fileShortcut.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingFileShortcut == null) {
            serviceContext.setUuid(fileShortcut.getUuid());

            importedFileShortcut = _dlAppLocalService.addFileShortcut(userId, groupId, folderId,
                    importedFileEntry.getFileEntryId(), serviceContext);
        } else {
            importedFileShortcut = _dlAppLocalService.updateFileShortcut(userId,
                    existingFileShortcut.getFileShortcutId(), folderId, importedFileEntry.getFileEntryId(),
                    serviceContext);
        }
    } else {
        importedFileShortcut = _dlAppLocalService.addFileShortcut(userId, groupId, folderId,
                importedFileEntry.getFileEntryId(), serviceContext);
    }

    portletDataContext.importClassedModel(fileShortcut, importedFileShortcut);
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FileShortcutStagedModelDataHandler.java

License:Open Source License

@Override
protected void doRestoreStagedModel(PortletDataContext portletDataContext, FileShortcut fileShortcut)
        throws Exception {

    long userId = portletDataContext.getUserId(fileShortcut.getUserUuid());

    FileShortcut existingFileShortcut = fetchStagedModelByUuidAndGroupId(fileShortcut.getUuid(),
            portletDataContext.getScopeGroupId());

    if ((existingFileShortcut == null) || !(existingFileShortcut.getModel() instanceof DLFileShortcut)) {

        return;// www  .  j av  a2  s. c om
    }

    DLFileShortcut dlFileShortcut = (DLFileShortcut) existingFileShortcut.getModel();

    if (!dlFileShortcut.isInTrash()) {
        return;
    }

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(DLFileShortcut.class.getName());

    if (trashHandler.isRestorable(existingFileShortcut.getFileShortcutId())) {

        trashHandler.restoreTrashEntry(userId, existingFileShortcut.getFileShortcutId());
    }
}

From source file:com.liferay.document.library.jaxrs.FolderResource.java

License:Open Source License

protected RepositoryContentObject toObjectRepository(Object rco) {
    if (rco instanceof FileEntry) {
        FileEntry fileEntry = (FileEntry) rco;

        String url = _fileUriBuilder.build(fileEntry.getFileEntryId()).toString();

        return new RepositoryContentObject(fileEntry.getFileEntryId(), fileEntry.getTitle(), url,
                RepositoryContentObject.RepositoryContentType.FILE, fileEntry.getCreateDate(),
                fileEntry.getModifiedDate());
    } else if (rco instanceof Folder) {
        Folder folder = (Folder) rco;//from   w  ww  . j  ava 2 s. co  m

        String url = _folderUriBuilder.build(Long.toString(folder.getFolderId())).toString();

        return new RepositoryContentObject(folder.getFolderId(), folder.getName(), url,
                RepositoryContentObject.RepositoryContentType.FOLDER, folder.getCreateDate(),
                folder.getModifiedDate());
    } else if (rco instanceof FileShortcut) {
        FileShortcut fileShortcut = (FileShortcut) rco;

        String url = _fileUriBuilder.build(Long.toString(fileShortcut.getToFileEntryId())).toString();

        return new RepositoryContentObject(fileShortcut.getFileShortcutId(), fileShortcut.getToTitle(), url,
                RepositoryContentObject.RepositoryContentType.SHORTCUT, fileShortcut.getCreateDate(),
                fileShortcut.getModifiedDate());
    } else {
        throw new IllegalArgumentException(
                "Object must be an instance of FileEntry, Folder of " + "FileShortcut");
    }
}

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

License:Open Source License

@Test
public void testFileShortcutTreePathWhenMovingSubfolderWithFileShortcut() throws Exception {

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

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

    Folder folderAA = DLAppServiceUtil.addFolder(_group.getGroupId(), folderA.getFolderId(), "Folder AA",
            RandomTestUtil.randomString(), serviceContext);

    FileEntry fileEntry = addFileEntry(folderA.getFolderId(), "Entry.txt");

    FileShortcut fileShortcut = addFileShortcut(fileEntry, TestPropsValues.getGroupId(),
            folderAA.getFolderId());/* w  ww .j  a  v a  2s . com*/

    DLAppLocalServiceUtil.moveFolder(TestPropsValues.getUserId(), folderAA.getFolderId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, serviceContext);

    DLFileShortcut dlFileShortcut = DLFileShortcutLocalServiceUtil
            .getDLFileShortcut(fileShortcut.getFileShortcutId());

    Assert.assertEquals(dlFileShortcut.buildTreePath(), dlFileShortcut.getTreePath());
}

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

License:Open Source License

@Test
public void testRebuildTree() throws Exception {
    createTree();//from w ww .j a va  2s. com

    for (FileShortcut fileShortcut : _fileShortcuts) {
        DLFileShortcut dlFileShortcut = DLFileShortcutLocalServiceUtil
                .getDLFileShortcut(fileShortcut.getFileShortcutId());

        dlFileShortcut.setTreePath(null);

        DLFileShortcutLocalServiceUtil.updateDLFileShortcut(dlFileShortcut);
    }

    DLFileShortcutLocalServiceUtil.rebuildTree(TestPropsValues.getCompanyId());

    for (FileShortcut fileShortcut : _fileShortcuts) {
        DLFileShortcut dlFileShortcut = DLFileShortcutLocalServiceUtil
                .getDLFileShortcut(fileShortcut.getFileShortcutId());

        Assert.assertEquals(dlFileShortcut.buildTreePath(), dlFileShortcut.getTreePath());
    }
}

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

License:Open Source License

@Test
public void testFindF_FE_FS_ByG_F_M_M() throws Exception {
    QueryDefinition<?> queryDefinition = new QueryDefinition<>();

    queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED);

    List<Object> results = DLFolderFinderUtil.filterFindF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), new String[] { ContentTypes.TEXT_PLAIN }, false, queryDefinition);

    Assert.assertEquals(results.toString(), 3, results.size());

    for (Object result : results) {
        Assert.assertTrue(String.valueOf(result.getClass()), result instanceof DLFileEntry
                || result instanceof DLFileShortcut || result instanceof DLFolder);

        if (result instanceof DLFileEntry) {
            DLFileEntry dlFileEntry = (DLFileEntry) result;

            Assert.assertEquals("FE1.txt", dlFileEntry.getTitle());
        } else if (result instanceof FileShortcut) {
            FileShortcut fileShortcut = (FileShortcut) result;

            Assert.assertEquals(this._fileShortcut.getFileShortcutId(), fileShortcut.getFileShortcutId());
        } else if (result instanceof DLFolder) {
            DLFolder dlFolder = (DLFolder) result;

            Assert.assertEquals("Folder B", dlFolder.getName());
        }/*from   w  w w  .j a  v  a 2s. c o m*/
    }

    results = DLFolderFinderUtil.filterFindF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, null, true, queryDefinition);

    Assert.assertEquals(results.toString(), 2, results.size());

    boolean assertMountPointFolder = false;
    boolean assertRegularFolder = false;

    for (Object result : results) {
        Assert.assertTrue(String.valueOf(result.getClass()), result instanceof DLFolder);

        DLFolder dlFolder = (DLFolder) result;

        if (dlFolder.isMountPoint()) {
            Assert.assertEquals("Test Repository", dlFolder.getName());

            assertMountPointFolder = true;
        } else {
            Assert.assertEquals("Folder A", dlFolder.getName());

            assertRegularFolder = true;
        }
    }

    Assert.assertTrue(assertMountPointFolder);
    Assert.assertTrue(assertRegularFolder);
}

From source file:com.liferay.document.library.util.test.RepositoryModelUtilTest.java

License:Open Source License

@Test
public void testToFileShortcuts() throws Exception {
    populateFolderWithDLFileShortcuts();

    List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getFileEntries(_group.getGroupId(),
            _folder.getFolderId());/*from   ww w. j  a v a2 s.  com*/

    DLFileEntry dlFileEntry = dlFileEntries.get(0);

    List<DLFileShortcut> dlFileShortcuts = dlFileEntry.getFileShortcuts();

    List<FileShortcut> fileShortcuts = RepositoryModelUtil.toFileShortcuts(dlFileShortcuts);

    Assert.assertEquals(fileShortcuts.toString(), dlFileShortcuts.size(), fileShortcuts.size());

    for (int i = 0; i < dlFileShortcuts.size(); i++) {
        DLFileShortcut dlFileShortcut = dlFileShortcuts.get(i);

        FileShortcut fileShortcut = fileShortcuts.get(i);

        Assert.assertEquals(dlFileShortcut.getFileShortcutId(), fileShortcut.getFileShortcutId());
    }
}

From source file:com.liferay.document.library.verify.test.DLServiceVerifyProcessTest.java

License:Open Source License

@Test
public void testDLFileShortcutTreePathWithDLFileShortcutInTrash() throws Exception {

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

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

    FileEntry fileEntry = addFileEntry(parentFolder.getFolderId());

    FileShortcut fileShortcut = DLAppLocalServiceUtil.addFileShortcut(TestPropsValues.getUserId(),
            _group.getGroupId(), parentFolder.getFolderId(), fileEntry.getFileEntryId(), serviceContext);

    DLTrashServiceUtil.moveFileShortcutToTrash(fileShortcut.getFileShortcutId());

    DLFolderLocalServiceUtil.deleteFolder(parentFolder.getFolderId(), false);

    doVerify();/* w  w  w.  j av  a  2  s . c  o m*/
}