Example usage for com.liferay.portal.kernel.portletfilerepository PortletFileRepositoryUtil deletePortletFileEntry

List of usage examples for com.liferay.portal.kernel.portletfilerepository PortletFileRepositoryUtil deletePortletFileEntry

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.portletfilerepository PortletFileRepositoryUtil deletePortletFileEntry.

Prototype

public static void deletePortletFileEntry(long fileEntryId) throws PortalException 

Source Link

Usage

From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsEntryUADEntityExporterTest.java

License:Open Source License

@Test
public void testExport() throws Exception {
    AnnouncementsEntry announcementsEntry = addAnnouncementsEntry(_user.getUserId());

    UADEntity uadEntity = _uadEntityAggregator.getUADEntity(String.valueOf(announcementsEntry.getEntryId()));

    _uadEntityExporter.export(uadEntity);

    FileEntry fileEntry = _getFileEntry(announcementsEntry.getCompanyId(), uadEntity.getUADEntityId());

    _verifyFileEntry(fileEntry, announcementsEntry);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
}

From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsEntryUADEntityExporterTest.java

License:Open Source License

@Test(expected = NoSuchFileEntryException.class)
public void testExportAll() throws Exception {
    AnnouncementsEntry announcementsEntry = addAnnouncementsEntry(TestPropsValues.getUserId());
    AnnouncementsEntry announcementsEntryExported = addAnnouncementsEntry(_user.getUserId());

    _uadEntityExporter.exportAll(_user.getUserId());

    FileEntry fileEntry = _getFileEntry(announcementsEntryExported.getCompanyId(),
            String.valueOf(announcementsEntryExported.getEntryId()));

    _verifyFileEntry(fileEntry, announcementsEntryExported);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());

    _getFileEntry(announcementsEntry.getCompanyId(), String.valueOf(announcementsEntry.getEntryId()));
}

From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsFlagUADEntityExporterTest.java

License:Open Source License

@Test
public void testExport() throws Exception {
    AnnouncementsFlag announcementsFlag = addAnnouncementsFlag(_user.getUserId());

    UADEntity uadEntity = _uadEntityAggregator.getUADEntity(String.valueOf(announcementsFlag.getFlagId()));

    _uadEntityExporter.export(uadEntity);

    FileEntry fileEntry = _getFileEntry(announcementsFlag.getCompanyId(), uadEntity.getUADEntityId());

    _verifyFileEntry(fileEntry, announcementsFlag);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
}

From source file:com.liferay.announcements.uad.exporter.test.AnnouncementsFlagUADEntityExporterTest.java

License:Open Source License

@Test(expected = NoSuchFileEntryException.class)
public void testExportAll() throws Exception {
    AnnouncementsFlag announcementsFlag = addAnnouncementsFlag(TestPropsValues.getUserId());
    AnnouncementsFlag announcementsFlagExported = addAnnouncementsFlag(_user.getUserId());

    _uadEntityExporter.exportAll(_user.getUserId());

    FileEntry fileEntry = _getFileEntry(announcementsFlagExported.getCompanyId(),
            String.valueOf(announcementsFlagExported.getFlagId()));

    _verifyFileEntry(fileEntry, announcementsFlagExported);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());

    _getFileEntry(announcementsFlag.getCompanyId(), String.valueOf(announcementsFlag.getFlagId()));
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.DELETE)
@Override//from   w  ww .  j a  v a  2  s . com
@SystemEvent(type = SystemEventConstants.TYPE_DELETE)
public BlogsEntry deleteEntry(BlogsEntry entry) throws PortalException {

    // Entry

    blogsEntryPersistence.remove(entry);

    // Resources

    resourceLocalService.deleteResource(entry.getCompanyId(), BlogsEntry.class.getName(),
            ResourceConstants.SCOPE_INDIVIDUAL, entry.getEntryId());

    // Image

    imageLocalService.deleteImage(entry.getSmallImageId());

    // Subscriptions

    subscriptionLocalService.deleteSubscriptions(entry.getCompanyId(), BlogsEntry.class.getName(),
            entry.getEntryId());

    // Statistics

    blogsStatsUserLocalService.updateStatsUser(entry.getGroupId(), entry.getUserId(), entry.getDisplayDate());

    // Asset

    assetEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entry.getEntryId());

    // Attachments

    long coverImageFileEntryId = entry.getCoverImageFileEntryId();

    if (coverImageFileEntryId != 0) {
        PortletFileRepositoryUtil.deletePortletFileEntry(coverImageFileEntryId);
    }

    long smallImageFileEntryId = entry.getSmallImageFileEntryId();

    if (smallImageFileEntryId != 0) {
        PortletFileRepositoryUtil.deletePortletFileEntry(smallImageFileEntryId);
    }

    // Comment

    deleteDiscussion(entry);

    // Expando

    expandoRowLocalService.deleteRows(entry.getEntryId());

    // Ratings

    ratingsStatsLocalService.deleteStats(BlogsEntry.class.getName(), entry.getEntryId());

    // Trash

    trashEntryLocalService.deleteEntry(BlogsEntry.class.getName(), entry.getEntryId());

    // Workflow

    workflowInstanceLinkLocalService.deleteWorkflowInstanceLinks(entry.getCompanyId(), entry.getGroupId(),
            BlogsEntry.class.getName(), entry.getEntryId());

    return entry;
}

