Search in sources :

Example 36 with ItemImpl

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

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 37 with ItemImpl

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

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 38 with ItemImpl

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

the class ItemsController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Component source, Event event) {
    // feed for this event and make sure the updated feed object is in the
    // view
    feedResource = feedManager.loadFeed(feedResource);
    accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (source == addItemButton) {
        currentItem = new ItemImpl(feedResource);
        currentItem.setDraft(true);
        currentItem.setAuthorKey(ureq.getIdentity().getKey());
        // Generate new GUID for item, needed for media files that are
        // stored relative to the GUID
        currentItem.setGuid(CodeHelper.getGlobalForeverUniqueID());
        itemFormCtr = uiFactory.createItemFormController(ureq, getWindowControl(), currentItem);
        activateModalDialog(itemFormCtr, uiFactory.getTranslator().translate("feed.edit.item"));
    } else if (editButtons != null && editButtons.contains(source)) {
        currentItem = (Item) ((Link) source).getUserObject();
        // meantime
        if (accessibleItems.contains(currentItem)) {
            lock = feedManager.acquireLock(feedResource, currentItem, getIdentity());
            if (lock.isSuccess()) {
                // reload to prevent stale object, then launch editor
                currentItem = feedManager.loadItem(currentItem.getKey());
                itemFormCtr = uiFactory.createItemFormController(ureq, getWindowControl(), currentItem);
                activateModalDialog(itemFormCtr, uiFactory.getTranslator().translate("feed.edit.item"));
            } else {
                String fullName = userManager.getUserDisplayName(lock.getOwner());
                showInfo("feed.item.is.being.edited.by", fullName);
            }
        } else {
            showInfo("feed.item.is.being.edited.by", "unknown");
        }
    } else if (deleteButtons != null && deleteButtons.contains(source)) {
        Item item = (Item) ((Link) source).getUserObject();
        confirmDialogCtr = activateYesNoDialog(ureq, null, translate("feed.item.confirm.delete"), confirmDialogCtr);
        confirmDialogCtr.setUserObject(item);
    } else if (itemLinks != null && itemLinks.contains(source)) {
        Item item = (Item) ((Link) source).getUserObject();
        if (item != null) {
            displayItemController(ureq, item);
        }
    } else if (source == externalUrlButton) {
        externalUrlCtr = uiFactory.createExternalUrlController(ureq, getWindowControl(), feedResource);
        activateModalDialog(externalUrlCtr, uiFactory.getTranslator().translate("feed.external.url"));
    } else if (source == makeInternalButton) {
        if (feedResource.isUndefined()) {
            feedResource = feedManager.updateFeedMode(Boolean.FALSE, feedResource);
        } else if (feedResource.isExternal()) {
            externalUrlButton = LinkFactory.createButtonSmall("feed.external.url", vcItems, this);
            externalUrlButton.setElementCssClass("o_sel_feed_item_new");
            // Very special case: another user concurrently changed feed to
            // external. Do nothing
            vcItems.setDirty(true);
            return;
        }
        // else nothing to do, already set to internal by a concurrent user
        // Add temporary item and open edit dialog
        addItemButton = LinkFactory.createButton("feed.add.item", vcItems, this);
        addItemButton.setElementCssClass("o_sel_feed_item_new");
        currentItem = new ItemImpl(feedResource);
        currentItem.setDraft(true);
        currentItem.setAuthorKey(ureq.getIdentity().getKey());
        // Generate new GUID for item, needed for media files that are
        // stored relative to the GUID
        currentItem.setGuid(CodeHelper.getGlobalForeverUniqueID());
        itemFormCtr = uiFactory.createItemFormController(ureq, getWindowControl(), currentItem);
        activateModalDialog(itemFormCtr, uiFactory.getTranslator().translate("feed.edit.item"));
        // do logging
        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_EDIT, getClass(), LoggingResourceable.wrap(feedResource));
    } else if (source == makeExternalButton) {
        if (feedResource.isUndefined()) {
            externalUrlButton = LinkFactory.createButtonSmall("feed.external.url", vcItems, this);
            externalUrlButton.setElementCssClass("o_sel_feed_item_new");
            feedResource = feedManager.updateFeedMode(Boolean.TRUE, feedResource);
            vcItems.setDirty(true);
            // Ask listening FeedMainController to open and handle a new
            // external
            // feed dialog.
            fireEvent(ureq, HANDLE_NEW_EXTERNAL_FEED_DIALOG_EVENT);
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_EDIT, getClass(), LoggingResourceable.wrap(feedResource));
        }
    } else if (source == olderItemsLink) {
        helper.olderItems();
        createEditButtons(ureq, feedResource);
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
    } else if (source == newerItemsLink) {
        helper.newerItems();
        createEditButtons(ureq, feedResource);
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
    } else if (source == startpageLink) {
        helper.startpage();
        createEditButtons(ureq, feedResource);
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
    } else if (source instanceof Link) {
        // if it's a link try to get attached identity and assume that user
        // wants
        // to see the users home page
        Link userLink = (Link) source;
        Object userObject = userLink.getUserObject();
        if (userObject instanceof Identity) {
            Identity chosenIdentity = (Identity) userObject;
            String bPath = "[HomePage:" + chosenIdentity.getKey() + "]";
            NewControllerFactory.getInstance().launch(bPath, ureq, getWindowControl());
        }
    }
    // Check if someone else added an item, reload everything
    List<Item> items = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (!isSameAllItems(items)) {
        resetItems(ureq, feedResource);
    }
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) Identity(org.olat.core.id.Identity) Link(org.olat.core.gui.components.link.Link)

