Search in sources :

Example 66 with Item

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

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

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

the class RomeFeedFetcherTest method convertEntry_Description_null.

@Test
public void convertEntry_Description_null() {
    when(syndEntryMock.getDescription()).thenReturn(null);
    when(syndEntryMock.getContents()).thenReturn(null);
    Item item = sut.convertEntry(feedMock, syndEntryMock);
    assertThat(item.getDescription()).isNull();
}
Also used : Item(org.olat.modules.webFeed.Item) Test(org.junit.Test)

Example 68 with Item

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

the class RomeFeedFetcherTest method convertEntry.

@Test
public void convertEntry() {
    // prepare the mock
    String author = "author";
    when(syndEntryMock.getAuthor()).thenReturn(author);
    String description = "description";
    when(syndEntryMock.getDescription().getValue()).thenReturn(description);
    String link = "link";
    when(syndEntryMock.getLink()).thenReturn(link);
    String title = "title";
    when(syndEntryMock.getTitle()).thenReturn(title);
    String uri = "uri";
    when(syndEntryMock.getUri()).thenReturn(uri);
    Date publishedDate = new Date();
    when(syndEntryMock.getPublishedDate()).thenReturn(publishedDate);
    Date updatedDate = new Date();
    when(syndEntryMock.getUpdatedDate()).thenReturn(updatedDate);
    List<SyndContent> contents = Arrays.asList(syndContentMock);
    when(syndEntryMock.getContents()).thenReturn(contents);
    when(syndEnclosureMock.getUrl()).thenReturn("URL");
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    when(syndEntryMock.getEnclosures()).thenReturn(enclosures);
    // call the method
    Item item = sut.convertEntry(feedMock, syndEntryMock);
    // test
    assertThat(item.getFeed()).isEqualTo(feedMock);
    assertThat(item.getAuthor()).isEqualTo(author);
    assertThat(item.getContent()).isNotNull();
    assertThat(item.getDescription()).isEqualTo(description);
    assertThat(item.getEnclosure()).isNotNull();
    assertThat(item.getExternalLink()).isEqualTo(link);
    assertThat(item.getTitle()).isEqualTo(title);
    assertThat(item.getGuid()).isEqualTo(uri);
    assertThat(item.getLastModified()).isEqualTo(updatedDate);
    assertThat(item.getPublishDate()).isEqualTo(publishedDate);
}
Also used : Item(org.olat.modules.webFeed.Item) SyndContent(com.rometools.rome.feed.synd.SyndContent) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Date(java.util.Date) Test(org.junit.Test)

Example 69 with Item

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

the class BlogArtefactHandler method prefillArtefactAccordingToSource.

/**
 * @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
 */
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
    super.prefillArtefactAccordingToSource(artefact, source);
    Feed feed = null;
    if (source instanceof Feed) {
        feed = (Feed) source;
        String subPath = getItemUUID(artefact.getBusinessPath());
        for (Item item : FeedManager.getInstance().loadItems(feed)) {
            if (subPath.equals(item.getGuid())) {
                prefillBlogArtefact(artefact, feed, item);
            }
        }
        artefact.setSignature(70);
    }
    String origBPath = artefact.getBusinessPath();
    String artSource = "";
    BusinessControl bc = BusinessControlFactory.getInstance().createFromString(origBPath);
    if (origBPath.contains(CourseNode.class.getSimpleName())) {
        // blog-post from inside a course, rebuild "course-name - feed-name"
        OLATResourceable ores = bc.popLauncherContextEntry().getOLATResourceable();
        RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(ores.getResourceableId());
        artSource = repoEntry.getDisplayname();
        if (feed != null) {
            artSource += " - " + feed.getTitle();
        }
    } else if (origBPath.contains(RepositoryEntry.class.getSimpleName())) {
        // blog-post from blog-LR, only get name itself
        if (feed != null) {
            artSource = feed.getTitle();
        }
    } else {
        // collecting a post from live-blog, [Identity:xy]
        if (feed != null) {
            artSource = feed.getTitle();
        }
    }
    artefact.setSource(artSource);
}
Also used : Item(org.olat.modules.webFeed.Item) OLATResourceable(org.olat.core.id.OLATResourceable) BusinessControl(org.olat.core.id.context.BusinessControl) CourseNode(org.olat.course.nodes.CourseNode) RepositoryEntry(org.olat.repository.RepositoryEntry) Feed(org.olat.modules.webFeed.Feed)

Example 70 with Item

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

the class FeedFileStorge method loadItemsFromXML.

/**
 * Load the XML file of all items of a feed and convert them to items.
 *
 * @param ores
 * @return
 */
public List<Item> loadItemsFromXML(OLATResourceable ores) {
    List<Item> items = new ArrayList<>();
    VFSContainer itemsContainer = getOrCreateFeedItemsContainer(ores);
    if (itemsContainer != null) {
        List<VFSItem> itemContainers = itemsContainer.getItems(new VFSItemMetaFilter());
        if (itemContainers != null && !itemContainers.isEmpty()) {
            for (VFSItem itemContainer : itemContainers) {
                Item item = loadItemFromXML((VFSContainer) itemContainer);
                if (item != null) {
                    shorteningItemToLengthOfDbAttributes(item);
                    items.add(item);
                }
            }
        }
    }
    return items;
}
Also used : VFSItemMetaFilter(org.olat.core.util.vfs.filters.VFSItemMetaFilter) Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

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