Search in sources :

Example 1 with Item

use of org.olat.modules.webFeed.Item in project OpenOLAT by OpenOLAT.

the class ItemsController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    // reload feed for this event and make sure the updated feed object is
    // in the view
    feedResource = feedManager.loadFeed(feedResource);
    accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (source == cmc) {
        if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
            // Check if this item has ever been added to the feed. If not,
            // remove the temp dir
            cleanupTmpItemMediaDir(currentItem);
            // internally or subscribe to an external feed.
            if (!feedManager.hasItems(feedResource)) {
                feedResource = feedManager.updateFeedMode(null, feedResource);
                makeInternalAndExternalButtons();
            }
            // release lock
            feedManager.releaseLock(lock);
        }
    } else if (source == confirmDialogCtr && DialogBoxUIFactory.isYesEvent(event)) {
        // The user confirmed that the item shall be deleted
        Item item = (Item) ((DialogBoxController) source).getUserObject();
        lock = feedManager.acquireLock(feedResource, item, getIdentity());
        if (lock.isSuccess()) {
            // remove the item from the naviCtr
            naviCtr.remove(item);
            // permanently remove item
            feedResource = feedManager.deleteItem(item);
            // remove delete and edit buttons of this item
            for (Link deleteButton : deleteButtons) {
                if (item.equals(deleteButton.getUserObject())) {
                    deleteButtons.remove(deleteButton);
                    break;
                }
            }
            for (Link editButton : editButtons) {
                if (item.equals(editButton.getUserObject())) {
                    editButtons.remove(editButton);
                    break;
                }
            }
            // items manually or from an external source/feed.
            if (!feedManager.hasItems(feedResource)) {
                makeInternalAndExternalButtons();
                // The subscription/feed url from the feed info is obsolete
                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
            } else {
                if (callback.mayEditItems() || callback.mayCreateItems()) {
                    createEditButtons(ureq, feedResource);
                }
                createCommentsAndRatingsLinks(ureq, feedResource);
            }
            vcItems.setDirty(true);
            // in case we were in single item view, show all items
            mainPanel.setContent(vcItems);
            feedManager.releaseLock(lock);
            lock = null;
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_DELETE, getClass(), LoggingResourceable.wrap(item));
        } else {
            String fullName = userManager.getUserDisplayName(lock.getOwner());
            showInfo("feed.item.is.being.edited.by", fullName);
        }
    } else if (source == itemFormCtr) {
        if (event.equals(Event.CHANGED_EVENT) || event.equals(Event.CANCELLED_EVENT)) {
            if (event.equals(Event.CHANGED_EVENT)) {
                FileElement mediaFile = currentItem.getMediaFile();
                if (feedManager.getItemContainer(currentItem) == null) {
                    // Ups, deleted in the meantime by someone else
                    // remove the item from the naviCtr
                    naviCtr.remove(currentItem);
                } else {
                    if (!accessibleItems.contains(currentItem)) {
                        // Add the modified item if it is not part of the
                        // feed
                        feedResource = feedManager.createItem(feedResource, currentItem, mediaFile);
                        if (feedResource != null) {
                            createButtonsForItem(ureq, feedResource, currentItem);
                            createItemLink(currentItem);
                            // Add date component
                            String guid = currentItem.getGuid();
                            if (currentItem.getDate() != null) {
                                DateComponentFactory.createDateComponentWithYear("date." + guid, currentItem.getDate(), vcItems);
                            }
                            // Add comments and rating
                            createCommentsAndRatingsLink(ureq, feedResource, currentItem);
                            // add it to the navigation controller
                            naviCtr.add(currentItem);
                            accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
                            if (accessibleItems != null && accessibleItems.size() == 1) {
                                // First item added, show feed url (for
                                // subscription)
                                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
                                // Set the base URI of the feed for the
                                // current user. All users
                                // have unique URIs.
                                helper.setURIs(currentItem.getFeed());
                            }
                        }
                    } else {
                        // Write item file
                        currentItem = feedManager.updateItem(currentItem, mediaFile);
                        if (itemCtr != null) {
                            displayItemController(ureq, currentItem);
                        }
                        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_EDIT, getClass(), LoggingResourceable.wrap(currentItem));
                    }
                }
                vcItems.setDirty(true);
                // if the current item is displayed, update the view
                if (itemCtr != null) {
                    itemCtr.getInitialComponent().setDirty(true);
                }
            } else if (event.equals(Event.CANCELLED_EVENT)) {
                // Check if this item has ever been added to the feed. If
                // not, remove the temp dir
                cleanupTmpItemMediaDir(currentItem);
                // internally or subscribe to an external feed.
                if (!feedManager.hasItems(feedResource)) {
                    feedResource = feedManager.updateFeedMode(null, feedResource);
                    makeInternalAndExternalButtons();
                }
            }
            // release the lock
            feedManager.releaseLock(lock);
            // Dispose the cmc and the podcastFormCtr.
            cmc.deactivate();
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
        }
    } else if (source == externalUrlCtr) {
        if (event.equals(Event.CHANGED_EVENT)) {
            String externalUrl = externalUrlCtr.getExternalFeedUrlEl();
            feedManager.updateExternalFeedUrl(feedResource, externalUrl);
        } else if (event.equals(Event.CHANGED_EVENT)) {
        // nothing to do
        }
        cmc.deactivate();
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(externalUrlCtr);
        externalUrlCtr = null;
    } else if (source == naviCtr && event instanceof NavigationEvent) {
        List<? extends Dated> selItems = ((NavigationEvent) event).getSelectedItems();
        List<Item> items = new ArrayList<>();
        for (Dated item : selItems) {
            if (item instanceof Item) {
                items.add((Item) item);
            }
        }
        if (callback.mayEditItems() || callback.mayCreateItems()) {
            createEditButtons(ureq, feedResource);
        }
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
        mainPanel.setContent(vcItems);
    } else if (source == itemCtr) {
        if (event == Event.BACK_EVENT) {
            mainPanel.setContent(vcItems);
            removeAsListenerAndDispose(itemCtr);
            itemCtr = null;
        }
    } else if (source instanceof UserCommentsAndRatingsController) {
        UserCommentsAndRatingsController commentsRatingsCtr = (UserCommentsAndRatingsController) source;
        if (event == UserCommentsAndRatingsController.EVENT_COMMENT_LINK_CLICKED) {
            // go to details page
            Item item = (Item) commentsRatingsCtr.getUserObject();
            if (item != null) {
                ItemController myItemCtr = displayItemController(ureq, item);
                List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(ItemController.ACTIVATION_KEY_COMMENTS);
                myItemCtr.activate(ureq, entries, null);
            }
        }
    }
    // reload everything
    if (feedResource != null) {
        resetItems(ureq, feedResource);
    }
}
Also used : NavigationEvent(org.olat.core.commons.controllers.navigation.NavigationEvent) ArrayList(java.util.ArrayList) ContextEntry(org.olat.core.id.context.ContextEntry) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Item(org.olat.modules.webFeed.Item) UserCommentsAndRatingsController(org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) Dated(org.olat.core.commons.controllers.navigation.Dated) Link(org.olat.core.gui.components.link.Link)

