Search in sources :

Example 6 with Enclosure

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

the class FeedManagerImpl method replaceEnclosure.

/**
 * Save or delete the media file to the file system and get the appropriate
 * Enclosure.
 *
 * @param item
 * @param file
 * @return
 */
private Enclosure replaceEnclosure(Item item, FileElement file) {
    Enclosure enclosure = item.getEnclosure();
    if (file != null) {
        if (file.isUploadSuccess()) {
            if (enclosure != null && enclosure.getFileName() != null) {
                feedFileStorage.deleteItemMedia(item, enclosure.getFileName());
            }
            // New uploaded file
            enclosure = new EnclosureImpl();
            enclosure.setLength(file.getUploadSize());
            enclosure.setType(file.getUploadMimeType());
            String saveFileName = feedFileStorage.saveItemMedia(item, file);
            enclosure.setFileName(saveFileName);
        } else if (file.getInitialFile() == null) {
            // If no or deleted initial file, delete the media file
            if (enclosure != null && enclosure.getFileName() != null) {
                feedFileStorage.deleteItemMedia(item, enclosure.getFileName());
            }
            enclosure = null;
        }
    }
    return enclosure;
}
Also used : Enclosure(org.olat.modules.webFeed.Enclosure) EnclosureImpl(org.olat.modules.webFeed.model.EnclosureImpl)

Example 7 with Enclosure

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

the class ItemDAOTest method updateItem.

@Test
public void updateItem() {
    OLATResource resource = JunitTestHelper.createRandomResource();
    Feed feed = feedDao.createFeedForResourcable(resource);
    dbInstance.commitAndCloseSession();
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("user-1234");
    Item item = itemDao.createItem(feed);
    dbInstance.commitAndCloseSession();
    // update the item
    item.setAuthor("author");
    item.setAuthorKey(1L);
    item.setContent("content");
    item.setDescription("description");
    item.setDraft(true);
    item.setExternalLink("https://example.com/");
    item.setGuid("guid-2");
    item.setHeight(3);
    item.setModifierKey(author.getKey());
    item.setPublishDate(new Date());
    item.setTitle("tile");
    item.setWidth(5);
    Enclosure enclosure = new EnclosureImpl();
    enclosure.setExternalUrl("http://exterla.url/abc.jpg");
    enclosure.setFileName("Filename.jpg");
    enclosure.setLength(9L);
    enclosure.setType("type");
    item.setEnclosure(enclosure);
    Item updated = itemDao.updateItem(item);
    // check values
    assertThat(updated.getAuthor()).isEqualTo(item.getAuthor());
    assertThat(updated.getAuthorKey()).isEqualTo(item.getAuthorKey());
    assertThat(updated.getContent()).isEqualTo(item.getContent());
    assertThat(updated.getDescription()).isEqualTo(item.getDescription());
    assertThat(updated.isDraft()).isEqualTo(item.isDraft());
    assertThat(updated.getExternalLink()).isEqualTo(item.getExternalLink());
    assertThat(updated.getGuid()).isEqualTo(item.getGuid());
    assertThat(updated.getHeight()).isEqualTo(item.getHeight());
    assertThat(updated.getModifierKey()).isEqualTo(item.getModifierKey());
    assertThat(updated.getPublishDate()).isEqualTo(item.getPublishDate());
    assertThat(updated.getTitle()).isEqualTo(item.getTitle());
    assertThat(updated.getWidth()).isEqualTo(item.getWidth());
    assertThat(updated.getEnclosure().getExternalUrl()).isEqualTo(item.getEnclosure().getExternalUrl());
    assertThat(updated.getEnclosure().getFileName()).isEqualTo(item.getEnclosure().getFileName());
    assertThat(updated.getEnclosure().getLength()).isEqualTo(item.getEnclosure().getLength());
    assertThat(updated.getEnclosure().getType()).isEqualTo(item.getEnclosure().getType());
}
Also used : Item(org.olat.modules.webFeed.Item) OLATResource(org.olat.resource.OLATResource) Enclosure(org.olat.modules.webFeed.Enclosure) EnclosureImpl(org.olat.modules.webFeed.model.EnclosureImpl) Identity(org.olat.core.id.Identity) Date(java.util.Date) LocalDate(java.time.LocalDate) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

Example 8 with Enclosure

use of org.olat.modules.webFeed.Enclosure in project openolat by klemens.

the class ItemDAOTest method updateItem.

