Search in sources :

Example 81 with Item

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

the class ItemsController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty() || feedResource == null)
        return;
    Item item = null;
    String itemId = entries.get(0).getOLATResourceable().getResourceableTypeName();
    if (itemId != null && itemId.startsWith("item=")) {
        itemId = itemId.substring(5, itemId.length());
        try {
            Long itemKey = Long.parseLong(itemId);
            item = FeedManager.getInstance().loadItem(itemKey);
        } catch (Exception e) {
            item = FeedManager.getInstance().loadItemByGuid(itemId);
        }
    }
    if (item != null) {
        activate(ureq, item);
    }
}
Also used : Item(org.olat.modules.webFeed.Item)

Example 82 with Item

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

the class FeedRepositoryIndexer 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 searchResourceContext, Object parentObject, OlatFullIndexer indexer) throws IOException, InterruptedException {
    RepositoryEntry repositoryEntry = (RepositoryEntry) parentObject;
    // used for log messages
    String repoEntryName = "*name not available*";
    try {
        repoEntryName = repositoryEntry.getDisplayname();
        if (isLogDebugEnabled()) {
            logDebug("Indexing: " + repoEntryName);
        }
        Feed feed = FeedManager.getInstance().loadFeed(repositoryEntry.getOlatResource());
        if (feed != null) {
            // Only index items. Feed itself is indexed by RepositoryEntryIndexer.
            List<Item> publishedItems = FeedManager.getInstance().loadPublishedItems(feed);
            if (isLogDebugEnabled()) {
                logDebug("PublishedItems size=" + publishedItems.size());
            }
            for (Item item : publishedItems) {
                SearchResourceContext feedContext = new SearchResourceContext(searchResourceContext);
                feedContext.setDocumentType(getDocumentType());
                OlatDocument itemDoc = new FeedItemDocument(item, feedContext);
                indexer.addDocument(itemDoc.getLuceneDocument());
            }
        }
    } catch (NullPointerException e) {
        logError("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) RepositoryEntry(org.olat.repository.RepositoryEntry) Feed(org.olat.modules.webFeed.Feed)

Example 83 with Item

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

the class FeedMainController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    Item item = null;
    String itemId = entries.get(0).getOLATResourceable().getResourceableTypeName();
    if (itemId != null && itemId.startsWith("item=")) {
        itemId = itemId.substring(5, itemId.length());
        try {
            Long itemKey = Long.parseLong(itemId);
            item = FeedManager.getInstance().loadItem(itemKey);
        } catch (Exception e) {
            item = FeedManager.getInstance().loadItemByGuid(itemId);
        }
    }
    if (item != null) {
        itemsCtr.activate(ureq, item);
    }
}
Also used : Item(org.olat.modules.webFeed.Item)

Example 84 with Item

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

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)

Example 85 with Item

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

the class FeedFileStorgeTest method loadItemsFromXML_shortening.

@Test
public void loadItemsFromXML_shortening() {
    StringBuffer sb = new StringBuffer(5000);
    for (int i = 0; i < 5000; i++) {
        sb.append("A");
    }
    String stringWith5000Chars = sb.toString();
    BlogFileResource resource = new BlogFileResource();
    Feed feed = new FeedImpl(resource);
    Item item = new ItemImpl(feed);
    String guid1 = "guid 1";
    item.setGuid(guid1);
    item.setAuthor(stringWith5000Chars);
    item.setExternalLink(stringWith5000Chars);
    item.setTitle(stringWith5000Chars);
    sut.saveItemAsXML(item);
    List<Item> items = sut.loadItemsFromXML(feed);
    Item reloadedItem = items.get(0);
    assertThat(reloadedItem.getAuthor()).hasSize(255);
    assertThat(reloadedItem.getExternalLink()).isNull();
    assertThat(reloadedItem.getTitle()).hasSize(1024);
    fileResourceManager.deleteFileResource(resource);
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) FeedImpl(org.olat.modules.webFeed.model.FeedImpl) BlogFileResource(org.olat.fileresource.types.BlogFileResource) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

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