Search in sources :

Example 61 with Item

use of org.olat.modules.webFeed.Item in project openolat by klemens.

the class LiveBlogArtefactHandler method getContent.

@Override
protected void getContent(AbstractArtefact artefact, StringBuilder sb, SearchResourceContext context, EPFrontendManager ePFManager) {
    String businessPath = artefact.getBusinessPath();
    if (StringHelper.containsNonWhitespace(businessPath)) {
        manager = FeedManager.getInstance();
        String oresId = businessPath.substring(LIVEBLOG.length(), businessPath.length() - 1);
        OLATResourceable ores = OresHelper.createOLATResourceableInstance(BlogFileResource.TYPE_NAME, Long.parseLong(oresId));
        Feed feed = manager.loadFeed(ores);
        List<Item> publishedItems = manager.loadPublishedItems(feed);
        for (Item item : publishedItems) {
            OlatDocument itemDoc = new FeedItemDocument(item, context);
            String content = itemDoc.getContent();
            sb.append(content);
        }
    }
}
Also used : Item(org.olat.modules.webFeed.Item) OlatDocument(org.olat.search.model.OlatDocument) FeedItemDocument(org.olat.modules.webFeed.search.document.FeedItemDocument) OLATResourceable(org.olat.core.id.OLATResourceable) Feed(org.olat.modules.webFeed.Feed)

Example 62 with Item

use of org.olat.modules.webFeed.Item in project openolat by klemens.

the class RomeFeedFetcher method convertEntry.

/**
 * Converts a <code>SyndEntry</code> into an <code>Item</code>
 *
 * @param entry
 * @return
 */
protected Item convertEntry(Feed feed, SyndEntry entry) {
    Item item = new ItemImpl(feed);
    item.setAuthor(entry.getAuthor());
    item.setExternalLink(entry.getLink());
    item.setGuid(entry.getUri());
    item.setLastModified(entry.getUpdatedDate());
    item.setPublishDate(entry.getPublishedDate());
    item.setTitle(entry.getTitle());
    if (entry.getDescription() != null) {
        item.setDescription(entry.getDescription().getValue());
    }
    List<SyndContent> contents = entry.getContents();
    item.setContent(joinContents(contents));
    List<SyndEnclosure> enclosures = entry.getEnclosures();
    item.setEnclosure(convertEnclosures(enclosures));
    return item;
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure)

Example 63 with Item

use of org.olat.modules.webFeed.Item in project openolat by klemens.

the class ItemsController method createEditButtons.

/**
 * Creates all necessary buttons for editing the feed's items
 *
 * @param feed
 *            the current feed object
 */
private void createEditButtons(UserRequest ureq, Feed feed) {
    editButtons = new ArrayList<>();
    deleteButtons = new ArrayList<>();
    artefactLinks = new HashMap<>();
    if (feed.isInternal()) {
        addItemButton = LinkFactory.createButtonSmall("feed.add.item", vcItems, this);
        addItemButton.setElementCssClass("o_sel_feed_item_new");
        if (accessibleItems != null) {
            for (Item item : accessibleItems) {
                createButtonsForItem(ureq, feed, item);
            }
        }
    } else if (feed.isExternal()) {
        externalUrlButton = LinkFactory.createButtonSmall("feed.external.url", vcItems, this);
        externalUrlButton.setElementCssClass("o_sel_feed_item_new");
    } else if (feed.isUndefined()) {
        // The feed is whether internal nor external:
        // That is,
        // - it has just been created,
        // - all items have been removed or
        // - the feed url of an external feed has been set empty.
        // In such a case, the user can decide whether to make it internal
        // or
        // external.
        makeInternalAndExternalButtons();
    }
}
Also used : Item(org.olat.modules.webFeed.Item)

Example 64 with Item

use of org.olat.modules.webFeed.Item in project openolat by klemens.

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 65 with Item

use of org.olat.modules.webFeed.Item in project openolat by klemens.

the class FeedCourseNodeIndexer method doIndex.

/**
 * @see org.olat.search.service.indexer.Indexer#doIndex(org.olat.search.service.SearchResourceContext,
 *      java.lang.Object, org.olat.search.service.indexer.OlatFullIndexer)
 */
@Override
public void doIndex(SearchResourceContext courseResourceContext, ICourse course, CourseNode courseNode, OlatFullIndexer indexer) throws IOException, InterruptedException {
    SearchResourceContext courseNodeResourceContext = createSearchResourceContext(courseResourceContext, courseNode, getDocumentType());
    Document document = CourseNodeDocument.createDocument(courseNodeResourceContext, courseNode);
    indexer.addDocument(document);
    RepositoryEntry repositoryEntry = courseNode.getReferencedRepositoryEntry();
    if (repositoryEntry != null) {
        // used for log messages
        String repoEntryName = "*name not available*";
        try {
            repoEntryName = repositoryEntry.getDisplayname();
            if (log.isDebug()) {
                log.info("Indexing: " + repoEntryName);
            }
            Feed feed = FeedManager.getInstance().loadFeed(repositoryEntry.getOlatResource());
            List<Item> publishedItems = FeedManager.getInstance().loadPublishedItems(feed);
            // Create the olatDocument for the feed course node itself
            OlatDocument feedNodeDoc = new FeedNodeDocument(feed, courseNodeResourceContext);
            indexer.addDocument(feedNodeDoc.getLuceneDocument());
            // Only index items. FeedImpl itself is indexed by RepositoryEntryIndexer.
            for (Item item : publishedItems) {
                OlatDocument itemDoc = new FeedItemDocument(item, courseNodeResourceContext);
                indexer.addDocument(itemDoc.getLuceneDocument());
            }
        } catch (NullPointerException e) {
            log.error("Error indexing feed:" + repoEntryName, e);
        }
    }
}
Also used : Item(org.olat.modules.webFeed.Item) OlatDocument(org.olat.search.model.OlatDocument) FeedItemDocument(org.olat.modules.webFeed.search.document.FeedItemDocument) SearchResourceContext(org.olat.search.service.SearchResourceContext) FeedNodeDocument(org.olat.modules.webFeed.search.document.FeedNodeDocument) RepositoryEntry(org.olat.repository.RepositoryEntry) FeedNodeDocument(org.olat.modules.webFeed.search.document.FeedNodeDocument) Document(org.apache.lucene.document.Document) OlatDocument(org.olat.search.model.OlatDocument) FeedItemDocument(org.olat.modules.webFeed.search.document.FeedItemDocument) CourseNodeDocument(org.olat.search.service.document.CourseNodeDocument) Feed(org.olat.modules.webFeed.Feed)

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