From source file:com.liferay.blogs.service.impl.BlogsEntryLocalServiceImpl.java

License:Open Source License

@Indexable(type = IndexableType.REINDEX)
@Override//  ww w . ja v a2  s  .co m
public BlogsEntry updateEntry(long userId, long entryId, String title, String subtitle, String urlTitle,
        String description, String content, Date displayDate, boolean allowPingbacks, boolean allowTrackbacks,
        String[] trackbacks, String coverImageCaption, ImageSelector coverImageImageSelector,
        ImageSelector smallImageImageSelector, ServiceContext serviceContext) throws PortalException {

    // Entry

    BlogsEntry entry = blogsEntryPersistence.findByPrimaryKey(entryId);

    validate(title, urlTitle, content);

    String oldUrlTitle = entry.getUrlTitle();

    entry.setTitle(title);
    entry.setSubtitle(subtitle);

    if (Validator.isNotNull(urlTitle)) {
        entry.setUrlTitle(getUniqueUrlTitle(entryId, entry.getGroupId(), urlTitle));
    }

    entry.setDescription(description);
    entry.setContent(content);
    entry.setDisplayDate(displayDate);
    entry.setAllowPingbacks(allowPingbacks);
    entry.setAllowTrackbacks(allowTrackbacks);

    if (entry.isPending() || entry.isDraft()) {
    } else {
        entry.setStatus(WorkflowConstants.STATUS_DRAFT);
    }

    entry.setExpandoBridgeAttributes(serviceContext);

    blogsEntryPersistence.update(entry);

    // Asset

    updateAsset(userId, entry, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(),
            serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority());

    // Images

    long coverImageFileEntryId = entry.getCoverImageFileEntryId();
    String coverImageURL = entry.getCoverImageURL();

    long deletePreviousCoverImageFileEntryId = 0;

    if (coverImageImageSelector != null) {
        coverImageURL = coverImageImageSelector.getImageURL();

        if (coverImageImageSelector.getImageBytes() != null) {
            coverImageFileEntryId = addCoverImageFileEntry(userId, entry.getGroupId(), entryId,
                    coverImageImageSelector);
        } else {
            coverImageFileEntryId = 0;
        }

        deletePreviousCoverImageFileEntryId = entry.getCoverImageFileEntryId();
    }

    long smallImageFileEntryId = entry.getSmallImageFileEntryId();
    String smallImageURL = entry.getSmallImageURL();

    long deletePreviousSmallImageFileEntryId = 0;

    if (smallImageImageSelector != null) {
        smallImageURL = smallImageImageSelector.getImageURL();

        if (smallImageImageSelector.getImageBytes() != null) {
            smallImageFileEntryId = addSmallImageFileEntry(userId, entry.getGroupId(), entryId,
                    smallImageImageSelector);
        } else {
            smallImageFileEntryId = 0;
        }

        deletePreviousSmallImageFileEntryId = entry.getSmallImageFileEntryId();
    }

    validate(smallImageFileEntryId);

    entry.setCoverImageCaption(coverImageCaption);
    entry.setCoverImageFileEntryId(coverImageFileEntryId);
    entry.setCoverImageURL(coverImageURL);

    if ((smallImageFileEntryId != 0) || Validator.isNotNull(smallImageURL)) {

        entry.setSmallImage(true);
    }

    entry.setSmallImageFileEntryId(smallImageFileEntryId);
    entry.setSmallImageURL(smallImageURL);

    blogsEntryPersistence.update(entry);

    // Workflow

    boolean pingOldTrackbacks = false;

    if (!oldUrlTitle.equals(entry.getUrlTitle())) {
        pingOldTrackbacks = true;
    }

    serviceContext.setAttribute("pingOldTrackbacks", String.valueOf(pingOldTrackbacks));

    if (ArrayUtil.isNotEmpty(trackbacks)) {
        serviceContext.setAttribute("trackbacks", trackbacks);
    } else {
        serviceContext.setAttribute("trackbacks", null);
    }

    entry = startWorkflowInstance(userId, entry, serviceContext);

    if (deletePreviousCoverImageFileEntryId != 0) {
        PortletFileRepositoryUtil.deletePortletFileEntry(deletePreviousCoverImageFileEntryId);
    }

    if (deletePreviousSmallImageFileEntryId != 0) {
        PortletFileRepositoryUtil.deletePortletFileEntry(deletePreviousSmallImageFileEntryId);
    }

    return entry;
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditEntryMVCActionCommand.java

License:Open Source License

protected Object[] updateEntry(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long entryId = ParamUtil.getLong(actionRequest, "entryId");

    String title = ParamUtil.getString(actionRequest, "title");
    String subtitle = ParamUtil.getString(actionRequest, "subtitle");
    String urlTitle = ParamUtil.getString(actionRequest, "urlTitle");

    String description = StringPool.BLANK;

    boolean customAbstract = ParamUtil.getBoolean(actionRequest, "customAbstract");

    if (customAbstract) {
        description = ParamUtil.getString(actionRequest, "description");

        if (Validator.isNull(description)) {
            throw new EntryDescriptionException();
        }/*  w  w w .  j  ava2s .  co m*/
    }

    String content = ParamUtil.getString(actionRequest, "content");

    int displayDateMonth = ParamUtil.getInteger(actionRequest, "displayDateMonth");
    int displayDateDay = ParamUtil.getInteger(actionRequest, "displayDateDay");
    int displayDateYear = ParamUtil.getInteger(actionRequest, "displayDateYear");
    int displayDateHour = ParamUtil.getInteger(actionRequest, "displayDateHour");
    int displayDateMinute = ParamUtil.getInteger(actionRequest, "displayDateMinute");
    int displayDateAmPm = ParamUtil.getInteger(actionRequest, "displayDateAmPm");

    if (displayDateAmPm == Calendar.PM) {
        displayDateHour += 12;
    }

    boolean allowPingbacks = ParamUtil.getBoolean(actionRequest, "allowPingbacks");
    boolean allowTrackbacks = ParamUtil.getBoolean(actionRequest, "allowTrackbacks");
    String[] trackbacks = StringUtil.split(ParamUtil.getString(actionRequest, "trackbacks"));

    long coverImageFileEntryId = ParamUtil.getLong(actionRequest, "coverImageFileEntryId");
    String coverImageURL = ParamUtil.getString(actionRequest, "coverImageURL");
    String coverImageFileEntryCropRegion = ParamUtil.getString(actionRequest, "coverImageFileEntryCropRegion");

    String coverImageCaption = ParamUtil.getString(actionRequest, "coverImageCaption");

    long oldCoverImageId = 0;
    String oldCoverImageURL = StringPool.BLANK;
    long oldSmallImageId = 0;
    String oldSmallImageURL = StringPool.BLANK;

    if (entryId != 0) {
        BlogsEntry entry = _blogsEntryLocalService.getEntry(entryId);

        oldCoverImageId = entry.getCoverImageFileEntryId();
        oldCoverImageURL = entry.getCoverImageURL();
        oldSmallImageId = entry.getSmallImageId();
        oldSmallImageURL = entry.getSmallImageURL();
    }

    BlogsEntryImageSelectorHelper blogsEntryCoverImageSelectorHelper = new BlogsEntryImageSelectorHelper(
            coverImageFileEntryId, oldCoverImageId, coverImageFileEntryCropRegion, coverImageURL,
            oldCoverImageURL);

    ImageSelector coverImageImageSelector = blogsEntryCoverImageSelectorHelper.getImageSelector();

    long smallImageFileEntryId = ParamUtil.getLong(actionRequest, "smallImageFileEntryId");
    String smallImageURL = ParamUtil.getString(actionRequest, "smallImageURL");

    BlogsEntryImageSelectorHelper blogsEntrySmallImageSelectorHelper = new BlogsEntryImageSelectorHelper(
            smallImageFileEntryId, oldSmallImageId, StringPool.BLANK, smallImageURL, oldSmallImageURL);

    ImageSelector smallImageImageSelector = blogsEntrySmallImageSelectorHelper.getImageSelector();

    ServiceContext serviceContext = ServiceContextFactory.getInstance(BlogsEntry.class.getName(),
            actionRequest);

    BlogsEntry entry = null;
    List<BlogsEntryAttachmentFileEntryReference> blogsEntryAttachmentFileEntryReferences = new ArrayList<>();

    if (entryId <= 0) {

        // Add entry

        entry = _blogsEntryService.addEntry(title, subtitle, urlTitle, description, content, displayDateMonth,
                displayDateDay, displayDateYear, displayDateHour, displayDateMinute, allowPingbacks,
                allowTrackbacks, trackbacks, coverImageCaption, coverImageImageSelector,
                smallImageImageSelector, serviceContext);

        BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentFileEntryHelper = new BlogsEntryAttachmentFileEntryHelper();

        List<FileEntry> tempBlogsEntryAttachments = blogsEntryAttachmentFileEntryHelper
                .getTempBlogsEntryAttachmentFileEntries(content);

        if (!tempBlogsEntryAttachments.isEmpty()) {
            Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(),
                    entry.getGroupId());

            blogsEntryAttachmentFileEntryReferences = blogsEntryAttachmentFileEntryHelper
                    .addBlogsEntryAttachmentFileEntries(entry.getGroupId(), themeDisplay.getUserId(),
                            entry.getEntryId(), folder.getFolderId(), tempBlogsEntryAttachments);

            content = blogsEntryAttachmentFileEntryHelper.updateContent(content,
                    blogsEntryAttachmentFileEntryReferences);

            entry.setContent(content);

            _blogsEntryLocalService.updateBlogsEntry(entry);
        }

        for (FileEntry tempBlogsEntryAttachment : tempBlogsEntryAttachments) {

            PortletFileRepositoryUtil.deletePortletFileEntry(tempBlogsEntryAttachment.getFileEntryId());
        }
    } else {

        // Update entry

        boolean sendEmailEntryUpdated = ParamUtil.getBoolean(actionRequest, "sendEmailEntryUpdated");

        serviceContext.setAttribute("sendEmailEntryUpdated", sendEmailEntryUpdated);

        String emailEntryUpdatedComment = ParamUtil.getString(actionRequest, "emailEntryUpdatedComment");

        serviceContext.setAttribute("emailEntryUpdatedComment", emailEntryUpdatedComment);

        entry = _blogsEntryLocalService.getEntry(entryId);

        BlogsEntryAttachmentFileEntryHelper blogsEntryAttachmentHelper = new BlogsEntryAttachmentFileEntryHelper();

        List<FileEntry> tempBlogsEntryAttachmentFileEntries = blogsEntryAttachmentHelper
                .getTempBlogsEntryAttachmentFileEntries(content);

        if (!tempBlogsEntryAttachmentFileEntries.isEmpty()) {
            Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(),
                    entry.getGroupId());

            blogsEntryAttachmentFileEntryReferences = blogsEntryAttachmentHelper
                    .addBlogsEntryAttachmentFileEntries(entry.getGroupId(), themeDisplay.getUserId(),
                            entry.getEntryId(), folder.getFolderId(), tempBlogsEntryAttachmentFileEntries);

            content = blogsEntryAttachmentHelper.updateContent(content,
                    blogsEntryAttachmentFileEntryReferences);
        }

        entry = _blogsEntryService.updateEntry(entryId, title, subtitle, urlTitle, description, content,
                displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
                allowPingbacks, allowTrackbacks, trackbacks, coverImageCaption, coverImageImageSelector,
                smallImageImageSelector, serviceContext);

        for (FileEntry tempBlogsEntryAttachmentFileEntry : tempBlogsEntryAttachmentFileEntries) {

            PortletFileRepositoryUtil
                    .deletePortletFileEntry(tempBlogsEntryAttachmentFileEntry.getFileEntryId());
        }
    }

    if (blogsEntryCoverImageSelectorHelper.isFileEntryTempFile()) {
        _blogsEntryLocalService.addOriginalImageFileEntry(themeDisplay.getUserId(), entry.getGroupId(),
                entry.getEntryId(), coverImageImageSelector);

        PortletFileRepositoryUtil.deletePortletFileEntry(coverImageFileEntryId);
    }

    if (blogsEntrySmallImageSelectorHelper.isFileEntryTempFile()) {
        _blogsEntryLocalService.addOriginalImageFileEntry(themeDisplay.getUserId(), entry.getGroupId(),
                entry.getEntryId(), smallImageImageSelector);

        PortletFileRepositoryUtil.deletePortletFileEntry(smallImageFileEntryId);
    }

    return new Object[] { entry, blogsEntryAttachmentFileEntryReferences };
}

