Search in sources :

Example 1 with FileArtefact

use of org.olat.portfolio.model.artefacts.FileArtefact in project OpenOLAT by OpenOLAT.

the class FileHandler method createMedia.

@Override
public Media createMedia(AbstractArtefact artefact) {
    Media media = null;
    if (artefact instanceof FileArtefact) {
        VFSContainer artefactFolder = oldPortfolioManager.getArtefactContainer(artefact);
        String filename = ((FileArtefact) artefact).getFilename();
        String extension = FileUtils.getFileSuffix(filename);
        String type = FILE_TYPE;
        if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension)) {
            type = ImageHandler.IMAGE_TYPE;
        }
        String businessPath = artefact.getBusinessPath();
        if (businessPath == null) {
            businessPath = "[PortfolioV2:0][MediaCenter:0]";
        }
        media = mediaDao.createMedia(artefact.getTitle(), artefact.getDescription(), filename, type, businessPath, artefact.getKey().toString(), artefact.getSignature(), artefact.getAuthor());
        ThreadLocalUserActivityLogger.log(PortfolioLoggingAction.PORTFOLIO_MEDIA_ADDED, getClass(), LoggingResourceable.wrap(media));
        File mediaDir = fileStorage.generateMediaSubDirectory(media);
        String storagePath = fileStorage.getRelativePath(mediaDir);
        mediaDao.updateStoragePath(media, storagePath, filename);
        VFSContainer mediaContainer = fileStorage.getMediaContainer(media);
        VFSManager.copyContent(artefactFolder, mediaContainer);
    }
    return media;
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) UploadMedia(org.olat.modules.portfolio.ui.media.UploadMedia) Media(org.olat.modules.portfolio.Media) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact) File(java.io.File)

Example 2 with FileArtefact

use of org.olat.portfolio.model.artefacts.FileArtefact in project OpenOLAT by OpenOLAT.

the class EPCreateFileArtefactStepForm00 method saveUpload.

private void saveUpload() {
    VFSLeaf contFile = vfsTemp.createChildLeaf(fileupload.getUploadFileName());
    VFSManager.copyContent(fileupload.getUploadInputStream(), contFile);
    ((FileArtefact) artefact).setFilename(fileupload.getUploadFileName());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact)

Example 3 with FileArtefact

use of org.olat.portfolio.model.artefacts.FileArtefact in project OpenOLAT by OpenOLAT.

the class EPArtefactManagerTest method testSaveFileArtefactWithAllProperties.

@Test
public void testSaveFileArtefactWithAllProperties() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact);
    assertTrue(artefact instanceof FileArtefact);
    FileArtefact fileArtefact = (FileArtefact) artefact;
    fileArtefact.setBusinessPath("[CourseModule:526834956][path=/test/test.html:0]");
    fileArtefact.setCollectionDate(new Date());
    fileArtefact.setDescription("A description of the file artefact");
    fileArtefact.setFulltextContent("The text of the artefact");
    fileArtefact.setReflexion("A deep reflexion caused by this artefact");
    fileArtefact.setSignature(90);
    fileArtefact.setSource("A file");
    fileArtefact.setTitle("File artefact");
    epFrontendManager.updateArtefact(artefact);
    dbInstance.commitAndCloseSession();
    assertNotNull(artefact.getKey());
    // reload the artefact
    AbstractArtefact persistedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
    assertNotNull(persistedArtefact);
    assertTrue(persistedArtefact instanceof FileArtefact);
    assertEquals("[CourseModule:526834956][path=/test/test.html:0]", persistedArtefact.getBusinessPath());
    assertNotNull(persistedArtefact.getCollectionDate());
    assertEquals("A description of the file artefact", persistedArtefact.getDescription());
    assertEquals("The text of the artefact", persistedArtefact.getFulltextContent());
    assertEquals("A deep reflexion caused by this artefact", persistedArtefact.getReflexion());
    assertEquals(90, persistedArtefact.getSignature());
    assertEquals("A file", persistedArtefact.getSource());
    assertEquals("File artefact", persistedArtefact.getTitle());
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact) Date(java.util.Date) Test(org.junit.Test)

Example 4 with FileArtefact

use of org.olat.portfolio.model.artefacts.FileArtefact in project openolat by klemens.

the class EPArtefactManagerTest method testSaveFileArtefactWithAllProperties.

@Test
public void testSaveFileArtefactWithAllProperties() {
    AbstractArtefact artefact = epFrontendManager.createAndPersistArtefact(ident1, "bc");
    assertNotNull(artefact);
    assertTrue(artefact instanceof FileArtefact);
    FileArtefact fileArtefact = (FileArtefact) artefact;
    fileArtefact.setBusinessPath("[CourseModule:526834956][path=/test/test.html:0]");
    fileArtefact.setCollectionDate(new Date());
    fileArtefact.setDescription("A description of the file artefact");
    fileArtefact.setFulltextContent("The text of the artefact");
    fileArtefact.setReflexion("A deep reflexion caused by this artefact");
    fileArtefact.setSignature(90);
    fileArtefact.setSource("A file");
    fileArtefact.setTitle("File artefact");
    epFrontendManager.updateArtefact(artefact);
    dbInstance.commitAndCloseSession();
    assertNotNull(artefact.getKey());
    // reload the artefact
    AbstractArtefact persistedArtefact = epFrontendManager.loadArtefactByKey(artefact.getKey());
    assertNotNull(persistedArtefact);
    assertTrue(persistedArtefact instanceof FileArtefact);
    assertEquals("[CourseModule:526834956][path=/test/test.html:0]", persistedArtefact.getBusinessPath());
    assertNotNull(persistedArtefact.getCollectionDate());
    assertEquals("A description of the file artefact", persistedArtefact.getDescription());
    assertEquals("The text of the artefact", persistedArtefact.getFulltextContent());
    assertEquals("A deep reflexion caused by this artefact", persistedArtefact.getReflexion());
    assertEquals(90, persistedArtefact.getSignature());
    assertEquals("A file", persistedArtefact.getSource());
    assertEquals("File artefact", persistedArtefact.getTitle());
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact) Date(java.util.Date) Test(org.junit.Test)

Example 5 with FileArtefact

use of org.olat.portfolio.model.artefacts.FileArtefact in project openolat by klemens.

the class EPCreateFileArtefactStepForm00 method saveUpload.

private void saveUpload() {
    VFSLeaf contFile = vfsTemp.createChildLeaf(fileupload.getUploadFileName());
    VFSManager.copyContent(fileupload.getUploadInputStream(), contFile);
    ((FileArtefact) artefact).setFilename(fileupload.getUploadFileName());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileArtefact(org.olat.portfolio.model.artefacts.FileArtefact)

Aggregations

FileArtefact (org.olat.portfolio.model.artefacts.FileArtefact)6 File (java.io.File)2 Date (java.util.Date)2 Test (org.junit.Test)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 Media (org.olat.modules.portfolio.Media)2 UploadMedia (org.olat.modules.portfolio.ui.media.UploadMedia)2 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)2