Search in sources :

Example 1 with Reference

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

the class QTITestHandler method createEditorController.

@Override
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl, TooledStackedPanel toolbar) {
    OLATResource res = re.getOlatResource();
    if (OnyxModule.isOnyxTest(res)) {
        return null;
    }
    TestFileResource fr = new TestFileResource();
    fr.overrideResourceableId(res.getResourceableId());
    // check if we can edit in restricted mode -> only typos
    List<Reference> referencees = CoreSpringFactory.getImpl(ReferenceManager.class).getReferencesTo(res);
    QTIEditorMainController editor = new QTIEditorMainController(ureq, wControl, re, referencees, fr);
    if (editor.isLockedSuccessfully()) {
        return editor;
    } else {
        return null;
    }
}
Also used : QTIEditorMainController(org.olat.ims.qti.editor.QTIEditorMainController) Reference(org.olat.resource.references.Reference) OLATResource(org.olat.resource.OLATResource) TestFileResource(org.olat.ims.qti.fileresource.TestFileResource) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 2 with Reference

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

the class QTISurveyHandler method createEditorController.

@Override
public Controller createEditorController(RepositoryEntry re, UserRequest ureq, WindowControl wControl, TooledStackedPanel toolbar) {
    OLATResource res = re.getOlatResource();
    if (OnyxModule.isOnyxTest(res)) {
        return null;
    }
    SurveyFileResource fr = new SurveyFileResource();
    fr.overrideResourceableId(res.getResourceableId());
    // check if we can edit in restricted mode -> only typos
    List<Reference> referencees = CoreSpringFactory.getImpl(ReferenceManager.class).getReferencesTo(res);
    QTIEditorMainController editor = new QTIEditorMainController(ureq, wControl, re, referencees, fr);
    if (editor.isLockedSuccessfully()) {
        return editor;
    } else {
        return null;
    }
}
Also used : SurveyFileResource(org.olat.ims.qti.fileresource.SurveyFileResource) QTIEditorMainController(org.olat.ims.qti.editor.QTIEditorMainController) Reference(org.olat.resource.references.Reference) OLATResource(org.olat.resource.OLATResource) ReferenceManager(org.olat.resource.references.ReferenceManager)

Example 3 with Reference

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

the class QTIEditorMainController method createReferenceesMsg.

/**
 * helper method to create the message about qti resource stakeholders and
 * from where the qti resource is referenced.
 *
 * @return
 */
private String createReferenceesMsg(UserRequest ureq) {
    /*
		 * problems: A tries to reference this test, after test editor has been
		 * started
		 */
    changeEmail = new ContactMessage(ureq.getIdentity());
    // the owners of this qtiPkg
    RepositoryEntry myEntry = repositoryManager.lookupRepositoryEntry(qtiPackage.getRepresentingResourceable(), false);
    // add qti resource owners as group
    ContactList cl = new ContactList("qtiPkgOwners");
    cl.addAllIdentites(repositoryService.getMembers(myEntry, GroupRoles.owner.name()));
    changeEmail.addEmailTo(cl);
    StringBuilder result = new StringBuilder();
    result.append(translate("qti.restricted.leading"));
    for (Iterator<Reference> iter = referencees.iterator(); iter.hasNext(); ) {
        Reference element = iter.next();
        if ("CourseModule".equals(element.getSource().getResourceableTypeName())) {
            ICourse course = null;
            try {
                course = CourseFactory.loadCourse(element.getSource().getResourceableId());
                if (course == null) {
                    continue;
                }
            } catch (CorruptedCourseException ex) {
                logError("", ex);
                continue;
            }
            CourseNode cn = course.getEditorTreeModel().getCourseNode(element.getUserdata());
            if (cn == null) {
                logError("Cannot find course element " + element.getUserdata() + " in course " + course, null);
                continue;
            }
            String courseTitle = course.getCourseTitle();
            StringBuilder stakeHolders = new StringBuilder();
            // the course owners
            RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course, false);
            if (entry != null) {
                // OO-1300
                List<Identity> stakeHoldersIds = repositoryService.getMembers(entry, GroupRoles.owner.name());
                if (stakeHoldersIds != null && stakeHoldersIds.size() > 0) {
                    // add stakeholders as group
                    cl = new ContactList(courseTitle);
                    cl.addAllIdentites(stakeHoldersIds);
                    changeEmail.addEmailTo(cl);
                    for (Identity stakeHoldersId : stakeHoldersIds) {
                        if (stakeHolders.length() > 0)
                            stakeHolders.append(", ");
                        User user = stakeHoldersId.getUser();
                        stakeHolders.append(user.getProperty(UserConstants.FIRSTNAME, getLocale())).append(" ").append(user.getProperty(UserConstants.LASTNAME, getLocale()));
                    }
                }
            }
            String courseNodeTitle = cn.getShortTitle();
            result.append(translate("qti.restricted.course", StringHelper.escapeHtml(courseTitle)));
            result.append(translate("qti.restricted.node", StringHelper.escapeHtml(courseNodeTitle)));
            result.append(translate("qti.restricted.owners", stakeHolders.toString()));
        }
    }
    return result.toString();
}
Also used : User(org.olat.core.id.User) Reference(org.olat.resource.references.Reference) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) ContactList(org.olat.core.util.mail.ContactList) ContactMessage(org.olat.core.util.mail.ContactMessage) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

