use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.
the class CourseHandler method importResource.
@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
OLATResource newCourseResource = OLATResourceManager.getInstance().createOLATResourceInstance(CourseModule.class);
ICourse course = CourseFactory.importCourseFromZip(newCourseResource, file);
// cfc.release();
if (course == null) {
return null;
}
RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, newCourseResource, RepositoryEntry.ACC_OWNERS);
DBFactory.getInstance().commit();
// create empty run structure
course = CourseFactory.openCourseEditSession(course.getResourceableId());
Structure runStructure = course.getRunStructure();
runStructure.getRootNode().removeAllChildren();
CourseFactory.saveCourse(course.getResourceableId());
// import references
CourseEditorTreeNode rootNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
importReferences(rootNode, course, initialAuthor, locale, withReferences);
if (withReferences && course.getCourseConfig().hasCustomSharedFolder()) {
importSharedFolder(course, initialAuthor);
}
if (withReferences && course.getCourseConfig().hasGlossary()) {
importGlossary(course, initialAuthor);
}
// create group management / import groups
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
File fImportBaseDirectory = course.getCourseExportDataDir().getBasefile();
CourseEnvironmentMapper envMapper = cgm.importCourseBusinessGroups(fImportBaseDirectory);
envMapper.setAuthor(initialAuthor);
// upgrade course
course = CourseFactory.loadCourse(cgm.getCourseResource());
course.postImport(fImportBaseDirectory, envMapper);
// rename root nodes, but only when user modified the course title
boolean doUpdateTitle = true;
File repoConfigXml = new File(fImportBaseDirectory, "repo.xml");
if (repoConfigXml.exists()) {
RepositoryEntryImport importConfig;
try {
importConfig = RepositoryEntryImportExport.getConfiguration(new FileInputStream(repoConfigXml));
if (importConfig != null) {
if (displayname.equals(importConfig.getDisplayname())) {
// do not update if title was not modified during import
// user does not expect to have an updated title and there is a chance
// the root node title is not the same as the course title
doUpdateTitle = false;
}
}
} catch (FileNotFoundException e) {
// ignore
}
}
if (doUpdateTitle) {
// do not use truncate!
course.getRunStructure().getRootNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
course.getRunStructure().getRootNode().setLongTitle(displayname);
}
// course.saveRunStructure();
CourseEditorTreeNode editorRootNode = ((CourseEditorTreeNode) course.getEditorTreeModel().getRootNode());
// do not use truncate!
editorRootNode.getCourseNode().setShortTitle(Formatter.truncateOnly(displayname, 25));
editorRootNode.getCourseNode().setLongTitle(displayname);
// mark entire structure as dirty/new so the user can re-publish
markDirtyNewRecursively(editorRootNode);
// root has already been created during export. Unmark it.
editorRootNode.setNewnode(false);
// save and close edit session
CourseFactory.saveCourse(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
RepositoryEntryImportExport imp = new RepositoryEntryImportExport(fImportBaseDirectory);
if (imp.anyExportedPropertiesAvailable()) {
re = imp.importContent(re, getMediaContainer(re));
}
// import reminders
importReminders(re, fImportBaseDirectory, envMapper, initialAuthor);
// clean up export folder
cleanExportAfterImport(fImportBaseDirectory);
return re;
}
use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.
the class RestSecurityHelper method isAuthorGrpManager.
public static boolean isAuthorGrpManager(ICourse course, HttpServletRequest request) {
try {
Roles roles = getRoles(request);
if (roles.isOLATAdmin())
return true;
if (roles.isAuthor()) {
UserRequest ureq = getUserRequest(request);
Identity identity = ureq.getIdentity();
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
boolean editor = cgm.hasRight(identity, CourseRights.RIGHT_GROUPMANAGEMENT);
return editor;
}
return false;
} catch (Exception e) {
return false;
}
}
use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.
the class PublishProcessTest method deployRawCourseFromZIP.
/**
* This method copy the edtiro tree model and run structure as is during the import.
* @param exportedCourseZIPFile
* @param softKey
* @param access
* @return
*/
private RepositoryEntry deployRawCourseFromZIP(File exportedCourseZIPFile, String softKey, int access) {
// create the course instance
OLATResource newCourseResource = olatResourceManager.createOLATResourceInstance(CourseModule.class);
ICourse course = CourseFactory.importCourseFromZip(newCourseResource, exportedCourseZIPFile);
// course is now also in course cache!
if (course == null) {
return null;
}
File courseExportData = course.getCourseExportDataDir().getBasefile();
// get the export data directory
// create the repository entry
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(courseExportData);
if (!StringHelper.containsNonWhitespace(softKey)) {
softKey = importExport.getSoftkey();
}
RepositoryEntry re = repositoryService.create(importExport.getInitialAuthor(), importExport.getResourceName(), importExport.getDisplayName(), importExport.getDescription(), newCourseResource);
// ok, continue import
re.setSoftkey(softKey);
// set access configuration
re.setAccess(access);
// save the repository entry
re = repositoryService.update(re);
// import groups
course = CourseFactory.openCourseEditSession(course.getResourceableId());
// create group management
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
// import groups
cgm.importCourseBusinessGroups(courseExportData);
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
// cleanup export data
FileUtils.deleteDirsAndFiles(courseExportData, true, true);
return re;
}
use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.
the class InLearningGroupFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.groupname"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.groupname"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.groupnameexpected", "solution.example.name.infunction"));
String groupName = (String) inStack[0];
groupName = groupName != null ? groupName.trim() : null;
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsGroup(groupName)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, groupName, "error.notfound.name", "solution.checkgroupmanagement"));
}
// remember the reference to the node id for this condtion
cev.addSoftReference("groupId", groupName, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
// the real function evaluation which is used during run time
if (StringHelper.isLong(groupName)) {
try {
Long groupKey = Long.parseLong(groupName);
return getUserCourseEnv().isIdentityInCourseGroup(groupKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
} catch (NumberFormatException e) {
log.error("" + groupName, e);
}
}
CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
List<Long> groupKeys = CoreSpringFactory.getImpl(BusinessGroupService.class).toGroupKeys(groupName, cgm.getCourseEntry());
if (!groupKeys.isEmpty()) {
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
return cgm.isIdentityInGroup(ident, groupKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
return ConditionInterpreter.INT_FALSE;
}
use of org.olat.course.groupsandrights.CourseGroupManager in project OpenOLAT by OpenOLAT.
the class InRightGroupFunction method call.
/**
* @see com.neemsoft.jmep.FunctionCB#call(java.lang.Object[])
*/
@Override
public Object call(Object[] inStack) {
/*
* argument check
*/
if (inStack.length > 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_FEWER_ARGUMENTS, name, "", "error.fewerargs", "solution.provideone.groupname"));
} else if (inStack.length < 1) {
return handleException(new ArgumentParseException(ArgumentParseException.NEEDS_MORE_ARGUMENTS, name, "", "error.moreargs", "solution.provideone.groupname"));
}
/*
* argument type check
*/
if (!(inStack[0] instanceof String))
return handleException(new ArgumentParseException(ArgumentParseException.WRONG_ARGUMENT_FORMAT, name, "", "error.argtype.groupnameexpected", "solution.example.name.infunction"));
String groupName = (String) inStack[0];
/*
* check reference integrity
*/
CourseEditorEnv cev = getUserCourseEnv().getCourseEditorEnv();
if (cev != null) {
if (!cev.existsGroup(groupName)) {
return handleException(new ArgumentParseException(ArgumentParseException.REFERENCE_NOT_FOUND, name, groupName, "error.notfound.name", "solution.checkgroupmanagement"));
}
// remember the reference to the node id for this condition
cev.addSoftReference("groupId", groupName, false);
// return a valid value to continue with condition evaluation test
return defaultValue();
}
/*
* the real function evaluation which is used during run time
*/
Identity ident = getUserCourseEnv().getIdentityEnvironment().getIdentity();
CourseGroupManager cgm = getUserCourseEnv().getCourseEnvironment().getCourseGroupManager();
if (StringHelper.isLong(groupName)) {
Long groupKey = new Long(groupName);
return cgm.isIdentityInGroup(ident, groupKey) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
// TODO gm
List<Long> groupKeys = CoreSpringFactory.getImpl(BusinessGroupService.class).toGroupKeys(groupName, cgm.getCourseEntry());
if (!groupKeys.isEmpty()) {
return cgm.isIdentityInGroup(ident, groupKeys.get(0)) ? ConditionInterpreter.INT_TRUE : ConditionInterpreter.INT_FALSE;
}
return ConditionInterpreter.INT_FALSE;
}
Aggregations