Search in sources :

Example 16 with Quota

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

the class ItemFormController method validateFormLogic.

@Override
protected boolean validateFormLogic(UserRequest ureq) {
    boolean allOk = true;
    String name = file.getUploadFileName();
    if (name != null) {
        if (!validateFilename(name)) {
            allOk = false;
        } else {
            flc.setDirty(true);
        }
        // quota check whole feed
        if (baseDir.getLocalSecurityCallback() == null || baseDir.getLocalSecurityCallback().getQuota() != null) {
            Quota feedQuota = baseDir.getLocalSecurityCallback().getQuota();
            Long remainingQuotaKb = feedQuota.getRemainingSpace();
            if (remainingQuotaKb != -1 && file.getUploadFile().length() / 1024 > remainingQuotaKb) {
                String supportAddr = WebappHelper.getMailConfig("mailQuota");
                Long uploadLimitKB = feedQuota.getUlLimitKB();
                file.setErrorKey("ULLimitExceeded", new String[] { Formatter.roundToString(uploadLimitKB.floatValue() / 1000f, 1), supportAddr });
                allOk = false;
            }
        }
    }
    String width = widthEl.getValue();
    if (StringHelper.containsNonWhitespace(width)) {
        try {
            Integer.parseInt(width);
        } catch (NumberFormatException e) {
            widthEl.setErrorKey("feed.item.file.size.error", null);
            allOk = false;
        }
    }
    String height = heightEl.getValue();
    if (StringHelper.containsNonWhitespace(height)) {
        try {
            Integer.parseInt(height);
        } catch (NumberFormatException e) {
            heightEl.setErrorKey("feed.item.file.size.error", null);
            allOk = false;
        }
    }
    return allOk & super.validateFormLogic(ureq);
}
Also used : Quota(org.olat.core.util.vfs.Quota)

Example 17 with Quota

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

the class LearningGroupWebService method getFolder.

@Path("{groupKey}/folder")
public VFSWebservice getFolder(@PathParam("groupKey") Long groupKey, @Context HttpServletRequest request) {
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    BusinessGroup bg = bgs.loadBusinessGroup(groupKey);
    if (bg == null) {
        return null;
    }
    if (!isGroupManager(request)) {
        Identity identity = RestSecurityHelper.getIdentity(request);
        if (!bgs.isIdentityInBusinessGroup(identity, bg)) {
            return null;
        }
    }
    CollaborationTools collabTools = CollaborationToolsFactory.getInstance().getOrCreateCollaborationTools(bg);
    if (!collabTools.isToolEnabled(CollaborationTools.TOOL_FOLDER)) {
        return null;
    }
    String relPath = collabTools.getFolderRelPath();
    QuotaManager qm = QuotaManager.getInstance();
    Quota folderQuota = qm.getCustomQuota(relPath);
    if (folderQuota == null) {
        Quota defQuota = qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_GROUPS);
        folderQuota = QuotaManager.getInstance().createQuota(relPath, defQuota.getQuotaKB(), defQuota.getUlLimitKB());
    }
    SubscriptionContext subsContext = null;
    VFSSecurityCallback secCallback = new VFSWebServiceSecurityCallback(true, true, true, folderQuota, subsContext);
    OlatRootFolderImpl rootContainer = new OlatRootFolderImpl(relPath, null);
    rootContainer.setLocalSecurityCallback(secCallback);
    return new VFSWebservice(rootContainer);
}
Also used : VFSWebServiceSecurityCallback(org.olat.core.util.vfs.restapi.VFSWebServiceSecurityCallback) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Quota(org.olat.core.util.vfs.Quota) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroup(org.olat.group.BusinessGroup) CollaborationTools(org.olat.collaboration.CollaborationTools) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) Identity(org.olat.core.id.Identity) QuotaManager(org.olat.core.util.vfs.QuotaManager) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback) VFSWebservice(org.olat.core.util.vfs.restapi.VFSWebservice) Path(javax.ws.rs.Path)

Example 18 with Quota

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

the class ModifyCourseEvent method copyCourse.

/**
 * Copies a course. More specifically, the run and editor structures and the
 * course folder will be copied to create a new course.
 *
 * @param sourceRes
 * @param ureq
 * @return copy of the course.
 */
