Search in sources :

Example 6 with Reference

use of org.olat.resource.references.Reference in project OpenOLAT by OpenOLAT.

the class GlossaryManagerImpl method deleteGlossary.

// TODO:RH:gloss change courseconfig, to keep more than 1 single glossary as a list
/**
 * @param res glossary to be deleted
 */
@Override
public void deleteGlossary(OLATResourceable res) {
    // first remove all references
    List<Reference> repoRefs = referenceManager.getReferencesTo(res);
    for (Iterator<Reference> iter = repoRefs.iterator(); iter.hasNext(); ) {
        Reference ref = iter.next();
        if (ref.getUserdata().equals(GLOSSARY_REPO_REF_IDENTIFYER)) {
            // remove the reference from the course configuration
            // TODO:RH:improvement: this should use a callback method or send a general delete
            // event so that the course can take care of this rather than having it
            // here hardcoded
            OLATResource courseResource = ref.getSource();
            // ICourse course = CourseFactory.loadCourse(courseResource);
            ICourse course = CourseFactory.openCourseEditSession(courseResource.getResourceableId());
            CourseConfig cc = course.getCourseEnvironment().getCourseConfig();
            cc.setGlossarySoftKey(null);
            CourseFactory.setCourseConfig(course.getResourceableId(), cc);
            CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            // remove reference from the references table
            referenceManager.delete(ref);
        }
    }
    // now remove the resource itself
    FileResourceManager.getInstance().deleteFileResource(res);
}
Also used : Reference(org.olat.resource.references.Reference) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig)

Example 7 with Reference

use of org.olat.resource.references.Reference in project OpenOLAT by OpenOLAT.

the class PublishProcess method deleteRefs.

/**
 * Delete references to resourceables of node with ident courseNodeIdent.
 *
 * @param courseNode
 */
private void deleteRefs(CourseNode courseNode) {
    ReferenceManager refM = CoreSpringFactory.getImpl(ReferenceManager.class);
    List<Reference> courseRefs = refM.getReferences(course);
    for (Iterator<Reference> iter = courseRefs.iterator(); iter.hasNext(); ) {
        Reference ref = iter.next();
        if (!ref.getUserdata().equals(courseNode.getIdent()))
            continue;
        refM.delete(ref);
        break;
    }
}
Also used : Reference(org.olat.resource.references.Reference) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 8 with Reference

use of org.olat.resource.references.Reference in project OpenOLAT by OpenOLAT.

the class CourseOptionsController method doChangeConfig.

private void doChangeConfig(UserRequest ureq) {
    OLATResourceable courseOres = entry.getOlatResource();
    ICourse course = CourseFactory.openCourseEditSession(courseOres.getResourceableId());
    courseConfig = course.getCourseEnvironment().getCourseConfig();
    boolean menuEnabled = menuEl.isSelected(0);
    courseConfig.setMenuEnabled(menuEnabled);
    boolean toolbarEnabled = toolbarEl.isSelected(0);
    courseConfig.setToolbarEnabled(toolbarEnabled);
    boolean enableSearch = searchEl.isSelected(0);
    boolean updateSearch = courseConfig.isCourseSearchEnabled() != enableSearch;
    courseConfig.setCourseSearchEnabled(enableSearch && toolbarEnabled);
    boolean enableChat = chatEl.isSelected(0);
    boolean updateChat = courseConfig.isChatEnabled() != enableChat;
    courseConfig.setChatIsEnabled(enableChat && toolbarEnabled);
    boolean enableCalendar = calendarEl == null ? false : calendarEl.isSelected(0);
    boolean updateCalendar = courseConfig.isCalendarEnabled() != enableCalendar && calendarModule.isEnableCourseToolCalendar();
    courseConfig.setCalendarEnabled(enableCalendar && toolbarEnabled);
    String currentGlossarySoftKey = courseConfig.getGlossarySoftKey();
    RepositoryEntry glossary = (RepositoryEntry) glossaryNameEl.getUserObject();
    String newGlossarySoftKey = (glossary == null || !toolbarEnabled) ? null : glossary.getSoftkey();
    boolean updateGlossary = (currentGlossarySoftKey == null && newGlossarySoftKey != null) || (currentGlossarySoftKey != null && newGlossarySoftKey == null) || (newGlossarySoftKey != null && !newGlossarySoftKey.equals(currentGlossarySoftKey));
    courseConfig.setGlossarySoftKey(newGlossarySoftKey);
    String currentFolderSoftKey = courseConfig.getSharedFolderSoftkey();
    RepositoryEntry folder = (RepositoryEntry) folderNameEl.getUserObject();
    String newFolderSoftKey = folder == null ? null : folder.getSoftkey();
    boolean updateFolder = (currentFolderSoftKey == null && newFolderSoftKey != null) || (currentFolderSoftKey != null && newFolderSoftKey == null) || (currentFolderSoftKey != null && !currentFolderSoftKey.equals(newFolderSoftKey));
    courseConfig.setSharedFolderSoftkey(newFolderSoftKey);
    if (folderReadOnlyEl.isEnabled()) {
        courseConfig.setSharedFolderReadOnlyMount(folderReadOnlyEl.isAtLeastSelected(1));
    } else {
        courseConfig.setSharedFolderReadOnlyMount(true);
    }
    CourseFactory.setCourseConfig(course.getResourceableId(), courseConfig);
    CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
    if (updateSearch) {
        ILoggingAction loggingAction = enableSearch ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_COURSESEARCH_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_COURSESEARCH_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.search, course.getResourceableId()), course);
    }
    if (updateChat) {
        ILoggingAction loggingAction = enableChat ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_IM_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_IM_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.chat, course.getResourceableId()), course);
    }
    if (updateCalendar) {
        ILoggingAction loggingAction = enableCalendar ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_CALENDAR_ENABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_CALENDAR_DISABLED;
        ThreadLocalUserActivityLogger.log(loggingAction, getClass());
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(), OresHelper.lookupType(CalendarManager.class));
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.calendar, course.getResourceableId()), course);
    }
    if (updateGlossary) {
        ILoggingAction loggingAction = (newGlossarySoftKey == null) ? LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_GLOSSARY_DISABLED : LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_GLOSSARY_ENABLED;
        LoggingResourceable lri = null;
        if (newGlossarySoftKey != null) {
            lri = LoggingResourceable.wrapNonOlatResource(StringResourceableType.glossarySoftKey, newGlossarySoftKey, newGlossarySoftKey);
        } else if (currentGlossarySoftKey != null) {
            lri = LoggingResourceable.wrapNonOlatResource(StringResourceableType.glossarySoftKey, currentGlossarySoftKey, currentGlossarySoftKey);
        }
        if (lri != null) {
            ThreadLocalUserActivityLogger.log(loggingAction, getClass(), lri);
        }
        // remove references
        List<Reference> repoRefs = referenceManager.getReferences(course);
        for (Reference ref : repoRefs) {
            if (ref.getUserdata().equals(GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER)) {
                referenceManager.delete(ref);
            }
        }
        // update references
        if (glossary != null) {
            referenceManager.addReference(course, glossary.getOlatResource(), GlossaryManager.GLOSSARY_REPO_REF_IDENTIFYER);
        }
        CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CourseConfigEvent(CourseConfigType.glossary, course.getResourceableId()), course);
    }
    if (updateFolder) {
        List<Reference> repoRefs = referenceManager.getReferences(course);
        for (Reference ref : repoRefs) {
            if (ref.getUserdata().equals(SharedFolderManager.SHAREDFOLDERREF)) {
                referenceManager.delete(ref);
            }
        }
        if (folder != null) {
            referenceManager.addReference(course, folder.getOlatResource(), SharedFolderManager.SHAREDFOLDERREF);
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_SHARED_FOLDER_REMOVED, getClass(), LoggingResourceable.wrapBCFile(folder.getDisplayname()));
        } else {
            ThreadLocalUserActivityLogger.log(LearningResourceLoggingAction.REPOSITORY_ENTRY_PROPERTIES_SHARED_FOLDER_ADDED, getClass(), LoggingResourceable.wrapBCFile(""));
        }
    }
    fireEvent(ureq, Event.CHANGED_EVENT);
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) CourseConfigEvent(org.olat.course.config.CourseConfigEvent) OLATResourceable(org.olat.core.id.OLATResourceable) Reference(org.olat.resource.references.Reference) ILoggingAction(org.olat.core.logging.activity.ILoggingAction) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) CalendarGUIModifiedEvent(org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent) LoggingResourceable(org.olat.util.logging.activity.LoggingResourceable)

