Search in sources :

Example 36 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.

the class VersionManagerTest method testAuthorsAndCreators.

@Test
public void testAuthorsAndCreators() throws IOException {
    // create a file
    OlatRootFolderImpl rootTest = new OlatRootFolderImpl("/test2", null);
    String filename = getRandomName();
    VFSLeaf file = rootTest.createChildLeaf(filename);
    OutputStream out = file.getOutputStream(false);
    InputStream in = VersionManagerTest.class.getResourceAsStream("test.txt");
    int byteCopied = IOUtils.copy(in, out);
    IOUtils.closeQuietly(in);
    assertFalse(byteCopied == 0);
    assertTrue(file instanceof Versionable);
    assertTrue(file instanceof MetaTagged);
    // set the author
    MetaTagged metaTagged = (MetaTagged) file;
    MetaInfo metaInfo = metaTagged.getMetaInfo();
    metaInfo.setAuthor(id1);
    metaInfo.setCreator(id1.getName());
    metaInfo.write();
    // save a first version -> id2
    Versionable versionedFile1 = (Versionable) file;
    InputStream in1 = new ByteArrayInputStream("Hello version 1".getBytes());
    versionedFile1.getVersions().addVersion(id2, "Version 1", in1);
    IOUtils.closeQuietly(in1);
    // save a second version -> id1
    Versionable versionedFile2 = (Versionable) file;
    InputStream in2 = new ByteArrayInputStream("Hello version 2".getBytes());
    versionedFile2.getVersions().addVersion(id1, "Version 2", in2);
    IOUtils.closeQuietly(in2);
    // save a third version -> id2
    Versionable versionedFile3 = (Versionable) file;
    InputStream in3 = new ByteArrayInputStream("Hello version 3".getBytes());
    versionedFile3.getVersions().addVersion(id2, "Version 3", in3);
    IOUtils.closeQuietly(in3);
    // make the checks
    VFSItem retrievedFile = rootTest.resolve(filename);
    assertTrue(retrievedFile instanceof Versionable);
    Versions versions = versionManager.createVersionsFor((VFSLeaf) retrievedFile);
    List<VFSRevision> revisions = versions.getRevisions();
    assertNotNull(revisions);
    assertEquals(3, revisions.size());
    assertTrue(retrievedFile instanceof MetaTagged);
    VFSRevision revision0 = revisions.get(0);
    // we don't set an author for the original file
    assertEquals(id1.getName(), revision0.getAuthor());
    VFSRevision revision1 = revisions.get(1);
    assertEquals(id2.getName(), revision1.getAuthor());
    VFSRevision revision2 = revisions.get(2);
    assertEquals(id1.getName(), revision2.getAuthor());
    // current
    assertEquals(id2.getName(), versions.getAuthor());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 37 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.

the class EditSolutionController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    solution.setTitle(titleEl.getValue());
    if (fileEl.getUploadFile() != null) {
        if (replaceFile && StringHelper.containsNonWhitespace(solution.getFilename())) {
            File currentFile = new File(solutionDir, solution.getFilename());
            if (currentFile.exists()) {
                currentFile.delete();
            }
        }
        String filename = fileEl.getUploadFileName();
        if (!replaceFile) {
            File currentFile = new File(solutionDir, filename);
            if (currentFile.exists()) {
                filename = VFSManager.rename(solutionContainer, filename);
            }
        }
        solution.setFilename(filename);
        try {
            Path upload = fileEl.getUploadFile().toPath();
            File newFile = new File(solutionDir, filename);
            Files.move(upload, newFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            VFSItem uploadedItem = solutionContainer.resolve(filename);
            if (uploadedItem instanceof MetaTagged) {
                MetaInfo metaInfo = ((MetaTagged) uploadedItem).getMetaInfo();
                metaInfo.setAuthor(ureq.getIdentity());
                metaInfo.write();
            }
        } catch (Exception ex) {
            logError("", ex);
        }
    }
    fireEvent(ureq, Event.DONE_EVENT);
}
Also used : Path(java.nio.file.Path) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) File(java.io.File)

Example 38 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.

the class DocumentPoolNotificationsHandler method createSubscriptionInfo.

private void createSubscriptionInfo(VFSContainer container, String prefixBusinessPath, Date compareDate, SubscriptionInfo si, Publisher p, Translator translator) {
    List<FileInfo> fInfos = FolderManager.getFileInfos(((OlatRelPathImpl) container).getRelPath(), compareDate);
    for (FileInfo infos : fInfos) {
        String title = infos.getRelPath();
        // known exclude prefixes
        if (title != null && title.indexOf("/.") != -1 && FileUtils.isMetaFilename(title)) {
            // skip this file, continue with next item in folder
            continue;
        }
        MetaInfo metaInfo = infos.getMetaInfo();
        String iconCssClass = null;
        if (metaInfo != null) {
            if (metaInfo.getTitle() != null) {
                title += " (" + metaInfo.getTitle() + ")";
            }
            iconCssClass = metaInfo.getIconCssClass();
        }
        Identity ident = infos.getAuthor();
        Date modDate = infos.getLastModified();
        String desc = translator.translate("notifications.document.entry", new String[] { title, NotificationHelper.getFormatedName(ident) });
        String urlToSend = null;
        String businessPath = null;
        if (p.getBusinessPath() != null) {
            businessPath = prefixBusinessPath + infos.getRelPath() + "]";
            urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        }
        si.addSubscriptionListItem(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) FileInfo(org.olat.core.commons.modules.bc.FileInfo) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) Identity(org.olat.core.id.Identity) Date(java.util.Date)

Example 39 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.

the class FolderManager method getFileInfosRecursively.

private static void getFileInfosRecursively(OlatRelPathImpl relPath, List<FileInfo> fileInfos, long newerThan, int basePathlen) {
    if (relPath instanceof VFSLeaf) {
        // is a file
        long lastModified = ((VFSLeaf) relPath).getLastModified();
        if (lastModified > newerThan) {
            MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPath);
            String bcrootPath = relPath.getRelPath();
            String bcRelPath = bcrootPath.substring(basePathlen);
            fileInfos.add(new FileInfo(bcRelPath, meta, new Date(lastModified)));
        }
    } else {
        // is a folder
        OlatRootFolderImpl container = (OlatRootFolderImpl) relPath;
        for (VFSItem item : container.getItems(new SystemItemFilter())) {
            getFileInfosRecursively((OlatRelPathImpl) item, fileInfos, newerThan, basePathlen);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date)

Example 40 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo in project openolat by klemens.

the class CmdCreateFolder method formOK.

@Override
protected void formOK(UserRequest ureq) {
    // create the folder
    String name = textElement.getValue();
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.createChildContainer(name);
    if (item instanceof OlatRelPathImpl) {
        // update meta data
        MetaInfo meta = metaInfoFactory.createMetaInfoFor((OlatRelPathImpl) item);
        meta.setAuthor(ureq.getIdentity());
        meta.write();
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FOLDER_EVENT, folderName));
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    } else {
        status = FolderCommandStatus.STATUS_FAILED;
        fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
    }
}
Also used : OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Aggregations

MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)108 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)40 Date (java.util.Date)18 OutputStream (java.io.OutputStream)14 File (java.io.File)12 IOException (java.io.IOException)12 Versionable (org.olat.core.util.vfs.version.Versionable)12 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)10 MediaResource (org.olat.core.gui.media.MediaResource)10 Identity (org.olat.core.id.Identity)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 FileInfo (org.olat.core.commons.modules.bc.FileInfo)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)8 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8