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;
}
}
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;
}
}
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();
}
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;
}
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();
}
Aggregations