Search in sources :

Example 26 with MetaTagged

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

the class FeedManagerImpl method createFeedMediaFile.

@Override
public VFSLeaf createFeedMediaFile(OLATResourceable feed, String fileName, Size thumbnailSize) {
    VFSLeaf mediaResource = null;
    // Brute force method for fast delivery
    try {
        VFSItem item = feedFileStorage.getOrCreateFeedMediaContainer(feed);
        item = item.resolve(fileName);
        if (thumbnailSize != null && thumbnailSize.getHeight() > 0 && thumbnailSize.getWidth() > 0 && item instanceof MetaTagged) {
            item = ((MetaTagged) item).getMetaInfo().getThumbnail(thumbnailSize.getWidth(), thumbnailSize.getHeight(), false);
        }
        if (item instanceof VFSLeaf) {
            mediaResource = (VFSLeaf) item;
        }
    } catch (NullPointerException e) {
        log.debug("Media resource could not be created from file: ", fileName);
    }
    return mediaResource;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 27 with MetaTagged

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

the class FileDocument method init.

protected void init(SearchResourceContext leafResourceContext, VFSLeaf leaf) throws IOException, DocumentException, DocumentAccessException {
    // Load metadata for this file
    MetaInfo meta = null;
    if (leaf instanceof MetaTagged) {
        meta = ((MetaTagged) leaf).getMetaInfo();
    }
    // Set all know attributes
    setResourceUrl(leafResourceContext.getResourceUrl());
    setLastChange(new Date(leaf.getLastModified()));
    // Check if there are documents attributes set in resource context
    if (StringHelper.containsNonWhitespace(leafResourceContext.getDocumentType())) {
        // document-type in context is set => get from there
        setDocumentType(leafResourceContext.getDocumentType());
    } else {
        setDocumentType(TYPE);
    }
    FileContent content = readContent(leaf);
    String metaTitle;
    if (meta != null && StringHelper.containsNonWhitespace(meta.getTitle())) {
        metaTitle = meta.getTitle();
    } else if (content != null && StringHelper.containsNonWhitespace(content.getTitle())) {
        metaTitle = content.getTitle();
    } else {
        String beautfiedName = leaf.getName();
        int dotpos = beautfiedName.lastIndexOf('.');
        if (dotpos > 0) {
            beautfiedName = beautfiedName.substring(0, dotpos);
        }
        metaTitle = beautfiedName.replace('_', ' ');
    }
    StringBuilder title = new StringBuilder();
    if (StringHelper.containsNonWhitespace(leafResourceContext.getTitle())) {
        // Title in context is set => get from there and add filename
        title.append(leafResourceContext.getTitle()).append(", ");
    }
    if (metaTitle != null) {
        title.append(metaTitle).append(" ( ");
    }
    title.append(leaf.getName());
    if (metaTitle != null) {
        title.append(" )");
    }
    setTitle(title.toString());
    String metaDesc = (meta == null ? null : meta.getComment());
    if (StringHelper.containsNonWhitespace(leafResourceContext.getDescription())) {
        // Title in context is set => get from there
        setDescription(leafResourceContext.getDescription() + (metaDesc == null ? "" : " " + metaDesc));
    } else if (metaDesc != null) {
        setDescription(metaDesc);
    }
    setParentContextType(leafResourceContext.getParentContextType());
    setParentContextName(leafResourceContext.getParentContextName());
    setContent(content.getContent());
    // Add other metadata from meta info
    if (meta != null) {
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DESCRIPTION, meta.getComment());
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_LANGUAGE, meta.getLanguage());
        // Date is 2009 200902 or 20090228
        String[] pubDateArray = meta.getPublicationDate();
        if (pubDateArray != null) {
            StringBuilder pubDate = new StringBuilder();
            for (String d : pubDateArray) {
                if (d != null) {
                    pubDate.append(d);
                }
            }
            addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_DATE, pubDate.toString());
            Date publicationDate = getDateFromPublicationDateArray(pubDateArray);
            if (publicationDate != null) {
                setPublicationDate(publicationDate);
            }
        }
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_PUBLISHER, meta.getPublisher());
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getSource());
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_SOURCE, meta.getUrl());
        // use creator and author as olat author
        setAuthor((meta.getCreator() == null ? meta.getAuthor() : meta.getAuthor() + " " + meta.getCreator()));
        addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_CREATOR, meta.getCreator());
    }
    // Add file type
    String mimeType = WebappHelper.getMimeType(leaf.getName());
    addMetadata(SimpleDublinCoreMetadataFieldsProvider.DC_FORMAT, mimeType);
    // License
    String licenseTypeKey = "";
    if (meta != null && StringHelper.containsNonWhitespace(meta.getLicenseTypeKey())) {
        licenseTypeKey = meta.getLicenseTypeKey();
    }
    setLicenseTypeKey(licenseTypeKey);
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) Date(java.util.Date)

Example 28 with MetaTagged

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

the class FileArtefactDetailsController method initFileView.

private void initFileView(VFSItem file, UserRequest ureq) {
    vC = createVelocityContainer("fileDetails");
    DownloadComponent downlC = new DownloadComponent("download", (VFSLeaf) file);
    vC.put("download", downlC);
    vC.contextPut("filename", fArtefact.getFilename());
    if (file instanceof MetaTagged) {
        MetaInfo meta = ((MetaTagged) file).getMetaInfo();
        vC.contextPut("meta", meta);
        // show a preview thumbnail if possible
        if (meta.isThumbnailAvailable()) {
            VFSLeaf thumb = meta.getThumbnail(200, 200, false);
            if (thumb != null) {
                mr = new VFSMediaResource(thumb);
            }
            if (mr != null) {
                String thumbMapper = registerMapper(ureq, new Mapper() {

                    @Override
                    public MediaResource handle(String relPath, HttpServletRequest request) {
                        return mr;
                    }
                });
                vC.contextPut("thumbMapper", thumbMapper);
            }
        }
    }
    if (!readOnlyMode) {
        // allow to delete
        delLink = LinkFactory.createLink("delete.file", vC, this);
        delLink.setUserObject(file);
    }
    viewPanel.setContent(vC);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Mapper(org.olat.core.dispatcher.mapper.Mapper) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) DownloadComponent(org.olat.core.gui.components.download.DownloadComponent) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 29 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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 30 with MetaTagged

use of org.olat.core.commons.modules.bc.meta.tagged.MetaTagged 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)

Aggregations

MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)92 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)86 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 VFSItem (org.olat.core.util.vfs.VFSItem)48 VFSContainer (org.olat.core.util.vfs.VFSContainer)34 File (java.io.File)16 OutputStream (java.io.OutputStream)14 Versionable (org.olat.core.util.vfs.version.Versionable)12 IOException (java.io.IOException)10 InputStream (java.io.InputStream)10 ArrayList (java.util.ArrayList)10 Date (java.util.Date)10 MediaResource (org.olat.core.gui.media.MediaResource)10 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)10 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)8 BufferedOutputStream (java.io.BufferedOutputStream)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Test (org.junit.Test)6 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)6 NotFoundMediaResource (org.olat.core.gui.media.NotFoundMediaResource)6