Example 2 with Item

use of org.olat.modules.webFeed.Item in project OpenOLAT by OpenOLAT.

the class FeedManagerImpl method copy.

@Override
public boolean copy(OLATResource sourceResource, OLATResource targetResource) {
    // copy the folders and files
    File sourceFileroot = fileResourceManager.getFileResourceRootImpl(sourceResource).getBasefile();
    File sourceFeedRoot = new File(sourceFileroot, getFeedKind(sourceResource));
    File targetFileroot = fileResourceManager.getFileResourceRootImpl(targetResource).getBasefile();
    FileUtils.copyFileToDir(sourceFeedRoot, targetFileroot, "add file resource");
    // load the feed and the items from the database
    Feed sourceFeed = feedDAO.loadFeed(sourceResource);
    List<Item> items = itemDAO.loadItems(sourceFeed);
    // copy the feed in the database
    Feed targetFeed = feedDAO.copyFeed(sourceResource, targetResource);
    // copy the items in the database
    for (Item item : items) {
        itemDAO.copyItem(targetFeed, item);
    }
    return true;
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) RSSFeed(org.olat.modules.webFeed.RSSFeed)

Example 3 with Item

use of org.olat.modules.webFeed.Item in project OpenOLAT by OpenOLAT.

the class FeedManagerImpl method saveExternalItems.

/**
 * Fetch all items of the external feed and store them in the database.
 *
 * @param feed
 */