@Test
public void updateItem() {
    OLATResource resource = JunitTestHelper.createRandomResource();
    Feed feed = feedDao.createFeedForResourcable(resource);
    dbInstance.commitAndCloseSession();
    Identity author = JunitTestHelper.createAndPersistIdentityAsAuthor("user-1234");
    Item item = itemDao.createItem(feed);
    dbInstance.commitAndCloseSession();
    // update the item
    item.setAuthor("author");
    item.setAuthorKey(1L);
    item.setContent("content");
    item.setDescription("description");
    item.setDraft(true);
    item.setExternalLink("https://example.com/");
    item.setGuid("guid-2");
    item.setHeight(3);
    item.setModifierKey(author.getKey());
    item.setPublishDate(new Date());
    item.setTitle("tile");
    item.setWidth(5);
    Enclosure enclosure = new EnclosureImpl();
    enclosure.setExternalUrl("http://exterla.url/abc.jpg");
    enclosure.setFileName("Filename.jpg");
    enclosure.setLength(9L);
    enclosure.setType("type");
    item.setEnclosure(enclosure);
    Item updated = itemDao.updateItem(item);
    // check values
    assertThat(updated.getAuthor()).isEqualTo(item.getAuthor());
    assertThat(updated.getAuthorKey()).isEqualTo(item.getAuthorKey());
    assertThat(updated.getContent()).isEqualTo(item.getContent());
    assertThat(updated.getDescription()).isEqualTo(item.getDescription());
    assertThat(updated.isDraft()).isEqualTo(item.isDraft());
    assertThat(updated.getExternalLink()).isEqualTo(item.getExternalLink());
    assertThat(updated.getGuid()).isEqualTo(item.getGuid());
    assertThat(updated.getHeight()).isEqualTo(item.getHeight());
    assertThat(updated.getModifierKey()).isEqualTo(item.getModifierKey());
    assertThat(updated.getPublishDate()).isEqualTo(item.getPublishDate());
    assertThat(updated.getTitle()).isEqualTo(item.getTitle());
    assertThat(updated.getWidth()).isEqualTo(item.getWidth());
    assertThat(updated.getEnclosure().getExternalUrl()).isEqualTo(item.getEnclosure().getExternalUrl());
    assertThat(updated.getEnclosure().getFileName()).isEqualTo(item.getEnclosure().getFileName());
    assertThat(updated.getEnclosure().getLength()).isEqualTo(item.getEnclosure().getLength());
    assertThat(updated.getEnclosure().getType()).isEqualTo(item.getEnclosure().getType());
}
Also used : Item(org.olat.modules.webFeed.Item) OLATResource(org.olat.resource.OLATResource) Enclosure(org.olat.modules.webFeed.Enclosure) EnclosureImpl(org.olat.modules.webFeed.model.EnclosureImpl) Identity(org.olat.core.id.Identity) Date(java.util.Date) LocalDate(java.time.LocalDate) Feed(org.olat.modules.webFeed.Feed) Test(org.junit.Test)

Example 9 with Enclosure

use of org.olat.modules.webFeed.Enclosure in project openolat by klemens.

the class RomeFeedFetcherTest method convertEnclosures.

@Test
public void convertEnclosures() {
    Long length = 1l;
    when(syndEnclosureMock.getLength()).thenReturn(length);
    String type = "type";
    when(syndEnclosureMock.getType()).thenReturn(type);
    String url = "url";
    when(syndEnclosureMock.getUrl()).thenReturn(url);
    List<SyndEnclosure> enclosures = Arrays.asList(syndEnclosureMock);
    Enclosure enclosure = sut.convertEnclosures(enclosures);
    assertThat(enclosure.getExternalUrl()).isEqualTo(url);
    assertThat(enclosure.getLength()).isEqualTo(length);
    assertThat(enclosure.getType()).isEqualTo(type);
}
Also used : SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) SyndEnclosure(com.rometools.rome.feed.synd.SyndEnclosure) Enclosure(org.olat.modules.webFeed.Enclosure) Test(org.junit.Test)

Example 10 with Enclosure

use of org.olat.modules.webFeed.Enclosure in project openolat by klemens.

the class FeedFileStorge method loadItemMedia.

/**
 * Load the media file of the item.
 *
 * @param item
 * @return
 */
public File loadItemMedia(Item item) {
    File file = null;
    Enclosure enclosure = item.getEnclosure();
    VFSContainer mediaDir = getOrCreateItemMediaContainer(item);
    if (mediaDir != null && enclosure != null) {
        VFSLeaf mediaFile = (VFSLeaf) mediaDir.resolve(enclosure.getFileName());
        if (mediaFile != null && mediaFile instanceof LocalFileImpl) {
            file = ((LocalFileImpl) mediaFile).getBasefile();
        }
    }
    return file;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Enclosure(org.olat.modules.webFeed.Enclosure) File(java.io.File)

Aggregations

Enclosure (org.olat.modules.webFeed.Enclosure)20 SyndEnclosure (com.rometools.rome.feed.synd.SyndEnclosure)10 Test (org.junit.Test)10 EnclosureImpl (org.olat.modules.webFeed.model.EnclosureImpl)6 Date (java.util.Date)4 Feed (org.olat.modules.webFeed.Feed)4 Item (org.olat.modules.webFeed.Item)4 SyndFeed (com.rometools.rome.feed.synd.SyndFeed)2 File (java.io.File)2 LocalDate (java.time.LocalDate)2 ArrayList (java.util.ArrayList)2 Identity (org.olat.core.id.Identity)2 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 RSSFeed (org.olat.modules.webFeed.RSSFeed)2 OLATResource (org.olat.resource.OLATResource)2