Example usage for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN

List of usage examples for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN.

Prototype

String TEXT_PLAIN

To view the source code for com.liferay.portal.kernel.util ContentTypes TEXT_PLAIN.

Click Source Link

Usage

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

License:Open Source License

protected FileEntry addFileEntry(long folderId, String sourceFileName) throws Exception {

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

    return DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), _group.getGroupId(), folderId,
            sourceFileName, ContentTypes.TEXT_PLAIN,
            RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext);
}

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

License:Open Source License

@Test
public void testFileEntryTypeRestrictions() throws Exception {

    // Configure folder

    DLAppLocalServiceUtil.updateFolder(_folder.getFolderId(), _folder.getParentFolderId(), _folder.getName(),
            _folder.getDescription(),//from  w  w w  .  j  av a  2  s  .c o  m
            _getFolderServiceContext(_contractDLFileEntryType, _marketingBannerDLFileEntryType));

    // Add file to folder

    String name = "Test.txt";
    byte[] bytes = _CONTENT.getBytes();

    FileEntry fileEntry = DLAppServiceUtil.addFileEntry(_group.getGroupId(), _folder.getFolderId(), name,
            ContentTypes.TEXT_PLAIN, name, "", "", bytes,
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    assertFileEntryType(fileEntry, _contractDLFileEntryType);

    // Add file to subfolder

    fileEntry = DLAppServiceUtil.addFileEntry(_group.getGroupId(), _subfolder.getFolderId(), name,
            ContentTypes.TEXT_PLAIN, name, "", "", bytes,
            ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

    assertFileEntryType(fileEntry, _contractDLFileEntryType);

    // Configure subfolder

    DLAppLocalServiceUtil.updateFolder(_subfolder.getFolderId(), _subfolder.getParentFolderId(),
            _subfolder.getName(), _subfolder.getDescription(),
            _getFolderServiceContext(_basicDocumentDLFileEntryType));

    fileEntry = DLAppServiceUtil.getFileEntry(fileEntry.getFileEntryId());

    assertFileEntryType(fileEntry, _basicDocumentDLFileEntryType);
}

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

License:Open Source License

protected FileEntry addFileEntry(long folderId, String sourceFileName) throws Exception {

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

    return DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), group.getGroupId(), folderId,
            sourceFileName, ContentTypes.TEXT_PLAIN,
            RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE), serviceContext);
}

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

License:Open Source License

protected void deleteVersion(boolean versioned, boolean leaveCheckedOut) throws Exception {

    _fileEntry = addFileEntry(parentFolder.getFolderId(), _VERSION_1_0);

    long fileEntryId = _fileEntry.getFileEntryId();

    if (versioned) {
        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
                TestPropsValues.getUserId());

        DLAppServiceUtil.updateFileEntry(fileEntryId, null, ContentTypes.TEXT_PLAIN, _VERSION_1_1,
                StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext);
    }/*from w ww  .j  a  va 2s.c om*/

    if (leaveCheckedOut) {
        DLAppServiceUtil.checkOutFileEntry(fileEntryId, new ServiceContext());

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

        DLAppServiceUtil.updateFileEntry(fileEntryId, null, ContentTypes.TEXT_PLAIN, _VERSION_PWC,
                StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext);
    }

    if (versioned && leaveCheckedOut) {
        Assert.assertEquals(3, getFileVersionsCount());

        failDeleteFileVersion("PWC");
        deleteFileVersion("1.1", _VERSION_PWC, true);
        failDeleteFileVersion("1.0");

        Assert.assertEquals(2, getFileVersionsCount());
    } else if (versioned) {
        Assert.assertEquals(2, getFileVersionsCount());

        deleteFileVersion("1.1", _VERSION_1_0, false);
        failDeleteFileVersion("1.0");

        Assert.assertEquals(1, getFileVersionsCount());
    } else if (leaveCheckedOut) {
        Assert.assertEquals(2, getFileVersionsCount());

        failDeleteFileVersion("PWC");
        failDeleteFileVersion("1.0");

        Assert.assertEquals(2, getFileVersionsCount());
    } else {
        Assert.assertEquals(1, getFileVersionsCount());

        failDeleteFileVersion("1.0");

        Assert.assertEquals(1, getFileVersionsCount());
    }
}

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

License:Open Source License

