Search in sources :

Example 91 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class FolderManager method getFileInfosRecursively.

private static void getFileInfosRecursively(OlatRelPathImpl relPath, List<FileInfo> fileInfos, long newerThan, int basePathlen) {
    if (relPath instanceof VFSLeaf) {
        // is a file
        long lastModified = ((VFSLeaf) relPath).getLastModified();
        if (lastModified > newerThan) {
            MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPath);
            String bcrootPath = relPath.getRelPath();
            String bcRelPath = bcrootPath.substring(basePathlen);
            fileInfos.add(new FileInfo(bcRelPath, meta, new Date(lastModified)));
        }
    } else {
        // is a folder
        OlatRootFolderImpl container = (OlatRootFolderImpl) relPath;
        for (VFSItem item : container.getItems(new SystemItemFilter())) {
            getFileInfosRecursively((OlatRelPathImpl) item, fileInfos, newerThan, basePathlen);
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) VFSItem(org.olat.core.util.vfs.VFSItem) SystemItemFilter(org.olat.core.util.vfs.filters.SystemItemFilter) Date(java.util.Date)

Example 92 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class MergedCourseContainer method initSharedFolder.

/**
 * Grab any shared folder that is configured, but only when in unchecked
 * security mode (no identity environment) or when the user has course
 * admin rights
 *
 * @param persistingCourse
 */
private void initSharedFolder(PersistingCourseImpl persistingCourse) {
    CourseConfig courseConfig = persistingCourse.getCourseConfig();
    String sfSoftkey = courseConfig.getSharedFolderSoftkey();
    if (StringHelper.containsNonWhitespace(sfSoftkey) && !CourseConfig.VALUE_EMPTY_SHAREDFOLDER_SOFTKEY.equals(sfSoftkey)) {
        RepositoryEntry re = persistingCourse.getCourseEnvironment().getCourseGroupManager().getCourseEntry();
        if (identityEnv == null || identityEnv.getRoles().isOLATAdmin() || RepositoryManager.getInstance().isOwnerOfRepositoryEntry(identityEnv.getIdentity(), re)) {
            OLATResource sharedResource = CoreSpringFactory.getImpl(RepositoryService.class).loadRepositoryEntryResourceBySoftKey(sfSoftkey);
            if (sharedResource != null) {
                OlatRootFolderImpl sharedFolder = SharedFolderManager.getInstance().getSharedFolder(sharedResource);
                if (sharedFolder != null) {
                    if (courseConfig.isSharedFolderReadOnlyMount() || courseReadOnly) {
                        sharedFolder.setLocalSecurityCallback(new ReadOnlyCallback());
                    }
                    // add local course folder's children as read/write source and any sharedfolder as subfolder
                    addContainer(new NamedContainerImpl("_sharedfolder", sharedFolder));
                }
            }
        }
    }
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) ReadOnlyCallback(org.olat.core.util.vfs.callbacks.ReadOnlyCallback) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) NamedContainerImpl(org.olat.core.util.vfs.NamedContainerImpl) CourseConfig(org.olat.course.config.CourseConfig) RepositoryService(org.olat.repository.RepositoryService)

Example 93 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class ModifyCourseEvent method getCourseBaseContainer.

/**
 * the provided resourceableID must belong to a ICourse.getResourceableId(), otherwise you
 * risk to use a wrong course base container.
 * @param resourceableId
 * @return
 */
public static VFSContainer getCourseBaseContainer(Long resourceableId) {
    String relPath = "/course/" + resourceableId.longValue();
    OlatRootFolderImpl courseRootContainer = new OlatRootFolderImpl(relPath, null);
    File fBasePath = courseRootContainer.getBasefile();
    if (!fBasePath.exists())
        throw new OLATRuntimeException(PersistingCourseImpl.class, "Could not resolve course base path:" + courseRootContainer, null);
    return courseRootContainer;
}
Also used : OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) File(java.io.File)

Example 94 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class ProjectBrokerCourseNode method exportNode.

