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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations