@Test public void testFindByMisversioned() throws Exception { long oldFileEntryId = _defaultRepositoryDLFileVersion.getFileEntryId(); try { _defaultRepositoryDLFileVersion.setFileEntryId(RandomTestUtil.randomLong()); DLFileVersionLocalServiceUtil.updateDLFileVersion(_defaultRepositoryDLFileVersion); List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getMisversionedFileEntries(); Assert.assertEquals(1, dlFileEntries.size()); DLFileEntry dlFileEntry = dlFileEntries.get(0); Assert.assertEquals("FE1.txt", dlFileEntry.getTitle()); } finally { _defaultRepositoryDLFileVersion.setFileEntryId(oldFileEntryId); DLFileVersionLocalServiceUtil.updateDLFileVersion(_defaultRepositoryDLFileVersion); } }
@Before public void setUp() throws Exception { setUpPermissionThreadLocal(); setUpPrincipalThreadLocal(); _group = GroupTestUtil.addGroup(); setUpParentFolder(); setUpResourcePermission(); List<DLFileEntryType> dlFileEntryTypes = DLFileEntryTypeLocalServiceUtil.getFileEntryTypes( PortalUtil.getCurrentAndAncestorSiteGroupIds(_group.getGroupId())); for (DLFileEntryType dlFileEntryType : dlFileEntryTypes) { String fileEntryTypeKey = dlFileEntryType.getFileEntryTypeKey(); if (fileEntryTypeKey.equals(DLFileEntryTypeConstants.FILE_ENTRY_TYPE_KEY_CONTRACT)) { _contractDLFileEntryTypeId = dlFileEntryType.getFileEntryTypeId(); } } ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.addDefaultTable( PortalUtil.getDefaultCompanyId(), DLFileEntry.class.getName()); ExpandoColumnLocalServiceUtil.addColumn( expandoTable.getTableId(), _EXPANDO_ATTRIBUTE_NAME, ExpandoColumnConstants.STRING, StringPool.BLANK); _serviceContext = getServiceContext(); FileEntry fileEntry = DLAppServiceUtil.addFileEntry( _group.getGroupId(), _parentFolder.getFolderId(), _SOURCE_FILE_NAME, ContentTypes.APPLICATION_OCTET_STREAM, _TITLE, StringPool.BLANK, StringPool.BLANK, _DATA_VERSION_1, _serviceContext); _fileVersion = DLFileVersionLocalServiceUtil.getFileVersion( fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT); }
@Test public void testRebuildTree() throws Exception { createTree(); for (FileEntry fileEntry : _fileEntries) { DLFileVersion dlFileVersion = DLFileVersionLocalServiceUtil.getFileVersion( fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT); dlFileVersion.setTreePath(null); DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion); } DLFileVersionLocalServiceUtil.rebuildTree(TestPropsValues.getCompanyId()); for (FileEntry fileEntry : _fileEntries) { DLFileVersion dlFileVersion = DLFileVersionLocalServiceUtil.getFileVersion( fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT); Assert.assertEquals(dlFileVersion.buildTreePath(), dlFileVersion.getTreePath()); } }
@Test public void testUpdateFileNameWhenUpdatingFileVersionStatus() throws Exception { DLFileEntry dlFileEntry = addDLFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, false); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId()); dlFileEntry = updateStatus(dlFileEntry.getLatestFileVersion(true), serviceContext); DLFileVersion dlFileVersion = dlFileEntry.getLatestFileVersion(true); String fileName = RandomTestUtil.randomString(); dlFileVersion.setFileName(fileName); DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion); dlFileEntry = updateStatus(dlFileVersion, serviceContext); Assert.assertEquals( DLUtil.getSanitizedFileName(fileName, dlFileEntry.getExtension()), dlFileEntry.getFileName()); }
@Test public void testFileVersionTreePathWhenMovingSubfolderWithFileVersion() 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(folderAA.getFolderId(), "Entry.txt"); DLAppLocalServiceUtil.moveFolder( TestPropsValues.getUserId(), folderAA.getFolderId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, serviceContext); DLFileVersion dlFileVersion = DLFileVersionLocalServiceUtil.getFileVersion( fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT); Assert.assertEquals(dlFileVersion.buildTreePath(), dlFileVersion.getTreePath()); }
protected static Object[] setUp( long repositoryId, String titleSuffix, ServiceContext serviceContext) throws Exception { Folder folder = DLAppLocalServiceUtil.addFolder( TestPropsValues.getUserId(), repositoryId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Folder A", StringPool.BLANK, serviceContext); DLAppLocalServiceUtil.addFolder( TestPropsValues.getUserId(), repositoryId, folder.getFolderId(), "Folder B", StringPool.BLANK, serviceContext); Folder folderC = DLAppLocalServiceUtil.addFolder( TestPropsValues.getUserId(), repositoryId, folder.getFolderId(), "Folder C", StringPool.BLANK, serviceContext); DLTrashServiceUtil.moveFolderToTrash(folderC.getFolderId()); FileEntry fileEntry = addFileEntry( _user.getUserId(), repositoryId, folder.getFolderId(), "FE1.txt", titleSuffix, ContentTypes.TEXT_PLAIN, DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT); LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry; DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry(); dlFileEntry.setExtraSettings("hello=world"); dlFileEntry.setSmallImageId(_SMALL_IMAGE_ID); dlFileEntry = DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry); DLFileVersion dlFileVersion = dlFileEntry.getFileVersion(); addFileEntry( TestPropsValues.getUserId(), repositoryId, folder.getFolderId(), "FE2.pdf", titleSuffix, ContentTypes.APPLICATION_PDF, DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL); fileEntry = addFileEntry( TestPropsValues.getUserId(), repositoryId, folder.getFolderId(), "FE3.txt", titleSuffix, ContentTypes.TEXT_PLAIN, DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL); fileEntry = DLAppServiceUtil.updateFileEntry( fileEntry.getFileEntryId(), "FE3.txt", ContentTypes.TEXT_PLAIN, "FE3.txt".concat(titleSuffix), StringPool.BLANK, StringPool.BLANK, false, RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext); dlFileEntry = ((LiferayFileEntry) fileEntry).getDLFileEntry(); dlFileEntry.setDescription("FE3.txt"); DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry); DLFileVersion dlFileVersion3 = dlFileEntry.getFileVersion(); dlFileVersion3.setExtraSettings("hello=world"); DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion3); DLTrashServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId()); return new Object[] {folder, dlFileVersion}; }