Search in sources :

Example 11 with Feed

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

the class RomeFeedFetcherTest method justifiyFeed_Feed_null.

@Test
public void justifiyFeed_Feed_null() {
    String urlOld = "http://example.com/image1.jpg";
    Feed feed = new FeedImpl(oresMock);
    feed.setExternalImageURL(urlOld);
    Feed justifiedFeed = sut.justifyFeed(feed, null);
    assertThat(justifiedFeed.getExternalImageURL()).isEqualTo(urlOld);
}
Also used : FeedImpl(org.olat.modules.webFeed.model.FeedImpl) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

Example 12 with Feed

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

the class FeedMediaDispatcher method deliverFile.

/**
 * Dispatch and deliver the requested file given in the path.
 *
 * @param request
 * @param response
 * @param feed
 * @param path
 */
private void deliverFile(HttpServletRequest request, HttpServletResponse response, OLATResourceable feed, Path path) {
    // OLAT-5243 related: deliverFile can last arbitrary long, which can cause the open db connection to timeout and cause errors,
    // hence we need to do an intermediateCommit here
    DBFactory.getInstance().intermediateCommit();
    // Create the resource to be delivered
    MediaResource resource = null;
    FeedManager manager = FeedManager.getInstance();
    if (path.isFeedType()) {
        // Only create feed if modified. Send not modified response else.
        Identity identity = getIdentity(path.getIdentityKey());
        long sinceModifiedMillis = request.getDateHeader("If-Modified-Since");
        Feed feedLight = manager.loadFeed(feed);
        long lastModifiedMillis = -1;
        if (feedLight != null) {
            lastModifiedMillis = feedLight.getLastModified().getTime();
        }
        if (sinceModifiedMillis >= (lastModifiedMillis / 1000L) * 1000L) {
            // Send not modified response
            response.setDateHeader("last-modified", lastModifiedMillis);
            try {
                response.sendError(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            } catch (IOException e) {
                // Send not modified failed
                log.error("Send not modified failed", e);
                return;
            }
        } else {
            resource = manager.createFeedFile(feed, identity, path.getCourseId(), path.getNodeId());
        }
    } else if (path.isItemType()) {
        resource = manager.createItemMediaFile(feed, path.getItemId(), path.getItemFileName());
    } else if (path.isIconType()) {
        Size thumbnailSize = null;
        String thumbnail = request.getParameter("thumbnail");
        if (StringHelper.containsNonWhitespace(thumbnail)) {
            thumbnailSize = Size.parseString(thumbnail);
        }
        VFSLeaf resourceFile = manager.createFeedMediaFile(feed, path.getIconFileName(), thumbnailSize);
        if (resourceFile != null) {
            resource = new VFSMediaResource(resourceFile);
        }
    }
    // Eventually deliver the requested resource
    ServletUtil.serveResource(request, response, resource);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FeedManager(org.olat.modules.webFeed.manager.FeedManager) Size(org.olat.core.commons.services.image.Size) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) Feed(org.olat.modules.webFeed.Feed) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 13 with Feed

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

the class FeedDAO method createFeedForResourcable.

public Feed createFeedForResourcable(OLATResourceable ores) {
    if (ores == null)
        return null;
    Feed feed = new FeedImpl(ores);
    feed.setCreationDate(new Date());
    feed.setLastModified(feed.getCreationDate());
    dbInstance.getCurrentEntityManager().persist(feed);
    return feed;
}
Also used : FeedImpl(org.olat.modules.webFeed.model.FeedImpl) Date(java.util.Date) Feed(org.olat.modules.webFeed.Feed)

Example 14 with Feed

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

the class FeedFileStorge method loadFeedFromXML.

/**
 * Load the XML file of the feed from the feed container and convert it to
 * a feed.
 *
 * @param ores
 * @return the feed or null
 */
public Feed loadFeedFromXML(OLATResourceable ores) {
    Feed feed = null;
    VFSContainer feedContainer = getOrCreateFeedContainer(ores);
    if (feedContainer != null) {
        VFSLeaf leaf = (VFSLeaf) feedContainer.resolve(FEED_FILE_NAME);
        if (leaf != null) {
            feed = (FeedImpl) XStreamHelper.readObject(xstream, leaf.getInputStream());
            shorteningFeedToLengthOfDbAttribues(feed);
        }
    } else {
        log.warn("Feed XML-File could not be found on file system. Feed container: " + feedContainer);
    }
    return feed;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) Feed(org.olat.modules.webFeed.Feed)

Example 15 with Feed

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

the class FeedManagerImpl method deleteFeed.

@Override
public void deleteFeed(OLATResourceable ores) {
    // delete the container on the file system
    fileResourceManager.deleteFileResource(ores);
    // delete comments and ratings
    CommentAndRatingService commentAndRatingService = CoreSpringFactory.getImpl(CommentAndRatingService.class);
    commentAndRatingService.deleteAllIgnoringSubPath(ores);
    // delete the feed and all items from the database
    Feed feed = feedDAO.loadFeed(ores);
    itemDAO.removeItems(feed);
    feedDAO.removeFeedForResourceable(ores);
    resourceManager.deleteOLATResourceable(ores);
    feed = null;
}
Also used : CommentAndRatingService(org.olat.core.commons.services.commentAndRating.CommentAndRatingService) SyndFeed(com.rometools.rome.feed.synd.SyndFeed) Feed(org.olat.modules.webFeed.Feed) RSSFeed(org.olat.modules.webFeed.RSSFeed)

Aggregations

Feed (org.olat.modules.webFeed.Feed)216 Test (org.junit.Test)162 Item (org.olat.modules.webFeed.Item)98 FeedImpl (org.olat.modules.webFeed.model.FeedImpl)76 OLATResource (org.olat.resource.OLATResource)72 BlogFileResource (org.olat.fileresource.types.BlogFileResource)60 ItemImpl (org.olat.modules.webFeed.model.ItemImpl)52 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)36 VFSContainer (org.olat.core.util.vfs.VFSContainer)28 RSSFeed (org.olat.modules.webFeed.RSSFeed)24 Date (java.util.Date)22 RepositoryEntry (org.olat.repository.RepositoryEntry)12 OLATResourceable (org.olat.core.id.OLATResourceable)8 Path (java.nio.file.Path)6 LocalDate (java.time.LocalDate)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 FeedItemDocument (org.olat.modules.webFeed.search.document.FeedItemDocument)6 OlatDocument (org.olat.search.model.OlatDocument)6 IOException (java.io.IOException)4