use of org.olat.modules.webFeed.model.ItemImpl in project openolat by klemens.
the class ItemDAOTest method loadItemByGuid_without_feed_multiple_guids.
@Test
public void loadItemByGuid_without_feed_multiple_guids() {
OLATResource resource = JunitTestHelper.createRandomResource();
Feed feed = feedDao.createFeedForResourcable(resource);
dbInstance.commitAndCloseSession();
// create an item
String guid = "guid-12345";
Item tempItem = new ItemImpl(feed);
tempItem.setGuid(guid);
itemDao.createItem(feed, tempItem);
dbInstance.commitAndCloseSession();
tempItem = new ItemImpl(feed);
tempItem.setGuid(guid);
itemDao.createItem(feed, tempItem);
dbInstance.commitAndCloseSession();
// reload the item from the database
Item item = itemDao.loadItemByGuid(guid);
// check values
assertThat(item).isNull();
}
use of org.olat.modules.webFeed.model.ItemImpl in project openolat by klemens.
the class ItemDAOTest method loadItemByGuid_without_feed.
@Test
public void loadItemByGuid_without_feed() {
OLATResource resource = JunitTestHelper.createRandomResource();
Feed feed = feedDao.createFeedForResourcable(resource);
dbInstance.commitAndCloseSession();
// create an item
String guid = "guid-123467890";
Item tempItem = new ItemImpl(feed);
tempItem.setGuid(guid);
itemDao.createItem(feed, tempItem);
dbInstance.commitAndCloseSession();
// reload the item from the database
Item item = itemDao.loadItemByGuid(guid);
// check values
assertThat(item).isNotNull();
// clean up
itemDao.removeItem(item);
}
use of org.olat.modules.webFeed.model.ItemImpl in project openolat by klemens.
the class ItemDAOTest method createItem_Feed_Item_keepDates.
@Test
public void createItem_Feed_Item_keepDates() {
OLATResource resource = JunitTestHelper.createRandomResource();
Feed feed = feedDao.createFeedForResourcable(resource);
dbInstance.commitAndCloseSession();
Item tempItem = new ItemImpl(feed);
Date created = new GregorianCalendar(2000, 1, 1).getTime();
tempItem.setCreationDate(created);
Date modified = new GregorianCalendar(2000, 2, 2).getTime();
tempItem.setLastModified(modified);
Item item = itemDao.createItem(feed, tempItem);
dbInstance.commitAndCloseSession();
// check values
assertThat(item.getCreationDate()).isCloseTo(created, 1000);
assertThat(item.getLastModified()).isCloseTo(modified, 1000);
}
use of org.olat.modules.webFeed.model.ItemImpl in project openolat by klemens.
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);
}
}
use of org.olat.modules.webFeed.model.ItemImpl in project openolat by klemens.
the class ItemDAO method createItem.
/**
* Create a new Item and connect it with the feed.
*
* @param feed
* @return the created item
*/
public Item createItem(Feed feed) {
if (feed == null)
return null;
Item item = new ItemImpl(feed);
item.setCreationDate(new Date());
item.setLastModified(item.getCreationDate());
dbInstance.getCurrentEntityManager().persist(item);
return item;
}
Aggregations