@Override
public void exportNode(File exportDirectory, ICourse course) {
    // initialize managers
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    ProjectBroker pb = projectBrokerManager.getProjectBroker(projectBrokerManager.getProjectBrokerId(cpm, this));
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    XStream xstream = XStreamHelper.createXStreamInstance();
    // folder for the pb node
    File pbNodeFolder = new File(exportDirectory, getIdent());
    pbNodeFolder.mkdirs();
    // for the broker prefs
    ProjectBrokerConfig brokerConfig = new ProjectBrokerConfig();
    brokerConfig.setAccountGroupKey(projectGroupManager.getAccountManagerGroupKey(cpm, this));
    File projectBrokerFile = new File(pbNodeFolder, "projectbroker.xml");
    XStreamHelper.writeObject(xstream, projectBrokerFile, brokerConfig);
    // get all the projects available in the pb
    List<Project> projects = projectBrokerManager.getProjectListBy(pb.getKey());
    for (Project project : projects) {
        File projectFolder = new File(pbNodeFolder, project.getKey().toString());
        projectFolder.mkdirs();
        // create a hashmap with the project configuration and insert the
        // project data
        File projectFile = new File(projectFolder, project.getKey() + ".xml");
        HashMap<String, Object> projectData = new HashMap<String, Object>();
        projectData.put("title", project.getTitle());
        projectData.put("description", project.getDescription());
        projectData.put("customFieldSize", project.getCustomFieldSize());
        projectData.put("maxMembers", project.getMaxMembers());
        projectData.put("mailNotificationEnabled", project.isMailNotificationEnabled());
        projectData.put("attachmentFileName", project.getAttachmentFileName());
        projectData.put("allowDeselection", projectGroupManager.isDeselectionAllowed(project));
        projectData.put("customeFieldSize", project.getCustomFieldSize());
        projectData.put("businessGroupKey", project.getProjectGroup().getKey());
        // iterate through the customFields
        for (int i = 0; i < project.getCustomFieldSize(); i++) {
            projectData.put("customFieldValue" + i, project.getCustomFieldValue(i));
        }
        // writeout the project data
        XStreamHelper.writeObject(xstream, projectFile, projectData);
        // add attachment file
        OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, course.getCourseEnvironment(), this), null);
        VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
        if (item instanceof VFSLeaf) {
            VFSLeaf itemLeaf = (VFSLeaf) item;
            File attachmentFolder = new File(projectFolder, "attachment");
            File attachment = new File(attachmentFolder, Base64.encodeBase64String(project.getAttachmentFileName().getBytes()));
            try {
                attachmentFolder.mkdirs();
                attachment.createNewFile();
                FileOutputStream attachmentOutputStream = new FileOutputStream(attachment);
                InputStream leafInputStream = itemLeaf.getInputStream();
                FileUtils.copy(leafInputStream, attachmentOutputStream);
                attachmentOutputStream.close();
                leafInputStream.close();
            } catch (IOException e) {
                log.error("Error while exporting attachments for projectbroker " + project.getTitle(), e);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 95 with OlatRootFolderImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl in project openolat by klemens.

the class ProjectBrokerCourseNode method postCopy.

/**
 * Do re-arrange the projects in a new project broker after the copy happened
 */
@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
    super.postCopy(envMapper, processType, course, null);
    if (processType.equals(Processing.runstructure)) {
        // initialize the managers and services
        ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
        ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
        CoursePropertyManager oldCpm = sourceCourse.getCourseEnvironment().getCoursePropertyManager();
        BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
        // create new Project broker and get the old one
        Long projectBrokerId = projectBrokerManager.createAndSaveProjectBroker().getKey();
        projectBrokerManager.saveProjectBrokerId(projectBrokerId, course.getCourseEnvironment().getCoursePropertyManager(), this);
        // find the group for account manager and remap the account group
        CourseNode sourceCourseNode = sourceCourse.getRunStructure().getNode(getIdent());
        Long sourceAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(oldCpm, sourceCourseNode);
        if (sourceAccountGroupKey != null) {
            Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(sourceAccountGroupKey);
            CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
            projectGroupManager.saveAccountManagerGroupKey(copiedGroupKey, cpm, this);
        }
        Long oldBrokerId = projectBrokerManager.getProjectBrokerId(oldCpm, this);
        List<Project> projectsFromGroup = projectBrokerManager.getProjectListBy(oldBrokerId);
        // loop create and configure the new Projects
        for (Project project : projectsFromGroup) {
            Long originalGroupKey = project.getProjectGroup().getKey();
            Long copiedGroupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
            Identity author = envMapper.getAuthor();
            BusinessGroup projectGroup = bgs.loadBusinessGroup(copiedGroupKey);
            if (projectGroup == null) {
                projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
            }
            if (author != null) {
                bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
            }
            Project newProject = projectBrokerManager.createAndSaveProjectFor(project.getTitle(), project.getDescription(), projectBrokerId, projectGroup);
            // copy all project configurations
            newProject.setMailNotificationEnabled(project.isMailNotificationEnabled());
            newProject.setMaxMembers(project.getMaxMembers());
            for (int i = 0; i < project.getCustomFieldSize(); i++) {
                newProject.setCustomFieldValue(i, project.getCustomFieldValue(i));
            }
            projectGroupManager.setDeselectionAllowed(newProject, project.getProjectGroup().isAllowToLeave());
            projectBrokerManager.updateProject(newProject);
            // attachment file
            OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, sourceCourse.getCourseEnvironment(), this), null);
            VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
            if (item instanceof VFSLeaf) {
                projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), this);
                newProject.setAttachedFileName(project.getAttachmentFileName());
                projectBrokerManager.updateProject(newProject);
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) BusinessGroup(org.olat.group.BusinessGroup) VFSItem(org.olat.core.util.vfs.VFSItem) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BusinessGroupService(org.olat.group.BusinessGroupService) Identity(org.olat.core.id.Identity) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Aggregations

OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)214 VFSContainer (org.olat.core.util.vfs.VFSContainer)86 VFSItem (org.olat.core.util.vfs.VFSItem)68 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)58 Identity (org.olat.core.id.Identity)50 Test (org.junit.Test)48 File (java.io.File)36 InputStream (java.io.InputStream)30 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)28 OutputStream (java.io.OutputStream)26 VFSSecurityCallback (org.olat.core.util.vfs.callbacks.VFSSecurityCallback)24 URI (java.net.URI)22 RepositoryEntry (org.olat.repository.RepositoryEntry)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 Path (java.nio.file.Path)20 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)18 IOException (java.io.IOException)16 HttpResponse (org.apache.http.HttpResponse)14 CollaborationTools (org.olat.collaboration.CollaborationTools)14 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)14