Example 9 with Reference

use of org.olat.resource.references.Reference in project OpenOLAT by OpenOLAT.

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 10 with Reference

use of org.olat.resource.references.Reference in project openolat by klemens.

the class GlossaryManagerImpl method deleteGlossary.

// TODO:RH:gloss change courseconfig, to keep more than 1 single glossary as a list
/**
 * @param res glossary to be deleted
 */
@Override
public void deleteGlossary(OLATResourceable res) {
    // first remove all references
    List<Reference> repoRefs = referenceManager.getReferencesTo(res);
    for (Iterator<Reference> iter = repoRefs.iterator(); iter.hasNext(); ) {
        Reference ref = iter.next();
        if (ref.getUserdata().equals(GLOSSARY_REPO_REF_IDENTIFYER)) {
            // remove the reference from the course configuration
            // TODO:RH:improvement: this should use a callback method or send a general delete
            // event so that the course can take care of this rather than having it
            // here hardcoded
            OLATResource courseResource = ref.getSource();
            // ICourse course = CourseFactory.loadCourse(courseResource);
            ICourse course = CourseFactory.openCourseEditSession(courseResource.getResourceableId());
            CourseConfig cc = course.getCourseEnvironment().getCourseConfig();
            cc.setGlossarySoftKey(null);
            CourseFactory.setCourseConfig(course.getResourceableId(), cc);
            CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
            // remove reference from the references table
            referenceManager.delete(ref);
        }
    }
    // now remove the resource itself
    FileResourceManager.getInstance().deleteFileResource(res);
}
Also used : Reference(org.olat.resource.references.Reference) OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseConfig(org.olat.course.config.CourseConfig)

Aggregations

Reference (org.olat.resource.references.Reference)14 ICourse (org.olat.course.ICourse)6 OLATResource (org.olat.resource.OLATResource)6 ReferenceManager (org.olat.resource.references.ReferenceManager)6 CourseConfig (org.olat.course.config.CourseConfig)4 QTIEditorMainController (org.olat.ims.qti.editor.QTIEditorMainController)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 File (java.io.File)2 CalendarManager (org.olat.commons.calendar.CalendarManager)2 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 User (org.olat.core.id.User)2 ILoggingAction (org.olat.core.logging.activity.ILoggingAction)2 ContactList (org.olat.core.util.mail.ContactList)2 ContactMessage (org.olat.core.util.mail.ContactMessage)2 Quota (org.olat.core.util.vfs.Quota)2 QuotaManager (org.olat.core.util.vfs.QuotaManager)2 CorruptedCourseException (org.olat.course.CorruptedCourseException)2 CourseConfigEvent (org.olat.course.config.CourseConfigEvent)2