Search in sources :

Example 1 with FeedEntry

use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.

the class FeedImplTest method setterGetterTest.

@Test
public void setterGetterTest() {
    instance.setTitle("text");
    logger.info(instance.getTitle().getValue());
    Assert.assertEquals(instance.getTitle().getValue(), "text");
    instance.setLink("http://localhost:8080/feeds/rss/2.0/test");
    Assert.assertEquals(instance.getLink(), "http://localhost:8080/feeds/rss/2.0/test");
    instance.setCopyright("text");
    Assert.assertEquals(instance.getCopyright(), "text");
    List<Person> person = new ArrayList<Person>();
    instance.setAuthors(person);
    Assert.assertEquals(instance.getAuthors(), person);
    instance.setContributors(person);
    Assert.assertEquals(instance.getContributors(), person);
    instance.setUri("http://testuri/");
    Assert.assertEquals(instance.getUri(), "http://testuri/");
    List<Category> category = new ArrayList<Category>();
    instance.setCategories(category);
    Assert.assertEquals(instance.getCategories(), category);
    instance.setDescription("description");
    Assert.assertEquals(instance.getDescription().getValue(), "description");
    Content content = new ContentImpl("desciption");
    instance.setDescription(content);
    Assert.assertEquals(instance.getDescription(), content);
    instance.setEncoding("encode");
    Assert.assertEquals(instance.getEncoding(), "encode");
    List<FeedEntry> feed = new ArrayList<FeedEntry>();
    instance.setEntries(feed);
    Assert.assertEquals(instance.getEntries(), feed);
    Image image = new ImageImpl("http://picture/");
    instance.setImage(image);
    Assert.assertEquals(instance.getImage(), image);
    instance.setLanguage("English");
    Assert.assertEquals(instance.getLanguage(), "English");
    List<Link> link = new ArrayList<Link>();
    instance.setLinks(link);
    Assert.assertEquals(instance.getLinks(), link);
    List<FeedExtension> feedExtension = new ArrayList<FeedExtension>();
    instance.setModules(feedExtension);
    Assert.assertEquals(instance.getModules(), feedExtension);
    Date date = new Date(21091981);
    instance.setPublishedDate(date);
    Assert.assertEquals(instance.getPublishedDate(), date);
    instance.setUpdatedDate(date);
    Assert.assertEquals(instance.getUpdatedDate(), date);
    instance.setTitle(content);
    Assert.assertEquals(instance.getTitle(), content);
}
Also used : FeedExtension(org.opencastproject.feed.api.FeedExtension) Category(org.opencastproject.feed.api.Category) ArrayList(java.util.ArrayList) Image(org.opencastproject.feed.api.Image) Date(java.util.Date) FeedEntry(org.opencastproject.feed.api.FeedEntry) Content(org.opencastproject.feed.api.Content) Person(org.opencastproject.feed.api.Person) Link(org.opencastproject.feed.api.Link) Test(org.junit.Test)

Example 2 with FeedEntry

use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.

the class FeedImplTest method testFeedImpl.

@Test
public void testFeedImpl() {
    try {
        Content title = new PlainTextContent("Test Feed");
        Content description = new HtmlContent("generated by <b>unit test</b>", Mode.Escaped);
        FeedImpl feed = new FeedImpl(Type.RSS, "http://localhost:8080/feeds/rss/2.0/test", title, description, "http://localhost:8080/feeds/rss/2.0/test");
        feed.addAuthor(new PersonImpl("Test User", "testuser@example.com", "http://www.example.com/testuser"));
        feed.addContributor(new PersonImpl("test university"));
        FeedEntry entry = new FeedEntryImpl(feed, "test entry", new LinkImpl("http://localhost:8080/feeds/rss/2.0/test/testentry"), "http://localhost:8080/feeds/rss/2.0/test/testentry");
        entry.addEnclosure(new EnclosureImpl("http://www.example.com/video.mp4", "video/mp4", "presenter/delivery", 12));
        feed.addEntry(entry);
        ITunesFeedExtension itunesmodule = new ITunesFeedExtension();
        itunesmodule.addKeyword("test");
        List<String> categories = new LinkedList<String>();
        categories.add("Higher Education");
        itunesmodule.setCategories(categories);
        feed.addModule(itunesmodule);
        DublinCoreExtension dcModule = new DublinCoreExtension();
        feed.addModule(dcModule);
        Assert.assertEquals(feed.getAuthors().get(0).getName(), "Test User");
        Assert.assertEquals(feed.getAuthors().get(0).getEmail(), "testuser@example.com");
        Assert.assertEquals(feed.getContributors().get(0).getName(), "test university");
        Assert.assertEquals(feed.getTitle().getValue(), "Test Feed");
        Assert.assertEquals(feed.getDescription().getType(), "text/html");
        Assert.assertEquals(feed.getType(), Type.RSS);
        Assert.assertEquals(feed.getLink(), "http://localhost:8080/feeds/rss/2.0/test");
    } catch (Exception e) {
        Assert.fail();
    }
// Todo test Services... but this cannot be done outside OSGI and the servlet Container, so this has to be done by
// an integration test.
}
Also used : LinkedList(java.util.LinkedList) FeedEntry(org.opencastproject.feed.api.FeedEntry) Content(org.opencastproject.feed.api.Content) Test(org.junit.Test)

