Search in sources :

Example 76 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.

the class MSCourseNode method cleanupOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#cleanupOnDelete(
 *      org.olat.course.ICourse)
 */
@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
    // Delete all properties: score, passed, log, comment, coach_comment
    pm.deleteNodeProperties(this, null);
    OLATResource resource = course.getCourseEnvironment().getCourseGroupManager().getCourseResource();
    CoreSpringFactory.getImpl(TaskExecutorManager.class).delete(resource, getIdent());
}
Also used : TaskExecutorManager(org.olat.core.commons.services.taskexecutor.TaskExecutorManager) OLATResource(org.olat.resource.OLATResource) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 77 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method informOnDelete.

/**
 * @see org.olat.course.nodes.CourseNode#informOnDelete(org.olat.core.gui.UserRequest,
 *      org.olat.course.ICourse)
 */
@Override
public String informOnDelete(Locale locale, ICourse course) {
    Translator trans = new PackageTranslator(PACKAGE_PROJECTBROKER, locale);
    CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
    List<Property> list = cpm.listCourseNodeProperties(this, null, null, null);
    // properties exist
    if (list.size() != 0)
        return trans.translate(NLS_WARN_NODEDELETE);
    File fDropboxFolder = new File(FolderConfig.getCanonicalRoot() + DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    // Dropbox folder contains files
    if (fDropboxFolder.exists() && fDropboxFolder.list().length > 0)
        return trans.translate(NLS_WARN_NODEDELETE);
    File fReturnboxFolder = new File(FolderConfig.getCanonicalRoot() + ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this));
    // Returnbox folder contains files
    if (fReturnboxFolder.exists() && fReturnboxFolder.list().length > 0)
        return trans.translate(NLS_WARN_NODEDELETE);
    // no data yet.
    return null;
}
Also used : PackageTranslator(org.olat.core.gui.translator.PackageTranslator) Translator(org.olat.core.gui.translator.Translator) PackageTranslator(org.olat.core.gui.translator.PackageTranslator) Property(org.olat.properties.Property) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 78 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.

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 79 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.

the class ProjectBrokerCourseNode method createInstanceForCopy.

/**
 * @see org.olat.course.nodes.CourseNode#createInstanceForCopy()
 */
@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
    // create the instance for the copy
    CourseNode copyInstance = super.createInstanceForCopy(isNewTitle, course, author);
    // get all the different managers
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    // get the pbID from the source pb
    Long oldProjectBrokerId = projectBrokerManager.getProjectBrokerId(cpm, this);
    // create a new projectBroker for the copyInstance
    ProjectBroker newBroker = projectBrokerManager.createAndSaveProjectBroker();
    Long projectBrokerId = newBroker.getKey();
    projectBrokerManager.saveProjectBrokerId(projectBrokerId, cpm, copyInstance);
    // configure the new Project like the old one
    // copy the old accountManagergroup to preserve the
    // "persons in charge"
    Long originalAccountGroupKey = projectGroupManager.getAccountManagerGroupKey(cpm, this);
    if (originalAccountGroupKey != null) {
        BusinessGroup originalAccountGroup = projectGroupManager.getAccountManagerGroupFor(cpm, this, course, getShortTitle(), getShortTitle(), null);
        BusinessGroup newAccountManagerGroup = bgs.copyBusinessGroup(author, originalAccountGroup, originalAccountGroup.getName(), originalAccountGroup.getDescription(), originalAccountGroup.getMinParticipants(), originalAccountGroup.getMaxParticipants(), false, false, true, false, false, true, false, false);
        projectGroupManager.saveAccountManagerGroupKey(newAccountManagerGroup.getKey(), cpm, copyInstance);
        bgs.addResourceTo(newAccountManagerGroup, course.getCourseEnvironment().getCourseGroupManager().getCourseEntry());
    }
    if (oldProjectBrokerId != null) {
        List<Project> projects = projectBrokerManager.getProjectListBy(oldProjectBrokerId);
        for (Project project : projects) {
            // create projectGroup
            BusinessGroup projectGroup = projectGroupManager.createProjectGroupFor(projectBrokerId, author, project.getTitle(), project.getDescription(), course.getResourceableId());
            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, course.getCourseEnvironment(), this), null);
            VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
            if (item instanceof VFSLeaf) {
                projectBrokerManager.saveAttachedFile(newProject, project.getAttachmentFileName(), (VFSLeaf) item, course.getCourseEnvironment(), copyInstance);
                newProject.setAttachedFileName(project.getAttachmentFileName());
                projectBrokerManager.updateProject(newProject);
            }
        }
    }
    return copyInstance;
}
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) ProjectBroker(org.olat.course.nodes.projectbroker.datamodel.ProjectBroker) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BusinessGroupService(org.olat.group.BusinessGroupService) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 80 with CoursePropertyManager

use of org.olat.course.properties.CoursePropertyManager in project OpenOLAT by OpenOLAT.

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

CoursePropertyManager (org.olat.course.properties.CoursePropertyManager)108 Property (org.olat.properties.Property)62 PersistingCoursePropertyManager (org.olat.course.properties.PersistingCoursePropertyManager)44 Identity (org.olat.core.id.Identity)28 File (java.io.File)18 ICourse (org.olat.course.ICourse)18 ProjectBrokerManager (org.olat.course.nodes.projectbroker.service.ProjectBrokerManager)14 CourseNode (org.olat.course.nodes.CourseNode)12 Project (org.olat.course.nodes.projectbroker.datamodel.Project)12 RepositoryEntry (org.olat.repository.RepositoryEntry)12 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)10 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)10 ProjectGroupManager (org.olat.course.nodes.projectbroker.service.ProjectGroupManager)10 BusinessGroup (org.olat.group.BusinessGroup)10 XStream (com.thoughtworks.xstream.XStream)8 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)8 TaskExecutorManager (org.olat.core.commons.services.taskexecutor.TaskExecutorManager)8 PackageTranslator (org.olat.core.gui.translator.PackageTranslator)8 Translator (org.olat.core.gui.translator.Translator)8 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)8