Example 39 with ItemImpl

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

the class FeedFileStorgeTest method loadItemsFromXML_shortening.

@Test
public void loadItemsFromXML_shortening() {
    StringBuffer sb = new StringBuffer(5000);
    for (int i = 0; i < 5000; i++) {
        sb.append("A");
    }
    String stringWith5000Chars = sb.toString();
    BlogFileResource resource = new BlogFileResource();
    Feed feed = new FeedImpl(resource);
    Item item = new ItemImpl(feed);
    String guid1 = "guid 1";
    item.setGuid(guid1);
    item.setAuthor(stringWith5000Chars);
    item.setExternalLink(stringWith5000Chars);
    item.setTitle(stringWith5000Chars);
    sut.saveItemAsXML(item);
    List<Item> items = sut.loadItemsFromXML(feed);
    Item reloadedItem = items.get(0);
    assertThat(reloadedItem.getAuthor()).hasSize(255);
    assertThat(reloadedItem.getExternalLink()).isNull();
    assertThat(reloadedItem.getTitle()).hasSize(1024);
    fileResourceManager.deleteFileResource(resource);
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) FeedImpl(org.olat.modules.webFeed.model.FeedImpl) BlogFileResource(org.olat.fileresource.types.BlogFileResource) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

Example 40 with ItemImpl

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

the class FeedFileStorgeTest method loadItemFromXML.

@Test
public void loadItemFromXML() {
    BlogFileResource resource = new BlogFileResource();
    Feed feed = new FeedImpl(resource);
    Item item = new ItemImpl(feed);
    String guid = "guid öüä";
    item.setGuid(guid);
    String autor = "autor";
    item.setAuthor(autor);
    sut.saveItemAsXML(item);
    VFSContainer itemContainer = sut.getOrCreateItemContainer(item);
    Item reloaded = sut.loadItemFromXML(itemContainer);
    assertThat(reloaded).isNotNull();
    assertThat(reloaded.getAuthor()).isEqualTo(autor);
    fileResourceManager.deleteFileResource(resource);
}
Also used : Item(org.olat.modules.webFeed.Item) ItemImpl(org.olat.modules.webFeed.model.ItemImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) FeedImpl(org.olat.modules.webFeed.model.FeedImpl) BlogFileResource(org.olat.fileresource.types.BlogFileResource) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

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