Search in sources :

Example 31 with MetaInfo

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

Example 32 with MetaInfo

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

the class OlatRootFolderTreeModel method createNode.

/**
 * Create a node out of a relative path vfs item. The user object is set to
 * the relative path.
 *
 * @param item
 */
private OlatRootFolderTreeNode createNode(OlatRelPathImpl item) {
    OlatRootFolderTreeNode node = new OlatRootFolderTreeNode(item, this);
    MetaInfo meta = metaInfoFactory.createMetaInfoFor(item);
    if (meta != null) {
        String title = meta.getTitle();
        if (StringHelper.containsNonWhitespace(title)) {
            node.setTitle(title);
        } else {
            node.setTitle(meta.getName());
        }
    } else {
    // TODO:GW log warning that
    // "metadate couldn't be loaded for folder relpath: " +
    // folder.getRelPath();
    }
    node.setUserObject(item.getRelPath());
    return node;
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo)

Example 33 with MetaInfo

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

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)

Example 34 with MetaInfo

use of org.olat.core.commons.modules.bc.meta.MetaInfo 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 35 with MetaInfo

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

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