Search in sources :

Example 71 with Item

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

the class FeedManagerImpl method loadFilteredAndSortedItems.

@Override
public List<Item> loadFilteredAndSortedItems(Feed feed, FeedSecurityCallback callback, Identity identity) {
    List<Item> items = loadItems(feed);
    List<Item> filteredItems = new ArrayList<>();
    final Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
    if (roles != null && (roles.isOLATAdmin() || feed.isExternal())) {
        // show all items
        filteredItems = items;
    } else {
        for (Item item : items) {
            if (item.isPublished()) {
                // everybody can see published items
                filteredItems.add(item);
            } else if (item.isScheduled() && callback.mayEditItems()) {
                // scheduled items can be seen by everybody who can edit items
                // (moderators)
                filteredItems.add(item);
            } else if (identity.getKey().equals(item.getAuthorKey())) {
                // scheduled items and drafts of oneself are shown
                filteredItems.add(item);
            } else if (item.isDraft()) {
                if (callback.mayViewAllDrafts()) {
                    filteredItems.add(item);
                } else if (identity.getKey() == item.getModifierKey()) {
                    filteredItems.add(item);
                }
            }
        }
    }
    Collections.sort(filteredItems, new ItemPublishDateComparator());
    return filteredItems;
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) ArrayList(java.util.ArrayList) Roles(org.olat.core.id.Roles) ItemPublishDateComparator(org.olat.modules.webFeed.model.ItemPublishDateComparator)

Example 72 with Item

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

the class FeedManagerImpl method getFeedArchive.

@Override
public VFSLeaf getFeedArchive(OLATResourceable resource) {
    VFSContainer rootContainer = feedFileStorage.getResourceContainer(resource);
    VFSContainer feedContainer = feedFileStorage.getOrCreateFeedContainer(resource);
    // Load the feed from database an store it to the XML file.
    Feed feed = feedDAO.loadFeed(resource);
    feed.setModelVersion(FeedImpl.CURRENT_MODEL_VERSION);
    feedFileStorage.saveFeedAsXML(feed);
    // Load the items from the database, make it export safe and store them
    // to XML files.
    List<Item> items = loadItems(feed);
    for (Item item : items) {
        if (feed.isInternal()) {
            // fallback in this case.
            if (!item.isAuthorFallbackSet()) {
                String author = item.getAuthor();
                if (StringHelper.containsNonWhitespace(author)) {
                    item.setAuthor(author);
                }
            }
        }
        feedFileStorage.saveItemAsXML(item);
    }
    // synchronize all zip processes for this feed
    // o_clusterOK by:fg
    VFSLeaf zip = coordinator.getSyncer().doInSync(resource, new SyncerCallback<VFSLeaf>() {

        @Override
        public VFSLeaf execute() {
            // Delete the old archive and recreate it from scratch
            String zipFileName = getZipFileName(resource);
            VFSItem oldArchive = rootContainer.resolve(zipFileName);
            if (oldArchive != null) {
                oldArchive.delete();
            }
            ZipUtil.zip(feedContainer.getItems(), rootContainer.createChildLeaf(zipFileName), false);
            return (VFSLeaf) rootContainer.resolve(zipFileName);
        }
    });
    // delete the XML files again. They are only needed for the export.
    for (Item item : items) {
        feedFileStorage.deleteItemXML(item);
    }
    feedFileStorage.deleteFeedXML(feed);
    return zip;
}
Also used : Item(org.olat.modules.webFeed.Item) VFSItem(org.olat.core.util.vfs.VFSItem) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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 73 with Item

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

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

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

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

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

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