protected void revertVersion(boolean versioned, boolean leaveCheckedOut) throws Exception {

    _fileEntry = addFileEntry(parentFolder.getFolderId(), _VERSION_1_0);

    long fileEntryId = _fileEntry.getFileEntryId();

    if (versioned) {
        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId(),
                TestPropsValues.getUserId());

        DLAppServiceUtil.updateFileEntry(fileEntryId, null, ContentTypes.TEXT_PLAIN, _VERSION_1_1,
                StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext);
    }//  w  w  w  .  j  av a  2s .  com

    if (leaveCheckedOut) {
        DLAppServiceUtil.checkOutFileEntry(fileEntryId, new ServiceContext());

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

        DLAppServiceUtil.updateFileEntry(fileEntryId, null, ContentTypes.TEXT_PLAIN, _VERSION_PWC,
                StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext);
    }

    if (versioned && leaveCheckedOut) {
        Assert.assertEquals(3, getFileVersionsCount());

        failRevertFileVersion("PWC");
        revertFileVersion("1.1", _VERSION_1_1);
        revertFileVersion("1.0", _VERSION_1_0);

        Assert.assertEquals(3, getFileVersionsCount());
    } else if (versioned) {
        Assert.assertEquals(2, getFileVersionsCount());

        failRevertFileVersion("1.1");
        revertFileVersion("1.0", _VERSION_1_0);

        Assert.assertEquals(3, getFileVersionsCount());
    } else if (leaveCheckedOut) {
        Assert.assertEquals(2, getFileVersionsCount());

        failRevertFileVersion("PWC");
        revertFileVersion("1.0", _VERSION_1_0);

        Assert.assertEquals(2, getFileVersionsCount());
    } else {
        Assert.assertEquals(1, getFileVersionsCount());

        failRevertFileVersion("1.0");

        Assert.assertEquals(1, getFileVersionsCount());
    }
}

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

License:Open Source License

@Test
public void testWithExtensionWithContent() throws Exception {
    testVersionUpdate(_FULL_FILE_NAME, _ZERO_BYTES, ContentTypes.TEXT_PLAIN, _FULL_FILE_NAME,
            CONTENT.getBytes(), ContentTypes.TEXT_PLAIN);
}

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

License:Open Source License

@Test
public void testWithExtensionWithoutContent() throws Exception {
    testVersionUpdate(_FULL_FILE_NAME, _ZERO_BYTES, ContentTypes.TEXT_PLAIN, _FULL_FILE_NAME, _ZERO_BYTES,
            ContentTypes.TEXT_PLAIN);//from  w  w  w  .j  a v a2s . c  o m
}

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

License:Open Source License

@Test
public void testWithoutExtensionWithContent() throws Exception {
    testVersionUpdate(_BASE_FILE_NAME, _ZERO_BYTES, ContentTypes.APPLICATION_OCTET_STREAM, _BASE_FILE_NAME,
            CONTENT.getBytes(), ContentTypes.TEXT_PLAIN);
}

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

License:Open Source License

@Before
public void setUp() throws Exception {
    _group = GroupTestUtil.addGroup();//from w  ww  .  ja v a 2 s  .c  o  m

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

    long classNameId = PortalUtil.getClassNameId(PortletRepository.class.getName());

    RepositoryLocalServiceUtil.addRepository(TestPropsValues.getUserId(), _group.getGroupId(), classNameId,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Test Repository", StringUtil.randomString(),
            StringUtil.randomString(), new UnicodeProperties(), false, serviceContext);

    _folder = DLAppLocalServiceUtil.addFolder(TestPropsValues.getUserId(), _group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "Folder A", StringPool.BLANK, serviceContext);

    DLAppLocalServiceUtil.addFolder(TestPropsValues.getUserId(), _group.getGroupId(), _folder.getFolderId(),
            "Folder B", StringPool.BLANK, serviceContext);

    Folder folder = DLAppLocalServiceUtil.addFolder(TestPropsValues.getUserId(), _group.getGroupId(),
            _folder.getFolderId(), "Folder C", StringPool.BLANK, serviceContext);

    DLTrashServiceUtil.moveFolderToTrash(folder.getFolderId());

    FileEntry fileEntry = addFileEntry(_group.getGroupId(), _folder.getFolderId(), "FE1.txt",
            ContentTypes.TEXT_PLAIN);

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

    addFileEntry(_group.getGroupId(), _folder.getFolderId(), "FE2.html", ContentTypes.TEXT_HTML);

    fileEntry = addFileEntry(_group.getGroupId(), _folder.getFolderId(), "FE3.txt", ContentTypes.TEXT_PLAIN);

    DLTrashServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());
}

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

License:Open Source License

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

    queryDefinition.setStatus(WorkflowConstants.STATUS_ANY);

    Assert.assertEquals(6, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), null, false, queryDefinition));
    Assert.assertEquals(5, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), new String[] { ContentTypes.TEXT_PLAIN }, false, queryDefinition));
    Assert.assertEquals(1, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, null, false, queryDefinition));
    Assert.assertEquals(2, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, null, true, queryDefinition));

    queryDefinition.setStatus(WorkflowConstants.STATUS_APPROVED);

    Assert.assertEquals(4, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), null, false, queryDefinition));
    Assert.assertEquals(2, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), new String[] { ContentTypes.TEXT_HTML }, false, queryDefinition));

    queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH);

    Assert.assertEquals(2, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), null, false, queryDefinition));

    queryDefinition.setStatus(WorkflowConstants.STATUS_IN_TRASH, true);

    Assert.assertEquals(4, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), null, false, queryDefinition));
    Assert.assertEquals(3, DLFolderFinderUtil.filterCountF_FE_FS_ByG_F_M_M(_group.getGroupId(),
            _folder.getFolderId(), new String[] { ContentTypes.TEXT_PLAIN }, false, queryDefinition));
}