use of org.olat.modules.webFeed.model.EnclosureImpl 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;
}
use of org.olat.modules.webFeed.model.EnclosureImpl 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());
}
use of org.olat.modules.webFeed.model.EnclosureImpl 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());
}
use of org.olat.modules.webFeed.model.EnclosureImpl in project openolat by klemens.
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;
}
use of org.olat.modules.webFeed.model.EnclosureImpl in project OpenOLAT by OpenOLAT.
the class RomeFeedFetcher method convertEnclosures.
/**
* Converts a List of <code>SyndEnclosures</code> into an <code>Enclosure</code>.
* Only one media file is supported. If the List has more than one entry, the
* first entry is taken.
* SyndEnclosures without an URL are not converted, because it is necessary to
* fetch the enclosure.
*
* @param enclosures
* @return the enclosure or null
*/
protected Enclosure convertEnclosures(List<SyndEnclosure> enclosures) {
if (enclosures == null || enclosures.isEmpty())
return null;
SyndEnclosure syndEnclosure = enclosures.get(0);
Enclosure enclosure = null;
if (StringHelper.containsNonWhitespace(syndEnclosure.getUrl())) {
enclosure = new EnclosureImpl();
enclosure.setExternalUrl(syndEnclosure.getUrl());
enclosure.setLength(syndEnclosure.getLength());
enclosure.setType(syndEnclosure.getType());
}
return enclosure;
}
Aggregations