Search in sources :

Example 31 with ItemImpl

use of org.olat.modules.webFeed.model.ItemImpl 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 32 with ItemImpl

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

the class BlogArtefactHandler method getContent.

@Override
protected void getContent(AbstractArtefact artefact, StringBuilder sb, SearchResourceContext context, EPFrontendManager ePFManager) {
    String content = ePFManager.getArtefactFullTextContent(artefact);
    if (content != null) {
        try {
            XStream xstream = XStreamHelper.createXStreamInstance();
            xstream.alias("item", ItemImpl.class);
            ItemImpl item = (ItemImpl) xstream.fromXML(content);
            String mapperBaseURL = "";
            Filter mediaUrlFilter = FilterFactory.getBaseURLToMediaRelativeURLFilter(mapperBaseURL);
            sb.append(mediaUrlFilter.filter(item.getDescription())).append(" ").append(mediaUrlFilter.filter(item.getContent()));
        } catch (Exception e) {
            log.warn("Cannot read an artefact of type blog while indexing", e);
        }
    }
}
Also used : Filter(org.olat.core.util.filter.Filter) XStream(com.thoughtworks.xstream.XStream) ItemImpl(org.olat.modules.webFeed.model.ItemImpl)

Example 33 with ItemImpl

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

the class ItemDAO method copyItem.

/**
 * Copy an Item to an other (or the same) feed.<br>
 * The attributes creationDate and lastModified are mandatory. If one of
 * these is null, no new item is created and the method returns null.
 *
 * @param feed
 * @param item
 * @return the created item or null
 */
public Item copyItem(Feed feed, Item item) {
    if (item == null) {
        return null;
    }
    Long key = item.getKey();
    Date creationDate = item.getCreationDate();
    Date lastModified = item.getLastModified();
    if (feed == null || key == null || creationDate == null || lastModified == null) {
        return null;
    }
    ItemImpl itemImpl = (ItemImpl) loadItem(item.getKey());
    dbInstance.getCurrentEntityManager().detach(itemImpl);
    itemImpl.setKey(null);
    itemImpl.setFeed(feed);
    dbInstance.getCurrentEntityManager().persist(itemImpl);
    return itemImpl;
}
Also used : ItemImpl(org.olat.modules.webFeed.model.ItemImpl) Date(java.util.Date)

Example 34 with ItemImpl

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

the class ItemDAO method createItem.

/**
 * Saves a new Item in the database. The Item has to have a Feed. Otherwise
 * the Item is not saved an the method returns null.
 *
 * @param feed
 * @param item
 * @return the created item or null
 */
public Item createItem(Feed feed, Item item) {
    if (feed == null)
        return null;
    ItemImpl itemImpl = (ItemImpl) item;
    itemImpl.setFeed(feed);
    if (itemImpl.getCreationDate() == null) {
        itemImpl.setCreationDate(new Date());
    }
    if (itemImpl.getLastModified() == null) {
        itemImpl.setLastModified(itemImpl.getCreationDate());
    }
    dbInstance.getCurrentEntityManager().persist(itemImpl);
    return itemImpl;
}
Also used : ItemImpl(org.olat.modules.webFeed.model.ItemImpl) Date(java.util.Date)

Example 35 with ItemImpl

use of org.olat.modules.webFeed.model.ItemImpl 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)

Aggregations

ItemImpl (org.olat.modules.webFeed.model.ItemImpl)70 Item (org.olat.modules.webFeed.Item)64 Test (org.junit.Test)58 Feed (org.olat.modules.webFeed.Feed)52 BlogFileResource (org.olat.fileresource.types.BlogFileResource)36 FeedImpl (org.olat.modules.webFeed.model.FeedImpl)36 VFSContainer (org.olat.core.util.vfs.VFSContainer)20 OLATResource (org.olat.resource.OLATResource)16 Date (java.util.Date)10 LocalDate (java.time.LocalDate)4 SyndContent (com.rometools.rome.feed.synd.SyndContent)2 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)2 XStream (com.thoughtworks.xstream.XStream)2 GregorianCalendar (java.util.GregorianCalendar)2 Link (org.olat.core.gui.components.link.Link)2 Identity (org.olat.core.id.Identity)2 Filter (org.olat.core.util.filter.Filter)2