From source file:com.liferay.blogs.web.internal.portlet.action.EditImageMVCActionCommand.java

License:Open Source License

protected void deleteImages(ActionRequest actionRequest) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long[] deleteFileEntryIds = null;

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");

    if (fileEntryId > 0) {
        deleteFileEntryIds = new long[] { fileEntryId };
    } else {//from w w  w.j a  v  a2 s .  c o m
        deleteFileEntryIds = StringUtil.split(ParamUtil.getString(actionRequest, "deleteFileEntryIds"), 0L);
    }

    Folder folder = _blogsEntryLocalService.addAttachmentsFolder(themeDisplay.getUserId(),
            themeDisplay.getScopeGroupId());

    for (long deleteFileEntryId : deleteFileEntryIds) {
        FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(deleteFileEntryId);

        if (fileEntry.getFolderId() != folder.getFolderId()) {
            continue;
        }

        if ((fileEntry.getUserId() == themeDisplay.getUserId()) || BlogsPermission.contains(
                themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), ActionKeys.UPDATE)) {

            PortletFileRepositoryUtil.deletePortletFileEntry(deleteFileEntryId);
        }
    }
}

From source file:com.liferay.bookmarks.uad.exporter.test.BookmarksEntryUADEntityExporterTest.java

License:Open Source License

