Search in sources :

Example 16 with MetaInfo

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

the class VersionManagerTest method testMove.

@Test
public void testMove() 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);
    // move the file
    VFSLeaf retrievedLeaf = (VFSLeaf) rootTest.resolve(filename);
    String copyFilename = getRandomName();
    VFSLeaf copyFile = rootTest.createChildLeaf(copyFilename);
    OutputStream copyOutput = copyFile.getOutputStream(false);
    InputStream copyInput = retrievedLeaf.getInputStream();
    IOUtils.copy(copyInput, copyOutput);
    IOUtils.closeQuietly(copyOutput);
    IOUtils.closeQuietly(copyInput);
    // move the revisions
    VersionsManager.getInstance().move(retrievedLeaf, copyFile, id2);
    // check if the revisions are moved
    VFSLeaf retirevedCopyFile = (VFSLeaf) rootTest.resolve(copyFilename);
    assertTrue(retirevedCopyFile instanceof Versionable);
    Versions versions = VersionsFileManager.getInstance().createVersionsFor(retirevedCopyFile);
    List<VFSRevision> revisions = versions.getRevisions();
    assertNotNull(revisions);
    assertEquals(2, revisions.size());
    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());
    // current
    assertEquals(id1.getName(), versions.getCreator());
    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) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 17 with MetaInfo

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

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 18 with MetaInfo

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

the class GTASampleSolutionsEditController method updateModel.

private void updateModel() {
    List<Solution> solutionList = gtaManager.getSolutions(courseEnv, gtaNode);
    List<SolutionRow> rows = new ArrayList<>(solutionList.size());
    for (Solution solution : solutionList) {
        String filename = solution.getFilename();
        String author = null;
        VFSItem item = solutionContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                author = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        DownloadLink downloadLink = null;
        if (item instanceof VFSLeaf) {
            downloadLink = uifactory.addDownloadLink("file_" + (++linkCounter), filename, null, (VFSLeaf) item, solutionTable);
        }
        rows.add(new SolutionRow(solution, author, downloadLink));
    }
    solutionModel.setObjects(rows);
    solutionTable.reset();
}
Also used : DownloadLink(org.olat.core.gui.components.form.flexible.elements.DownloadLink) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) 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) Solution(org.olat.course.nodes.gta.model.Solution)

Example 19 with MetaInfo

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

the class GTASampleSolutionsEditController method doCreateSolutionEditor.

private void doCreateSolutionEditor(UserRequest ureq, Solution solution) {
    String documentName = solution.getFilename();
    VFSItem item = solutionContainer.resolve(documentName);
    if (item == null) {
        item = solutionContainer.createChildLeaf(documentName);
    } else {
        documentName = VFSManager.rename(solutionContainer, documentName);
        item = solutionContainer.createChildLeaf(documentName);
    }
    if (item instanceof MetaTagged) {
        MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
        if (metaInfo != null) {
            metaInfo.setAuthor(getIdentity());
        }
        metaInfo.write();
    }
    newSolutionEditorCtrl = WysiwygFactory.createWysiwygController(ureq, getWindowControl(), solutionContainer, documentName, "media", true, true);
    newSolutionEditorCtrl.getRichTextConfiguration().disableMedia();
    newSolutionEditorCtrl.getRichTextConfiguration().setAllowCustomMediaFactory(false);
    newSolutionEditorCtrl.setNewFile(true);
    newSolutionEditorCtrl.setUserObject(solution);
    listenTo(newSolutionEditorCtrl);
    cmc = new CloseableModalController(getWindowControl(), "close", newSolutionEditorCtrl.getInitialComponent());
    listenTo(cmc);
    cmc.activate();
}
Also used : CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) 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)

Example 20 with MetaInfo

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

the class PFNotifications method gatherItems.

private void gatherItems(Identity participant, Publisher p, CourseEnvironment courseEnv, CourseNode node) {
    Path folderRoot = Paths.get(courseEnv.getCourseBaseContainer().getRelPath(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant));
    final List<FileInfo> fInfos = FolderManager.getFileInfos(folderRoot.toString(), compareDate);
    SubscriptionListItem subListItem;
    for (Iterator<FileInfo> it_infos = fInfos.iterator(); it_infos.hasNext(); ) {
        FileInfo fi = it_infos.next();
        MetaInfo metaInfo = fi.getMetaInfo();
        String filePath = fi.getRelPath();
        Date modDate = fi.getLastModified();
        String action = "upload";
        try {
            Path basepath = courseEnv.getCourseBaseContainer().getBasefile().toPath();
            Path completepath = Paths.get(basepath.toString(), PFManager.FILENAME_PARTICIPANTFOLDER, node.getIdent(), pfManager.getIdFolderName(participant), filePath);
            BasicFileAttributes attrs = Files.readAttributes(completepath, BasicFileAttributes.class);
            if (attrs.creationTime().toMillis() < attrs.lastModifiedTime().toMillis()) {
                action = "modify";
            }
        } catch (IOException ioe) {
            log.error("IOException", ioe);
        }
        String forby = translator.translate("notifications.entry." + (filePath.contains(PFManager.FILENAME_DROPBOX) ? "by" : "for"));
        String userDisplayName = userManager.getUserDisplayName(participant);
        String desc = translator.translate("notifications.entry." + action, new String[] { filePath, forby, userDisplayName });
        String businessPath = p.getBusinessPath();
        String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        String iconCssClass = null;
        if (metaInfo != null) {
            iconCssClass = metaInfo.getIconCssClass();
        }
        if (metaInfo != null && !metaInfo.getName().startsWith(".")) {
            subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass);
            items.add(subListItem);
        }
    }
}
Also used : Path(java.nio.file.Path) 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) IOException(java.io.IOException) Date(java.util.Date) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

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