Search in sources :

Example 21 with MetaTagged

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

the class RepositoryManager method setImage.

public boolean setImage(VFSLeaf newImageFile, RepositoryEntry re) {
    VFSLeaf currentImage = getImage(re);
    if (currentImage != null) {
        if (currentImage instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) currentImage).getMetaInfo();
            if (info != null) {
                info.clearThumbnails();
            }
        }
        currentImage.delete();
    }
    if (newImageFile == null || !newImageFile.exists() || newImageFile.getSize() <= 0) {
        return false;
    }
    String targetExtension = ".png";
    String extension = FileUtils.getFileSuffix(newImageFile.getName());
    if ("jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension)) {
        targetExtension = ".jpg";
    }
    VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome()));
    VFSLeaf repoImage = repositoryHome.createChildLeaf(re.getResourceableId() + targetExtension);
    if (targetExtension.equals(".png") || targetExtension.equals(".jpg")) {
        Size newImageSize = imageHelper.getSize(newImageFile, extension);
        if (newImageSize != null && newImageSize.getWidth() <= PICTURE_WIDTH && newImageSize.getHeight() <= PICTURE_HEIGHT) {
            boolean success = VFSManager.copyContent(newImageFile, repoImage);
            return success;
        }
    }
    Size size = imageHelper.scaleImage(newImageFile, repoImage, PICTURE_WIDTH, PICTURE_WIDTH, false);
    return size != null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) File(java.io.File) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl)

Example 22 with MetaTagged

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

the class CatalogEntryImageMapper method handle.

@Override
public MediaResource handle(String relPath, HttpServletRequest request) {
    if (relPath.startsWith("/")) {
        relPath = relPath.substring(1, relPath.length());
    }
    VFSContainer categoryResources = catalogManager.getCatalogResourcesHome();
    VFSItem image = categoryResources.resolve(relPath);
    MediaResource resource = null;
    if (image instanceof VFSLeaf) {
        if (image instanceof MetaTagged) {
            MetaInfo info = ((MetaTagged) image).getMetaInfo();
            if (info != null) {
                VFSLeaf thumbnail = info.getThumbnail(180, 180, true);
                if (thumbnail != null) {
                    resource = new VFSMediaResource(thumbnail);
                }
            }
        }
        if (resource == null) {
            resource = new VFSMediaResource((VFSLeaf) image);
        }
    } else {
        resource = new NotFoundMediaResource();
    }
    return resource;
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 23 with MetaTagged

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

the class SubmitDocumentsController method doUpload.

private void doUpload(UserRequest ureq, File file, String filename) {
    try {
        Path documentPath = documentsDir.toPath().resolve(filename);
        Files.move(file.toPath(), documentPath, StandardCopyOption.REPLACE_EXISTING);
        VFSItem downloadedFile = documentsContainer.resolve(filename);
        if (downloadedFile instanceof MetaTagged) {
            MetaInfo metadata = ((MetaTagged) downloadedFile).getMetaInfo();
            metadata.setAuthor(ureq.getIdentity());
            metadata.write();
        }
    } catch (IOException e) {
        logError("", e);
        showError("");
    }
    updateModel();
}
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) IOException(java.io.IOException)

Example 24 with MetaTagged

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

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 25 with MetaTagged

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

the class CmdMoveCopy method doMove.

private void doMove(UserRequest ureq) {
    FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
    String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
    if (selectedPath == null) {
        abortFailed(ureq, "failed");
        return;
    }
    VFSStatus vfsStatus = VFSConstants.SUCCESS;
    VFSContainer rootContainer = folderComponent.getRootContainer();
    VFSItem vfsItem = rootContainer.resolve(selectedPath);
    if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
        abortFailed(ureq, "failed");
        return;
    }
    // copy the files
    VFSContainer target = (VFSContainer) vfsItem;
    List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
    if (sources == null)
        return;
    boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
    for (VFSItem vfsSource : sources) {
        if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
            // copy the metainfo first
            MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
            if (meta != null) {
                meta.moveCopyToDir((OlatRelPathImpl) target, move);
            }
        }
        VFSItem targetFile = target.resolve(vfsSource.getName());
        if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
            // add a new version to the file
            ((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
        } else {
            vfsStatus = target.copyFrom(vfsSource);
        }
        if (vfsStatus != VFSConstants.SUCCESS) {
            String errorKey = "failed";
            if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
                errorKey = "QuotaExceeded";
            abortFailed(ureq, errorKey);
            return;
        }
        if (move) {
            // if move, delete the source. Note that meta source
            // has already been delete (i.e. moved)
            vfsSource.delete();
        }
    }
    // after a copy or a move, notify the subscribers
    VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
    if (secCallback != null) {
        SubscriptionContext subsContext = secCallback.getSubscriptionContext();
        if (subsContext != null) {
            NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
        }
    }
    fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
    notifyFinished(ureq);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

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