public static OLATResourceable copyCourse(OLATResourceable sourceRes, OLATResource targetRes) {
    PersistingCourseImpl sourceCourse = (PersistingCourseImpl) loadCourse(sourceRes);
    PersistingCourseImpl targetCourse = new PersistingCourseImpl(targetRes);
    File fTargetCourseBasePath = targetCourse.getCourseBaseContainer().getBasefile();
    // close connection before file copy
    DBFactory.getInstance().commitAndCloseSession();
    synchronized (sourceCourse) {
        // o_clusterNOK - cannot be solved with doInSync since could take too long (leads to error: "Lock wait timeout exceeded")
        // copy configuration
        CourseConfig courseConf = CourseConfigManagerImpl.getInstance().copyConfigOf(sourceCourse);
        targetCourse.setCourseConfig(courseConf);
        // save structures
        targetCourse.setRunStructure((Structure) XStreamHelper.xstreamClone(sourceCourse.getRunStructure()));
        targetCourse.saveRunStructure();
        targetCourse.setEditorTreeModel((CourseEditorTreeModel) XStreamHelper.xstreamClone(sourceCourse.getEditorTreeModel()));
        targetCourse.saveEditorTreeModel();
        // copy course folder
        File fSourceCourseFolder = sourceCourse.getIsolatedCourseBaseFolder();
        if (fSourceCourseFolder.exists())
            FileUtils.copyDirToDir(fSourceCourseFolder, fTargetCourseBasePath, false, "copy course folder");
        // copy folder nodes directories
        File fSourceFoldernodesFolder = new File(FolderConfig.getCanonicalRoot() + BCCourseNode.getFoldernodesPathRelToFolderBase(sourceCourse.getCourseEnvironment()));
        if (fSourceFoldernodesFolder.exists())
            FileUtils.copyDirToDir(fSourceFoldernodesFolder, fTargetCourseBasePath, false, "copy folder nodes directories");
        // copy task folder directories
        File fSourceTaskfoldernodesFolder = new File(FolderConfig.getCanonicalRoot() + TACourseNode.getTaskFoldersPathRelToFolderRoot(sourceCourse.getCourseEnvironment()));
        if (fSourceTaskfoldernodesFolder.exists())
            FileUtils.copyDirToDir(fSourceTaskfoldernodesFolder, fTargetCourseBasePath, false, "copy task folder directories");
        // update references
        List<Reference> refs = referenceManager.getReferences(sourceCourse);
        int count = 0;
        for (Reference ref : refs) {
            referenceManager.addReference(targetCourse, ref.getTarget(), ref.getUserdata());
            if (count % 20 == 0) {
                DBFactory.getInstance().intermediateCommit();
            }
        }
        // set quotas
        Quota sourceQuota = VFSManager.isTopLevelQuotaContainer(sourceCourse.getCourseFolderContainer());
        Quota targetQuota = VFSManager.isTopLevelQuotaContainer(targetCourse.getCourseFolderContainer());
        if (sourceQuota != null && targetQuota != null) {
            QuotaManager qm = QuotaManager.getInstance();
            if (sourceQuota.getQuotaKB() != qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_COURSE).getQuotaKB()) {
                targetQuota = qm.createQuota(targetQuota.getPath(), sourceQuota.getQuotaKB(), sourceQuota.getUlLimitKB());
                qm.setCustomQuotaKB(targetQuota);
            }
        }
    }
    return targetRes;
}
Also used : Quota(org.olat.core.util.vfs.Quota) Reference(org.olat.resource.references.Reference) QuotaManager(org.olat.core.util.vfs.QuotaManager) File(java.io.File) CourseConfig(org.olat.course.config.CourseConfig)

Example 19 with Quota

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

the class FolderNodeCallback method getQuota.

/**
 * @see org.olat.modules.bc.callbacks.SecurityCallback#getQuotaKB(org.olat.modules.bc.Path)
 */
@Override
public Quota getQuota() {
    if (nodeFolderQuota == null) {
        QuotaManager qm = QuotaManager.getInstance();
        nodeFolderQuota = qm.getCustomQuota(relPath);
        if (nodeFolderQuota == null) {
            Quota defQuota = qm.getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_NODES);
            nodeFolderQuota = qm.createQuota(relPath, defQuota.getQuotaKB(), defQuota.getUlLimitKB());
        }
    }
    return nodeFolderQuota;
}
Also used : Quota(org.olat.core.util.vfs.Quota) QuotaManager(org.olat.core.util.vfs.QuotaManager)

Example 20 with Quota

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

the class BCCourseNodeEditController method getSecurityCallbackWithQuota.

private VFSSecurityCallback getSecurityCallbackWithQuota(String relPath) {
    Quota quota = quotaManager.getCustomQuota(relPath);
    if (quota == null) {
        Quota defQuota = QuotaManager.getInstance().getDefaultQuota(QuotaConstants.IDENTIFIER_DEFAULT_NODES);
        quota = QuotaManager.getInstance().createQuota(relPath, defQuota.getQuotaKB(), defQuota.getUlLimitKB());
    }
    return new FullAccessWithQuotaCallback(quota);
}
Also used : FullAccessWithQuotaCallback(org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback) Quota(org.olat.core.util.vfs.Quota)

Aggregations

Quota (org.olat.core.util.vfs.Quota)50 QuotaManager (org.olat.core.util.vfs.QuotaManager)18 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)12 FullAccessWithQuotaCallback (org.olat.core.util.vfs.callbacks.FullAccessWithQuotaCallback)12 CollaborationTools (org.olat.collaboration.CollaborationTools)6 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)6 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)6 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)6 BusinessGroup (org.olat.group.BusinessGroup)6 Property (org.olat.properties.Property)6 Path (javax.ws.rs.Path)4 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)4 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 Identity (org.olat.core.id.Identity)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSWebServiceSecurityCallback (org.olat.core.util.vfs.restapi.VFSWebServiceSecurityCallback)4 VFSWebservice (org.olat.core.util.vfs.restapi.VFSWebservice)4 BusinessGroupService (org.olat.group.BusinessGroupService)4 File (java.io.File)2