Example 3 with FeedEntry

use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.

the class RomeRssFeed method init.

/**
 * Converts the replay feed to a rome feed, that can then be written to the reponse.
 *
 * @param originalFeed
 *          the original feed
 * @param feedInfo
 *          the feed info
 */
private void init(Feed originalFeed, FeedInfo feedInfo) {
    if (originalFeed == null)
        throw new IllegalArgumentException("Feed is null");
    // Create SyndFeed
    setEncoding(originalFeed.getEncoding());
    setFeedType(feedInfo.toROMEVersion());
    // Convert fields
    setModules(toRomeModules(originalFeed.getModules()));
    setAuthors(toRomePersons(originalFeed.getAuthors()));
    setCategories(toRomeCategories(originalFeed.getCategories()));
    setContributors(toRomePersons(originalFeed.getContributors()));
    setDescriptionEx(toRomeContent(originalFeed.getDescription()));
    setImage(toRomeImage(originalFeed.getImage()));
    setLanguage(originalFeed.getLanguage());
    setLinks(toRomeLinks(originalFeed.getLinks()));
    setPublishedDate(originalFeed.getPublishedDate());
    setTitleEx(toRomeContent(originalFeed.getTitle()));
    setCopyright(originalFeed.getCopyright());
    setUri(originalFeed.getUri());
    setLink(originalFeed.getLink());
    // Add SyndFeedEntries
    if (originalFeed.getEntries() != null) {
        List<SyndEntry> romeEntries = new ArrayList<SyndEntry>();
        for (FeedEntry entry : originalFeed.getEntries()) {
            SyndEntryImpl e = new SyndEntryImpl();
            e.setModules(toRomeModules(entry.getModules()));
            e.setAuthors(toRomePersons(entry.getAuthors()));
            e.setCategories(toRomeCategories(entry.getCategories()));
            e.setContents(toRomeContents(entry.getContents()));
            e.setContributors(toRomePersons(entry.getContributors()));
            e.setDescription(toRomeContent(entry.getDescription()));
            e.setEnclosures(toRomeEnclosures(entry.getEnclosures()));
            e.setPublishedDate(entry.getPublishedDate());
            e.setTitleEx(toRomeContent(entry.getTitle()));
            e.setUpdatedDate(entry.getUpdatedDate());
            e.setUri(entry.getUri());
            List<SyndLink> links = toRomeLinks(entry.getLinks());
            e.setLinks(links);
            // todo this strategy seems to work but is unproven
            if (links.size() > 0)
                e.setLink(links.get(0).getHref());
            romeEntries.add(e);
        }
        setEntries(romeEntries);
    }
}
Also used : FeedEntry(org.opencastproject.feed.api.FeedEntry) SyndEntry(com.rometools.rome.feed.synd.SyndEntry) SyndEntryImpl(com.rometools.rome.feed.synd.SyndEntryImpl) ArrayList(java.util.ArrayList) SyndLink(com.rometools.rome.feed.synd.SyndLink)

Example 4 with FeedEntry

use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.

the class AbstractFeedGenerator method addEpisode.

/**
 * Adds episode information to the feed.
 *
 * @param feed
 *          the feed
 * @param query
 *          the query that results in the feed
 * @param resultItem
 *          the episodes item
 * @param organization
 *          the organization
 * @return the feed
 */
protected Feed addEpisode(Feed feed, String[] query, SearchResultItem resultItem, Organization organization) {
    String link = getLinkForEntry(feed, resultItem, organization);
    String title = resultItem.getDcTitle();
    // Get the media enclosures
    List<MediaPackageElement> enclosures = getEnclosures(feed, resultItem);
    if (enclosures.size() == 0) {
        logger.debug("No media formats found for feed entry: {}", title);
        return feed;
    }
    String entryUri = null;
    // For RSS feeds, create multiple entries (one per enclosure). For Atom, add all enclosures to the same item
    switch(feed.getType()) {
        case RSS:
            entryUri = resultItem.getId();
            for (MediaPackageElement e : enclosures) {
                List<MediaPackageElement> enclosure = new ArrayList<MediaPackageElement>(1);
                enclosure.add(e);
                FeedEntry entry = createEntry(feed, title, link, entryUri);
                entry = populateFeedEntry(entry, resultItem, enclosure);
                entry.setUri(entry.getUri() + "/" + e.getIdentifier());
                feed.addEntry(entry);
            }
            break;
        case Atom:
            entryUri = generateEntryUri(resultItem.getId());
            FeedEntry entry = createEntry(feed, title, link, entryUri);
            entry = populateFeedEntry(entry, resultItem, enclosures);
            if (getLinkSelf(organization) != null) {
                LinkImpl self = new LinkImpl(getSelfLinkForEntry(feed, resultItem, organization));
                self.setRel("self");
                entry.addLink(self);
            }
            feed.addEntry(entry);
            if (feed.getUpdatedDate() == null)
                feed.setUpdatedDate(entry.getUpdatedDate());
            else if (entry.getUpdatedDate().before(feed.getUpdatedDate()))
                feed.setUpdatedDate(entry.getUpdatedDate());
            break;
        default:
            throw new IllegalStateException("Unsupported feed type " + feed.getType());
    }
    return feed;
}
Also used : FeedEntry(org.opencastproject.feed.api.FeedEntry) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList)

