Search in sources :

Example 1 with VFSStatus

use of org.olat.core.util.vfs.VFSStatus in project OpenOLAT by OpenOLAT.

the class VFSResourceRoot method delete.

@Override
public boolean delete(WebResource resource) {
    boolean deleted = false;
    if (resource instanceof VFSResource) {
        VFSResource vfsResource = (VFSResource) resource;
        VFSItem item = vfsResource.getItem();
        if (item != null && VFSConstants.YES.equals(item.canDelete())) {
            VFSStatus status = item.delete();
            deleted = (status == VFSConstants.YES || status == VFSConstants.SUCCESS);
        }
    }
    return deleted;
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 2 with VFSStatus

use of org.olat.core.util.vfs.VFSStatus in project OpenOLAT by OpenOLAT.

the class VFSResourceRoot method canWrite.

@Override
public boolean canWrite(String name) {
    // resolve item if it already exists
    VFSItem item = resolveFile(name);
    if (item == null) {
        // try to resolve parent in case the item does not yet exist
        int lastSlash = name.lastIndexOf("/");
        if (lastSlash > 0) {
            String containerName = name.substring(0, lastSlash);
            item = resolveFile(containerName);
        }
    }
    if (item == null) {
        return false;
    }
    VFSStatus status;
    if (item instanceof VFSContainer) {
        status = item.canWrite();
    } else {
        // read/write is not defined on item level, only on directory level
        status = item.getParentContainer().canWrite();
    }
    return VFSConstants.YES.equals(status);
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 3 with VFSStatus

use of org.olat.core.util.vfs.VFSStatus in project OpenOLAT by OpenOLAT.

the class VFSWebservice method deleteItem.

@DELETE
@Path("{path:.*}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteItem(@PathParam("path") List<PathSegment> path) {
    if (container.getLocalSecurityCallback() != null && !container.getLocalSecurityCallback().canDelete()) {
        return Response.serverError().status(Status.UNAUTHORIZED).build();
    }
    VFSItem item = resolveFile(path);
    if (item == null) {
        return Response.serverError().status(Status.NOT_FOUND).build();
    }
    VFSStatus status = item.delete();
    if (status == VFSConstants.YES) {
        return Response.ok().build();
    }
    // need something better
    return Response.ok().build();
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus) VFSItem(org.olat.core.util.vfs.VFSItem) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 4 with VFSStatus

use of org.olat.core.util.vfs.VFSStatus 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 5 with VFSStatus

use of org.olat.core.util.vfs.VFSStatus in project openolat by klemens.

the class VideoManagerImpl method deleteVideoTranscodings.

@Override
public boolean deleteVideoTranscodings(OLATResource videoResource) {
    videoTranscodingDao.deleteVideoTranscodings(videoResource);
    VFSStatus deleteStatus = getTranscodingContainer(videoResource).delete();
    return (deleteStatus == VFSConstants.YES ? true : false);
}
Also used : VFSStatus(org.olat.core.util.vfs.VFSStatus)

Aggregations

VFSStatus (org.olat.core.util.vfs.VFSStatus)14 VFSItem (org.olat.core.util.vfs.VFSItem)8 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 DELETE (javax.ws.rs.DELETE)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 CalendarManager (org.olat.commons.calendar.CalendarManager)2 ImportToCalendarManager (org.olat.commons.calendar.manager.ImportToCalendarManager)2 FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 TaskExecutorManager (org.olat.core.commons.services.taskexecutor.TaskExecutorManager)2 FolderTreeModel (org.olat.core.gui.control.generic.folder.FolderTreeModel)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 TreeVisitor (org.olat.core.util.tree.TreeVisitor)2 Visitor (org.olat.core.util.tree.Visitor)2 OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)2 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)2 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)2