private void saveExternalItems(Feed feed) {
    List<Item> externalItems = externalFeedFetcher.fetchItems(feed);
    for (Item externalItem : externalItems) {
        Item reloaded = itemDAO.loadItemByGuid(feed.getKey(), externalItem.getGuid());
        if (reloaded == null) {
            Date now = new Date();
            externalItem.setCreationDate(now);
            // Init the last modified
            if (externalItem.getLastModified() == null) {
                externalItem.setLastModified(now);
            }
            // published date should never be null because it triggers notifications
            if (externalItem.getPublishDate() == null) {
                externalItem.setPublishDate(now);
            }
            if (dbInstance.isMySQL()) {
                mysqlCleanUp(externalItem);
            }
            itemDAO.createItem(feed, externalItem);
        } else {
            // Do not overwrite initial values
            if (externalItem.getLastModified() != null) {
                reloaded.setLastModified(externalItem.getLastModified());
            }
            if (externalItem.getPublishDate() != null) {
                reloaded.setPublishDate(externalItem.getPublishDate());
            }
            reloaded.setAuthor(externalItem.getAuthor());
            reloaded.setExternalLink(externalItem.getExternalLink());
            reloaded.setTitle(externalItem.getTitle());
            reloaded.setDescription(externalItem.getDescription());
            reloaded.setContent(externalItem.getContent());
            reloaded.setEnclosure(externalItem.getEnclosure());
            if (dbInstance.isMySQL()) {
                mysqlCleanUp(externalItem);
            }
            itemDAO.updateItem(reloaded);
        }
    }
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Date(java.util.Date)

Example 4 with Item

use of org.olat.modules.webFeed.Item in project OpenOLAT by OpenOLAT.

the class FeedNotificationsHandler method createSubscriptionInfo.

@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si;
    Publisher p = subscriber.getPublisher();
    Date latestNews = p.getLatestNewsDate();
    try {
        final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            String title;
            try {
                RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
                if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
                    return notificationsManager.getNoSubscriptionInfo();
                }
                String displayName = re.getDisplayname();
                if ("CourseModule".equals(p.getResName())) {
                    ICourse course = CourseFactory.loadCourse(re);
                    CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
                    if (node == null) {
                        notificationsManager.deactivate(p);
                        return notificationsManager.getNoSubscriptionInfo();
                    }
                    title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
                } else {
                    title = getHeader(translator, displayName);
                }
            } catch (Exception e) {
                log.error("Unknown Exception", e);
                return notificationsManager.getNoSubscriptionInfo();
            }
            OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
            Feed feed = feedManager.loadFeed(feedOres);
            List<Item> listItems = feedManager.loadItems(feed);
            List<SubscriptionListItem> items = new ArrayList<>();
            for (Item item : listItems) {
                if (!item.isDraft()) {
                    appendSubscriptionItem(item, p, compareDate, translator, items);
                }
            }
            si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
        } else {
            // no news
            si = notificationsManager.getNoSubscriptionInfo();
        }
    } catch (Exception e) {
        log.error("Unknown Exception", e);
        si = notificationsManager.getNoSubscriptionInfo();
    }
    return si;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) ArrayList(java.util.ArrayList) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) RepositoryEntry(org.olat.repository.RepositoryEntry) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Date(java.util.Date) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) Item(org.olat.modules.webFeed.Item) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) CourseNode(org.olat.course.nodes.CourseNode) Feed(org.olat.modules.webFeed.Feed)

Example 5 with Item

use of org.olat.modules.webFeed.Item in project OpenOLAT by OpenOLAT.

the class ItemDAO method createItem.

/**
 * Create a new Item and connect it with the feed.
 *
 * @param feed
 * @return the created item
 */
public Item createItem(Feed feed) {
    if (feed == null)
        return null;
    Item item = new ItemImpl(feed);
    item.setCreationDate(new Date());
    item.setLastModified(item.getCreationDate());
    dbInstance.getCurrentEntityManager().persist(item);
    return item;
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) Date(java.util.Date)

Aggregations

Item (org.olat.modules.webFeed.Item)142 Test (org.junit.Test)98 Feed (org.olat.modules.webFeed.Feed)98 ItemImpl (org.olat.modules.webFeed.model.ItemImpl)64 OLATResource (org.olat.resource.OLATResource)44 BlogFileResource (org.olat.fileresource.types.BlogFileResource)38 FeedImpl (org.olat.modules.webFeed.model.FeedImpl)38 VFSContainer (org.olat.core.util.vfs.VFSContainer)26 Date (java.util.Date)16 VFSItem (org.olat.core.util.vfs.VFSItem)14 ArrayList (java.util.ArrayList)8 OLATResourceable (org.olat.core.id.OLATResourceable)8 RepositoryEntry (org.olat.repository.RepositoryEntry)8 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)6 LocalDate (java.time.LocalDate)6 RSSFeed (org.olat.modules.webFeed.RSSFeed)6 FeedItemDocument (org.olat.modules.webFeed.search.document.FeedItemDocument)6 OlatDocument (org.olat.search.model.OlatDocument)6 SyndContent (com.rometools.rome.feed.synd.SyndContent)4 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)4