Example 4 with Reference

use of org.olat.resource.references.Reference 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 5 with Reference

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

the class QTIEditorMainController method createReferenceesMsg.

/**
 * helper method to create the message about qti resource stakeholders and
 * from where the qti resource is referenced.
 *
 * @return
 */
private String createReferenceesMsg(UserRequest ureq) {
    /*
		 * problems: A tries to reference this test, after test editor has been
		 * started
		 */
    changeEmail = new ContactMessage(ureq.getIdentity());
    // the owners of this qtiPkg
    RepositoryEntry myEntry = repositoryManager.lookupRepositoryEntry(qtiPackage.getRepresentingResourceable(), false);
    // add qti resource owners as group
    ContactList cl = new ContactList("qtiPkgOwners");
    cl.addAllIdentites(repositoryService.getMembers(myEntry, GroupRoles.owner.name()));
    changeEmail.addEmailTo(cl);
    StringBuilder result = new StringBuilder();
    result.append(translate("qti.restricted.leading"));
    for (Iterator<Reference> iter = referencees.iterator(); iter.hasNext(); ) {
        Reference element = iter.next();
        if ("CourseModule".equals(element.getSource().getResourceableTypeName())) {
            ICourse course = null;
            try {
                course = CourseFactory.loadCourse(element.getSource().getResourceableId());
                if (course == null) {
                    continue;
                }
            } catch (CorruptedCourseException ex) {
                logError("", ex);
                continue;
            }
            CourseNode cn = course.getEditorTreeModel().getCourseNode(element.getUserdata());
            if (cn == null) {
                logError("Cannot find course element " + element.getUserdata() + " in course " + course, null);
                continue;
            }
            String courseTitle = course.getCourseTitle();
            StringBuilder stakeHolders = new StringBuilder();
            // the course owners
            RepositoryEntry entry = repositoryManager.lookupRepositoryEntry(course, false);
            if (entry != null) {
                // OO-1300
                List<Identity> stakeHoldersIds = repositoryService.getMembers(entry, GroupRoles.owner.name());
                if (stakeHoldersIds != null && stakeHoldersIds.size() > 0) {
                    // add stakeholders as group
                    cl = new ContactList(courseTitle);
                    cl.addAllIdentites(stakeHoldersIds);
                    changeEmail.addEmailTo(cl);
                    for (Identity stakeHoldersId : stakeHoldersIds) {
                        if (stakeHolders.length() > 0)
                            stakeHolders.append(", ");
                        User user = stakeHoldersId.getUser();
                        stakeHolders.append(user.getProperty(UserConstants.FIRSTNAME, getLocale())).append(" ").append(user.getProperty(UserConstants.LASTNAME, getLocale()));
                    }
                }
            }
            String courseNodeTitle = cn.getShortTitle();
            result.append(translate("qti.restricted.course", StringHelper.escapeHtml(courseTitle)));
            result.append(translate("qti.restricted.node", StringHelper.escapeHtml(courseNodeTitle)));
            result.append(translate("qti.restricted.owners", stakeHolders.toString()));
        }
    }
    return result.toString();
}
Also used : User(org.olat.core.id.User) Reference(org.olat.resource.references.Reference) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) ContactList(org.olat.core.util.mail.ContactList) ContactMessage(org.olat.core.util.mail.ContactMessage) CorruptedCourseException(org.olat.course.CorruptedCourseException) CourseNode(org.olat.course.nodes.CourseNode) Identity(org.olat.core.id.Identity)

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