Example 5 with FeedEntry

use of org.opencastproject.feed.api.FeedEntry in project opencast by opencast.

the class RomeAtomFeed method init.

/**
 * Converts the replay feed to a rome feed, that can then be written to the reponse.
 *
 * @param originalFeed
 *          the original feed
 * @param feedInfo
 *          the feed info
 */
private void init(Feed originalFeed, FeedInfo feedInfo) {
    if (originalFeed == null)
        throw new IllegalArgumentException("Feed is null");
    // Create SyndFeed
    setEncoding(originalFeed.getEncoding());
    setFeedType(feedInfo.toROMEVersion());
    // Convert fields
    setModules(toRomeModules(originalFeed.getModules()));
    setAuthors(toRomeAtomPersons(originalFeed.getAuthors()));
    setCategories(toRomeAtomCategories(originalFeed.getCategories()));
    setContributors(toRomeAtomPersons(originalFeed.getContributors()));
    setInfo(toRomeAtomContent(originalFeed.getDescription()));
    setLanguage(originalFeed.getLanguage());
    setAlternateLinks(toRomeAtomLinks(originalFeed.getLinks()));
    setUpdated(originalFeed.getUpdatedDate());
    setTitleEx(toRomeAtomContent(originalFeed.getTitle()));
    setId(originalFeed.getUri());
    setCopyright(originalFeed.getCopyright());
    List<Link> otherLinks = new ArrayList<Link>();
    otherLinks.add(new LinkImpl(originalFeed.getLink()));
    setOtherLinks(toRomeAtomLinks(otherLinks));
    // Add SyndFeedEntries
    if (originalFeed.getEntries() != null) {
        List<Entry> romeEntries = new ArrayList<Entry>();
        for (FeedEntry entry : originalFeed.getEntries()) {
            Entry e = new Entry();
            e.setModules(toRomeModules(entry.getModules()));
            e.setAuthors(toRomeAtomPersons(entry.getAuthors()));
            e.setCategories(toRomeAtomCategories(entry.getCategories()));
            e.setContents(toRomeAtomContents(entry.getContents()));
            e.setContributors(toRomeAtomPersons(entry.getContributors()));
            e.setSummary(toRomeAtomContent(entry.getDescription()));
            e.setPublished(entry.getPublishedDate());
            e.setTitleEx(toRomeAtomContent(entry.getTitle()));
            e.setUpdated(entry.getUpdatedDate());
            e.setId(entry.getUri());
            List<com.rometools.rome.feed.atom.Link> links = toRomeAtomLinks(entry.getLinks());
            links.addAll(toRomeAtomEnclosures(entry.getEnclosures()));
            e.setOtherLinks(links);
            // todo this strategy seems to work but is unproven
            // if (links.size() > 0)
            // e.setLink(links.get(0).getHref());
            romeEntries.add(e);
        }
        setEntries(romeEntries);
    }
}
Also used : Entry(com.rometools.rome.feed.atom.Entry) FeedEntry(org.opencastproject.feed.api.FeedEntry) FeedEntry(org.opencastproject.feed.api.FeedEntry) ArrayList(java.util.ArrayList) Link(org.opencastproject.feed.api.Link)

Aggregations

FeedEntry (org.opencastproject.feed.api.FeedEntry)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)2 Content (org.opencastproject.feed.api.Content)2 Link (org.opencastproject.feed.api.Link)2 Entry (com.rometools.rome.feed.atom.Entry)1 SyndEntry (com.rometools.rome.feed.synd.SyndEntry)1 SyndEntryImpl (com.rometools.rome.feed.synd.SyndEntryImpl)1 SyndLink (com.rometools.rome.feed.synd.SyndLink)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Category (org.opencastproject.feed.api.Category)1 FeedExtension (org.opencastproject.feed.api.FeedExtension)1 Image (org.opencastproject.feed.api.Image)1 Person (org.opencastproject.feed.api.Person)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1