@Test
public void testExport() throws Exception {
    BookmarksEntry bookmarksEntry = addBookmarksEntry(_user.getUserId());

    List<UADEntity> uadEntities = _uadEntityAggregator.getUADEntities(_user.getUserId());

    UADEntity uadEntity = uadEntities.get(0);

    _uadEntityExporter.export(uadEntity);

    FileEntry fileEntry = _getFileEntry(bookmarksEntry.getCompanyId(), uadEntity.getUADEntityId());

    _verifyFileEntry(fileEntry, bookmarksEntry);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());
}

From source file:com.liferay.bookmarks.uad.exporter.test.BookmarksEntryUADEntityExporterTest.java

License:Open Source License

@Test(expected = NoSuchFileEntryException.class)
public void testExportAll() throws Exception {
    BookmarksEntry bookmarksEntry = addBookmarksEntry(TestPropsValues.getUserId());
    BookmarksEntry bookmarksEntryExported = addBookmarksEntry(_user.getUserId());

    _uadEntityExporter.exportAll(_user.getUserId());

    FileEntry fileEntry = _getFileEntry(bookmarksEntry.getCompanyId(),
            String.valueOf(bookmarksEntryExported.getEntryId()));

    _verifyFileEntry(fileEntry, bookmarksEntryExported);

    PortletFileRepositoryUtil.deletePortletFileEntry(fileEntry.getFileEntryId());

    _getFileEntry(bookmarksEntry.getCompanyId(), String.valueOf(bookmarksEntry.getEntryId()));
}