Search in sources :

Example 56 with Item

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

the class ItemDAOTest method createItem_Feed_Null.

@Test
public void createItem_Feed_Null() {
    Item tempItem = new ItemImpl(null);
    Item item = itemDao.createItem(null, tempItem);
    dbInstance.commitAndCloseSession();
    // check values
    assertThat(item).isNull();
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) Test(org.junit.Test)

Example 57 with Item

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

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

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

the class FeedManagerImpl method importFeedFromXML.

@Override
public void importFeedFromXML(OLATResource ores, boolean removeIdentityKeys) {
    Feed feedFromXml = feedFileStorage.loadFeedFromXML(ores);
    if (feedFromXml == null)
        return;
    // Check if the feed already exits or create it. The feed exists
    // possibly, if a previous migration from an XML feed was not
    // successful.
    Feed feed = feedDAO.loadFeed(ores);
    if (feed == null) {
        feedFromXml.setResourceableId(ores.getResourceableId());
        // Use the display name instead of the username
        if (!removeIdentityKeys && feedFromXml.getAuthor() != null) {
            String authorName = UserManager.getInstance().getUserDisplayName(feedFromXml.getAuthor());
            if (authorName != null) {
                feedFromXml.setAuthor(authorName);
            }
        }
        feed = feedDAO.createFeed(feedFromXml);
        log.info("Feed imported " + "(" + ores.getResourceableTypeName() + "): " + ores.getResourceableId());
    }
    List<Item> itemsFromXml = feedFileStorage.loadItemsFromXML(ores);
    itemsFromXml = fixFeedVersionIssues(feedFromXml, itemsFromXml);
    for (Item itemFromXml : itemsFromXml) {
        // Check if the item already exits or create it.
        Item item = itemDAO.loadItemByGuid(feed.getKey(), itemFromXml.getGuid());
        if (item == null) {
            if (removeIdentityKeys) {
                itemFromXml.setAuthorKey(null);
                itemFromXml.setModifierKey(null);
            } else {
                // Check if the identity exists
                if (itemFromXml.getAuthorKey() != null && securityManager.loadIdentityShortByKey(itemFromXml.getAuthorKey()) == null) {
                    itemFromXml.setAuthorKey(null);
                }
                if (itemFromXml.getModifierKey() != null && securityManager.loadIdentityShortByKey(itemFromXml.getModifierKey()) == null) {
                    itemFromXml.setModifierKey(null);
                }
            }
            itemDAO.createItem(feed, itemFromXml);
            log.info("Item imported: " + itemFromXml.getGuid());
        }
        feedFileStorage.deleteItemXML(itemFromXml);
    }
    if (feed.isExternal()) {
        saveExternalItems(feed);
        saveExternalFeed(feed);
    }
    feedFileStorage.deleteFeedXML(feed);
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) RSSFeed(org.olat.modules.webFeed.RSSFeed)

Example 59 with Item

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

the class FeedManagerImpl method updateItem.

@Override
public Item updateItem(Item item, FileElement file) {
    if (item == null)
        return null;
    Item updatedItem = itemDAO.loadItem(item.getKey());
    if (updatedItem != null) {
        Enclosure enclosure = replaceEnclosure(item, file);
        item.setEnclosure(enclosure);
        updatedItem = itemDAO.updateItem(item);
        markPublisherNews(updatedItem.getFeed());
    }
    return updatedItem;
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) Enclosure(org.olat.modules.webFeed.Enclosure)

Example 60 with Item

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

the class BlogEntryMediaHandler method getInformations.

@Override
public MediaInformations getInformations(Object mediaObject) {
    BlogEntryMedia entry = (BlogEntryMedia) mediaObject;
    Item item = entry.getItem();
    return new Informations(item.getTitle(), item.getDescription());
}
Also used : Item(org.olat.modules.webFeed.Item) MediaInformations(org.olat.modules.portfolio.MediaInformations)

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